-
Notifications
You must be signed in to change notification settings - Fork 0
/
Intarsis_04a_merge
executable file
·160 lines (138 loc) · 5.03 KB
/
Intarsis_04a_merge
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
################################################
# Intarsis_04a_merge: #
# This program merges several swaths from the #
# same track together. This is a optional step #
# Joaquin Escayo [email protected] November 2019 #
################################################
if [ -f "intarsis.config" ]; then
MERGE=$(grep merge_swaths intarsis.config | awk '{print $2}')
SWATHS=$(grep swaths_to_merge intarsis.config | awk '{print $2}' | tr '[:lower:]' '[:upper:]')
MM=$(grep master_slc intarsis.config | awk '{print $2}')
fi
if ! $MERGE; then
echo "Merge swaths is disabled in intarsis.config, exitting"
exit
fi
if [[ ! -z $1 ]]; then
SWATHS=($(echo $1 | sed 's/,/\ /g')) # Converting into an array the SWATHS variable
SWATHS_config=false
else
SWATHS=($(echo $SWATHS | sed 's/,/\ /g')) # Converting into an array the SWATHS variable
SWATHS_config=true
fi
# Sorting the SWATHS array
IFS=$'\n' MERGE_SWATHS=($(sort <<<"${SWATHS[*]}"))
unset IFS
if [[ ${SWATHS[*]} == "F1 F2 F3" ]] || [[ ${SWATHS[*]} == "F1 F2" ]] || [[ ${SWATHS[*]} == "F2 F3" ]]; then
VALID=true
else
echo "Invalid Swaths detected or bad formating, only consecutive arrays are posible to merge"
exit
fi
if [ ${#MERGE_SWATHS[@]} -lt 2 ]; then
echo "There is not enough swaths to merge. Please check configuration"
exit
fi
if [ -z $MM ]; then
echo "Error on Master Master image, please check intarsis.config"
exit
fi
# Intarsis root folder check
if [ ! -f ".intarsis_folder" ]; then
echo "You must run Intarsis_04a_merge inside a Intarsis root folder"
echo "Run Intarsis_01_file_preparation and other routines first"
exit
fi
# Intarsis step 02 check
for i in $SWATHS; do
if [ ! -f ".intarsis_step03_$i" ]; then
echo "Interferograms from swath $i are not present"
echo "You must run Intarsis_03_interferograms $i first"
exit
fi
done
echo "###################################################################"
echo "Intarsis swath merging parameters:"
echo "Merging ${#MERGE_SWATHS[@]} swaths: ${MERGE_SWATHS[*]}"
if $SWATHS_config; then
echo "Imported from intarsis.config"
else
echo "Configured via command-line"
fi
echo "Master-Master SLC date: $MM (Imported from intarsis.config)"
echo "###################################################################"
echo "$(date "+%d/%m/%y %H:%M") - Starting Swath Merging ${MERGE_SWATHS[*]}" >> intarsis.log
##############################################
# Data check (folder,swaths, intf, etc) #
##############################################
# Check that the interograms are ready for all swaths
for i in ${MERGE_SWATHS[@]}; do
if [ ! -d $i/intf_all ]; then
echo "Missing interferogram folder for swath $i"
exit
else
echo "Found interferogram folder for $i"
fi
done
# Check there are the same interferograms in every swath
for i in $(ls -d ${MERGE_SWATHS[0]}/intf_all/2*); do
INTF=${i##*/}
for i in ${MERGE_SWATHS[@]}; do
if [ ! -d "$i/intf_all/$INTF" ]; then
echo "The interferograms are not the same across all the swaths. Please check $INTF"
exit
fi
done
done
#############################################
# Creation of merge_list file #
#############################################
if [ -d "merged" ]; then
echo "Directory merged is present"
read -p "Do you want to overwrite it? Yes/No" -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf merged &> /dev/null
mkdir merged
else
echo "Check merged directory and try again"
exit
fi
else
mkdir merged
fi
for i in $(ls -d ${MERGE_SWATHS[0]}/intf_all/2*); do
INTF=${i##*/}
MASTER=$(echo $INTF | cut -c1-7)
SLAVE=$(echo $INTF | cut -c9- )
MASTER_FILE=$(cat ${MERGE_SWATHS[0]}/baseline_table.dat | grep -F $MASTER"." | awk '{print $1}' | cut -c1-16)
SLAVE_FILE=$(cat ${MERGE_SWATHS[0]}/baseline_table.dat | grep -F $SLAVE"." | awk '{print $1}' | cut -c1-16)
counter=0
unset line # clean line var
for swath in ${MERGE_SWATHS[@]}; do
line[$counter]=$(echo "../"$swath"/intf_all/"$INTF"/:"$MASTER_FILE"$swath".PRM":"$SLAVE_FILE$swath".PRM")
counter=$((counter+1))
done
# Generating the list
echo ${line[*]} | sed 's/\ ../,../g' >> merged/merge_tmp
done
# Copy baseline_line.dat of the first Swath to merge
cp ${MERGE_SWATHS[0]}/baseline_table.dat merged/ &> /dev/null
# Put first lines that contain the MM SLC
grep $MM merged/merge_tmp | sed -n '1!G;h;$p' > merged/merge_MM # Getting lines with the MM and reverse the list
grep -v $MM merged/merge_tmp > merged/merge_rest # getting lines without MM
cat merged/merge_MM > merged/merge_list
cat merged/merge_rest >> merged/merge_list
rm merged/merge_MM merged/merge_rest merged_tmp # cleanup of temporal files
# Copying batch_tops.config from first swath
cp ${MERGE_SWATHS[0]}/batch_tops.config merged/
# Linking dem to this
ln -s ../topo/dem.grd merged/
# Starting the merge procedure
cd merged
merge_batch.csh merge_list batch_tops.config
# Update log & create control files
cd ..
touch .intarsis_step04a &> /dev/null # Intarsis step control file
echo "$(date "+%d/%m/%y %H:%M") - Finished Merge Swaths ${MERGE_SWATHS[*]}" >> intarsis.log