Skip to content

Commit efc1ac2

Browse files
committed
Merge branch 'implement_mean_min_max' into implement_quantiles
2 parents 2feb7d2 + 23660de commit efc1ac2

File tree

4 files changed

+23
-29
lines changed

4 files changed

+23
-29
lines changed

climada/engine/impact_forecast.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,29 +242,29 @@ def select(
242242
reset_frequency=reset_frequency,
243243
)
244244

245-
def _reduce_attrs(self, reduce_method: str):
245+
def _reduce_attrs(self, event_name: str):
246246
"""
247247
Reduce the attributes of an ImpactForecast to a single value.
248248
249249
Attributes are modified as follows:
250250
- lead_time: set to NaT
251251
- member: set to -1
252252
- event_id: set to 0
253-
- event_name: set to reduce_method
254-
- date: set to the minimum value
253+
- event_name: set to the name of the reduction method (default)
254+
- date: set to 0
255255
- frequency: set to 1
256256
257257
Parameters
258258
----------
259-
reduce_method : str
260-
The reduction method used to reduce the attributes.
259+
event_name : str
260+
The event name given to the reduced data.
261261
"""
262262
reduced_attrs = {
263263
"lead_time": np.array([np.timedelta64("NaT")]),
264264
"member": np.array([-1]),
265265
"event_id": np.array([0]),
266-
"event_name": np.array([reduce_method]),
267-
"date": np.array([self.date.min()]),
266+
"event_name": np.array([event_name]),
267+
"date": np.array([0]),
268268
"frequency": np.array([1]),
269269
}
270270

@@ -346,9 +346,6 @@ def mean(self):
346346
"""
347347
Reduce the impact matrix and at_event of an ImpactForecast to the mean value.
348348
349-
The mean value is computed by taking the mean of the impact matrix along the
350-
exposure points axis (axis=1) and then taking the mean of the resulting array.
351-
352349
Parameters
353350
----------
354351
None

climada/engine/test/test_impact_forecast.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,6 @@ def test_impact_forecast_mean_min_max(impact_forecast):
258258
assert imp_fcst_mean.frequency == 1
259259
assert imp_fcst_min.frequency == 1
260260
assert imp_fcst_max.frequency == 1
261-
assert imp_fcst_mean.date == impact_forecast.date.min()
262-
assert imp_fcst_min.date == impact_forecast.date.min()
263-
assert imp_fcst_max.date == impact_forecast.date.min()
261+
assert imp_fcst_mean.date == 0
262+
assert imp_fcst_min.date == 0
263+
assert imp_fcst_max.date == 0

climada/hazard/forecast.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,29 +106,29 @@ def _check_sizes(self):
106106
size(exp_len=num_entries, var=self.member, var_name="Forecast.member")
107107
size(exp_len=num_entries, var=self.lead_time, var_name="Forecast.lead_time")
108108

109-
def _reduce_attrs(self, reduce_method: str):
109+
def _reduce_attrs(self, event_name: str):
110110
"""
111111
Reduce the attributes of a HazardForecast to a single value.
112112
113113
Attributes are modified as follows:
114114
- lead_time: set to NaT
115115
- member: set to -1
116116
- event_id: set to 0
117-
- event_name: set to reduce_method
118-
- date: set to the minimum value
117+
- event_name: set to the name of the reduction method (default)
118+
- date: set to 0
119119
- frequency: set to 1
120120
121121
Parameters
122122
----------
123-
reduce_method : str
124-
The reduction method used to reduce the attributes.
123+
event_name : str
124+
The event_name given to the reduced data.
125125
"""
126126
reduced_attrs = {
127127
"lead_time": np.array([np.timedelta64("NaT")]),
128128
"member": np.array([-1]),
129129
"event_id": np.array([0]),
130-
"event_name": np.array([reduce_method]),
131-
"date": np.array([self.date.min()]),
130+
"event_name": np.array([event_name]),
131+
"date": np.array([0]),
132132
"frequency": np.array([1]),
133133
"orig": np.array([True]),
134134
}
@@ -137,7 +137,7 @@ def _reduce_attrs(self, reduce_method: str):
137137

138138
def min(self):
139139
"""
140-
Reduce the impact matrix and at_event of a HazardForecast to the minimum
140+
Reduce the intensity and fraction of a HazardForecast to the minimum
141141
value.
142142
143143
Parameters
@@ -171,7 +171,7 @@ def min(self):
171171

172172
def max(self):
173173
"""
174-
Reduce the impact matrix and at_event of a HazardForecast to the maximum
174+
Reduce the intensity and fraction of a HazardForecast to the maximum
175175
value.
176176
177177
Parameters
@@ -205,10 +205,7 @@ def max(self):
205205

206206
def mean(self):
207207
"""
208-
Reduce the impact matrix and at_event of a HazardForecast to the mean value.
209-
210-
The mean value is computed by taking the mean of the impact matrix along the
211-
exposure points axis (axis=1) and then taking the mean of the resulting array.
208+
Reduce the intensity and fraction of a HazardForecast to the mean value.
212209
213210
Parameters
214211
----------

climada/hazard/test/test_forecast.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ def test_hazard_forecast_mean_min_max(haz_fc):
209209
assert haz_fcst_mean.frequency == 1
210210
assert haz_fcst_min.frequency == 1
211211
assert haz_fcst_max.frequency == 1
212-
assert haz_fcst_mean.date == haz_fc.date.min()
213-
assert haz_fcst_min.date == haz_fc.date.min()
214-
assert haz_fcst_max.date == haz_fc.date.min()
212+
assert haz_fcst_mean.date == 0
213+
assert haz_fcst_min.date == 0
214+
assert haz_fcst_max.date == 0
215215
assert np.all(haz_fcst_mean.orig)
216216
assert np.all(haz_fcst_min.orig)
217217
assert np.all(haz_fcst_max.orig)

0 commit comments

Comments
 (0)