Skip to content

Commit

Permalink
Rewinding back to using CDO for RDRS spatial subsetting (#61)
Browse files Browse the repository at this point in the history
Since using spatial indices and `ncks` proved to be problematic and
missing the full spatial extents given. This commit rewinds the script
to use `CDO` again.

Reported-by: Wouter Knoben <[email protected]>

Signed-off-by: Kasra Keshavarz <[email protected]>
  • Loading branch information
kasra-keshavarz authored Jul 3, 2024
1 parent 6b0f0af commit 0ac000b
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions scripts/eccc-rdrs/rdrs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ maxLat=$(bc <<< "$maxLat + 0.1")
minLon=$(bc <<< "$minLon - 0.1")
maxLon=$(bc <<< "$maxLon + 0.1")

# updating $latLims and $lonLims based on new values
latLims="${minLat},${maxLat}"
lonLims="${minLon},${maxLon}"

# extract the associated indices corresponding to $latLims and $lonLims
coordIdx="$(ncl -nQ 'coord_file='\"$domainFile\" 'minlat='"$minLat" 'maxlat='"$maxLat" 'minlon='"$minLon" 'maxlon='"$maxLon" "$coordIdxScript")"

Expand Down Expand Up @@ -288,15 +292,15 @@ for yr in $yearsRange; do
# creating file name
file="${toDateFormatted}12.nc" # current file name

# extracting variables from the files and spatial subsetting
# assuring the process finished using an `until` loop
until ncks -A -v ${variables} \
-d "$latDim","${latLimsIdx}" \
-d "$lonDim","${lonLimsIdx}" \
${datasetDir}/${yr}/${file} \
${cache}/${yr}/${file}; do
# extracting spatial extents and variables
until cdo -z zip \
-s -L \
-sellonlatbox,"$lonLims","$latLims" \
-selvar,"$variables" \
"${datasetDir}/${yr}/${file}" \
"${cache}/${yr}/${file}"; do
echo "$(logDate)$(basename $0): Process killed: restarting process in 10 sec" >&2
echo "NCKS [...] failed" >&2
echo "CDO [...] failed" >&2
sleep 10;
done # until ncks

Expand All @@ -306,6 +310,7 @@ for yr in $yearsRange; do
fi

# wait for any left-over processes to finish
# note to self: not sure this even does anything, but anyways
wait

# change lon values so the extents are from ~-180 to 0
Expand All @@ -318,13 +323,14 @@ for yr in $yearsRange; do
echo "$(logDate)$(basename $0): NCAP2 -s [...] failed" >&2
sleep 10;
done

# remove any left-over .tmp file
if [[ -e ${cache}/${yr}/${file}*.tmp ]]; then
rm -r "${cache}/${yr}/${file}*.tmp"
fi

# wait for any left-over processes to finish
# note to self: not sure this even does anything, but anyways
wait

# increment time-step by one unit
Expand Down

0 comments on commit 0ac000b

Please sign in to comment.