New error with collocation appeared

Hello,

I have had an error that has newly appeared when trying to collocate products using snappy. The following snippet of code (that used to work):

from snappy import ProductIO
from snappy import HashMap
from snappy import GPF

FILENAME1 = ‘/path/to/file’
FILENAME2 = ‘/path/to/file’

im1 = ProductIO.readProduct(FILENAME1)
im2 = ProductIO.readProduct(FILENAME2)

source = parameters = HashMap()

source.put(‘master’, im1)
source.put(‘slave’, im2)

parameters.put(‘renameMasterComponents’, True)
parameters.put(‘renameSlaveComponents’, True)
parameters.put(‘masterComponentPattern’, ‘${ORIGINAL_NAME}_M’)
parameters.put(‘slaveComponentPattern’, ‘${ORIGINAL_NAME}_S’)
parameters.put(‘resamplingType’, ‘BILINEAR_INTERPOLATION’)

collocated = GPF.createProduct(‘Collocate’, parameters, source)

generates the following error:

RuntimeError: java.lang.ClassCastException: java.lang.String cannot be cast to org.esa.snap.core.datamodel.Product

The only thing I can think of is that I have updated SNAP recently. Any idea of what this could be due to? Or how I could get around this?

Max

Hi Max,

Carsten was just at my desk and told me that you are working in the snow project. So were are in the same team :wink:

The problem with the script is the creation of the HashMap. Both, parameters and sources use the same.
Change to:

# …
sources = HashMap()
sources.put(‘master’, im1)
sources.put(‘slave’, im2)

parameters = HashMap()
parameters.put(‘renameMasterComponents’, True)
# …

Then it should work.

Happy to be on the team :wink:

Thanks for the solution, it works well now. I thought it would be more concise to declare them together, without realising the source and product needed their own HashMap.

Max

PS: as always 99% of the problems are between the chair and the keyboard!