How to use Sen2Cor in a Workflows application


#1

The SENTINEL 2 Level 2A prototype processor (Sen2Cor) processes Top-Of-Atmosphere (TOA) Level-1C ortho-image reflectance products, to generate Level-2A Bottom-Of-Atmosphere (BOA) corrected reflectance products, alongside with an Aerosol Optical Thickness (AOT) map, a Water Vapour (WV) map and a Scene Classification (SC) map with Quality Indicators for cloud and snow probabilities.

There are a few steps to follow to use Sen2Cor in a Workflows application:

  1. Install the Python miniconda and its dependencies
    
  2. Install the Sen2Cor conda package
    
  3. Configure the environment variables
    
  4. Test the installation
    
  5. Run Sen2Cor 
    

Installing miniconda and dependencies

miniconda is a free Python distribution that includes a minimal set of Python packages.

To install miniconda, run the simple step below on your Sandbox shell:

sudo yum install -y miniconda openjpeg2

Installing Sen2Cor conda package

Conda is a cross-platform package manager and environment manager program that installs, runs, and updates packages and their dependencies. It is included in miniconda installed in the previous step.

To install Sen2Cor conda package, run the simple step below on your Sandbox shell:

sudo conda install -y sen2cor

The Sen2Cor L2A_Process binary is found in /opt/anaconda/bin/L2A_Process

Configuring the environment

Sen2Cor needs the variable below for executing the L2A_Process application:

export SEN2COR_BIN=/opt/anaconda/lib/python2.7/site-packages/sen2cor
export GDAL_DATA=/opt/anaconda/share/gdal
export PATH=/opt/anaconda/bin/:$PATH
export SEN2COR_HOME=$TMPDIR/sen2cor/

At runtime, in the application executable (run), create a folder to host the Sen2Cor configuration file:

mkdir -p $SEN2COR_HOME/cfg

Copy the configuration file in the created folder:

cp $SEN2COR_BIN/cfg/L2A_GIPP.xml $SEN2COR_HOME/cfg/
cp $SEN2COR_BIN/cfg/L2A_CAL_AC_GIPP.xml $SEN2COR_HOME/cfg/
cp $SEN2COR_BIN/cfg/L2A_CAL_SC_GIPP.xml $SEN2COR_HOME/cfg/

Test the installation

From the Developer Cloud Sandbox shell, type:

L2A_Process --help

If all steps above were correctly ran, the shell console will display

Sentinel-2 Level 2A Prototype Processor (Sen2Cor). Version: 2.2.1, created:
2016.04.29, supporting Level-1C product version: 13.1.

positional arguments:
 directory Directory where the Level-1C input files are located

optional arguments:
 -h, --help show this help message and exit
 --resolution {10,20,60}
 Target resolution, can be 10, 20 or 60m. If omitted,
 all resolutions will be processed
 --sc_only Performs only the scene classification at 60 or 20m
 resolution
 --cr_only Performs only the creation of the L2A product tree, no
 processing
 --refresh Performs a refresh of the persistent configuration
 before start
 --GIP_L2A GIP_L2A Select the user GIPP
 --GIP_L2A_SC GIP_L2A_SC
 Select the scene classification GIPP
 --GIP_L2A_AC GIP_L2A_AC
 Select the atmospheric correction GIPP

Running Sen2Cor out of the application executable (run)

Adapt the runtime environment configuration with:

export TMPDIR=/tmp
export SEN2COR_BIN=/opt/anaconda/lib/python2.7/site-packages/sen2cor
export GDAL_DATA=/opt/anaconda/share/gdal
export PATH=/opt/anaconda/bin/:$PATH
export SEN2COR_HOME=$TMPDIR/sen2cor/
mkdir -p $SEN2COR_HOME/cfg
cp $SEN2COR_BIN/cfg/L2A_GIPP.xml $SEN2COR_HOME/cfg/
cp $SEN2COR_BIN/cfg/L2A_CAL_AC_GIPP.xml $SEN2COR_HOME/cfg/
cp $SEN2COR_BIN/cfg/L2A_CAL_SC_GIPP.xml $SEN2COR_HOME/cfg/

Download a Sentinel-2 product and run L2A_Process:

ciop-copy -z s3://eo-samples/S2A_OPER_PRD_MSIL1C_PDMC_20160212T125437_R061_V20160212T035042_20160212T035042.zip
unzip S2A_OPER_PRD_MSIL1C_PDMC_20160212T125437_R061_V20160212T035042_20160212T035042.zip
L2A_Process S2A_OPER_PRD_MSIL1C_PDMC_20160212T125437_R061_V20160212T035042_20160212T035042.SAFE

Wait for the completion of the process. Enjoy!