Currently trying to perform Band Maths on a image using snappy.
When I do the maths in the SNAP Gui it works fine, however when I run it in python I get:
RuntimeError: org.esa.snap.core.gpf.OperatorException: Could not parse expression: '255*(Sigma0_VV<2.22E-2)'. Numeric operands expected for binary '*' operator.
My code is as follows:
params = HashMap()
BandDescriptor = jpy.get_type('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor')
targetBand = BandDescriptor()
targetBand.name = 'Sigma0_VV'
targetBand.type = 'float32'
targetBand.expression = '255*(Sigma0_VV<2.22E-2)'
targetBands = jpy.array('org.esa.snap.core.gpf.common.BandMathsOp$BandDescriptor', 1)
targetBands = targetBand
product = GPF.createProduct('BandMaths', params, product)
This seems to be a bug, but not really.
There is a little difference between the expression parsing in the GUI and in the operator.
In the operator the type checking is enabled. It is checked if the arguments to the operators, like ‘*’, are of the expected data type.
The multiply expects numerical values. The expression within the braces evaluates to a boolean. That’s the reason why the error occurs. In the GUI the boolean is automatically converted to a numerical value and therefore it works.
So it is not really a bug, but it should be investigated why the operator does the type checking. Maybe there is some reason for it. I don’t know at the moment.
You could change your expression to
(Sigma0_VV < 2.22E-2) ? 255 : 0
i try to do the following band math command:
threshold.expression = ‘if savi_indices_differencing >= 0.15 <= 0.35 then 1 else 0’
I get the message Numeric operands expected for binary ‘>=’ operator.
Can somebody help me?
It works fine in the SNAP desktop aplication!