I am still new to SNAP and am now trying to co-register images with ‘create stack’ using the snap python binding. I have a pipeline to preprocess single files using snap (apply orbit-radiometric calibration-terrain flattening-terrain correction), and can then otherwise align these nicely using the xml graphs approach-but ideally would like to continue in python.
To do individual files, I start with ProductIO:
ProductIO.readProduct(file_path)
But for the ‘create-stack’ I would like to read multiple files (ideally in a list) using the ‘ProductSet-Reader’.
*Edit: I think have found Operator().ProductSetReaderOp()
but it throws as error (see code below)
I would be grateful if you could guide me how to:
Call the product set reader while passing a list of files (such as file locations or preprocessed products)
Call the ‘create stack’ method taking the product-set as input
Something along the lines of:
from snappy import ProductIO, GPF, jpy, Operator
GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis()
HashMap = jpy.get_type('java.util.HashMap')
files_list = ['C:\myGRDH_file1.dim', 'C:\myGRDH_file2.dim']`
#read set of products or files
product_set = Operator().ProductSetReaderOp(files_list)
#********
#gives error:
'RuntimeError: no constructor found (missing JType attribute '__jinit__')'
#**************
#create stack
params = HashMap()
params.put('resamplingType', None)
params.put('initialOffsetMethod', 'Product Geolocation')
params.put('extent', 'Master')
create_stack = GPF.createProduct('CreateStack', params, product_set)
Thank you for your response. Unfortunately this does not appear to be the case - in a stack sorted by time, the master product is chosen from the middle of the input stack! I can’t seem to force the first (earliest) product to be the master.
The first sort is not correct because getStartTime() returns a java ProductData.UTC Object. I think python can’t handle this properly. The getAsDate returns a Date object. For some reason this works, as you say. But I wonder why. To be save you should use p.getStartTime().getAsDate().getTime(). This return a long value. The time in ms.
If the masterBandNames parameter specifies specific bands then the master product will be the first product containing the band names. If none are specified then the first product in the list is used.
Ordered the products (each of which contains a single band) by date.
Rename the bands in the products incrementally (0000, 0001, 0002…)
Call CreateStack with params.put('masterBands', '0000')
This results in:
RuntimeError: org.esa.snap.core.gpf.OperatorException: Operator 'CreateStackOp': Value for 'Master Band' is invalid: '0000'
However I can set masterBands to any other bandname (e.g. 0001, 0002…) and it works fine! The only band I cannot select as the master is the one I want to use?!
However all of them get to the same non-order stack. When I run it in the GUI it works fine, but I’m processing 70 S-1 images and the plan is adding every 12 days a new image automatically.