It works well now for polarisations , thx.
In python you donât need the XML. here you can use the output of one operator as in input to the next operator.
You can start command line sub-processes to start the processing with gpt, or execute the graph directly as in the following snippet:
import snappy
from snappy import jpy, ProgressMonitor
FileReader = jpy.get_type('java.io.FileReader')
GraphIO = jpy.get_type('org.esa.snap.core.gpf.graph.GraphIO')
Graph = jpy.get_type('org.esa.snap.core.gpf.graph.Graph')
GraphProcessor = jpy.get_type('org.esa.snap.core.gpf.graph.GraphProcessor')
graphFile = FileReader('Path-to-graph-file.xml')
graph = GraphIO.read(graphFile)
GraphProcessor.executeGraph(graph, ProgressMonitor.NULL)
I havenât tested this code snippet. it is a translation from the java code. But I guess it will work.
If you want to get more progress output you can have a look at this thread, on how to do it:
Thanks for your great help. Iâll try right now.
Hi, @marpet
I tested this code snippet, but it occured an error.
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
Traceback (most recent call last):
File âE:/Fogo Volcano 2014 Eruption/how_to_run_graph_with_python.pyâ, line 11, in
GraphProcessor.executeGraph(graph, ProgressMonitor.NULL)
RuntimeError: no matching Java method overloads found
Oh yes. I overlooked that this is not a static method.
You need to do:
graphProcessor = GraphProcessor()
graphProcessor.executeGraph(graph, ProgressMonitor.NULL)
Yes. It works perfectly!
And, may I specify input products and output path for pre-built graph in python scripts? thx.
I mean, could I change the pre-set source products and the write folder for a given graph.xml in python scripts?
cause I want to do batch processing by changing the input files and output files.
Thanks in advance!
Hi, @marpet Shall I use the code below for changing pre-set source products?
graph = GraphIO.read(Reader reader, Map<String,String> variables)
Thanks for your great help, I finally implement batch processing by runing graph from python.
and I set read and write nodes as follows:
graph.getNode(âreadâ).getConfiguration().getChild(0).setValue(String input1)
graph.getNode(âread(2)â).getConfiguration().getChild(0).setValue(String input2)
graph.getNode(âwriteâ).getConfiguration().getChild(0).setValue(String write)
Hi,
Thx for this useful snippet. I am not yet familiar with java and would like to include a Progress Monitor for my python code. So i implemented your code and created a .xml file from scratch. How can i include the file to the source product within this xml file?
I wonder how i change the follwoing line:
<sourceProducts>${SourceProducts}</sourceProducts>
to something like
<sourceProducts>${âPath to my source productâ}</sourceProducts>
is this possible?
thx!
This is not possible in this way.
You can add a read operator in front of your graph and reference this node.
See this example:
<graph id="Graph">
<version>1.0</version>
<node id="Read">
<operator>Read</operator>
<sources/>
<parameters>
<file>G:\EOData\Meris\RR\MER_RR__1PNBCG20050709_101121_000001802038_00466_17554_0001.N1</file>
</parameters>
</node>
<node id="BandMaths">
<operator>BandMaths</operator>
<sources>
<source>Read</source>
</sources>
...
However, I would not recommend it.
This makes the xml files not reusable, and this was actually the intention. Write one graph and let it run on thousands of products.
It is better to set up the graph by Python.
Iâll find several examples in the forum by searching for [GPF.createProduct(](Search results for 'GPF.createProduct()' - STEP Forum
Regarding ProgressMonitor, this might be of interest to you:
Where can i find the list of OperatorNames?
You can go to the command line and call gpt with the help option. Then all available operators are listed.
> gpt -h
In Python you can use the example code:
Still iâm getting the same error.
Which error? This thread is not about an error
pls how to set parameters to choise the decomposition : I tried parameters.put(âDecompositionâ,âYAMAGUCHI_DECOMPOSITIONâ) ⊠but doesnât work, still giving the sinclair set as default
Try âdecompositionâ, with a small âdâ.
This is what the help shows on the command line:
Usage:
gpt Polarimetric-Decomposition [options]
Description:
Perform Polarimetric decomposition of a given product
Source Options:
-Ssource=<file> Sets source 'source' to <filepath>.
This is a mandatory source.
Parameter Options:
-Pdecomposition=<string> Sets parameter 'decomposition' to <string>.
Value must be one of 'Sinclair Decomposition', 'Pauli Decomposition', 'Freeman-Durden Decomposition', 'Generalized Freeman-Durden Decomposition', 'Yamaguchi Decomposition', 'van Zyl Decomposition', 'H-A-Alpha Quad Pol Decomposition', 'H-Alpha Dual Pol Decomposition', 'Cloude Decomposition', 'Touzi Decomposition'.
Default value is 'Sinclair Decomposition'.
-PoutputAlpha123=<boolean> Output alpha 1, 2, 3
Default value is 'false'.
...
snappy.GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis()
ProductIO.getProductWriter(âGeoTIFFâ)
p = ProductIO.readProduct(âD:\TESTS\product.xmlâ)
print(*p.getBandNames(), sep = â\nâ)
HashMap = jpy.get_type(âjava.util.HashMapâ)
parameters = HashMap()
parameters.put(âPdecompositionâ,âYamaguchi Decompositionâ)
my_pol_decomposition = GPF.createProduct(âPolarimetric-Decompositionâ, parameters, p)
ProductIO.writeProduct(my_pol_decomposition, âYAMAGUCHI_DECOMPOSITION.tifâ, âGeoTIFF-BigTIFFâ)
but still giving âsinclair decompositionâ
did I miss something
Remove the âPâ. This is just the indicator on the command line to tell gpt the next value is a parameter.
Just use:
parameters.put(âdecompositionâ,âYamaguchi Decompositionâ)
thank you.
another question plz,
Can we use the operators like this:
polOP = snappy.jpy.get_type(âorg.csa.rstb.polarimetric.gpf.PolarimetricDecompositionOpâ)
decom_type= polOP.YAMAGUCHI_DECOMPOSITION
GPF.SetDecomposition(decom_type)
#do the decomposition_
polOP.initialize()
#or GPF.PolarimetricDecompositionOp(source_pro, target_product,parameters)
##______ récupérer le résultat : produit résultant
result=polOP.getTargetProduct()
polOP.dispose() # free all resources previously allocated by the operator