Today we start our quest in the world of Space Imagery. Through the Sentinels Scientific Data Hub, the European Space Agency offers the citizens a mean to access the Open Data from the European Copernicus Earth observation program.

As part of this program, 4 satellites have reached orbit since 2014:

  • Sentinel 1-A and Sentinel 1-B, in charge of providing radar imagery of land and oceans ;
  • Sentinel 2-A, in charge of providing multispectral imagery for land monitoring ;
  • Sentinel 3-A, in charge of providing data on the topography and temperature of oceans and land.
The Copernicus Sentinel series of satellites (Credit: Airbus D&S)

The Copernicus Sentinel series of satellites (Credit: Airbus D&S)

The data hub already allows the public to download data from the Sentinel 1 and Sentinel 2 satellites, and the Sentinel 3 data should be available in the future. Through this portal, it is possible to select and download data according to different criteria, selecting for instance the target area and target dates.

However, the downloaded data does not simply consist in standard image files that could be processed using familiar software, but rather in a set of large files (several gigabytes is a common order of magnitude) that requires particular image processing software. Lucky we are! Brockmann Consult, Array Systems Computing and C-S developed SNAP, the Sentinel Application Platform, a set of toolboxes that is freely accessible and relatively easy to set up on any system (Windows, Mac OS, Linux).

A number of blogs (here, here and here for example) already provide tutorials for getting started with downloading from the data hub and processing the Sentinel data through this toolboxes. Our approach in this series of articles will be to make use of the SNAP API in order to develop processing scripts using Python. Although the API itself is in Java, we will be able to rely on a Python module named snappy that will give us access to the SNAP toolboxes in a Pythonistic fashion.

This tutorial will focus on the installation of snappy under a Linux operating system, which is very convenient when you want to develop in Python. Installing the SNAP toolboxes is easily done using the files available here. Under Linux, simply execute the Sentinel Toolboxes script that you just downloaded (be sure not to execute as root):

chmod +x esa-snap_sentinel_unix_3_0.sh ./esa-snap_sentinel_unix_3_0.sh

The installation of snappy described below has been conducted under Python 3.4 but it should work properly with most version after the 2.7.

In order to make it easier to manage the different Python modules and packages you need to use in your different projects, we recommend the installation of virtualenv and virtualenvwrapper that allow you to have independent sets of packages and modules without polluting your global Python installation. You can find tutorials on how to install them under Linux here. You will first create the virtual environment using the wrapper:

mkvirtualenv sentinel workon sentinel 

Since the SNAP API is originally written under Java and we want to work in Python, we will rely on the jpy package (Java-Python bridge). You need to be sure that the Java JDK is installed on your system and that proper environment variable is set by executing this line (the path needs to be adapted depending on your Java JDK setup):

export JDK_HOME=/usr/lib/jvm/java-8-openjdk/

The jpy package version available in the Python Package Index (PyPI) is the 0.7.5 while snappy requires at least the version 0.8. We will thus need to install it manually following the instructions below and considering that the Sentinel Toolboxes (SNAP) have been installed in the Home folder of the user:

git clone https://github.com/bcdev/jpy.git cd jpy python setup.py bdist_wheel mkdir /home/user/.snap/snap-python mkdir /home/user/.snap/snap-python/snappy cp dist/jpy-0.9_SNAPSHOT-cp35-cp35m-linux_x86_64.whl "/home/user/.snap/snap-python/snappy" cd /home/user/snap/bin ./snappy-conf /home/user/.virtualenvs/sentinel/bin/python cp -R /home/user/.snap/snap-python/snappy /home/user/.virtualenvs/sentinel/lib/python3.5/site-packages/

If you did not use a virtual environment, you need to provide the path to your python interpreter which can be found using the command  which python .

We now simply want to confirm that our setup is correct and that we have effectively access to the SNAP API under Python. We first need to install the numpy package for scientific computing in our virtual environment:

workon sentinel pip install numpy 

Next we will make a first attempt at processing a sample image provided with the SNAP toolboxes. To do so, we first need to enter the Python console by simply issuing a  python command in the shell. Finally, we run the following commands in Python:

from snappy import ProductIO file = '/home/user/.snap/snap-python/snappy/testdata/MER_FRS_L1B_SUBSET.dim' p = ProductIO.readProduct(file) list(p.getBandNames())

Make sure to replace user with your own username and do not worry if you see some warnings appearing when you issue the readProduct command.

If the last command gives you the following output, you’re all set, congratulations!

>>> list(p.getBandNames()) ['radiance_1', 'radiance_2', 'radiance_3', 'radiance_4', 'radiance_5', 'radiance_6', 'radiance_7', 'radiance_8', 'radiance_9', 'radiance_10', 'radiance_11', 'radiance_12', 'radiance_13', 'radiance_14', 'radiance_15', 'l1_flags', 'detector_index']