-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcreateDeltas-NorESM-atm.sh
64 lines (51 loc) · 2.46 KB
/
createDeltas-NorESM-atm.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
#!/bin/bash
# Load required CDO module
module load CDO/1.9.3-intel-2018a
# Trond Kristiansen, 15-18 January 2019, San Francisco
export inputdir="/cluster/projects/nn9412k/A20/FORCING/RCP85_atm/"
export outdir="/cluster/projects/nn9412k/A20/DELTA/results/"
export rundir="/cluster/projects/nn9412k/A20/DELTA/"
export pattern="NORESM_ATM.cam2.hmlvl.2006-2100.nc"
export pattern="CO2.cam2.hmlvl.2006-2100.nc"
# Calculate global monthly, detrended values of atmospheric forcing from NorESM
for filename in $inputdir$pattern; do
echo "Working with file:" $filename;
# Get the filename without path and setup temporary files in work dir
basefilename=$(basename $filename);
export extractedyears=$outdir$"extractedyears.nc"
export noseasonality=$outdir$"noseasonality.nc"
export tmpfile3=$outdir$"tmp3.nc"
export tmpfile4=$outdir$"tmp4.nc"
export detrended=$outdir${basefilename%.nc}"_detrend.nc"
export detrendedclim=$outdir${basefilename%.nc}"_detrend_monclim.nc"
export hindcastdeltas=$outdir${basefilename%.nc}"_2006-2015_deltas.nc"
export hindcastdeltasmonthly=$outdir${basefilename%.nc}"_2006-2015_deltas_monthly.nc"
export monthlymean=$outdir${basefilename%.nc}"_monclim.nc"
# Extract the years of interest
cdo --verbose selyear,2006/2015 $filename $extractedyears
# Calculate the monthly climatology
cdo ymonmean $extractedyears $monthlymean
# Remove the seasonality
cdo ymonsub $extractedyears $monthlymean $noseasonality
# Remove the linear trend from the timeseries with removed seasonality
cdo trend $noseasonality $tmpfile3 $tmpfile4
cdo subtrend $extractedyears $tmpfile3 $tmpfile4 $detrended
# Calculate the monthly mean from the detrended timeseries 2006-2015
cdo ymonmean $detrended $detrendedclim
# Calculate the 2006-2015 deltas (used for fractional bias correction)
cdo ymonsub $extractedyears $detrendedclim $hindcastdeltas
cdo ymonmean $hindcastdeltas $hindcastdeltasmonthly
# Calculate the deltas by subtracting the detrended,
# climatology from the full timeseries
export deltafile=$outdir${basefilename%.nc}"_delta.nc"
cdo ymonsub $filename $detrendedclim $deltafile
cdo ymonsub $filename $detrendedclim $deltafile
echo "Delta results saved to file:" $deltafile
echo "Climatology results saved to file:" $detrendedclim
rm $tmpfile3
rm $tmpfile4
rm $extractedyears
rm $noseasonality
rm $detrended
rm $monthlymean
done