I am learning how to mosaic two bands named ‘CI’ of two different products ‘product1’ and ‘product2’ using snappy. I have used the following code to achieve this goal:
products = jpy.array('org.esa.snap.core.datamodel.Product', 2)
Variable = jpy.get_type('org.esa.snap.core.gpf.common.MosaicOp$Variable')
vars = jpy.array('org.esa.snap.core.gpf.common.MosaicOp$Variable', 1)
products = product1
products = product2
parameters = HashMap()
vars = Variable('CI_demo','CI')
Mosaic = GPF.createProduct('Mosaic', parameters, products)
The code throws the error: RuntimeError: org.esa.snap.core.gpf.OperatorException
Can anyone please tell me how to resolve this error?
P.S. I was able to mosaic the products using SNAP desktop.
Two things look odd:
- vars = jpy.array(…, 1), but vars needs a name and and expression (which may just be the name)
vars = Variable('CI_demo', 'CI_demo')
vars = `Variable('CI', 'CI')
- you don’t have
Thanks, George. Yes, inserting ‘parameters.put(‘variables’, vars)’ worked. Though I kept ‘vars’ unchanged.
George: There is still one problem I have not been able to solve regarding mosaicing.
The final result of mosaicing obtained by using snappy is different from that obtained by using SNAP desktop. When I use snappy, all the pixels with NaNs are replaced by zeros. Here are some details:
product2 contains a band ‘CI’ with all pixels filled with NaN values, and the product1 contains the ‘CI’ band that needs to be mosaiced with product2. What I really need is to lay product1 over product2 which SNAP desktop seems to be doing.
The CI band in product 1:
The CI band in product 2 (All pixels contain NaN values, therefore, all pixels are white):
Mosaiced band obtained using SNAP desktop (this is what I need):
Mosaiced band obtained using using snappy:
The metadata for the two mosaic results should include some details of the processing history, so may provide insight into the difference. Otherwise you will need to work with the variables and conditions sections. A closer look at how you set
vars might be useful.
I see. I will work on this problem following these tips.