Hi,
I am trying to follow different examples of script to process a S1 scene with a python script.
I just made 2 simple functions but it seems the GPT function is not found. So there is mention here of an “environment variable” for GPT but its name is not cited and I have not found mention in the documentation of SNAP itself.
Option A: Process a product using a SNAP Engine Operator and write the target product
SNAP Operators are available in snappy via
GPF.createProduct()
. Its first parameter is a String denoting the name of the Operator as denoted in the Engine and available via GPT. If you have added GPT to your environment variables, you may call GPT from cmd in order to check out the available Operators, their description and parameters. In snappy, we provide the parameters through the second parameter ofGPF.createProduct()
. This parameter is a Java Hashmap, an object that is equivalent to a Python dictionary. The parameters must be named exactly with the String parameter name provided in GPT.
So I tried to understand the thing and made these 2 functions
def tune(params):
'''
Prepare parameters for process
params: dictionary with the parameters'''
parameters=es.HashMap()
for k in params.keys():
parameters.put(k,params[k])
return parameters
def read_scenes(work_dir,S):
'''
Read a scene and prepare them for interferometry
'''
Sp= es.ProductIO.readProduct(work_dir+os.sep+S['name'])
params={'orbitType':'Sentinel Precise (Auto Download)',
'polyDegree':3}
#params={'Apply-Orbit-File': True}
return es.GPF('Apply-Orbit-File', tune(params),Sp)
import esa_snappy as es
work_dir='path/to/scene'
S={'name':'scene.SAFE.zip'}
p=read_scenes(work_dir,S)
It returns
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-19-373169b20aff> in <module>
----> 1 p=read_scenes(work_dir,S1o)
<ipython-input-11-b477b853e5f2> in read_scenes(work_dir, S)
7 'polyDegree':3}
8 params={'Apply-Orbit-File': True}
----> 9 return es.GPF('Apply-Orbit-File', tune(params),Sp)
10
RuntimeError: no constructor found (missing JType attribute '__jinit__')
Which I understand means GPF cannot find ‘Apply-Orbit-File’
But in the shell I can:
~/esa-snap/bin$ gpt Apply-Orbit-File -h
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.esa.snap.runtime.Engine (file:/home/***/esa-snap/snap/modules/ext/org.esa.snap.snap-core/org-esa-snap/snap-runtime.jar) to method java.lang.ClassLoader.initializePath(java.lang.String)
WARNING: Please consider reporting this to the maintainers of org.esa.snap.runtime.Engine
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
WARNING: org.esa.snap.core.util.ServiceLoader: org.esa.snap.core.gpf.OperatorSpi: Provider eu.esa.opt.meris.sdr.aerosol.AerosolMergerOp$Spi not found
WARNING: org.esa.snap.core.util.ServiceLoader: org.esa.snap.core.gpf.OperatorSpi: Provider eu.esa.opt.meris.sdr.aerosol.ModisAerosolOp$Spi not found
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
INFO: org.esa.snap.core.util.EngineVersionCheckActivator: Please check regularly for new updates for the best SNAP experience.
Usage:
gpt Apply-Orbit-File [options]
Description:
Apply orbit file
Source Options:
-Ssource=<file> Sets source 'source' to <filepath>.
This is a mandatory source.
Parameter Options:
-PcontinueOnFail=<boolean> Sets parameter 'continueOnFail' to <boolean>.
Default value is 'false'.
-PorbitType=<string> Sets parameter 'orbitType' to <string>.
Value must be one of 'Sentinel Precise (Auto Download)', 'Sentinel Restituted (Auto Download)', 'DORIS Preliminary POR (ENVISAT)', 'DORIS Precise VOR (ENVISAT) (Auto Download)', 'DELFT Precise (ENVISAT, ERS1&2) (Auto Download)', 'PRARE Precise (ERS1&2) (Auto Download)', 'Kompsat5 Precise'.
Default value is 'Sentinel Precise (Auto Download)'.
-PpolyDegree=<int> Sets parameter 'polyDegree' to <int>.
Default value is '3'.
Graph XML Format:
<graph id="someGraphId">
<version>1.0</version>
<node id="someNodeId">
<operator>Apply-Orbit-File</operator>
<sources>
<source>${source}</source>
</sources>
<parameters>
<orbitType>string</orbitType>
<polyDegree>int</polyDegree>
<continueOnFail>boolean</continueOnFail>
</parameters>
</node>
</graph>
Thanks