Snappy Merge bands

Hi!
I’m try to merge 2 products. Each product has 1 band.
In the resulting product, I expect 2 bands, but there’s only one band.

red = ProductIO.readProduct(‘D:\tmp\T41VPD_20170603T065021_B04.jp2’)
green = ProductIO.readProduct(‘D:\tmp\T41VPD_20170603T065021_B03.jp2’)
sourceProducts= HashMap()
sourceProducts.put(‘masterProduct’, red)
sourceProducts.put(‘slaveProduct’, green)
parameters = HashMap()
target = GPF.createProduct(‘Merge’, parameters, sourceProducts)
bands = target.getBandNames()
print list(bands)

I’m setting the incorrect parameters?

The reason is that the name within the inputs is the same. So only one wins. You can set more parameters.
Following how it can be done:
I assume that the names of the bands are simply ‘band_1’

NodeDescriptor = jpy.get_type(‘org.esa.snap.core.gpf.common.MergeOp$NodeDescriptor’)
include_1 = NodeDescriptor()
include_1.setProductId(‘masterProduct’)
include_1.setNamePattern(‘band_1’)
include_1.setNewName(‘red’)

include_2 = NodeDescriptor()
include_2.setProductId(‘slaveProduct1’)
include_2.setName(‘band_1’)
include_1.setNewName(‘green’)

included_bands = jpy.array(‘org.esa.snap.core.gpf.common.MergeOp$NodeDescriptor’, 2)
included_bands[0] = include_1
included_bands[1] = include_2

parameters.put(‘includes’, included_bands)

1 Like

Hello
I think the topic of my question fits in this discussion:
Same scenario to merge two tiff files but I need to rename the band names of one of the files, what is the simplest way to do it?
I do the “merge” and it works absolutely fine, I think there must be kindof parameter setting to avoid re-opening the outcome file and rename bands with “BandMaths”, Is there?
Thank you
Panteha

You can use the newName paramter to change the name of an included band.
Like in my post above.
There band_1 is renamed to red from the first product and band_1 is renamed to green from the second product.

And you can always combine multiple operators. So there is no need to close and reopen the products.

Maybe you are not working with python or on the command line?

1 Like

Thank you!
I got it done.
I am new to SNAP and still in the exploration phase :wink:
In fact I am working on python but preferred to do the merge & rename in one shot, as you explained here.
Best
Panteha

1 Like