Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

SNAP implementation language is Java and therefore SNAP's "native" API is a Java API. According to the SNAP architecture, the reference SNAP Java API documentation of the two SNAP sub-systems SNAP Engine and SNAP Desktop nearly fully applies to use from Python as well.

It With the recommended standard Python (CPython) approach, it is possible to use the call SNAP Java API code from your Python and there are in principle two different ways to achieve this:

  1. Use a standard Python (CPython) installation
  2. Use the Jython approach. Note: For the most recent versions of SNAP we discourage the usage of Jython. As of SNAP 8 the Jython support is not part of the SNAP standard distribution anymore. Documentation and examples how to use Jython in older SNAP versions are kept here.

With the recommended standard Python (CPython) approach, it is possible to call SNAP code from your Python programs/scripts and to extend SNAP by plugins written in Python. Use this approach if

...

programs/scripts and to extend SNAP by plugins written in Python. Use this approach if

  • you require using the Python scientific extension libraries such as numpy, scipy, matplotlib, etc.;
  • you already have CPython code and you want to incorporate SNAP functions;
  • you plan to implement a fast data processor plugin in Python;
  • you do not plan to develop SNAP Desktop user interface extensions;
  • you do not require full portability on all platforms;
  • your code has (or will have) dependencies on a lot of non-standard libraries.

With the standard Python approach extension of SNAP is currently limited to raster data processor (Operator) plugins. You need to use a standard Python (CPython) interpreter installed on your computer (SNAP does not include a CPython interpreter.) The For the recent SNAP versions, the supported versions are Python 23.7, 6 to 3.10 for SNAP 11 and will be 3.6 to 3.10 for the upcoming SNAP 12, both for 64-bit (Linux + Darwin) and both 32-bit and 64-bit (Windows) as well as Anaconda distributions. 

Info
titleWindows users

Please note that you must use a 32-bit Python if your SNAP installation is 32-bit and accordingly use a 64-bit Python if your SNAP installation is 64-bit.

...

Note: The following examples assume that you work with SNAP 10+ and the new esa_snappy interface. Differences to the previous snappy interface are outlined in the text or in comment lines in the Python code snippets.

For SNAP 10+, esa_snappy is provided as built-in plugin which allows you to access the SNAP Java API from Python.

...

For a guideline how to access, install and configure Python for SNAP please see Configure Python to use the new SNAP-Python (esa_snappy) interface (SNAP version 10+) for the most recent SNAP 10+ versions, or Configure Python to use the SNAP-Python (snappy) interface (SNAP versions <= 9) for older SNAP versions. A documentation update describing recent changes is in preparation and will be published here along with the release of SNAP 12. 

Examples of SNAP API usage from Python

...

The target Product is ready for data to be written to it. Check out  out the esa_snappy examples on GitHub in order to know how to use readPixels() and writePixels() for reading data tiles, rows, columns or single pixels into numpy arrays and write them from output arrays into the respective band of the target Product. These same examples are also provided in the esa_snappy installation directory (see below).

...

cd <esa_snappy-dir>/examples
$ <python-exe> snappy_ndvi.py ../testdata/MER_FRS_L1B_SUBSET.dim


Import of Java API classes

Note that the one and only reference for the SNAP Python API is the SNAP Java API documentation. All Java classes from the API can be "imported" by the jpy Java-Python bridge  which is implicitely used by esa_snappy. For example:

...

esa_snappy. For example:
 
ProductIOPlugInManager = esa_snappy.jpy.get_type('org.esa.snap.framework.dataio.ProductIOPlugInManager')
plugins = ProductIOPlugInManager.getInstance().getAllReaderPlugIns()
 
However, the most frequently used Java API classes are already imported by default and do not require another explicit call of get_type(..):
 

Frequently used classes & interfaces from JRE

  • String = jpy.get_type('java.lang.String')
  • File = jpy.get_type('java.io.File')
  • Point = jpy.get_type('java.awt.Point')
  • Rectangle = jpy.get_type('java.awt.Rectangle')
  • Arrays = jpy.get_type('java.util.Arrays')
  • Collections = jpy.get_type('java.util.Collections')
  • List = jpy.get_type('java.util.List')
  • Map = jpy.get_type('java.util.Map')
  • Set = jpy.get_type('java.util.Set')
  • ArrayList = jpy.get_type('java.util.ArrayList')
  • HashMap = jpy.get_type('java.util.HashMap')
  • HashSet = jpy.get_type('java.util.HashSet')

Frequently used classes & interfaces from SNAP Engine

Product tree & associates:

  • Product = jpy.get_type('org.esa.snap.core.datamodel.Product')
  • VectorDataNode = jpy.get_type('org.esa.snap.core.datamodel.VectorDataNode')
  • RasterDataNode = jpy.get_type('org.esa.snap.core.datamodel.RasterDataNode')
  • TiePointGrid = jpy.get_type('org.esa.snap.core.datamodel.TiePointGrid')
  • AbstractBand = jpy.get_type('org.esa.snap.core.datamodel.AbstractBand')
  • Band = jpy.get_type('org.esa.snap.core.datamodel.Band')
  • VirtualBand = jpy.get_type('org.esa.snap.core.datamodel.VirtualBand')
  • Mask = jpy.get_type('org.esa.snap.core.datamodel.Mask')
  • GeneralFilterBand = jpy.get_type('org.esa.snap.core.datamodel.GeneralFilterBand')
  • ConvolutionFilterBand = jpy.get_type('org.esa.snap.core.datamodel.ConvolutionFilterBand')

Product tree associates:

  • ProductData = jpy.get_type('org.esa.snap.core.datamodel.ProductData')
  • GeoCoding = jpy.get_type('org.esa.snap.core.datamodel.GeoCoding')
  • TiePointGeoCoding = jpy.get_type('org.esa.snap.core.datamodel.TiePointGeoCoding')
  • PixelGeoCoding = jpy.get_type('org.esa.snap.core.datamodel.PixelGeoCoding')
  • PixelGeoCoding2 = jpy.get_type('org.esa.snap.core.datamodel.PixelGeoCoding2')
  • CrsGeoCoding = jpy.get_type('org.esa.snap.core.datamodel.CrsGeoCoding')
  • GeoPos = jpy.get_type('org.esa.snap.core.datamodel.GeoPos')
  • PixelPos = jpy.get_type('org.esa.snap.core.datamodel.PixelPos')
  • FlagCoding = jpy.get_type('org.esa.snap.core.datamodel.FlagCoding')
  • ProductNodeGroup = jpy.get_type('org.esa.snap.core.datamodel.ProductNodeGroup')

Graph Processing Framework:

  • GPF = jpy.get_type('org.esa.snap.core.gpf.GPF')
  • Operator = jpy.get_type('org.esa.snap.core.gpf.Operator')
  • Tile = jpy.get_type('org.esa.snap.core.gpf.Tile')

Utilities:

  • EngineConfig = jpy.get_type('org.esa.snap.runtime.EngineConfig')
  • Engine = jpy.get_type('org.esa.snap.runtime.Engine')
  • SystemUtils = jpy.get_type('org.esa.snap.core.util.SystemUtils')
  • ProductIO = jpy.get_type('org.esa.snap.core.dataio.ProductIO')
  • ProductUtils = jpy.get_type('org.esa.snap.core.util.ProductUtils')
  • GeoUtils = jpy.get_type('org.esa.snap.core.util.GeoUtils')
  • ProgressMonitor = jpy.get_type('com.bc.ceres.core.ProgressMonitor')
  • PlainFeatureFactory = jpy.get_type('org.esa.snap.core.datamodel.PlainFeatureFactory')
  • FeatureUtils = jpy.get_type('org.esa.snap.core.util.FeatureUtils')

GeoTools:

  • DefaultGeographicCRS = jpy.get_type('org.geotools.referencing.crs.DefaultGeographicCRS')
  • ListFeatureCollection = jpy.get_type('org.geotools.data.collection.ListFeatureCollection')
  • SimpleFeatureBuilder = jpy.get_type('org.geotools.feature.simple.SimpleFeatureBuilder')

JTS:

  • Geometry = jpy.get_type('org.

...

  • locationtech.

...

  • jts.

...

  • geom.

...

  • Geometry')

...

  • WKTReader =

...

  • jpy.

...

  • get_type('org.locationtech.jts.io.WKTReader')