Tutorials/Post - Remote Sensing, GIS, Earth System, Geo-AI/ML

Setup development environment for SNAP

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.

  1. Make sure you have SNAP installed in your machine. You can download SNAP from here.
  2. 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.
  3. Next, add Community package management system. start “Anaconda Prompt” with admin privileges and then
    conda config --prepend channels conda-forge
    
  4. 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 C:\Anaconda3\envs\snap

  5. Next, cd into your snap installation directory. And further to bin. Then run the following command. Here C:/Anaconda3/envs/snap/python.exe is the virtual environment python executable and C:/Anaconda3/envs/snap/Lib is 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.installation

  6. You can configure the snappy to use the RAM of your machine. Go to the snappy installation directory from 5. and look for snappy.ini file. Usually, 70-80% of your total RAM is recommended. The java_max_mem is 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
    
  7. 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 python and 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.snappy-confirmation

  8. (Optional) If you are eclipse or any other IDE for debugging purpose, you can easily use only this virtual environment and just do import snappy to make it work.

Previous

Removing the whitespace from the GeoJSON file

Next

Processing Sentinel-1 SAR images using Snappy – SNAP Python Interface

2 Comments

  1. Puneeth Shankar

    First of all thanks for something other than the STEP FORUM. Coming to setting up snappy; how long did step5 take? Mine runs endlessly and never returns program control. Can be seen below

    https://geospocworld-my.sharepoint.com/:i:/g/personal/puneeth_geospoc_com/EYYQHk7VSKVLoYjd9kKJfxsBh_TyZrrmXkMZwUP3rl5cYQ?e=0YHLYI

    • biplovbhandari

      It should not take much time. The control never returned for my case, however the message of success was issued. Please check you have same bit program for your python environment as you have for SNAP. Maybe worth trying again! Good luck.

Leave a Reply

Powered by WordPress & Theme by Anders Norén