Binning
In [1]:
from snapista.binning import aggregators
from snapista.binning import BinningVariable, BinningOutputBands, BinningBand, Aggregators, BinningVariables
from snapista import Graph
from snapista import Operator
import lxml.etree as etree
import os
In [2]:
os.environ['PATH'] = '/srv/conda/envs/env_snap/snap/bin:' + os.environ['PATH']
Create an Aggregator¶
In [3]:
ag = aggregators.AggregatorAvg(varName='OTCI', targetName="otci", outputCounts='true', outputSums='true', weightCoeff=1.0)
Create a binning operator¶
In [4]:
binning = Operator('Binning')
binning.sourceProductFormat = 'sen3'
binning.aggregatorConfigs = Aggregators([ag,
aggregators.AggregatorAvgOutlier(varName='OTCI', targetName='outlier'),
aggregators.AggregatorMinMax(varName='OTCI', targetName='otci'),
aggregators.AggregatorOnMaxSet(targetName='omvn', onMaxVarName='OTCI', setVarNames='OTCI'),
aggregators.AggregatorPercentile(varName='OTCI', percentage=90, targetName='percent'),
aggregators.AggregatorSum(varName='OTCI', targetName='sum')])
binning.sourceProductPaths = '/data/S3*/*.xml'
binning.outputFile = '/home/vscode/binned_new.dim'
In [5]:
binning
Out[5]:
Operator('Binning', sourceProductPaths='/data/S3*/*.xml', sourceProductFormat='sen3', sourceGraphPaths='None', region='None', startDateTime='None', periodDuration='None', timeFilterMethod='NONE', minDataHour='None', numRows='2160', superSampling='1', maxDistanceOnEarth='-1', maskExpr='None', variableConfigs='None', aggregatorConfigs='<snapista.binning.aggregators.Aggregators object at 0x7f1da3cb10d0>', postProcessorConfig='None', outputType='Product', outputFile='/home/vscode/binned_new.dim', outputFormat='BEAM-DIMAP', bandConfigurations='None', productCustomizerConfig='None', outputBinnedData='false', outputTargetProduct='true', metadataPropertiesFile='./metadata.properties', metadataTemplateDir='.', metadataAggregatorName='NAME', planetaryGridClass='org.esa.snap.binning.support.SEAGrid')
Create the Graph¶
In [6]:
g = Graph()
g.add_node(operator=binning,
node_id='binning_1')
aggregatorConfigs <snapista.binning.aggregators.Aggregators object at 0x7f1da3cb10d0> bandConfigurations None postProcessorConfig None productCustomizerConfig None variableConfigs None
In [7]:
g.add_node(operator=binning,
node_id='binning_1')
In [8]:
g.view()
<graph> <version>1.0</version> <node id="binning_1"> <operator>Binning</operator> <sources/> <parameters class="com.bc.ceres.binding.dom.XppDomElement"> <aggregators> <aggregator> <type>AVG</type> <varName>OTCI</varName> <targetName>otci</targetName> <weightCoeff>1.0</weightCoeff> <outputCounts>true</outputCounts> <outputSums>true</outputSums> </aggregator> <aggregator> <type>AVG_OUTLIER</type> <varName>OTCI</varName> <targetName>outlier</targetName> </aggregator> <aggregator> <type>MIN_MAX</type> <varName>OTCI</varName> <targetName>otci</targetName> </aggregator> <aggregator> <type>ON_MAX_SET</type> <targetName>omvn</targetName> <onMaxVarName>OTCI</onMaxVarName> <setVarNames>OTCI</setVarNames> </aggregator> <aggregator> <type>PERCENTILE</type> <varName>OTCI</varName> <targetName>percent</targetName> <percentage>90</percentage> </aggregator> <aggregator> <type>SUM</type> <varName>OTCI</varName> <targetName>sum</targetName> </aggregator> </aggregators> <maskExpr/> <maxDistanceOnEarth>-1</maxDistanceOnEarth> <metadataAggregatorName>NAME</metadataAggregatorName> <metadataPropertiesFile>./metadata.properties</metadataPropertiesFile> <metadataTemplateDir>.</metadataTemplateDir> <minDataHour/> <numRows>2160</numRows> <outputBinnedData>false</outputBinnedData> <outputFile>/home/vscode/binned_new.dim</outputFile> <outputFormat>BEAM-DIMAP</outputFormat> <outputTargetProduct>true</outputTargetProduct> <outputType>Product</outputType> <periodDuration/> <planetaryGridClass>org.esa.snap.binning.support.SEAGrid</planetaryGridClass> <region/> <sourceGraphPaths/> <sourceProductFormat>sen3</sourceProductFormat> <sourceProductPaths>/data/S3*/*.xml</sourceProductPaths> <startDateTime/> <superSampling>1</superSampling> <timeFilterMethod>NONE</timeFilterMethod> </parameters> </node> </graph>
In [9]:
g.save_graph(filename='s3.xml')
#g.run()
Processing the graph Executing processing graph INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters 45%90% done. INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: GDAL not found on system. Internal GDAL 3.0.0 from distribution will be used. (f1) INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: Internal GDAL 3.0.0 set to be used by SNAP. INFO: org.esa.snap.core.util.EngineVersionCheckActivator: Please check regularly for new updates for the best SNAP experience. INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: Internal GDAL 3.0.0 set to be used by SNAP.
Out[9]:
0
In [ ]:
In [ ]: