-
Notifications
You must be signed in to change notification settings - Fork 5
/
wrapper_miles.sh
executable file
·343 lines (289 loc) · 11.1 KB
/
wrapper_miles.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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#!/bin/bash
set -eu
################################################
#------- MidLatitude Evaluation System --------#
#------------------MiLES v0.7------------------#
#----------Dec 2018, P. Davini, CNR-ISAC-------#
#
#
#
#
usage()
{
echo "Usage:"
echo " ./wrapper_miles.sh namelist"
echo " Namelists are configuration files introduced since MiLES v0.7"
echo " You can specificy everything you need, a template is available namelist/namelist.tmpl"
echo
}
if [ $# -ne 1 ]; then
usage
exit 1
fi
namelist=$1
if [ ! -f $namelist ] ; then
"The namelist does not exists!"
exit
else
. $namelist
fi
# zero order configuration checker function
function has_config()
{
for option in $options ; do
if [[ $option == $1 ]] ; then
return 0
exit
fi
done
return 1
}
################################################
#- ------user configurations variables---------#
################################################
# output file type for figures (pdf, png, eps)
# pdf are set by default
#output_file_type="pdf"
# map projection that is used for plotting
# "no": standard lon-lat plotting (fastest)
# "azequalarea": polar plot with equal area
# these are suggested: any other polar plot by "mapproj" R package are supported
# "azequalarea" set by default
#map_projection="azequalarea"
###############################################
#-------------Configuration scripts------------#
################################################
# machine dependent script (set above)
project="" ; dataset=""; expid="" ens=""; expected_input_name="" #declared to avoid problems with set -u
. config/config_${machine}.sh
# this script controls some of the graphical parameters
# as plot resolutions and palettes
CFGSCRIPT=$PROGDIR/config/R_config.R
# select how many clusters for k-means over the North Atlantic
# NB: only 4 clusters supported so far.
nclusters=4
# set variable identifier
identifier=${varname}${level}
################################################
##NO NEED TO TOUCHE BELOW THIS LINE#############
################################################
#check if you can compare run with std_clim=true
if ${std_clim} ; then
for tele in $teles ; do
if ! { [ "$tele" = NAO ] || [ "$tele" = AO ] || [ "$tele" = PNA ]; } ; then
echo "Error: you cannot use non-standard EOFs region with std_clim=true"
exit
fi
done
for season in $seasons ; do
if has_config figures ; then
if ! { [ "$season" = DJF ] || [ "$season" = MAM ] || [ "$season" = SON ] || [ "$season" = JJA ]; } ; then
echo "Error: you cannot use non-standard seasons with std_clim=true"
exit
fi
fi
done
fi
# check if we need to force some part of the code
has_config forcedata && doforcedata=true || doforcedata=false
has_config forceanl && doforceanl=true || doforceanl=false
# set unbound variables
expid_exp=${expid_exp:-}
ens_exp=${ens_exp:-}
project_exp=${project_exp:-}
expid_ref=${expid_ref:-}
ens_ref=${ens_ref:-}
project_ref=${project_ref:-}
# create a unique identifieri for each experiment
info_exp=${project_exp}!${dataset_exp}!${expid_exp}!${ens_exp}!${year1_exp}!${year2_exp}
# if we are using standard climatology
if ${std_clim} ; then
dataset_ref="ERAI_clim"
year1_ref=1979
year2_ref=2017
REFDIR=$PROGDIR/clim
infos=${info_exp}
else
REFDIR=$FILESDIR
info_ref=${project_ref}!${dataset_ref}!${expid_ref}!${ens_ref}!${year1_ref}!${year2_ref}
infos=$(echo ${info_exp} ${info_ref})
fi
################################################
#-------------Computation----------------------#
################################################
# loop to produce data: on experiment and - if needed - reference
for info in $infos ; do
echo $info
project=$(echo $info | cut -f1 -d"!")
dataset=$(echo $info | cut -f2 -d"!")
expid=$(echo $info | cut -f3 -d"!")
ens=$(echo $info | cut -f4 -d"!")
year1=$(echo $info | cut -f5 -d"!")
year2=$(echo $info | cut -f6 -d"!")
## select for experiment
#if [[ $dataset == $dataset_exp ]] ; then
# year1=${year1_exp}; year2=${year2_exp}; expid=${expid_exp}; ens=${ens_exp}; project=${project_exp}
#fi
# select for reference
#if [[ $dataset == $dataset_ref ]] ; then
# if ${std_clim} ; then
# echo "skip!"
# else
# year1=${year1_ref}; year2=${year2_ref}; expid=${expid_ref}; ens=${ens_ref}; project=${project_ref}
# fi
#fi
echo "year1=${year1}; year2=${year2}; expid=${expid}; ens=${ens}; project=${project}"
# some informations on screen
RED='\033[0;31m'; GREEN='\033[0;32m'; BLUE='\033[0;34m'; NC='\033[0m'
echo "###########################################################"
echo "MiLES is running on:"
echo -e "${BLUE}$dataset $expid $ens $year1 $year2${NC}"
echo "Active options are:"
echo -e "${BLUE}$options${NC}"
echo "###########################################################"
#definition of the fullfile name
ZDIR=$OUTPUTDIR/data/${identifier}/${project}
mkdir -p $ZDIR
zfile=${identifier}
for dcode in $dataset $expid $ens ; do
if [[ ! -z "$dcode" ]] ; then
zfile=${zfile}_${dcode}
ZDIR=$ZDIR/$dcode
fi
done
fullfilename=$ZDIR/${zfile}_fullfile.nc
if has_config bcblock ; then
biasdataset=ERA5
biasfile=$OUTPUTDIR/data/${identifier}/OBS/$biasdataset/zg500_${biasdataset}_fullfile.nc
echo $biasfile
if [ ! -f $biasfile ] ; then
return 1
fi
fi
echo "Full filename is: $fullfilename"
#fullfile prepare
time . $PROGDIR/script/assimilate.sh -d "$dataset" -e "$expid" -r "$ens" -v $varname -l $level \
-o $fullfilename -c $machine -f $doforcedata
# exit if the assimilation has gone wrong
if [ "$?" == 1 ] ; then
return 1
fi
for season in $seasons ; do
echo -e "${GREEN}Working on $season season${NC}"
# Rbased EOFs
if has_config eofs ; then
for tele in $teles ; do
time $Rscript "$PROGDIR/script/eof_fast.R" "$project" "$dataset" "$expid" "$ens" $year1 $year2 $season \
$tele $fullfilename $FILESDIR $PROGDIR $doforceanl
done
fi
# blocking
if has_config block ; then
[[ $varname == "zg" ]] && blockscript="block_multiple_fast.R"
[[ $varname == "ua" ]] && blockscript="u500_block_multiple.R"
time $Rscript "$PROGDIR/script/$blockscript" "$project" "$dataset" "$expid" "$ens" $year1 $year2 $season \
$fullfilename $FILESDIR $PROGDIR $doforceanl "false" ""
fi
# blocking
if has_config bcblock ; then
[[ $varname == "zg" ]] && blockscript="block_multiple_fast.R"
[[ $varname == "ua" ]] && blockscript="u500_block_multiple.R"
time $Rscript "$PROGDIR/script/$blockscript" "$project" "$dataset" "$expid" "$ens" $year1 $year2 $season \
$fullfilename $FILESDIR $PROGDIR $doforceanl "true" $biasfile
fi
# regimes
if has_config regimes && [[ $season == DJF ]] ; then
time $Rscript "$PROGDIR/script/regimes_fast.R" "$project" "$dataset" "$expid" "$ens" $year1 $year2 $season \
$fullfilename $FILESDIR $PROGDIR $nclusters $doforceanl
fi
# meandering index
if has_config meandering ; then
time $Rscript "$PROGDIR/script/meandering_fast.R" "$project" "$dataset" "$expid" "$ens" $year1 $year2 $season \
$fullfilename $FILESDIR $PROGDIR $doforceanl
fi
done
done
################################################
#-----------------Figures----------------------#
################################################
if has_config figures ; then
for season in $seasons ; do
echo "###########################################################"
echo -e "${GREEN}Producing figures for $season season ${NC}"
echo "###########################################################"
# EOFs figures
if has_config eofs ; then
for tele in $teles ; do
time $Rscript "$PROGDIR/script/eof_figures.R" "$project_exp" "$dataset_exp" "$expid_exp" "$ens_exp" "$year1_exp" "$year2_exp" \
"$project_ref" "$dataset_ref" "$expid_ref" "$ens_ref" "$year1_ref" "$year2_ref" \
$season $FIGDIR $FILESDIR $REFDIR $CFGSCRIPT $PROGDIR $tele
done
fi
# blocking figures
if has_config block ; then
time $Rscript "$PROGDIR/script/block_figures.R" "$project_exp" "$dataset_exp" "$expid_exp" "$ens_exp" "$year1_exp" "$year2_exp" \
"$project_ref" "$dataset_ref" "$expid_ref" "$ens_ref" "$year1_ref" "$year2_ref" \
$varname $season $FIGDIR $FILESDIR $REFDIR $CFGSCRIPT $PROGDIR
fi
# regimes figures
if has_config regimes && [[ $season == DJF ]] ; then
time $Rscript "$PROGDIR/script/regimes_figures.R" "$project_exp" "$dataset_exp" "$expid_exp" "$ens_exp" "$year1_exp" "$year2_exp" \
"$project_ref" "$dataset_ref" "$expid_ref" "$ens_ref" "$year1_ref" "$year2_ref" \
$season $FIGDIR $FILESDIR $REFDIR $CFGSCRIPT $PROGDIR $nclusters
fi
done
fi
# clean empty folders
#echo "Checking if there are empty folders..."
#find $OUTPUTDIR -type d -empty -delete -print
echo "###########################################################"
echo -e "${BLUE} MiLES is over, go and enjoy your life outside! ${NC}"
echo "###########################################################"
################################################
#--------------Ensemble mean-------------------#
################################################
#check how many ensemble you have
#aens=($ens_list); nens=${!ens[@]}
#echo "Ensemble members are $ens_list"
#
##For blocking only
#if [[ "${ens_list}" == "NO" ]] || [[ ${nens} -eq 0 ]] ; then
#echo "Only one ensemble member, exiting..."
#else
#echo "Create ensemble mean... "
##create loop using flags
#kinds=${kinds:-}
#[[ has_config block ]] && kinds="$kinds Block"
##[[ has_config eofs ]] && kinds="$kinds EOF"
##[[ has_config regimes ]] && kinds="$kinds Regimes"
#echo $kinds
#
#for kind in $kinds ; do
#
#for season in ${seasons} ; do
#
#case for file names
#case $kind in
#Block)
#MEANFILE=$FILESDIR/${dataset_exp}/mean/${kind}/${year1}_${year2}/$season/BlockClim_${dataset_exp}_mean_${year1}_${year2}_${season}.nc
#INFILES='$FILESDIR/${dataset_exp}/*/${kind}/${year1}_${year2}/$season/BlockClim_${dataset_exp}_*.nc'
#ARGS="$dataset_exp mean $year1_exp $year2_exp $dataset_ref $ens_ref $year1_ref $year2_ref $season $FIGDIR $FILESDIR $REFDIR $CFGSCRIPT $PROGDIR"
#SCRIPT=$PROGDIR/script/block_figures.R
#;;
#Regimes)
## MEANFILE=$FILESDIR/${dataset_exp}/mean/${kind}/${year1}_${year2}/$season/RegimesPattern_${dataset_exp}_mean_${year1}_${year2}_${season}.nc
## INFILES='$FILESDIR/${dataset_exp}/*/${kind}/${year1}_${year2}/$season/RegimesPattern_${dataset_exp}_*.nc'
## ARGS="$dataset_exp mean $year1_exp $year2_exp $dataset_ref $ens_ref $year1_ref $year2_ref $season $FIGDIR $FILESDIR $REFDIR $CFGSCRIPT $PROGDIR $nclusters"
## SCRIPT=$PROGDIR/script/regimes_figures.R
## ;;
#esac
#
##mean and plot
#MEANDIR=$(dirname $MEANFILE)
#rm -rf $MEANDIR; mkdir -p $MEANDIR
#$cdo4 timmean -cat $(eval echo $INFILES) $MEANFILE
#time $Rscript "$SCRIPT" $ARGS
#
#done
#done
#fi