-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcdo_precipitation_Noongar_anomalies.sh
executable file
·103 lines (80 loc) · 3.39 KB
/
cdo_precipitation_Noongar_anomalies.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
#!/bin/bash
#the following script is to run CDO to calculate rainfall anomolies for Noongar seasons
# step 1: need to extract the months of interest from main SWWA file
##### Inputs ###########################
input_file="/Programs/Climate/NoongarProcessedMarch24/Anomalies/masked_precipitation_noongar.nc"
#Noongar seasons
#Birak season:December-January (12/01)
#season="birak"
#Bunuru: February-March (02/03)
season="bunuru"
#Djeran: April-May (04/05)
#season="djeran"
#Makuru: June-July (06/07)
#season="makuru"
#Djilba: August-September (08/09)
#season="djilba"
#Kambarang: October-November (10/11)
#season="kambarang"
# Define the season of interest (e.g., June to August for winter in the Southern Hemisphere)
month_start="02" # Replace with your specific months
month_end="03"
# Define the climatology period (e.g., 1981-2010)
year_in="1961"
year_out="1990"
# Define output files
seasonal_output=${output_dir}${season}_precip.nc
climatology_output=${output_dir}${year_in}_to_${year_out}_${season}.nc
anomaly_output=${output_dir}${season}_precip_anomaly.nc
anomaly_mean_output=${output_dir}${season}_precip_mean_anomaly.nc
# Extract seasonal precipitation for each year
#when calculating over Dec/Jan you need to use seassum or seasmean
#however, every other time period yearsum or yearmean is used
#cdo -seassum -select,season=AS $input_file $seasonal_output
cdo -yearsum -select,season=FM $input_file $seasonal_output
# Calculate the 30-year climatology for the season of interest
cdo -timmean -selyear,${year_in}/${year_out} $seasonal_output $climatology_output
# Calculate anomalies: (seasonal precipitation - climatology)
cdo sub $seasonal_output $climatology_output $anomaly_output
#calculate field mean
cdo fldmean $anomaly_output $anomaly_mean_output
#old code from before
#month_start="12"
#month_end="01"
#output_dir="/Programs/Climate/NoongarProcessedMarch24/Anomalies/"
########################################
# code starts here
# create the output_dir in case it does not already exist
#mkdir -p ${output_dir}
# define an output file name that makes sense
#file_out=${output_dir}precip_sum${season}_${month_start}_to_${month_end}.nc
# delete the output file in case it already exists
#rm -f ${file_out}
#select own season and take sum of precipitation for that season
#when calculating over Dec/Jan you need to use seassum or seasmean
#however, every other time period yearsum or yearmean is used
#cdo -seassum -select,season=DJ ${input_file} ${file_out}
#cdo -yearsum -select,season=ON ${input_file} ${file_out_winter}
#step 2 select year ranges you want to compare
#we are using 1961-1990 as historic
#1993-2022 as current
#hyear_in="1961"
#hyear_out="1990"
#cyear_in="1993"
#cyear_out="2022"
#define output file
#winter_hist=${output_dir}precip_${season}timmean_${hyear_in}_to_${hyear_out}.nc
#winter_curr=${output_dir}precip_${season}timmean_${cyear_in}_to_${cyear_out}.nc
#delete the outputs if already there
#rm -f ${winter_hist}
#rm -f ${winter_curr}
#select and sum years
#cdo -timmean -selyear,${hyear_in}/${hyear_out} ${file_out_winter} ${winter_hist}
#cdo -timmean -selyear,${cyear_in}/${cyear_out} ${file_out_winter} ${winter_curr}
#step 4: compare historic to current
#define output
#winter_diff=${output_dir}agcd_v2_precip_${season}_${cyear_in}_${cyear_out}_minus_${hyear_in}_${hyear_out}.nc
#delete if already there
#rm -f ${winter_diff}
#calculate difference
#cdo sub ${winter_curr} ${winter_hist} ${winter_diff}