/
cycle_zonal.ncl
152 lines (122 loc) · 4.56 KB
/
cycle_zonal.ncl
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
; #############################################################################
; PROCEDURE FOR THE CYCLE-ZONAL PLOT OF THE PERFORMANCE METRICS
; Author: Bettina Gier (University of Bremen, Germany)
; ESMVal project
; #############################################################################
load "$diag_scripts/shared/plot/style.ncl"
procedure perfmetrics_ptype_script()
begin
; Set dataset indexes, with reference and alternative datasets first
modidx = ispan(0, nDatasets - 1, 1)
if (l_altern) then
modidx := array_append_record( \
(/ref_ind, alt_ind/), \
modidx(ind(modidx.ne.ref_ind .and. modidx.ne.alt_ind)), 0)
else
modidx := array_append_record(ref_ind, modidx(ind(modidx.ne.ref_ind)), 0)
end if
if (isatt(diag_script_info, "annots")) then
annots = metadata_att_as_array(info_items, diag_script_info@annots)
else
annots = project_style(info_items, diag_script_info, "annots")
end if
; Loop over datasets
do ii = 0, dimsizes(modidx) - 1
imod = modidx(ii)
log_debug("Processing " + datasetnames(imod))
; Set path for saving processed data
system("mkdir -p " + config_user_info@work_dir)
fname = \
str_join((/"perfmetrics", "cycle_zonal", annots(imod), var0, \
diag_script_info@time_avg, diag_script_info@region/), "_")
workpath = config_user_info@work_dir + fname + ".nc"
; Determine start/end year
start_year = info_items[imod]@start_year
end_year = info_items[imod]@end_year
; Read data
var = read_data(info_items[imod])
; Calculate zonal mean
var_reg = dim_avg_Wrap(var)
delete(var)
; Calculate time average
var_avg = time_operations(var_reg, start_year, end_year, "average", \
diag_script_info@time_avg, True)
delete(var_reg)
; Standard deviation calculation for this ptype is not yet implemented in
; diag_scripts/shared/statistics.ncl, but is anyway not required here
; Store in global array
var_all = new(array_append_record(dimsizes(var_avg), 2, 0), float)
var_all!3 = "statistic"
var_all&statistic = (/"mean", "stddev"/)
var_all(:, :, :, 0) = var_avg
var_all@var = var0
var_all@diag_script = (/DIAG_SCRIPT/)
copy_VarAtts(diag_script_info, var_all)
var_all@ref_model = variable_info[0]@reference_dataset
delete(var_avg)
; Store reference dataset
if (imod.eq.ref_ind) then
var_ref = var_all
end if
; Store alternative dataset
if (l_altern) then
if (imod.eq.alt_ind) then
var_alt = var_all
end if
end if
; Write output
var_all@ncdf = workpath
ncdf = ncdf_write(var_all, workpath)
; Call provenance logger
log_provenance(ncdf, \
"n/a", \
"n/a", \
(/"mean", "rmsd"/), \
diag_script_info@region, \
"other", \
(/"winterstein_franziska", "righi_mattia", \
"eyring_veronika"/), \
(/"righi15gmd", "gleckler08jgr"/), \
info_items[imod]@filename)
; Calculate grading
if (.not.diag_script_info@calc_grading) then
continue
end if
; Loop over requested metrics
do met = 0, nmetrics - 1
if (diag_script_info@metric(met).eq."taylor") then
locidx = ind(datasetnames(imod).eq.taylor&models)
if (ismissing(locidx)) then
continue
end if
taylor(0, locidx, 0) = \
calculate_metric(var_all(:, :, :, 0), var_ref(:, :, :, 0), \
"stddev_ratio")
taylor(0, locidx, 1) = \
calculate_metric(var_all(:, :, :, 0), var_ref(:, :, :, 0), \
"correlation")
elseif (diag_script_info@metric(met).eq."SMPI") then
locidx = ind(datasetnames(imod).eq.smpi&models)
if (ismissing(locidx)) then
continue
end if
smpi(:, locidx) = \
(/calculate_metric(var_all(:, :, :, 0), var_ref(:, :, :, 0), \
"SMPI")/)
else
locidx = ind(datasetnames(imod).eq.grading&models)
if (ismissing(locidx)) then
continue
end if
grading(met, 0, locidx, 0) = \
calculate_metric(var_all(:, :, :, 0), var_ref(:, :, :, 0), \
diag_script_info@metric(met))
if (l_altern) then
grading(met, 0, locidx, 1) = \
calculate_metric(var_all(:, :, :, 0), var_alt(:, :, :, 0), \
diag_script_info@metric(met))
end if
end if
end do
end do
end