I’ve been looking into using snappy (the python SNAP API) to replace my graph processing tool (gpt) command line calls in my scripts.
However, when I am looking for operators e.g. Rad2Refl, these do not appear to be available in snappy (I am looking at http://step.esa.int/docs/v4.0/apidoc/engine/) in the gpt operators at org.esa.snap.core.gpf.common. I’d like to import these like done with the subset tool, e.g.:
NameOp = snappy.jpy.get_type(‘org.esa.snap.core.gpf.common.NameOp’)
where Name is the name of operator.
Am I correct in saying that all the operators available in the command line gpt tool are not all available with snappy? If false, could you point me to where they are sitting so I can import them? If true, are there plans to put more operators into snappy?
Hi Mark
All operators from the command line are also available via snappy. But you should not instantiate the operator classes directly as long as there is no very good reason for it. (However I wonder why it didn’t work.)
It is much better to invoke the operators via GPF.
I have answered my own post by digging into the script shared in this previous post:
, but it’s not very obvious so I’ll spell it out here for future users:.
For those wanting to use GPT tools / operators in snappy this is the general procedure, in python:
import snappy
snappy.GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() # Load all available operators
HashMap = snappy.jpy.get_type(‘java.util.HashMap’)
parameters = HashMap() #Specify the parameters, these can be seen from the command line using gpt -h operator
parameters.put(‘sensor’,‘OLCI’)
parameters.put(‘copyNonSpectralBands’,‘False’) # I had to use this option due to an error
refl_product = GPF.createProduct(‘Rad2Refl’, parameters, sub_product) # compute the product from input called sub_product
Hope that helps!
This can also be seen in the snappy_bandmaths.py example and here: [quote=“marpet, post:2, topic:2636”]
[/quote]