How do I setup snappy (the SNAP-Python bridge)? I don’t see all of it (e.g., snappy.py) in the SNAP 2.0 distribution. In my case, I want to call SNAP from Python. FYI, I’m on Mac OS X 10.8.5 … but possibly 10.9 or 10.10 soon.
You can’t find it, because (1) the SNAP-Python bridge is not yet documented at all and (2) because snappy is generated. Sorry for the missing documentation, we’ll provide a description and a tutorial as soon as possible possible after the Summer gap.
To use the SNAP (Java) API from Python, you can force the generation of the snappy module as follows. Open a command-line shell and type:
> cd ${SNAP_HOME}/bin
> ./snap.sh --nogui --nosplash --python <your-python-interpreter-exe> [<snappy-target-dir>]
where ${SNAP_HOME} points to SNAP’s installation directory.After successfuul configuration, the <snappy-target-dir> folder should contain the Python snappy module folder. If omitted, <snappy-target-dir> becomes ${USER_HOME}/.snap/snap-python/. Note that only Python 2.7, 3.3, and 3.4 are supported. In the snappy module folder you also find test and example code for the snappy module in Python.
If you use Python from Java, e.g. as a processor plugin, and snappy has not yet been generated, then snappy will configure itself to its default location. If you are interested, an example of a Python plugin processor is provided at https://github.com/senbox-org/snap-examples/tree/master/snap-engine-python-operator (it is the good, old NDVI algorithm for optical sensors).
Will snappy allow to make use of all functionality that is available through the GUI (I am especially interested in using the typical SAR tools like calibration and terrain correction)? In case you have any examples for these radar tools it would be great.
I am looking forward to the release of the documentation!
I am trying a bit with the example you provided, but the first problem already appears with the import of HashMap. The following error message is normally thrown if there are circular dependencies within several imports. Any idea on this?
C:\Anaconda3\python.exe D:/temp/Code/calibrate.py
Traceback (most recent call last):
File “D:/temp/Code/calibrate.py”, line 6, in
from snappy import HashMap
ImportError: cannot import name ‘HashMap’
Note that since beta 8 you can use the bin/snappy-conf command-line tool to configure the snappy module:
Usage:
cd ${SNAP_HOME}/bin
./snappy-conf <your python executable> [<your snappy target dir>]
where <your snappy target dir> is the directory that will contain the snappy module and that that must be on Python’s sys.path. It is an optional parameter and defaults to ~/.snap/snap-python.