Snappy: Collocate, set 'masterProduct'


I am trying to implement Collocate into a Python Script.

trg_data = GPF.createProduct(‘Collocate’, parameters, src_data)

I get the following error:

RuntimeError: org.esa.snap.core.gpf.OperatorException: Operator ‘CollocateOp’: Mandatory source product (field ‘masterProduct’) not set.

Does anyone know how to set this field?

Similar to the parameters you can create a map for the source products and then call GPF

sourceProducts = HashMap()
sourceProducts.put("master", mProduct)
sourceProducts.put("slave", sProduct)
GPF.createProduct('Collocate', parameters, sourceProducts)

Again thank you very much for your help! It works.

What is mProduct and sProduct here? I mean, I have 15 images , then how will I define mProduct and sProduct?

The example is from the times were on two products could be collocated in one step.
Now, you can collocate more products and there are more options. This can make it more complicated or easier.
If all your products cover already the same region, and you just want to create a stack then you can leave out the master/slave parameters.
Instead you can simply add a comma separated list of all products paths to the parameters map.

parameters.put("sourceProductPaths", pathsList)
GPF.createProduct('Collocate', parameters)

If you want to define a master, the one which defines the geographical extent, then find this one in SNAP desktop and get the name of it.
Right-click on it in the Product Explorer and select Properties. Here the name is shown and you can copy it.
Set this name as parameter ‘masterProductName’.

parameters.put("sourceProductPaths", pathsList)
parameters.put("masterProductName", 'THE_NAME_OF_THE_PRODUCT')
GPF.createProduct('Collocate', parameters)

This should do it.

I will follow up this question with another of mine, since I have a similar/related doubt.
I’ve been processing Sentinl-1 for a while, but recently I found that none of the processed images align with each other.
E.g. I have 60 Sentinel-1 images of one area from one year from the same orbit. I didn’t use ApplyOrbitFile step as I would like to use the image as soon as it has been acquired and not wait 20 days for it (as I saw in other discussions).
For the sake of my research (crop classification) I want images to align, pixel to pixel between all the images.
Would collocation be a good solution? What is a good way to implement it in processing workflow that is performed for each image individually? I would like to keep each image independently, not as a stack.
In case ApplyPreciseOrbit step was included in workflow, would the processed images align or still no?

P.S. Good to hear that more than two product can be collocated at once.

As this question is very radar related, maybe @ABraun you can make a suggestion what to do here?

My images :

My code :

coreg_set = [’/home/ubuntu/SOIL_MOISTURE/PROCESSED_DATA/S1A_IW_GRDH_1SDV_20200103T003500_20200103T003525_030629_038272_70BC_orbit_border_thermal_calib_subset_terrain_subset.dim’,

parameters = HashMap()
parameters.put(“sourceProductPaths”, coreg_set)
coll_img = GPF.createProduct(‘Collocate’, parameters)

Forget about terrain in file name. Terrain correction is not applied, only naming is added by mistake.

Getting the following error:

ValueError Traceback (most recent call last)
13 ‘/home/ubuntu/SOIL_MOISTURE/PROCESSED_DATA/S1A_IW_GRDH_1SDV_20200220T003458_20200220T003523_031329_039AE1_97D5_orbit_border_thermal_calib_subset_terrain_subset.dim’]
14 parameters = HashMap()
—> 15 parameters.put(“sourceProductPaths”, coreg_set)
16 coll_img = GPF.createProduct(‘Collocate’, parameters)

ValueError: cannot convert a Python ‘list’ to a Java ‘java.lang.Object’

Try just a string not a python list.



coreg_set = ‘/home/ubuntu/SOIL_MOISTURE/PROCESSED_DATA/S1A_IW_GRDH_1SDV_20200103T003500_20200103T003525_030629_038272_70BC_orbit_border_thermal_calib_subset_terrain_subset.dim, /home/ubuntu/SOIL_MOISTURE/PROCESSED_DATA/S1A_IW_GRDH_1SDV_20200115T003459_20200115T003524_030804_03888F_9715_orbit_border_thermal_calib_subset_terrain_subset.dim’

parameters = HashMap()
parameters.put(“sourceProductPaths”, coreg_set)
coll_img = GPF.createProduct(‘Collocate’, parameters)


RuntimeError Traceback (most recent call last)
19 parameters.put(“sourceProductPaths”, coreg_set)
20 parameters.put(“resamplingType”,‘NEAREST_NEIGHBOUR’)
—> 21 coll_img = GPF.createProduct(‘Collocate’, parameters)
23 band_names = coll_img.getBandNames()

RuntimeError: java.lang.NullPointerException

Hi @janardanroy,

Was wondering if you managed to resolve the null pointer exception error?
I am also facing the same issue here and would appreciate any insights.

My code is as follow:
# Read the product name of Sen1 data so that we can set it as the master
s1_product = ProductIO.readProduct(sen1)
s1_product_name = s1_product.getName()

    parameters = HashMap()
    parameters.put('sourceProductPaths', path_str)
    parameters.put('masterProductName', s1_product_name)
    parameters.put('renameMasterComponents', 'false')
    parameters.put('renameSlaveComponents', 'false')
    parameters.put('resamplingType', 'NEAREST_NEIGHBOUR')

    colocated = GPF.createProduct('Collocate', parameters)
1 Like