BandMaths¶
In [1]:
Copied!
from snapista import Graph
from snapista import Operator
from snapista import TargetBand
from snapista import TargetBandDescriptors
from snapista import Graph
from snapista import Operator
from snapista import TargetBand
from snapista import TargetBandDescriptors
The BandMaths operator creates TargetBands
In [2]:
Copied!
band_maths = Operator('BandMaths')
band_maths = Operator('BandMaths')
In [3]:
Copied!
band_maths.describe()
band_maths.describe()
Operator name: BandMaths Description: Create a product with one or more bands using mathematical expressions. Authors: Marco Zuehlke, Norman Fomferra, Marco Peters org.esa.snap.core.gpf.common.BandMathsOp Version: 1.1 Parameters: targetBandDescriptors: List of descriptors defining the target bands. Default Value: None Possible values: [] variables: List of variables which can be used within the expressions. Default Value: None Possible values: []
The XML representation of a targetBand is:
<targetBand>
<name>active_fire_detected</name>
<type>float32</type>
<expression>S9_BT_in < 265 ? 0 : F1_BT_in > 315 and (F1_BT_in - F2_BT_in) > 15 ? 1 : 0</expression>
<description/>
<unit/>
<noDataValue>NaN</noDataValue>
</targetBand>
With snapista
a targetBand is created with:
In [4]:
Copied!
active_fire_band = TargetBand(name='active_fire_detected',
expression='S9_BT_in < 265 ? 0 : F1_BT_in > 315 and (F1_BT_in - F2_BT_in) > 15 ? 1 : 0')
active_fire_band = TargetBand(name='active_fire_detected',
expression='S9_BT_in < 265 ? 0 : F1_BT_in > 315 and (F1_BT_in - F2_BT_in) > 15 ? 1 : 0')
In [5]:
Copied!
active_fire_band
active_fire_band
Out[5]:
TargetBand(name='active_fire_detected', expression='S9_BT_in < 265 ? 0 : F1_BT_in > 315 and (F1_BT_in - F2_BT_in) > 15 ? 1 : 0', type='float32', description=None, unit=None, no_data_value='NaN')
And associated to the BandMaths operator with:
In [6]:
Copied!
band_maths.targetBandDescriptors = TargetBandDescriptors([active_fire_band])
band_maths.targetBandDescriptors = TargetBandDescriptors([active_fire_band])
A complete graph is thus done with:
In [7]:
Copied!
g = Graph()
g.add_node(operator=Operator('Read'),
node_id='read_1')
g = Graph()
g.add_node(operator=Operator('Read'),
node_id='read_1')
In [8]:
Copied!
g.add_node(operator=band_maths,
node_id='band_maths',
source='read_1')
g.add_node(operator=band_maths,
node_id='band_maths',
source='read_1')
In [9]:
Copied!
g.view()
g.view()
<graph> <version>1.0</version> <node id="read_1"> <operator>Read</operator> <sources/> <parameters class="com.bc.ceres.binding.dom.XppDomElement"> <bandNames/> <copyMetadata>true</copyMetadata> <file/> <formatName/> <geometryRegion/> <maskNames/> <pixelRegion/> </parameters> </node> <node id="band_maths"> <operator>BandMaths</operator> <sources> <sourceProduct refid="read_1"/> </sources> <parameters class="com.bc.ceres.binding.dom.XppDomElement"> <targetBands> <targetBand> <name>active_fire_detected</name> <expression>S9_BT_in &lt; 265 ? 0 : F1_BT_in &gt; 315 and (F1_BT_in - F2_BT_in) &gt; 15 ? 1 : 0</expression> <type>float32</type> <description/> <unit/> <no_data_value>NaN</no_data_value> </targetBand> </targetBands> <variables/> </parameters> </node> </graph>
In [ ]:
Copied!