-
Notifications
You must be signed in to change notification settings - Fork 0
/
worsica_atmospheric_correction_service.sh
executable file
·107 lines (103 loc) · 6.18 KB
/
worsica_atmospheric_correction_service.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
source ./worsica_bash_common.sh
function control_c {
echo "[worsica_atmospheric_correction_service.sh] HALT! Caught ctrl+c; Clean up and Exit \n"
if [[ ${SIMULATION_STATE} == *'converting'* ]] ; then
SIMULATION_STATE='error-converting'
fi
#remove imageset to free up the workspace folder
rm -rf ${PATH_TO_PRODUCTS}/${IMAGESET_NAME}.zip
rm -rf ${PATH_TO_PRODUCTS}/${NEW_IMAGESET_NAME}.zip
#remove folder (either .safe or not)
rm -rf ${PATH_TO_PRODUCTS}/${IMAGESET_NAME}*
rm -rf ${PATH_TO_PRODUCTS}/${NEW_IMAGESET_NAME}*
if (dirname $(find . -name MTD_MSIL2A.xml)); then
L2ASAFE_PATH=$(dirname $(find . -name MTD_MSIL2A.xml))
echo "remove ${L2ASAFE_PATH}"
rm -rf ${PATH_TO_PRODUCTS}/${L2ASAFE_PATH}*
else
echo "New .SAFE folder generated by the sen2cor not found"
fi
echo "[worsica_atmospheric_correction_service.sh] ${SERVICE}-user${USER_ID}-roi${ROI_ID}-s${SIMULATION_ID} state: ${SIMULATION_STATE}"
exit 1
}
trap control_c SIGINT
trap control_c SIGTERM
SERVICE=$1
USER_ID=$2
ROI_ID=$3
SIMULATION_ID=$4
SIMULATION_STATE=$5
SIMULATION_NAME=$6
IMAGESET_NAME=$7 #L1C
NEW_IMAGESET_NAME=$8 #L2A
PATH_TO_PRODUCTS=$(get_path_to_products ${SERVICE} ${USER_ID} ${ROI_ID} ${SIMULATION_ID})
WORSICA_FOLDER_PATH=$(pwd)
#[Converting]
if [[ ${SIMULATION_STATE} == *'downloaded'* ]] || [[ ${SIMULATION_STATE} == *'error-converting'* ]] ; then
create_folder ${SERVICE} ${USER_ID} ${ROI_ID} ${SIMULATION_ID} ${SIMULATION_STATE}
echo "[worsica_atmospheric_correction_service.sh] [Converting] ${SERVICE}-user${USER_ID}-roi${ROI_ID}-s${SIMULATION_ID} state: converting"
echo "==========================Converting=============================="
#echo "[worsica_atmospheric_correction_service.sh] [Converting] Download content from the nextcloud ${NEXTCLOUD_REMOTE_PATH}/${ROI_SIMULATION_FOLDER}"
#download_folder ${PATH_TO_PRODUCTS} ${NEXTCLOUD_PATH_TO_PRODUCTS}
#pull_processing ${SERVICE} ${USER_ID} ${ROI_ID} ${SIMULATION_ID} ${IMAGESET_NAME}
pull_imageset ${SERVICE} ${USER_ID} ${ROI_ID} ${SIMULATION_ID} ${IMAGESET_NAME}
pull_imageset ${SERVICE} ${USER_ID} ${ROI_ID} ${SIMULATION_ID} ${NEW_IMAGESET_NAME}
cd ${PATH_TO_PRODUCTS}
if ([ -f ${NEW_IMAGESET_NAME}.zip ]); then
echo "[worsica_atmospheric_correction_service.sh] [Converting] File exists, skip conversion!"
echo "[worsica_atmospheric_correction_service.sh] [Converting] ${SERVICE}-user${USER_ID}-roi${ROI_ID}-s${SIMULATION_ID} state: converted"
rm -rf ${PATH_TO_PRODUCTS}/${IMAGESET_NAME}.zip
rm -rf ${PATH_TO_PRODUCTS}/${NEW_IMAGESET_NAME}.zip
exit 0
else
echo "[worsica_atmospheric_correction_service.sh] [Converting] File does not exist. Start!"
unzip ${IMAGESET_NAME}.zip
DATASTRIP_PATH=$(dirname $(find ${IMAGESET_NAME}.SAFE/DATASTRIP -name MTD_DS.xml))
#echo ${DATASTRIP_PATH}
#create qi data folder to be able to run the conversion
mkdir ${PATH_TO_PRODUCTS}/${NEW_IMAGESET_NAME}.SAFE
if (cd ${PATH_TO_PRODUCTS} && ([ -d ${DATASTRIP_PATH}/QI_DATA ] || mkdir ${DATASTRIP_PATH}/QI_DATA) && L2A_Process ${IMAGESET_NAME}.SAFE --output_dir ${PATH_TO_PRODUCTS}/${NEW_IMAGESET_NAME}.SAFE); then
rm -rf ${PATH_TO_PRODUCTS}/${IMAGESET_NAME}.zip
#/NEW_IMAGESET_NAME/[N9999_FOLDER]
#/S2B_MSIL2A_20211006T112119_N0301_R037_T29SNC_20211006T122732.SAFE/S2B_MSIL2A_20210916T112109_N9999_R037_T29SNC_20211007T143412.SAFE
if (cd ${PATH_TO_PRODUCTS}/${NEW_IMAGESET_NAME}.SAFE && dirname $(find . -name MTD_MSIL2A.xml)); then
L2ASAFE_PATH=$(cd ${PATH_TO_PRODUCTS}/${NEW_IMAGESET_NAME}.SAFE && dirname $(find . -name MTD_MSIL2A.xml)) #get sen2cor generated folder name
#dirname is S2B_MSIL2A_20210916T112109_N9999_R037_T29SNC_20211007T143412.SAFE
echo "[worsica_atmospheric_correction_service.sh] [Converting] Go to ${L2ASAFE_PATH}"
cd ${PATH_TO_PRODUCTS}/${NEW_IMAGESET_NAME}.SAFE/${L2ASAFE_PATH}
echo "[worsica_atmospheric_correction_service.sh] [Converting] Move contents from ${L2ASAFE_PATH} to top folder ${NEW_IMAGESET_NAME}.SAFE"
mv * ../ && cd ${PATH_TO_PRODUCTS}/${NEW_IMAGESET_NAME}.SAFE
echo "[worsica_atmospheric_correction_service.sh] [Converting] ...and remove it"
rm -rf ${PATH_TO_PRODUCTS}/${NEW_IMAGESET_NAME}.SAFE/${L2ASAFE_PATH}
cd ${PATH_TO_PRODUCTS}
echo "[worsica_atmospheric_correction_service.sh] [Converting] ZIP ./${NEW_IMAGESET_NAME}.SAFE"
zip -r ${PATH_TO_PRODUCTS}/${NEW_IMAGESET_NAME}.zip ${NEW_IMAGESET_NAME}.SAFE
push_imageset ${SERVICE} ${USER_ID} ${ROI_ID} ${SIMULATION_ID} ${NEW_IMAGESET_NAME}
#remove folder (either .safe or not)
rm -rf ${PATH_TO_PRODUCTS}/${IMAGESET_NAME}*
rm -rf ${PATH_TO_PRODUCTS}/${NEW_IMAGESET_NAME}*
echo "[worsica_atmospheric_correction_service.sh] [Converting] ${SERVICE}-user${USER_ID}-roi${ROI_ID}-s${SIMULATION_ID} state: converted"
exit 0
else
echo "New .SAFE folder generated by the sen2cor not found"
echo "[worsica_atmospheric_correction_service.sh] [Converting] ${SERVICE}-user${USER_ID}-roi${ROI_ID}-s${SIMULATION_ID} state: error-converting"
exit 1
fi
else
#remove imageset to free up the workspace folder
rm -rf ${PATH_TO_PRODUCTS}/${IMAGESET_NAME}.zip
rm -rf ${PATH_TO_PRODUCTS}/${NEW_IMAGESET_NAME}.zip
#remove folder (either .safe or not)
rm -rf ${PATH_TO_PRODUCTS}/${IMAGESET_NAME}*
rm -rf ${PATH_TO_PRODUCTS}/${NEW_IMAGESET_NAME}*
if (dirname $(find . -name MTD_MSIL2A.xml)); then
L2ASAFE_PATH=$(dirname $(find . -name MTD_MSIL2A.xml))
rm -rf ${PATH_TO_PRODUCTS}/${L2ASAFE_PATH}*
else
echo "New .SAFE folder generated by the sen2cor not found"
fi
echo "[worsica_atmospheric_correction_service.sh] [Converting] ${SERVICE}-user${USER_ID}-roi${ROI_ID}-s${SIMULATION_ID} state: error-converting"
exit 1
fi
fi
fi