-
Notifications
You must be signed in to change notification settings - Fork 0
/
05_execute_sen2cor.sh
executable file
·61 lines (52 loc) · 2.19 KB
/
05_execute_sen2cor.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
#
# script to run Sen2Cor (Sentinel-2 atmospheric correction)
# on each L1C realization drawn from the radiometric uncertainty
# modelling approach.
# The resulting L2A data is stored in the same directory as the
# input L1C datasets, i.e., in the single scenario folders.
#
# NOTE: To speed things up, it might be useful to run several
# instances of Sen2Cor in parallel. In this case, the variable
# $unc_scenarios (L#28) might have when the scenarios are located
# at different locations on the file system.
#
# Requires Sen2Cor (atmospheric correction and scene classification software).
# In our case, version 2.09.00 is used.
# Make sure that the L2A_Bashrc file can be found and sourced! We placed it
# in the ../bin directory but other locations (usually in your home directory) are
# possible as well. In this case replace the path in line 29 of this script.
#
# USER INPUT
# define directory where Sen2Cor is installed to
sen2cor_install_dir="/home/graflu/Downloads/Sen2Cor-02.09.00-Linux64"
source "$sen2cor_install_dir"/L2A_Bashrc
# define directory where the L1C realizations are located
unc_scenarios="../../S2A_MSIL1C_RUT-Scenarios"
cd "$unc_scenarios"
IFS=""
# find all sub-directories (each scene is a sub-directory without the .SAFE of the original dataset)
mapfile -t scenario_list < <( find ${unc_scenarios} -maxdepth 1 -mindepth 1 -type d -printf '%f\n' )
# loop over single scenes
for unc_dir in ${scenario_list[@]}; do
# check if directory starts with S2
if [[ "$unc_dir" == S2* ]]
then
# find the scenarios of each scene (each scenario run is a sub-directory labelled starting from
# 1, 2, ..., n_scenarios)
mapfile -t dirlist < <( find ${unc_scenarios}/${unc_dir} -maxdepth 2 -mindepth 2 -type d -printf '%f\n' )
# loop over scenarios
counter=1
for dir in ${dirlist[@]}; do
if [[ "$dir" == S2*_MSIL1C_* ]]
then
scenario="${unc_dir}"/"${counter}"/"${dir}"
output_dir="${unc_dir}"/"${counter}"
counter=$((counter+1))
# call Sen2Cor (L2A_Process must be located in $PATH or provide full path to executable)
L2A_process --resolution 10 --output_dir "${output_dir}" "${scenario}"
echo Processed "${scenario}"
fi
done
fi
done