-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_climateset.sh
executable file
·62 lines (47 loc) · 1.79 KB
/
run_climateset.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
#!/bin/bash
# script to transform climateset data into icosahedral grid. assumes annual data.
# stores the new data in a seperate folder given by user
# First argument: folder with all subdirs, where each dir is a seperate year. assumes annual data.
# Second argument: folder where the new grib files should be stored
# Third argument: how the climate variable is named in the data file(s)
# Fourth argument: how the climate variable needs to be renamed for GRIB2 conventions
# Fifth argument: NI parameter (distance between hexagon grid cells in km)
# Sixth argument: type of remapping (default: remapcon2)
INPUT_DIR=$1
STORE_DIR=$2
VARNC=${3:-"tas"}
VARGRIB=${4:-"t"}
NI=${5:-24}
REMAP=${6:-"remapcon"}
echo "Remap files in $INPUT_DIR with NI=$NI and remapping function $REMAP..."
echo $INPUT_DIR
echo $STORE_DIR
# make new dir if it does not exist yet
# create subdir icosahedral and subdir longlat
mkdir -p $STORE_DIR/icosahedral
mkdir -p $STORE_DIR/longlat
# iterate through all dirs & files in INPUT_DIR
for dir in $INPUT_DIR/*/; do
if [[ -d $dir ]]; then
# create year as subdir in STORE_DIR
dir=${dir%*/}
year=${dir##*/}
mkdir -p $STORE_DIR/icosahedral/$year
mkdir -p $STORE_DIR/longlat/$year
# run run.sh on each file
for file in $dir/*.nc; do
file_path=`readlink -f $file`
./remap2icosahedral.sh $file_path $NI $REMAP 1 $VARNC $VARGRIB "grib"
done
# Move grib files: "_icosahedral.grib" & "_longlat.grib"
mv $dir/*_icosahedral.grib $STORE_DIR/icosahedral/$year
mv $dir/*_longlat.grib $STORE_DIR/longlat/$year
else
echo "$dir is not valid"
exit 1
fi
done
# if needed, create vertex to lonlat mapping:
# (as long as 6250 steps -> use the one that is already uploaded)
# ./getlonlat.sh [SPECIFIC GRIB FILE]
echo "... finished. Stored in $STORE_DIR."