Difference between revisions of "Python example: editing HV results"
Line 20: | Line 20: | ||
=== Python code === | === Python code === | ||
+ | The legend retrieved from a ''LineLayer'' is just a local copy of the internal properties of the ''LineLayer''. Modifying the obtained legend has no effect before calling ''setLegend''. Childs and values of a legend are references through XML tags and attributes. To get a list of the available tags, untar a .legend file and inspect the file ''contents.xml''. | ||
+ | |||
def setWidth(s): | def setWidth(s): | ||
n=s.numberOfObjects() | n=s.numberOfObjects() | ||
Line 30: | Line 32: | ||
leg=l.legend() | leg=l.legend() | ||
pen=leg.child("LegendItem index='0'").child("Pen") | pen=leg.child("LegendItem index='0'").child("Pen") | ||
− | pen.setValue("width", | + | pen.setValue("width", 0.3) |
l.setLegend(leg) | l.setLegend(leg) | ||
# stddev | # stddev | ||
Line 37: | Line 39: | ||
leg=l.legend() | leg=l.legend() | ||
pen=leg.child("LegendItem index='0'").child("Pen") | pen=leg.child("LegendItem index='0'").child("Pen") | ||
− | pen.setValue("width", | + | pen.setValue("width", 0.3) |
pen=leg.child("LegendItem index='1'").child("Pen") | pen=leg.child("LegendItem index='1'").child("Pen") | ||
− | pen.setValue("width", | + | pen.setValue("width", 0.3) |
l.setLegend(leg) | l.setLegend(leg) | ||
Line 53: | Line 55: | ||
pen=leg.child("LegendItem index='0'").child("Pen") | pen=leg.child("LegendItem index='0'").child("Pen") | ||
pen.setValue("color", '#FF0000') | pen.setValue("color", '#FF0000') | ||
− | pen.setValue("width", | + | pen.setValue("width", 0.3) |
l.setLegend(leg) | l.setLegend(leg) | ||
# stddev | # stddev | ||
Line 61: | Line 63: | ||
pen=leg.child("LegendItem index='0'").child("Pen") | pen=leg.child("LegendItem index='0'").child("Pen") | ||
pen.setValue("color", '#FF0000') | pen.setValue("color", '#FF0000') | ||
− | pen.setValue("width", | + | pen.setValue("width", 0.3) |
pen=leg.child("LegendItem index='1'").child("Pen") | pen=leg.child("LegendItem index='1'").child("Pen") | ||
pen.setValue("color", '#FF0000') | pen.setValue("color", '#FF0000') | ||
− | pen.setValue("width", | + | pen.setValue("width", 0.3) |
l.setLegend(leg) | l.setLegend(leg) | ||
+ | |||
+ | C++ supports overload of functions and operators. A function name may be defined several times with distinct argument number and types. Pyhton does not. To solve this issue, the Python interface renames the C++ functions appearing with the same name by adding a numbered suffix. Run ''help(gc)'' to get the possible variants of function ''saveLayers''. Version ''_3'' accepts two arguments: the file name to save to and the name of the layer to save. Only one layer is saved unlike other variants that save all layers. | ||
def saveLayers(s): | def saveLayers(s): |
Revision as of 09:08, 22 October 2024
This script works only with GeopsyPack>=3.6
Import SciFigs module and create a blank sheet
import GeopsyPySciFigs as sf s=sf.newSheet()
Open the .page file saved from Geopsy H/V module
s.fileOpen_2("hv-before-9.10.page")
Import a few Python functions to manipulate graphical objects.
import hvedit
Change the color and the width of the average and stddev curves
hvedit.setRed(s)
Save the average and stddev layers
hvedit.saveLayers(s)
Open other results with the same stations, change the width of curves and compare the results
s.fileNew() s.fileOpen_2("hv-after-9.10.page") hvedit.setWidth(s) hvedit.addLayer(s)
Python code
The legend retrieved from a LineLayer is just a local copy of the internal properties of the LineLayer. Modifying the obtained legend has no effect before calling setLegend. Childs and values of a legend are references through XML tags and attributes. To get a list of the available tags, untar a .legend file and inspect the file contents.xml.
def setWidth(s): n=s.numberOfObjects() for i in range(0, n): g=s.object_1(i) print(g.objectName()) # Average l=g.object(1).graphContents().layer(3) if l: leg=l.legend() pen=leg.child("LegendItem index='0'").child("Pen") pen.setValue("width", 0.3) l.setLegend(leg) # stddev l=g.object(1).graphContents().layer(4) if l: leg=l.legend() pen=leg.child("LegendItem index='0'").child("Pen") pen.setValue("width", 0.3) pen=leg.child("LegendItem index='1'").child("Pen") pen.setValue("width", 0.3) l.setLegend(leg)
def setRed(): n=s.numberOfObjects() for i in range(0, n): g=s.object_1(i) print(g.objectName()) # Average l=g.object(1).graphContents().layer(3) if l: leg=l.legend() pen=leg.child("LegendItem index='0'").child("Pen") pen.setValue("color", '#FF0000') pen.setValue("width", 0.3) l.setLegend(leg) # stddev l=g.object(1).graphContents().layer(4) if l: leg=l.legend() pen=leg.child("LegendItem index='0'").child("Pen") pen.setValue("color", '#FF0000') pen.setValue("width", 0.3) pen=leg.child("LegendItem index='1'").child("Pen") pen.setValue("color", '#FF0000') pen.setValue("width", 0.3) l.setLegend(leg)
C++ supports overload of functions and operators. A function name may be defined several times with distinct argument number and types. Pyhton does not. To solve this issue, the Python interface renames the C++ functions appearing with the same name by adding a numbered suffix. Run help(gc) to get the possible variants of function saveLayers. Version _3 accepts two arguments: the file name to save to and the name of the layer to save. Only one layer is saved unlike other variants that save all layers.
def saveLayers(s): n=s.numberOfObjects() for i in range(0, n): g=s.object_1(i) print(g.objectName()) gc=g.object(1).graphContents() if gc: gc.saveLayers_3(g.objectName()+"-average.layer", "Average") gc.saveLayers_3(g.objectName()+"-stddev.layer", "Stddev")
def addLayer(s): n=s.numberOfObjects() for i in range(0, n): g=s.object_1(i) print(g.objectName()) gc=g.object(1).graphContents() if gc: gc.insertLayers(g.objectName()+"-average.layer", "Stddev") gc.insertLayers(g.objectName()+"-stddev.layer", "Stddev")