Snappy and ApplyOrbitFileOp

Hi folks,

I’m new to SNAP and snappy, but wanted to see if I could use Python to callout to the appropriate Java APIs to do some InSAR on Sentinel-1A granules. I’m stuck already trying to call org.esa.s1tbx.sar.gpf.orbits.ApplyOrbitFileOp.

The code is pretty simple - I read a files in as a Product, set it as sourceProduct, and then try to Apply the Orbit file, but it crashes. I tried pulling bits out of ApplyOrbitFileOp to see what the problem might be, but I can’t set private members of the class, like absRoot and mission, so I can’t tell if I’m able to find an orbitProvider and that’s the problem or if it’s really further down.

To be honest, I’m not sure if I’m using ApplyOrbitFileOp class properly, but can’t seem to find a better way from Python. Any suggestions welcome!

file1 = ProductIO.readProduct(’/…/…/Downloads/’)

ApplyOrbitFileOp = jpy.get_type(‘org.esa.s1tbx.sar.gpf.orbits.ApplyOrbitFileOp’)
myApp = ApplyOrbitFileOp()
myApp.setSourceProduct(“sourceProduct”, file1)

RuntimeError: org.esa.snap.core.gpf.OperatorException: Apply-Orbit-File: java.lang.NullPointerException

First of all, I would like to commend your approach it is a good one.

I found out that more flexible is to call the “gpt” directly as a program via python.[gpt, “your operator/graph”, “options”, “more options”])

By this approach you can bind python and the gpt (SNAP toolbox) for more complex tasks. You can then tinker your graph and python separately. I do not say it is the most proper solution only it might be a viable approach.

I use snappy only for file handling operations like altering raster nodes, units, filename, etc.

The way @Suprd suggested is good but becomes sometimes unhandy.
Another way to call operators is to use the GPF class. It has some static methods to invoke an operator.
To make your way work you should use setParameter(parameterName, value) in order to set parameters which are private.
For example:

myApp.setParameter("mission", "SENTINEL");
myApp.setParameter("orbitType", SentinelPODOrbitFile.PRECISE);

Additionally you should call getTargetProduct() instead of initialize(). This will ensure that some general initialisation is performed on the operator and also that you get the resulting product.

Oh, I may have answered my own question. I was using the Operator incorrectly but calling it like a regular ol’ java class. Using GPF as @marpet suggested is the right way to go so far:

file1 = ProductIO.readProduct(’/Downloads/’)

target = GPF.createProduct(“Apply-Orbit-File”, parameters, file1)

ofile = ‘/Downloads/S1A_S1_ApplyOrbit’

ProductIO.writeProduct(target, ofile, ‘BEAM-DIMAP’)

… and this works. Will start a new thread for my next issue :wink: