Skip to content

Commit 8e55b44

Browse files
Fixing spatial subsetting coverage (#66)
The problem of not fully covering subsetted areas is resolved with this PR. The basic idea as expanding the required spatial extends by the resolution of the datset, i.e., 0.25 degree. Reported-by: Hongli Liu <[email protected]> Signed-off-by: Kasra Keshavarz <[email protected]>
1 parent 764fd39 commit 8e55b44

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

scripts/ecmwf-era5/era5_simplified.sh

+28-9
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ if [[ -z $prefix ]]; then
9898
prefix="data_"
9999
fi
100100

101+
# useful log date format function
102+
logDate () { echo "($(date +"%Y-%m-%d %H:%M:%S")) "; }
101103

102104
# =====================
103105
# Necessary assumptions
@@ -156,16 +158,29 @@ lims_to_float () { IFS=',' read -ra l <<< $@; f_arr=(); for i in "${l[@]}"; do f
156158
# Data processing
157159
# ===============
158160
# display info
159-
echo "$(basename $0): processing ECMWF ERA5..."
161+
echo "$(logDate)$(basename $0): processing ECMWF ERA5..."
160162

161163
# make the output directory
162-
echo "$(basename $0): creating output directory under $outputDir"
164+
echo "$(logDate)$(basename $0): creating output directory under $outputDir"
163165
mkdir -p "$outputDir"
164166

167+
# take care of dates
165168
toDate="$startDate"
166169
toDateUnix="$(unix_epoch "$toDate")"
167170
endDateUnix="$(unix_epoch "$endDate")"
168171

172+
# parse the upper and lower bounds of a given spatial limit
173+
minLat=$(lims_to_float $latLims | cut -d ',' -f 1)
174+
maxLat=$(lims_to_float $latLims | cut -d ',' -f 2)
175+
minLon=$(lims_to_float $lonLims | cut -d ',' -f 1)
176+
maxLon=$(lims_to_float $lonLims | cut -d ',' -f 2)
177+
178+
# adding/subtracting 0.1 degree to/from max/min values
179+
minLat=$(bc <<< "$minLat - 0.25")
180+
maxLat=$(bc <<< "$maxLat + 0.25")
181+
minLon=$(bc <<< "$minLon - 0.25")
182+
maxLon=$(bc <<< "$maxLon + 0.25")
183+
169184
# creating yearly directory
170185
mkdir -p "$outputDir" # making the output directory
171186

@@ -177,13 +192,17 @@ while [[ "$toDateUnix" -le "$endDateUnix" ]]; do
177192
# creating file name
178193
file="${fileStruct}_${toDateFormatted}.nc" # current file name
179194

195+
# wait to be trapped
196+
trap 'wait' CHLD
197+
180198
# extracting variables from the files and spatial subsetting
181-
ncks -O -v "$variables" \
182-
-d latitude,"$(lims_to_float "$latLims")" \
183-
-d longitude,"$(lims_to_float "$lonLims")" \
184-
"${datasetDir}/${file}" "${outputDir}/${prefix}${file}"
199+
(ncks -O -v "$variables" \
200+
-d latitude,"${minLat},${maxLat}" \
201+
-d longitude,"${minLon},${maxLon}" \
202+
"${datasetDir}/${file}" "${outputDir}/${prefix}${file}") &
185203

186-
[ $( jobs | wc -l ) -ge $( nproc ) ] && wait # forking shell processes
204+
# make sure ncks finishes
205+
wait $!
187206

188207
# increment time-step by one unit
189208
toDate="$(date --date "$toDate 1month")" # current time-step
@@ -198,6 +217,6 @@ if [[ "$toDateUnix" == "$endOfCurrentYearUnix" ]]; then
198217
toDate=$(date --date "$toDate 1month")
199218
fi
200219

201-
202-
echo "$(basename $0): results are produced under $outputDir."
220+
# exit message
221+
echo "$(logDate)$(basename $0): results are produced under $outputDir."
203222

0 commit comments

Comments
 (0)