forked from trondkr/downscaleA20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateDeltas-SODA-ocean.sh
60 lines (47 loc) · 2.16 KB
/
createDeltas-SODA-ocean.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
#!/bin/bash
# Load required CDO module
# module load CDO/1.9.3-intel-2018a
# Trond Kristiansen, 15-18 January 2019, San Francisco
export inputdir="/Users/trondkr/Dropbox/NIVA/DownscaleA20/BRY/"
export outdir="/Users/trondkr/Dropbox/NIVA/DownscaleA20/RESULTS/"
export rundir="/Users/trondkr/Dropbox/NIVA/DownscaleA20/"
export pattern="a20_bry_SODA_BCG_20060115_to_20151215.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 xstdh=$outdir$"Xstdh.nc"
export detrended=$outdir${basefilename%.nc}"_detrend.nc"
export detrendedclim=$outdir${basefilename%.nc}"_detrend_monclim.nc"
export monthlymean=$outdir${basefilename%.nc}"_monclim.nc"
# Extract the years of interest
cdo --verbose -b F64 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
cdo ymonstd $detrended $xstdh
# 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