SNAP Command Line Tutorial: Graph Processing
SNAP Command Line Tutorial: Graph Processing
Graph Processing
Issued July 2016
Updated January 2020
Luis Veci
2
SNAP Command Line Tutorial
within a headless operating system shell would access only the SNAP Engine while the SNAP Desktop is
used for creating a client graphical user interface.
The server-mode Toolbox is self-contained and does not depend on any GUI functionality for setup or
operation.
For Linux, download the 64-bit unix installer from the STEP website (http://step.esa.int).
$ chmod +x esa-snap_sentinel_unix_4_0.sh
$ ./esa-snap_sentinel_unix_4_0.sh
snap --help
The parameter --nogui is missing in this list. This parameter prevents the SNAP GUI from being started.
This will give you an output similar to what you can see in the following image.
3
SNAP Command Line Tutorial
The installation should have added the SNAP/bin folder to the system path in order to call the gpt from
any folder.
Usage:
gpt <op>|<graph-file> [options] [<source-file-1> <source-file-2> ...]
Description:
This tool is used to execute SNAP raster data operators in batch-mode. The
operators can be used stand-alone or combined as a directed acyclic graph
(DAG). Processing graphs are represented using XML. More info about
processing graphs, the operator API, and the graph XML format can be found
in the SNAP documentation.
Arguments:
<op> Name of an operator. See below for the list of <op>s.
<graph-file> Operator graph file (XML format).
<source-file-i> The <i>th source product file. The actual number of source
file arguments is specified by <op>. May be optional for
operators which use the -S option.
Options:
-h Displays command usage. If <op> is given, the specific
operator usage is displayed.
-e Displays more detailed error messages. Displays a stack
trace, if an exception occurs.
-t <file> The target file. Default value is './target.dim'.
-f <format> Output file format, e.g. 'GeoTIFF', 'HDF5',
'BEAM-DIMAP'. If not specified, format will be derived
from the target filename extension, if any, otherwise the
default format is 'BEAM-DIMAP'. Only used if the graph
in <graph-file> does not specify its own 'Write' operator.
-p <file> A (Java Properties) file containing processing
parameters in the form <name>=<value> or a XML file
containing a parameter DOM for the operator. Entries in this
file are overwritten by the -P<name>=<value> command-line
option (see below). The following variables are substituted in
4
SNAP Command Line Tutorial
With the gpt, you could process individual operators or you could process a graph of connected operators.
Type gpt operator-name –h to get usage information on each operator. The usage text of an operator also
displays a template clipping of the operators configuration when used in a graph.
gpt Calibration -h
Usage:
gpt Calibration [options]
Description:
Calibration of products
Source Options:
-Ssource=<file> Sets source 'source' to <filepath>.
This is a mandatory source.
Parameter Options:
5
SNAP Command Line Tutorial
gpt Write –h
6
SNAP Command Line Tutorial
Usage:
gpt Write [options]
Description:
Writes a data product to a file.
Source Options:
-Ssource=<file> The source product to be written.
This is a mandatory source.
Parameter Options:
-PclearCacheAfterRowWrite=<boolean> If true, the internal tile cache is cleared after a tile row has
been written. Ignored if writeEntireTileRows=false.
Default value is 'false'.
-PdeleteOutputOnFailure=<boolean> If true, all output files are deleted after a failed write operation.
Default value is 'true'.
-Pfile=<file> The output file to which the data product is written.
-PformatName=<string> The name of the output file format.
Default value is 'BEAM-DIMAP'.
-PwriteEntireTileRows=<boolean> If true, the write operation waits until an entire tile row is
computed.
Default value is 'true'.
The Write operator help shows that you can use the parameters –Pfile to specify an output file name and
–Pformat to specify the file format.
To actually run an operator using the GPT, it is necessary to indicate the path to the source product(s), to
the target product and to other operator-specific parameters which might be mandatory or specific.
7
SNAP Command Line Tutorial
The gpt can be run on several products in batch by using it within scripts and replacing the input files and
output files.
<graph id="someGraphId">
<version>1.0</version>
<node id="someNodeId">
<operator>OperatorName</operator>
<sources>
<sourceProducts>${sourceProducts}</sourceProducts>
</sources>
<parameters>
....
</parameters>
</node>
</graph>
You can use the operator help (gpt operatorName –h) to get a listing of the configuration of operator
parameters within a graph.
For example, as shown above, the graph configuration for Calibration is:
<graph id="someGraphId">
<version>1.0</version>
<node id="someNodeId">
<operator>Calibration</operator>
<sources>
<source>${source}</source>
</sources>
<parameters>
<sourceBands></sourceBands>
<auxFile>string</auxFile>
<externalAuxFile>file</externalAuxFile>
<outputImageInComplex>boolean</outputImageInComplex>
<outputImageScaleInDb>boolean</outputImageScaleInDb>
<createGammaBand>boolean</createGammaBand>
<createBetaBand>boolean</createBetaBand>
<selectedPolarisations>string,string,string,...</selectedPolarisations>
<outputSigmaBand>boolean</outputSigmaBand>
<outputGammaBand>boolean</outputGammaBand>
<outputBetaBand>boolean</outputBetaBand>
8
SNAP Command Line Tutorial
<outputDNBand>boolean</outputDNBand>
</parameters>
</node>
</graph>
Replace the parameter data types (string, boolean, etc) with actual values.
Save the graph to an XML text file calibrateGraph.xml.
Note that in the list of available operators a Read and a Write operator exists. These are not needed
because GPF will add those operators to the graph on its own for this simple case. However, they could be
specified in more complex graphs.
To run this graph with gpt and write the output product to a specific path, type:
When you save a graph, the parameters you have specified for
the current data product(s) are also saved to the graph file. To
reuse the graph from the command line using gpt, you may need
to open the graph XML file in a text editor and remove or replace
the value for some parameters in order to make the graph generic
for any input product.
<parameters>
<file>${myFilename}</file>
</parameters>
9
SNAP Command Line Tutorial
Calibration
For all envisat products in folder c:\ASAR run gpt Calibration and produce the output in the folder
c:\output
Terrain Correction
For all dimap products in folder c:\data run the graph TC_Graph.xml and output to c:\output with the same
name as the input file.
10