{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "c4bf59c7-78f2-4e94-a6b9-da0c8a04368d", "metadata": {}, "outputs": [], "source": [ "from snapista.binning import aggregators\n", "from snapista.binning import BinningVariable, BinningOutputBands, BinningBand, Aggregators, BinningVariables\n", "from snapista import Graph\n", "from snapista import Operator\n", "import lxml.etree as etree\n", "import os" ] }, { "cell_type": "code", "execution_count": 2, "id": "201edf84-dfe7-4346-8898-884530be354d", "metadata": {}, "outputs": [], "source": [ "os.environ['PATH'] = '/srv/conda/envs/env_snap/snap/bin:' + os.environ['PATH']" ] }, { "cell_type": "markdown", "id": "9ad15f94-d193-49a3-98a0-d79bc8f8a86e", "metadata": {}, "source": [ "## Create an Aggregator" ] }, { "cell_type": "code", "execution_count": 3, "id": "ba09111e-e105-4b63-a838-9ec767191a73", "metadata": {}, "outputs": [], "source": [ "ag = aggregators.AggregatorAvg(varName='OTCI', targetName=\"otci\", outputCounts='true', outputSums='true', weightCoeff=1.0)" ] }, { "cell_type": "markdown", "id": "d51bac07-aae0-4ce7-b1eb-d783b692b731", "metadata": {}, "source": [ "## Create a binning operator" ] }, { "cell_type": "code", "execution_count": 4, "id": "bb37992a-5f51-4399-add4-e23c3493a188", "metadata": {}, "outputs": [], "source": [ "binning = Operator('Binning')\n", "\n", "binning.sourceProductFormat = 'sen3'\n", "\n", "binning.aggregatorConfigs = Aggregators([ag,\n", " aggregators.AggregatorAvgOutlier(varName='OTCI', targetName='outlier'),\n", " aggregators.AggregatorMinMax(varName='OTCI', targetName='otci'),\n", " aggregators.AggregatorOnMaxSet(targetName='omvn', onMaxVarName='OTCI', setVarNames='OTCI'),\n", " aggregators.AggregatorPercentile(varName='OTCI', percentage=90, targetName='percent'),\n", " aggregators.AggregatorSum(varName='OTCI', targetName='sum')])\n", "\n", "binning.sourceProductPaths = '/data/S3*/*.xml'\n", "\n", "binning.outputFile = '/home/vscode/binned_new.dim'" ] }, { "cell_type": "code", "execution_count": 5, "id": "6fa5b71e-a3ae-4f78-a00d-e9c8795bfee3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "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='', 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')" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "binning" ] }, { "cell_type": "markdown", "id": "8ab19cbd-5175-4948-827b-269337839c3d", "metadata": {}, "source": [ "## Create the Graph" ] }, { "cell_type": "code", "execution_count": 6, "id": "e5c0e2c1-6896-4db7-b90d-ad2d7da9beb6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "aggregatorConfigs \n", "bandConfigurations None\n", "postProcessorConfig None\n", "productCustomizerConfig None\n", "variableConfigs None\n" ] } ], "source": [ "g = Graph()\n", "\n", "g.add_node(operator=binning, \n", " node_id='binning_1')" ] }, { "cell_type": "code", "execution_count": 7, "id": "4fb07cc7-52d8-464c-83cc-c496b50df848", "metadata": {}, "outputs": [], "source": [ "g.add_node(operator=binning, \n", " node_id='binning_1')" ] }, { "cell_type": "markdown", "id": "89cecd6a-cab5-4ced-ac19-9b8a8b093f7b", "metadata": {}, "source": [ "```xml\n", "\n", " \n", " AVG\n", " OTCI\n", " avg\n", " 1.0\n", " true\n", " true\n", " \n", " \n", " MIN_MAX\n", " OTCI\n", " otci\n", " \n", " \n", " AVG_OUTLIER\n", " OTCI\n", " \n", " \n", " \n", " SUM\n", " OTCI\n", " aaa\n", " \n", " \n", " PERCENTILE\n", " OTCI\n", " \n", " \n", " ON_MAX_SET\n", " OTCI\n", " OTCI\n", " \n", " \n", "```" ] }, { "cell_type": "code", "execution_count": 8, "id": "54468091-3227-419e-b949-f8b86fcb9eef", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", " 1.0\n", " \n", " Binning\n", " \n", " \n", " \n", " \n", " AVG\n", " OTCI\n", " otci\n", " 1.0\n", " true\n", " true\n", " \n", " \n", " AVG_OUTLIER\n", " OTCI\n", " outlier\n", " \n", " \n", " MIN_MAX\n", " OTCI\n", " otci\n", " \n", " \n", " ON_MAX_SET\n", " omvn\n", " OTCI\n", " OTCI\n", " \n", " \n", " PERCENTILE\n", " OTCI\n", " percent\n", " 90\n", " \n", " \n", " SUM\n", " OTCI\n", " sum\n", " \n", " \n", " \n", " -1\n", " NAME\n", " ./metadata.properties\n", " .\n", " \n", " 2160\n", " false\n", " /home/vscode/binned_new.dim\n", " BEAM-DIMAP\n", " true\n", " Product\n", " \n", " org.esa.snap.binning.support.SEAGrid\n", " \n", " \n", " sen3\n", " /data/S3*/*.xml\n", " \n", " 1\n", " NONE\n", " \n", " \n", "\n", "\n" ] } ], "source": [ "g.view()" ] }, { "cell_type": "code", "execution_count": 9, "id": "5a56860a-fcc2-408c-93fd-f667b64680a7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Processing the graph\n", "Executing processing graph\n", "INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters\n", "45%90% done.\n", "INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: GDAL not found on system. Internal GDAL 3.0.0 from distribution will be used. (f1)\n", "INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: Internal GDAL 3.0.0 set to be used by SNAP.\n", "INFO: org.esa.snap.core.util.EngineVersionCheckActivator: Please check regularly for new updates for the best SNAP experience.\n", "INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: Internal GDAL 3.0.0 set to be used by SNAP.\n" ] }, { "data": { "text/plain": [ "0" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g.save_graph(filename='s3.xml')\n", "\n", "g.run()" ] }, { "cell_type": "code", "execution_count": null, "id": "72c1f5b1-e6ed-4e79-9fce-3455cc9a304d", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "7390f902-9415-4d1b-ab77-c7bc4554eace", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.4" } }, "nbformat": 4, "nbformat_minor": 5 }