Can snappy BandMaths result include original?

When I run the BandMaths in snappy I only get the single band that I calculated. How do I get a product that retains all the bands in the product, plus the new calculated one?

BANDDESCRIPTOR = jpy.get_type('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor')
band = BANDDESCRIPTOR()
band.name = b_name
band.type = b_type
band.expression = b_expression

product = ProductIO.readProduct(input)

targetBands = jpy.array('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor', 1)
targetBands[0] = band
parameters = HashMap()
parameters.put('targetBands',targetBands)
result = GPF.createProduct('BandMaths',parameters,product)

Do I need to add all the existing bands to the targetBands HashMap?

  • Count the bands in the product
  • Create a HashMap of that length, plus 1 for the new band
  • Add all the bands, expression is just the band
  • Add the new band to the HashMap
  • Then createProduct?

BandMaths does not include the original product. But you can simply copy the calculated band into your source product.
You can use ProductUtils.copyBand() see here:
snappy - ProductUtils.copyBand usage - development / python - STEP Forum (esa.int)

Or you can use the Merge operator and merge the two products