Skip to content

Commit 5d1a10e

Browse files
Iss57 (#58)
* Considering future runs of GWF WRF-CONUS II product The future runs, unfortunately, follow a different file/folder structure and they needed to be handled a bit differently than the historical files which are all in `.tar` format. This PR adds the capability to process this period of data for this product to the script. Minimal adjustments were done to make the script almost intact. Reported-by: Logan Fang <[email protected]> Signed-off-by: Kasra Keshavarz <[email protected]> * Minimal typo corrections * Adding information for the future runs files --------- Signed-off-by: Kasra Keshavarz <[email protected]>
1 parent 963c652 commit 5d1a10e

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

scripts/gwf-ncar-conus_i/conus_i.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ function date_match_idx () {
268268
# defining local variables
269269
local str="$1" # string to be matched
270270
local matchPos="$2" # the position of the matching string within the "YYYY-MM-DD",
271-
# 1: year, 2: month, 3: day
272-
# 1,2: year and month, 2,3: month and day, 1,3: year and day
273-
# 1-3: complete date
271+
# 1: year, 2: month, 3: day
272+
# 1,2: year and month, 2,3: month and day, 1,3: year and day
273+
# 1-3: complete date
274274
local delim="$3" # delimiter
275275
shift 3 # shift argument positins by 3
276276
local strArr=("$@") # arrays of string

scripts/gwf-ncar-conus_ii/README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ In this file, the details of the dataset is explained.
1414
1515
## Location of Dataset Files
1616

17-
The `WRF-CONUSII` simulation outputs are located under the following directory accessible from Compute Canada (CC) Graham Cluster:
17+
The `WRF-CONUSII` simulation outputs are located under the following directories accessible from Compute Canada (CC) Graham Cluster:
1818
```
19-
/project/rpp-kshook/Model_Output/wrf-conus/CONUSII/hist
19+
/project/rpp-kshook/Model_Output/wrf-conus/CONUSII/hist # years 1995-2015
20+
/project/rpp-kshook/Model_Output/wrf-conus/CONUSII/fut # years 2080-2100
2021
```
2122
and the structure of the dataset hourly files is as following:
2223
```console
@@ -106,7 +107,7 @@ foo@bar:~$ ncdump -h /path/to/extracted/conusii/netcdf/file.nc
106107
The spatial extent of the `WRF-CONUSII` is on latitutes from `15.02852` to `73.27542` and longitudes from `-156.8242` to `-40.3046`.
107108

108109
## Temporal Extent
109-
As is obvious from the nomenclature of the dataset files, the time-steps are hourly covering from the January 1995 to December 2015.
110+
As is obvious from the nomenclature of the dataset files, the time-steps are hourly covering from the January 1995 to December 2015 (`hist` dataset directory). Also, the dataset covers data from January 2080 to December 2100 (`fut` dataset directory).
110111

111112
# Short Description on `WRF-CONUSII` Variables
112113
In most hydrological modelling applications, usually 7 variables are needed detailed as following: 1) specific humidity at 2 meters, 2) surface pressure, 3) air temperature at 2 meters, 4) wind speed at 10 meters, 5) precipitation, 6) downward short wave radiation, and 7) downward long wave radiation. These variables are available through `WRF-CONUSII` dataset and their details are described in the table below:

scripts/gwf-ncar-conus_ii/conus_ii.sh

+36-14
Original file line numberDiff line numberDiff line change
@@ -431,18 +431,34 @@ for yr in $yearsRange; do
431431

432432
# extract variables from the forcing data files
433433
while [[ "$toDateUnix" -le "$endPointUnix" ]]; do
434-
# date manipulations
435-
toDateFormatted=$(date --date "$toDate" "+$tarFormat") # current timestamp formatted to conform to CONUSII naming convention
436-
437-
# creating file name
438-
file="${tarFileStruct}_${toDateFormatted}.tar" # current file name
434+
435+
if [[ "$yr" -ge "2080" ]] && [[ "$yr" -le "2100" ]]; then
436+
# date manipulations
437+
# current timestamp formatted to conform to CONUSII naming convention
438+
toDateFormatted=$(date --date "$toDate" "+$format")
439+
440+
# copy files to $cache
441+
cp "${datasetDir}/${yr}/${fileStruct}_${toDateFormatted}" \
442+
"${cacheDir}/${yr}/${fileStruct}_${toDateFormatted}"
443+
444+
# for compatibility in the next few lines
445+
tarFiles=( "${fileStruct}_${toDateFormatted}" )
446+
447+
else
448+
# date manipulations
449+
# current timestamp formatted to conform to CONUSII naming convention
450+
toDateFormatted=$(date --date "$toDate" "+$tarFormat")
439451

440-
# untar files one day at a time
441-
tar --strip-components=6 -xf "$datasetDir/$yr/$file" -C "$cacheDir/$yr/"
452+
# creating file name
453+
file="${tarFileStruct}_${toDateFormatted}.tar" # current file name
442454

443-
# parse tar file contents
444-
tarFiles="$(tar -tf $datasetDir/$yr/$file)"
445-
IFS=' ' read -ra tarFiles <<< $(echo $tarFiles)
455+
# untar files one day at a time
456+
tar --strip-components=6 -xf "$datasetDir/$yr/$file" -C "$cacheDir/$yr/"
457+
458+
# parse tar file contents
459+
tarFiles="$(tar -tf $datasetDir/$yr/$file)"
460+
IFS=' ' read -ra tarFiles <<< $(echo $tarFiles)
461+
fi
446462

447463
# extracting variables from the files and spatial subsetting
448464
for f in "${tarFiles[@]}"; do
@@ -453,15 +469,21 @@ for yr in $yearsRange; do
453469
-d "$lonVar","$lonLimsIdx" \
454470
"$cacheDir/$yr/$f2" "$cacheDir/$yr/$f2"; do
455471

456-
echo "$(basename $0): Process killed: restarting process" >$2
457-
sleep 5;
472+
echo "$(basename $0): Process killed: restarting process" >$2
473+
sleep 5;
458474
done
459475

460476
done
461477

462478
# increment time-step by one unit
463-
toDate=$(date --date "$toDate 1day") # current time-step
464-
toDateUnix=$(date --date="$toDate" "+%s") # current timestamp in unix EPOCH time
479+
if [[ "$yr" -ge "2080" ]] && [[ "$yr" -le "2100" ]]; then
480+
toDate=$(date --date "$toDate 1hours") # current time-step
481+
else
482+
toDate=$(date --date "$toDate 1days") # current time-step
483+
fi
484+
485+
# conversion current time-step to UNIX EPOCH
486+
toDateUnix=$(date --date="$toDate" "+%s")
465487
done
466488

467489
# go to the next year if necessary

0 commit comments

Comments
 (0)