Skip to content

Commit a5a1058

Browse files
committed
changes in docstrings, gsmt output as dict, percentiles as string
1 parent 2a4b05e commit a5a1058

File tree

2 files changed

+87
-47
lines changed

2 files changed

+87
-47
lines changed

climada/hazard/tc_clim_change.py

Lines changed: 79 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@
3535
zip(['cat05', 'cat45', 'intensity'], range(3))
3636
)
3737

38+
MAP_PERC_NAMES = dict(
39+
zip(['5/10', '25', '50', '75', '90/95'], range(5))
40+
)
41+
3842
def get_knutson_scaling_factor(
39-
pct=0,
43+
percentile='50',
4044
basin='NA',
4145
variable='cat05',
4246
baseline=(1950, 2018)
@@ -62,13 +66,12 @@ def get_knutson_scaling_factor(
6266
6367
Parameters
6468
----------
65-
pct: int
66-
percentile of interest:
67-
0 = 5% or 10%
68-
1 = 25%
69-
2 = 50%
70-
3 = 75%
71-
4 = 95% or 90%
69+
percentile: str
70+
percentile of Knutson et al. 2020 estimates. These estimates come from a
71+
review of state-of-the-art literature and models. See Knutson et al. 2020
72+
for more details. Possible values are:
73+
'5/10', '25', '50', '75', '90/95'
74+
Default: '50'
7275
basin : str
7376
region of interest, possible choices are:
7477
'NA', 'WP', 'EP', 'NI', 'SI', 'SP'
@@ -79,6 +82,11 @@ def get_knutson_scaling_factor(
7982
the starting and ending years that define the historical
8083
baseline. The historical baseline period must fall within
8184
the GSMT data period, i.e., 1880-2100.
85+
Returns
86+
-------
87+
future_change_variable : pd.DataFrame
88+
data frame with future projections of the selected variables at different
89+
times (indexes) and for RCPs 2.6, 4.5, 6.0 and 8.5 (columns).
8290
"""
8391

8492
# this could become an input variable in the future
@@ -88,13 +96,16 @@ def get_knutson_scaling_factor(
8896
}
8997

9098
base_start_year, base_end_year = baseline
91-
gmst_data, gmst_start_year, gmst_end_year, rcps = get_gmst_info()
99+
gmst_info = get_gmst_info()
100+
92101
knutson_data = get_knutson_data()
93102

94-
nrcps, gmst_years = gmst_data.shape
103+
nrcps, gmst_years = gmst_info['gmst_data'].shape
95104

96-
if ((base_start_year <= gmst_start_year) or (base_start_year >= gmst_end_year) or
97-
(base_end_year <= gmst_start_year) or (base_end_year >= gmst_end_year)):
105+
if ((base_start_year <= gmst_info['gmst_start_year']) or
106+
(base_start_year >= gmst_info['gmst_end_year']) or
107+
(base_end_year <= gmst_info['gmst_start_year']) or
108+
(base_end_year >= gmst_info['gmst_end_year'])):
98109

99110
raise ValueError("The selected historical baseline falls outside"
100111
"the GMST data period 1880-2100")
@@ -103,10 +114,11 @@ def get_knutson_scaling_factor(
103114
# (these annual values correspond to y in the paper)
104115

105116
var_id = MAP_VARS_NAMES[variable]
117+
perc_id = MAP_PERC_NAMES[percentile]
106118

107119
try:
108120
basin_id = MAP_BASINS_NAMES[basin]
109-
knutson_value = knutson_data[var_id, basin_id, pct]
121+
knutson_value = knutson_data[var_id, basin_id, perc_id]
110122

111123
except KeyError:
112124
# no scaling factors are defined for this basin. Most likely SA.
@@ -117,12 +129,12 @@ def get_knutson_scaling_factor(
117129

118130
for i in range(nrcps):
119131
for j in range(gmst_years):
120-
tc_properties[i, j] = exp(beta * gmst_data[i, j])
132+
tc_properties[i, j] = exp(beta * gmst_info['gmst_data'][i, j])
121133

122134
# calculate baselines for each RCP as averages of the annual values
123135

124-
base_start_index = base_start_year - gmst_start_year
125-
base_end_index = base_end_year - gmst_start_year
136+
base_start_index = base_start_year - gmst_info['gmst_start_year']
137+
base_end_index = base_end_year - gmst_info['gmst_start_year']
126138

127139
baseline_properties = np.empty(nrcps)
128140
for i in range(nrcps):
@@ -140,7 +152,7 @@ def get_knutson_scaling_factor(
140152
for window in range(windows_props['windows']):
141153
mid_year = windows_props['start'] + (window) * windows_props['interval']
142154
mid_years[window] = mid_year
143-
mid_index = mid_year - gmst_start_year
155+
mid_index = mid_year - gmst_info['gmst_start_year']
144156
actual_smoothing = min(
145157
windows_props['smoothing'],
146158
gmst_years - mid_index - 1,
@@ -155,20 +167,38 @@ def get_knutson_scaling_factor(
155167
) / baseline_properties[i]
156168
count += 1
157169

158-
return pd.DataFrame(predicted_property_pcs,
159-
index=mid_years, columns=rcps)
170+
future_change_variable = pd.DataFrame(predicted_property_pcs,
171+
index=mid_years,
172+
columns=gmst_info['rcps'])
173+
return future_change_variable
160174

161175
def get_gmst_info():
162176
"""
163-
Get Global Mean Surface Temperature data from 1880 to 2100 for RCPs 2.6, 4.5, 6.0 and 8.5
177+
Get Global Mean Surface Temperature (GMST) data from 1880 to 2100 for
178+
RCPs 2.6, 4.5, 6.0 and 8.5.
179+
180+
Returns
181+
-------
182+
gmst_info : dict
183+
dictionary with keys:
184+
- rcps: list of strings referring to RCPs 2.6, 4.5, 6.0 and 8.5
185+
- gmst_start_year: integer with the GMST data starting year, 1880
186+
- gmst_start_year: integer with the GMST data ending year, 2100
187+
- gmst_data: array with GMST data across RCPs (first dim) and years (second dim)
164188
"""
165-
rcps = ['2.6', '4.5', '6.0', '8.5']
166-
gmst_start_year = 1880
167-
gmst_end_year = 2100
168189

169-
gmst_data = np.empty((len(rcps), gmst_end_year-gmst_start_year+1))
190+
gmst_info = {}
191+
192+
gmst_info.update({'rcps' : ['2.6', '4.5', '6.0', '8.5']})
193+
gmst_info({'gmst_start_year' : 1880})
194+
gmst_info({'gmst_end_year' : 2100})
170195

171-
gmst_data[0] = [
196+
gmst_info.update({'gmst_data':
197+
np.empty((len(gmst_info['rcps']),
198+
gmst_info['gmst_end_year']-gmst_info['gmst_start_year']+1))
199+
})
200+
201+
gmst_info['gmst_data'][0] = [
172202
-0.16,-0.08,-0.1,-0.16,-0.28,-0.32,-0.3,-0.35,-0.16,-0.1,
173203
-0.35,-0.22,-0.27,-0.31,-0.3,-0.22,-0.11,-0.11,-0.26,-0.17,
174204
-0.08,-0.15,-0.28,-0.37, -0.47,-0.26,-0.22,-0.39,-0.43,-0.48,
@@ -200,7 +230,7 @@ def get_gmst_info():
200230
1.297514286,1.312114286,1.276714286,1.281414286,1.276414286
201231
]
202232

203-
gmst_data[1] = [
233+
gmst_info['gmst_data'][1] = [
204234
-0.16,-0.08,-0.1,-0.16,-0.28,-0.32,-0.3,-0.35,-0.16,-0.1,
205235
-0.35, -0.22,-0.27,-0.31,-0.3,-0.22,-0.11,-0.11,-0.26,-0.17,
206236
-0.08,-0.15,-0.28,-0.37,-0.47,-0.26,-0.22,-0.39,-0.43,-0.48,
@@ -229,7 +259,7 @@ def get_gmst_info():
229259
2.186492857,2.181092857,2.217592857,2.210492857,2.223692857
230260
]
231261

232-
gmst_data[2] = [
262+
gmst_info['gmst_data'][2] = [
233263
-0.16,-0.08,-0.1,-0.16,-0.28,-0.32,-0.3,-0.35,-0.16,-0.1,-0.35,-0.22,-0.27,
234264
-0.31,-0.3,-0.22,-0.11,-0.11,-0.26,-0.17,-0.08,-0.15,-0.28,-0.37,-0.47,-0.26,
235265
-0.22,-0.39,-0.43,-0.48,-0.43,-0.44,-0.36,-0.34,-0.15,-0.14,-0.36,-0.46,-0.29,
@@ -253,7 +283,7 @@ def get_gmst_info():
253283
2.644714286,2.688414286,2.688514286,2.685314286,2.724614286,2.746214286,2.773814286
254284
]
255285

256-
gmst_data[3] = [
286+
gmst_info['gmst_data'][3] = [
257287
-0.16,-0.08,-0.1,-0.16,-0.28,-0.32,-0.3,-0.35,-0.16,-0.1,-0.35,-0.22,-0.27,
258288
-0.31,-0.3,-0.22,-0.11,-0.11,-0.26,-0.17,-0.08,-0.15,-0.28,-0.37,-0.47,-0.26,
259289
-0.22,-0.39,-0.43,-0.48,-0.43,-0.44,-0.36,-0.34,-0.15,-0.14,-0.36,-0.46,-0.29,
@@ -277,7 +307,7 @@ def get_gmst_info():
277307
4.172064286,4.225264286,4.275064286,4.339064286,4.375864286,4.408064286,4.477764286
278308
]
279309

280-
return gmst_data, gmst_start_year, gmst_end_year, rcps
310+
return gmst_info
281311

282312
def get_knutson_data():
283313
"""
@@ -286,39 +316,51 @@ def get_knutson_data():
286316
Tropical cyclones and climate change assessment. Part II: Projected
287317
response to anthropogenic warming. Bull. Amer. Meteor. Soc., 101 (3), E303–E322,
288318
https://doi.org/10.1175/BAMS-D-18-0194.1.
289-
290-
for 4 variables (i.e., cat05 frequency, cat45 frequency, intensity precipitation rate),
319+
320+
for 4 variables (i.e., cat05 frequency, cat45 frequency, intensity, precipitation rate),
291321
6 regions (i.e., N. Atl, NW Pac., NE Pac., N. Ind, S. Ind., SW Pac.) and
292-
5 metrics (i.e., 5% or 10%, 25%, median, 75%, 95% or 90%).
322+
5 metrics (i.e., 5% or 10%, 25%, 50%, 75%, 95% or 90%).
323+
324+
Returns
325+
-------
326+
knutson_data : np.array of dimension (4x6x5)
327+
array contaning data used by Knutson et al. (2020) to project changes in cat05 frequency,
328+
cat45 frequency, intensity and precipitation rate (first array's dimension), for the
329+
N. Atl, NW Pac., NE Pac., N. Ind, S. Ind., SW Pac. regions (second array's dimension)
330+
for the 5%/10%, 25%, 50%, 75%, 95%/90% percentiles (thirs array's dimension).
293331
"""
294332

295-
knutson_data = np.empty((4, 6, 5))
333+
knutson_data = np.empty((4,6,5))
296334

297-
# fig 1 in Knutson et al. 2020 (except min, max metrics and global region)
335+
# fig 1 in Knutson et al. 2020
336+
# (except min, max metrics and global region): cat05 frequency
298337
knutson_data[0,0]=[-34.49,-24.875,-14.444,3.019,28.737]
299338
knutson_data[0,1]=[-30.444,-20,-10.27,0.377,17.252]
300339
knutson_data[0,2]=[-32.075,-18.491,-3.774,11.606,36.682]
301340
knutson_data[0,3]=[-35.094,-15.115,-4.465,5.785,29.405]
302341
knutson_data[0,4]=[-32.778,-22.522,-17.297,-8.995,7.241]
303342
knutson_data[0,5]=[-40.417,-26.321,-18.113,-8.21,4.689]
304343

305-
# fig 2 in Knutson et al. 2020 (except min, max metrics and global region)
344+
# fig 2 in Knutson et al. 2020
345+
# (except min, max metrics and global region): cat45 frequency
306346
knutson_data[1,0]=[-38.038,-22.264,11.321,38.302,81.874]
307347
knutson_data[1,1]=[-25.811,-14.34,-4.75,16.146,41.979]
308348
knutson_data[1,2]=[-24.83,-6.792,22.642,57.297,104.315]
309349
knutson_data[1,3]=[-30.566,-16.415,5.283,38.491,79.119]
310350
knutson_data[1,4]=[-23.229,-13.611,4.528,26.645,63.514]
311351
knutson_data[1,5]=[-42.453,-29.434,-14.467,-0.541,19.061]
312352

313-
# fig 3 in Knutson et al. 2020 (except min, max metrics and global region)
353+
# fig 3 in Knutson et al. 2020
354+
# (except min, max metrics and global region): intensity
314355
knutson_data[2,0]=[0.543,1.547,2.943,4.734,6.821]
315356
knutson_data[2,1]=[1.939,3.205,5.328,6.549,9.306]
316357
knutson_data[2,2]=[-2.217,0.602,5.472,9.191,10.368]
317358
knutson_data[2,3]=[-0.973,1.944,4.324,6.15,7.808]
318359
knutson_data[2,4]=[1.605,3.455,5.405,7.69,10.884]
319360
knutson_data[2,5]=[-6.318,-0.783,0.938,5.314,12.213]
320361

321-
# fig 4 in Knutson et al. 2020 (except min, max metrics and global region)
362+
# fig 4 in Knutson et al. 2020:
363+
# (except min, max metrics and global region): precipitation rate
322364
knutson_data[3,0]=[5.848,9.122,15.869,20.352,22.803]
323365
knutson_data[3,1]=[6.273,12.121,16.486,18.323,23.784]
324366
knutson_data[3,2]=[6.014,8.108,21.081,29.324,31.838]

climada/hazard/trop_cyclone.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def from_tracks(
336336

337337
def apply_climate_scenario_knu(
338338
self,
339-
pct: int = 2,
339+
percentile: str = '50',
340340
rcp_scenario: int = 85,
341341
ref_year: int = 2035,
342342
baseline: tuple = (1982, 2022)
@@ -369,14 +369,12 @@ def apply_climate_scenario_knu(
369369
Default: 85
370370
baseline : tuple of int
371371
the starting and ending years that define the historical baseline.
372-
pct: int
373-
percentile of interest:
374-
0 = 5% or 10%
375-
1 = 25%
376-
2 = 50%
377-
3 = 75%
378-
4 = 95% or 90%
379-
Default: 2
372+
percentile: str
373+
percentile of Knutson et al. 2020 estimates. These estimates come from a
374+
review of state-of-the-art literature and models. See Knutson et al. 2020
375+
for more details. Possible values are:
376+
'5/10', '25', '50', '75', '90/95'
377+
Default: '50'
380378
Returns
381379
-------
382380
haz_cc : climada.hazard.TropCyclone
@@ -397,7 +395,7 @@ def apply_climate_scenario_knu(
397395
for basin in np.unique(tc_cc.basin):
398396
scale_year_rcp_05, scale_year_rcp_45 = [
399397
get_knutson_scaling_factor(
400-
pct=pct,
398+
percentile=percentile,
401399
variable=variable,
402400
basin=basin,
403401
baseline=baseline

0 commit comments

Comments
 (0)