-
Notifications
You must be signed in to change notification settings - Fork 1
/
CalcAnomalies.sh
61 lines (50 loc) · 1.58 KB
/
CalcAnomalies.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
#===============================================================================
#
# FILE: CalcAnomalies.sh
#
# USAGE: bash CalcAnomalies.sh ~/shared/CMIP5/CESM1-BGC zg500hpa ~/shared/CMIP5/CESM1-BGC 1976 2005
#
# DESCRIPTION: Calculate (standardized) anomalies of a climate input field
#
# ARGUMENTS:
# 1) Input directory,
# eg. ~/shared/CMIP5/CESM1-BGC
# 2) Variable name
# eg. zg500hpa
# 3) Output directory
# eg. ~/shared/CMIP5/CESM1-BGC
# 4) Start year to calculate climatology
# eg. 1976
# 5) End year to calculate climatology
# eg. 2005
# AUTHOR: M. Demuzere, matthias.demuzere@ugent.be
# COMPANY: Ghent University
# VERSION: 1.0
# CREATED: 25/10/2017
# REVISION: ---
#
#===============================================================================
idir=$1
ivar=$2
odir=$3
climstart=$4
climstop=$5
## Go to input dir
cd $idir
## Inputfile and extension
ifile=$ivar'_Amon_CESM1-BGC_historical_r1i1p1_185001-200512'
ext='.nc'
## Create temp directory
tmpdir=$idir/tmp
mkdir -p $tmpdir
## Calculate climatology and standard deviation
cdo -P 4 ymonmean -selyear,$climstart/$climstop $ifile$ext $tmpdir/ymonmean.nc
cdo -P 4 ymonstd -selyear,$climstart/$climstop $ifile$ext $tmpdir/ymonstd.nc
## Calculate anomalies
cdo -P 4 sub $ifile$ext $tmpdir/ymonmean.nc $odir/$ifile'_anom'$ext
## Calculate standardized anomalies
cdo -P 4 div $odir/$ifile'_anom'$ext $tmpdir/ymonstd.nc $odir/$ifile'_stdanom'$ext
echo 'Cleaning up ...'
rm -rf $tmpdir
echo 'Routine ready and file available here: '$odir/$ifile'_stdanom'$ext