Mosaicing using snappy

Hello all

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[0] = product1
products[1] = product2

parameters = HashMap()
parameters.put('westBound',-83.61)
parameters.put('eastBound',-81.79)
parameters.put('northBound',42.31)
parameters.put('southBound',41.19)
parameters.put('pixelSizeY',0.002)
parameters.put('pixelSizeX',0.002)
parameters.put('resampling','Nearest')


vars[0] = 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:

  1. vars = jpy.array(…, 1), but vars needs a name and and expression (which may just be the name)
vars[0] = Variable('CI_demo', 'CI_demo')
vars[1] = `Variable('CI', 'CI')
  1. you don’t have parameters.put('variables', vars)

Thanks, George. Yes, inserting ‘parameters.put(‘variables’, vars)’ worked. Though I kept ‘vars’ unchanged.

Thanks again.

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.
Thank you.