Unit 19 - Sentinel downloader

There are plenty of libraries or tools which enable downloading Sentinel products from Copernicus Open Access Hub.

One of such tool will be introduced in this unit. For GRASS GIS there is available i.sentinel Addon extension. It consists of two GRASS modules:

Let’s install this addon by using g.extension and try it out (more about installing addons in Unit 17). Note that i.sentinel.download requires also sentinelsat library to be installed.

pip install sentinelsat
g.extension extension=i.sentinel

Let’s download suitable Sentinel product for you favorite place and perform for simplicity NDVI calculation as described in Unit 05 - Perform computation (implemented as a Python script in Unit 12 - Script tuning).

At first we need to define our area of interest. In our case AOI region will be downloaded from OpenStreetMap database, similarly as we did for study area in Unit 02 - First steps. Go to http://overpass-turbo.eu, enter query (Run) similar as below and download data directly (Export ‣ Data ‣ Download as GeoJSON).

/*added by auto repair*/
/*end of auto repair*/

Create a new GRASS location in UTM zone of your region. In our case UTM zone 33N EPSG:25833), see Unit 24 for details.


If you are not scared of terminal, you can easily create a new location from command line. In example below a new location myregion-sentinel is created in /opt/grassdata directory.

grass -c EPSG:32633 /opt/grassdata/myregion-sentinel

GRASS will start with PERMANENT as current mapset.

Enter new GRASS session and import our area of interest by v.import (see notes about import in Unit 03 - Data Management).

v.import input=export.geojson out=aoi

Now we can search for suitable Sentinel products. We will prefer Sentinel-2 L2A products, we don’t want to compute atmospheric corrections on our own at this moment. Let’s search for latest available product by i.sentinel.download. At first with -l flag given, just to print results, download procedure will be performed later. In order to search and download Sentinel products, you have to create an user account in Copernicus Open Access Hub, see manual page of i.sentinel.download module for details. Create a new file sentinel.txt containing two lines with your username and password.

i.sentinel.download -l map=aoi producttype=S2MSI2Ap settings=sentinel.txt
2 Sentinel product(s) found
4cfab7d-2a1a-4d60-b8a7-c5e9d74f1bee 2018-01-14T10:13:49Z  5% S2MSI2Ap
27ad33ac-d3b4-4488-ad25-d2abec035f5d 2018-01-06T10:04:01Z 26% S2MSI2Ap

By default the module returns products for last 60 days. Let’s change search period by start and end options. To be sure that our AOI is fully covered by a Sentinel product we also set area_relation option. We can also limit products by clouds coverage percentage threshold.

i.sentinel.download -l map=aoi producttype=S2MSI2Ap settings=sentinel.txt \
start=2017-01-01 end=2018-02-05 area_relation=Contains clouds=10
1 Sentinel product(s) found
a4cfab7d-2a1a-4d60-b8a7-c5e9d74f1bee 2018-01-14T10:13:49Z  5% S2MSI2Ap


If more products have been found you can limit search by limit option.

Let’s download desired product(s). Just remove -l flag and add output options in order to define path to output directory where data should be saved.

i.sentinel.download map=aoi producttype=S2MSI2Ap settings=sentinel.txt \
start=2017-01-01 end=2018-02-05 area_relation=Contains clouds=10 limit=1 output=/opt/geodata/sentinel

When download is successfully finished we can import data by i.sentinel.import. The command will import all Sentinel bands from input directory recursively. Sentinel bands to be imported can be optionally filtered by pattern option. In example below only 4th and 8th bands in 10m resolution will be imported. By default input data are imported into GRASS format, alternatively data can be linked (see Unit 03) if -l is given. It is also useful to import cloud mask features by -c flag.

i.sentinel.import -l -c input=/opt/geodata/sentinel pattern="B0[4|8]_10m"


Before importing or linking try to print list of found raster files including projection match. If projection of input data differs from current location consider reprojection (-r) or creating a new location for import.

i.sentinel.import -p input=/opt/geodata/sentinel pattern="B0[4|8]_10m"

Now start our NDVI sample script created in Unit 12 - Script tuning, enter input parameters and run.

#.. figure:: ../images/units/20/run-script.png

Run NDVI script to compute classes.
#.. figure:: ../images/units/20/ndvi-classes-ltm.png

Resultant NDVI classes for AOI.