Band Maths for Mask Coherence with snappy

Hi all,

my idea is to mask low values of coherence in filtered images before snaphu export, as we can see here in this tutorial Filter Out Low Coherence Pixels Before Phase Unwrapping – Endless Curiosity, but using snappy.

I’ve tried a lot of codes thanks to the search but none of them help me to clarify the error i’m getting. Anyone that make this before or its used to snappy can identify where im failing and help?

def mask_coherence(product):
… BandDescriptor = jpy.get_type(‘org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor’)
… targetBand1 = BandDescriptor()
… = ‘newband’
… targetBand1.type = ‘float32’
… targetBand1.expression = ‘if coh_IW3_VV_03Jan2017_15Jan2017>0.4 then Phase_ifg_VV_03Jan2017_15Jan2017 else 0’
… return GPF.createProduct(‘BandMaths’, parameters, product)

I am getting the following error:
RuntimeError: org.esa.snap.core.gpf.OperatorException: No target bands specified.

Have a look at <user_home_dir>/.snap/snap-python/snappy/examples/

Yes, thank you, but i’ve tried before with this code and this make a new product with only one band.

Its possible to just replace the band expression?

What version of SNAP do you have? In my SNAP 8 installations with all updates, makes a new product with 2 bands: band_1 and band_2.

You are right, makes a new product with 2 bands. As its not my need, I’ve adjusted the code. If I copy and paste the code without modifications it will works as supposed to be.

Now the question is that all the other bands from my source product are left behind with the create of a new product, and I need them all for the snaphu unwrapping

I recall a request for an option to include all input bands in BandMaths output, but a) I don’t see such an option, and b) the request may have made in a BEAM or SeaDAS forum as I can’t find it in this (STEP) Forum. NASA SeaDAS (based on SNAP) GPT Cookbook: BandMaths has one example that just copies the bands that are to be preserved. You could also use Merge to add the new bands to your input file.