lnd_obs.sh 3.94 KB
Newer Older
1
2
#!/bin/bash

3
4
#if run stand alone
#	module load nco/4.6.9
5
6
7
8
9
10
11
12

#var=("t2m")
var=("t2m" "swsn" "swsd" "lwsn" "lwsd" "smb" "latf" "senf" "gbot" "alb")
casename=racmo23_GRN_monthly
file_start_year=1958
start_year=1980
end_year=1999

13
14
hist_path=$obspath/$casename
echo "$hist_path"
15
16
lndpath=$hist_path/climos
outseries=$hist_path/tseries
17
18
#mask_file=RACMO23_masks_ZGRN11_latlon.nc 
mask_file=RACMO23_masks_ZGRN11.nc 
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
gris_pcnt_file=greenland_percent_coverage_latlon.nc

for ivar in "${var[@]}"
do
echo "make RACMO23 climos for" $ivar

filename=${ivar}.1958-2013.BN_1958_2013.MM.nc
outfile=$casename.${ivar}.$start_year-$end_year
tseries_file=$casename.${ivar}.ann_tseries

mkdir -p "$outseries"
mkdir -p "$lndpath"

let "go=($start_year-$file_start_year)*12"
let "stop=($end_year-$file_start_year)*12"

month=("01" "02" "03" "04" "05" "06" "07" "8" "9" "10" "11" "12")
for m in "${month[@]}"
do

# set the time to start averging to $go
mon=$go

# set the time to start averging for each month
let mon="($go+$m)"

ncra -O -h -F -d time,$mon,$stop,12 $hist_path/$filename  $lndpath/$outfile.$m.nc
# -F = fortran indexing (starts with 1)
# -O 
# -h keep history
# -d dimension 

done

#stupid fix because bash bug with 07 08 and 09 sometimes
mv -f $lndpath/$outfile.8.nc $lndpath/$outfile.08.nc 
mv -f $lndpath/$outfile.9.nc $lndpath/$outfile.09.nc 

if [ "$ivar" == "smb" ]; then

echo "create DJF sum to get mmWE/season or year $ivar"
ncra -O -y ttl -h -F $lndpath/$outfile.12.nc $lndpath/$outfile.01.nc $lndpath/$outfile.02.nc $lndpath/$outfile.DJF.nc
echo "create JJA sum $ivar"
ncra  -O -y ttl -h -F $lndpath/$outfile.06.nc $lndpath/$outfile.07.nc $lndpath/$outfile.08.nc $lndpath/$outfile.JJA.nc
echo "create ANN sum $ivar"
ncra  -O -y ttl -h -F $lndpath/$outfile.01.nc $lndpath/$outfile.02.nc $lndpath/$outfile.03.nc \
$lndpath/$outfile.04.nc $lndpath/$outfile.05.nc $lndpath/$outfile.06.nc \
$lndpath/$outfile.07.nc $lndpath/$outfile.08.nc $lndpath/$outfile.09.nc \
$lndpath/$outfile.10.nc $lndpath/$outfile.11.nc $lndpath/$outfile.12.nc \
$lndpath/$outfile.ANN.nc

else

# all others are monthly averaged
echo "create DJF avg $ivar"
ncra -O -h -F $lndpath/$outfile.12.nc $lndpath/$outfile.01.nc $lndpath/$outfile.02.nc $lndpath/$outfile.DJF.nc
echo "create JJA avg $ivar"
ncra  -O -h -F $lndpath/$outfile.06.nc $lndpath/$outfile.07.nc $lndpath/$outfile.08.nc $lndpath/$outfile.JJA.nc
echo "create ANN avg/month"
ncra  -O -h -F $lndpath/$outfile.01.nc $lndpath/$outfile.02.nc $lndpath/$outfile.03.nc \
$lndpath/$outfile.04.nc $lndpath/$outfile.05.nc $lndpath/$outfile.06.nc \
$lndpath/$outfile.07.nc $lndpath/$outfile.08.nc $lndpath/$outfile.09.nc \
$lndpath/$outfile.10.nc $lndpath/$outfile.11.nc $lndpath/$outfile.12.nc \
$lndpath/$outfile.ANN.nc

fi

wait

echo "make annual time series for RACMO23 $ivar"
#uses nco's --mro, multi-record output feature see nco documentation section 3.18, -h retains history of commands
if [ "$ivar" == "smb" ]; then  # make an annual sum not average for smb, since we want an integrated annual not avg flux
ncra --mro -O -y ttl -h -d time,,,12,12 $hist_path/$filename  $outseries/${tseries_file}.nc

else # average other variables
ncra --mro -O -h -d time,,,12,12 $hist_path/$filename  $outseries/${tseries_file}.nc

fi

echo "add mask and area variables to time series of $ivar"
ncks -A -v gridarea,GrIS_mask $hist_path/$mask_file -o $outseries/${tseries_file}.nc

#if [ "$ivar" == "smb" ]; then 

#echo "average over ice sheet for $ivar without the percent of glacier"
#ncwa -O -a lat,lon -w gridarea -B "GrIS_mask == 1" $outseries/${tseries_file}.nc $outseries/${tseries_file}_aavg.nc
#
#else

echo "average over ice sheet for $ivar" without the percent of glacier
ncwa -O -a lat,lon -w gridarea -B "GrIS_mask == 1" $outseries/${tseries_file}.nc $outseries/${tseries_file}_aavg.nc

#fi

if test -a $outseries/${tseries_file}_aavg.nc; then
        echo "Global avg annual time series of ${casename} made"
else
        echo "Global avg annual time series of ${casename} NOT made"
       exit
fi

done