- PROVA CAMBIAMENTO
- An R toolbox to find, download and preprocess Sentinel-2 data
sen2r is an R library which helps to download and preprocess Sentinel-2 optical images. The purpose of the functions contained in the library is to provide the instruments required to easily perform (and eventually automate) all the steps necessary to build a complete Sentinel-2 processing chain, without the need of any manual intervention nor the needing to manually integrate any external tool.
In particular, sen2r allows to:
- retrieve the list of available products on a selected area (which can be provided by specifying a bounding box, by loading a vector file or by drawing it on a map) in a given time window;
- download the required SAFE Level-1C products, or retrieve the required SAFE Level-2A products by downloading them (if available) or downloading the corresponding Level-1C and correcting them with sen2cor;
- obtain the required products (Top of Atmosphere radiances, Bottom of Atmosphere reflectances, Surface Classification Maps, True Colour Images) clipped on the specified area (adjacent tiles belonging to the same frame are merged);
- mask cloudy pixels (using the Surface Classification Map as masking layer);
- computing spectral indices.
Setting the execution of this processing chain is particularly easy using the sen2r GUI, which allows to set the parameters, to directly launch the main function or to save them in a JSON file which can be used to launch the processing at a later stage.
The possibility to launch the processing with a set of parameters saved in a JSON file (or directly passed as function arguments) makes easy to build scripts to automatically update an archive of Sentinel-2 products. Specific processing operations (i.e. applying sen2cor on Level-1c SAFE products, merging adjacent tiles, computing spectral indices from existing products) can also be performed using intermediate functions (see usage).
This package is under construction (current version is pre-release 0.3.3). Please refer to the crontab of release 0.4.0 to know which implementations should already be performed.
sen2r is supported over Linux and Windows operating systems; the support for Mac will be added soon.
The package can be installed from GitHub with the R package devtools. To do it:
-
install the package devtools, if missing:
install.packages("devtools")
-
load it and install sen2r:
library(devtools) install_github("ranghetti/sen2r")
This will install the R package along with its R dependences, containing all the functions necessary to preprocess data.
To run the functions correctly, some external dependences are required:
- GDAL (with support for JP2OpenJPEG format): this is a mandatory dependency, needed for all the processing operations and to retrieve metadata from SAFE products;
- sen2cor is used to perform atmospheric correction of Sentinel-2 Level-1C products: it is required by the package, unless you choose not to correct products locally (using only Level-1C – TOA products or dowloading directly Level-2A products).
- Wget is the downloader used by the package; it is required to work online.
- aria2 is an alternative downloader which can be used to faster the download of SAFE archives; it can be optionally installed and used.
These dependences can be graphically checked launching the function
library(sen2r)
check_sen2r_deps()
This function opens a GUI which help to check that they are satisfied; if some of them are missing, follow the instructions provided by the GUI to install them (on Windows, the GUI allows to install them directly).
The simplest way to use sen2r is to execute it in interactive mode:
library(sen2r)
sen2r()
this opens a GUI which allows to set the required processing parameters, and then launches the main function.
Alternatively, [`sen2r()`](reference/sen2r.md) can be launched with a list of parameters (created with [`s2_gui()`](reference/s2_gui.md)) or passing manually the parameters as arguments of the function (see [the documentation of the function](reference/sen2r.md) for further details).Other specific functions can be used to run single steps separately:
s2_list()
to retrieve the list of available Sentinel-2 products basing on input parameters;s2_download()
to download Sentinel-2 products;sen2cor()
to correct level-1C products using sen2cor;s2_translate()
to convert Sentinel-2 products from SAFE format to a format managed by GDAL;s2_merge()
to merge Sentinel-2 tiles which have the same date and orbit;gdal_warp()
to clip, reproject and warp raster files (this is a wrapper to call gdal_translate or gdalwarp basing on input parameters);s2_mask()
to apply a cloud mask to Sentinel-2 products;s2_calcindices()
to compute maps of spectral indices from Sentinel-2 Surface Reflectance multiband raster files;s2_thumbnails()
to generate RGB thumbnails (JPEG or PNG) of the products.
sen2r is being developed by Luigi Ranghetti and Lorenzo Busetto (IREA-CNR), and it is released under the GNU General Public License version 3 (GPL‑3).
The sen2r logo, partially derived from the R logo, is released under the Creative Commons Attribution-ShareAlike 4.0 International license (CC-BY-SA 4.0).
To cite this library, please use the following entry:
Ranghetti, L. and Busetto, L. (2018). sen2r: an R toolbox to find, download and preprocess Sentinel-2 data. R package version 0.3.3. DOI: 10.5281/zenodo.1240384.
@Manual{sen2r,
title = {sen2r: an R toolbox to find, download and preprocess Sentinel-2 data},
author = {Luigi Ranghetti and Lorenzo Busetto},
year = {2018},
note = {R package version 0.3.3},
doi = {10.5281/zenodo.1240384},
url = {https://ranghetti.github.io/sen2r},
}