In this tutorial, we will learn how we can set up a development environment for Snappy. Snappy is the python interface for accessing the JAVA API of SNAP. SNAP can be used to process the Sentinel series of sensors. I prefer to have a separate environment for the Snappy so I can keep it clean and that it does not clutter with my base environment. Snappy has two methods of implementation namely CPython and Jython approach. I am using CPython which is the standard approach and that works for most of the use cases. However, if you are interested in more advanced stuff like using the SNAP API for plugin development or the user interface development, you can use the Jython approach.
- Make sure you have SNAP installed in your machine. You can download SNAP from here.
- I will be using anaconda for my python environment. Download Anaconda from here. Make sure that you have the same bit of SNAP and Python, i.e. if you downloaded and installed 64-bit python, you should download and install 64-bit SNAP, and 32-bit otherwise.
- Next, add Community package management system. start “Anaconda Prompt” with admin privileges and then
conda config --prepend channels conda-forge
- Create a new anaconda environment. I am using Python 2.7 for this. As of August 2019, SNAP supports Python version 2.7, 3.3 and 3.4.
conda create -n snap python=2.7 conda activate snap
where snap is the name of the environment, and the python version is 2.7. Then we activate the environment by using its name snap. This will create a new environment inside your Anaconda directory. In my case under
- Next, cd into your snap installation directory. And further to
bin. Then run the following command. Here
C:/Anaconda3/envs/snap/python.exeis the virtual environment python executable and
C:/Anaconda3/envs/snap/Libis the directory where snappy will be installed. I prefer this way because then I can directly use the virtual environment for debugging purpose which has snappy included in it.
cd C:/Program Files/snap/bin snappy-conf C:/Anaconda3/envs/snap/python.exe C:/Anaconda3/envs/snap/Lib
If everything is successful, you should see the message as in the image below.
- You can configure the snappy to use the RAM of your machine. Go to the snappy installation directory from 5. and look for
snappy.inifile. Usually, 70-80% of your total RAM is recommended. The
java_max_memis the one that needs to be changed.
[DEFAULT] snap_home = C:\Program Files\snap java_max_mem: 5G # snap_start_engine: False # java_class_path: ./target/classes # java_library_path: ./lib # java_options: -Djava.awt.headless=false # debug: False
- You are ready to do the development with snappy. To confirm that everything is working correctly, activate your python environment, cd into your snappy directory from 5. and then type
pythonand the following code after.
from snappy import ProductIO file = ProductIO.readProduct('snappy/testdata/MER_FRS_L1B_SUBSET.dim') print(list(file.getBandNames()))
Refer to the image below.
- (Optional) If you are eclipse or any other IDE for debugging purpose, you can easily use only this virtual environment and just do
import snappyto make it work.