Unit 20 - Sentinel downloader

There are plenty of libraries or tools which allow downloading Sentinel products.

For GRASS GIS there is the i.sentinel toolbox. It consists of six GRASS addon modules:

The addon can be installed by g.extension or from the main menu Settings ‣ Addons extensions ‣ Install extension from addons.

g.extension extension=i.sentinel
../_images/g-extension1.png

Fig. 106 Install i.sentinel GRASS Addon.

Note

Note that i.sentinel.download requires also sentinelsat to be installed. It can be easily installed from the Console tab by entering the command below.

python3 -m pip install sentinelsat pandas

Important

Copernicus Open Access Hub was closed at the end of October 2023 (source). Copernicus Sentinel data are now available in the Copernicus Data Space Ecosystem (CDSE). Currently, sentinelsat package is not compatible with the new CDSE. See sentinelsat Github repository for details. See also related GRASS issue reported on GitHub.

Switch to jena-region location which was created in Unit 02 - First steps.

Download data

Let’s download suitable Sentinel products for our area of interest (AOI) and perform the NDVI calculation as described in Unit 05 - Raster processing (implemented as a model in Unit 08 - Modeler or as a Python script in Unit 11 - PyGRASS scripting). AOI region is defined by Jena city region created in Unit 03 - Data Management. Sentinel-2 L2A products will be used to avoid computing atmospheric corrections.

Important

Pre-downloaded Sentinel scenes are available in the sample dataset (directory sentinel/2019). Readers can continue with importing sample data.

Let’s search for the latest available product by means of i.sentinel.download. Setting the -l flag, the result will only be printed. The download procedure will be performed later. In order to search and download Sentinel products from the Copernicus Open Access Hub, you have to create an account first. See the manual page of i.sentinel.download module for details. Create a new text file sentinel.txt containing two lines (username and password).

Note

To get username and password you need to register at the Copernicus Open Access Hub, see Register new account page for signing up.

i.sentinel.download -l map=jena_boundary producttype=S2MSI2A settings=sentinel.txt
11 Sentinel product(s) found
37438a05-f795-4e77-b68e-3a3c0ec5f04b ... 2022-01-06T10:23:19Z  4% S2MSI2A 1.08 GB
b4bc9d3b-1e1a-4cfd-bd01-14c21a596e8a ... 2022-02-05T10:21:19Z 64% S2MSI2A 1.03 GB
f2a604a6-8e50-4c62-b98b-22077365df7a ... 2022-01-21T10:23:31Z 65% S2MSI2A 933.01 MB
...

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

i.sentinel.download -l map=jena_boundary producttype=S2MSI2A settings=sentinel.txt \
start=2021-04-01 end=2021-10-01 area_relation=Contains clouds=10
6 Sentinel product(s) found
a844500a-049f-46a3-92de-bcda2c38fc3c ... 2021-05-31T10:15:59Z  2% S2MSI2A 1.09 GB
d5b73db9-0acf-401d-9bf4-a6f199df1119 ... 2021-09-08T10:15:59Z  3% S2MSI2A 1.09 GB
b00d5dfd-9cce-48c6-a011-fd46b85de814 ... 2021-09-03T10:20:21Z  3% S2MSI2A 1.09 GB
...

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

i.sentinel.download map=jena_boundary producttype=S2MSI2A settings=sentinel.txt \
start=2021-04-01 end=2021-10-01 area_relation=Contains clouds=10 \
limit=1 output=geodata/sentinel/2021

Note

Note all products are NOT available online. In this case the module fails with Product a844500a-049f-46a3-92de-bcda2c38fc3c is not online. Triggering retrieval from long term archive. error message. Try to download affected product in the next days.

Import data

Before importing or linking Sentinel data try to print a list of filtered raster files including projection match (second column, 1 for match otherwise 0). If the CRS of input data differs from the current location consider reprojection (-r) or creating a new location for import.

Data will be imported into the GRASS location by means of the i.sentinel.import tool. The command will import all Sentinel bands from input directory recursively. Before importing data let’s check content of the input directory by -p flag. The import procedure will be limited to the 4th and 8th bands in 10m spatial resolution by pattern option.

i.sentinel.import -p input=geodata/sentinel/2019 pattern="20190626T102031_B0[4|8]_10m"
...L2A_T32UPB_A020940_20190626T102028/IMG_DATA/R10m/T32UPB_20190626T102031_B08_10m.jp2 1 (EPSG: 32632)
...L2A_T32UPB_A020940_20190626T102028/IMG_DATA/R10m/T32UPB_20190626T102031_B04_10m.jp2 1 (EPSG: 32632)

By default, input data are imported into GRASS data format. Alternatively, data can be linked if -l is given. It is also useful to import cloud mask vector features by -c flag.

i.sentinel.import -l -c input=geodata/sentinel/2019 pattern="20190626T102031_B0[4|8]_10m"

Note

Cloud mask is computed by i.sentinel.import, the module doesn’t use cloud mask product stored in a SAFE directory.

Todo

Fix i.sentinel.import -c flag to respect pattern parameter.

Now launch the NDVI sample script created in Unit 12 - Script User Interface (ndvi-v4.py) in order to compute NDVI classes (see processing workflow described in Unit 09 - Model tuning).

../_images/run-script1.png

Fig. 107 Run script to compute NDVI classes.

../_images/ndvi-classes.png

Fig. 108 Computed NDVI classes for given AOI.