The easiest way to configure your Python installation for the usage SNAP-Python (snappy) interface is to do it during the installation of SNAP. Within the installer you can simply activate a checkbox and select the path to the python executable.
But it is also not a big deal to do it later manually if you might have forgotten it or if you want to configure an other Python installation for snappy. Open the command line at the
bin folder of the SNAP installation directory. On Windows you can simply choose 'SNAP Command-Line' from the Start menu.
$ cd <snap-install-dir>/bin
$ ./snappy-conf <python-exe>
$ snappy-conf <python-exe>
This will generate the Python module
snappy configured for the current SNAP installation and your Python interpreter
<python-exe> into the
directory of the user home directory. The parameter
<python-exe> must be the full path to the Python interpreter executable which you want to use with SNAP (supported versions are 2.7, 3.3 to 3.6). If you want the snappy module to be placed somewhere else use:
Next you can call the tool with the path to the python executable and optionally you can specify a directory where the snappy folder should be created.
When seeing result below the configuration was successful.
To test snappy,
$ (start your Python interpreter)
Then try the following code:
from snappy import ProductIO
p = ProductIO.readProduct('snappy/testdata/MER_FRS_L1B_SUBSET.dim')
This approach only works if the current working directory is in the
<snappy-dir>. To generally make use of snappy you need to do one of the following configuration steps.
To effectively use the SNAP Python API from Python, the
snappy module must be detectable by your Python interpreter. There are a number of ways to achieve this.
- To make
snappy permanently accessible, you could install it into your Python installation. On the command line (shell, terminal window on Unixes,
cmd on Windows), type
$ cd <snappy-dir>/snappyThis might require root privileges on Unix systems and results in a snappy folder in
$ <python-exe> setup.py install
- If you encounter any problems with this approach, you can also try to copy the
<snappy-dir>/snappy directory directly into the site-packages directory of your Python installation.
- Or you could also temporarily or permanently set your
PYTHONPATH environment variable:
export PYTHONPATH=$PYTHONPATH:<snappy-dir> (on Unix OS)
(on Windows OS)
- Finally, you could also append
<snappy-dir> to the
sys.path variable in your Python code before importing
sys.path.append('<snappy-dir>') # or sys.path.insert(1, '<snappy-dir>')
- In case you seek for a generic solution without needing to set <snappy-dir> you may automatically find snappy through the 'USERPROFILE' environment variable. Note that this solution requires snappy to be located at the value of 'USERPROFILE':
snappy_envar = 'USERPROFILE'
envs = os.environ
if not snappy_envar in envs.keys():
raise Exception('Can’t find snappy')
snappy_dir = os.path.join(envs.get(snappy_envar), '.snap', 'snap-python')
Change the Memory Settings
<snappy-dir> a file named
snappy.ini is located. here you can change how much memory snappy can use.
Change the line from
# java_max_mem: 4G
This means that snappy can use 6GB of your RAM. A recommended value is 70%-80% of the available RAM in your system.