Skip to content

Commit b11e9c5

Browse files
committed
Add test for quantile calc
1 parent ab5b551 commit b11e9c5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

climada/hazard/test/test_forecast.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,33 @@ def test_hazard_forecast_mean_min_max(haz_fc):
215215
assert np.all(haz_fcst_mean.orig)
216216
assert np.all(haz_fcst_min.orig)
217217
assert np.all(haz_fcst_max.orig)
218+
219+
220+
def test_hazard_forecast_quantile(haz_fc):
221+
"""Check quantile method for HazardForecast"""
222+
for q in [0.0, 0.5, 0.8]:
223+
haz_fcst_quantile = haz_fc.quantile(q)
224+
225+
# assert intensity
226+
npt.assert_array_equal(
227+
haz_fcst_quantile.intensity.toarray().squeeze(),
228+
np.quantile(haz_fc.intensity.toarray(), q, axis=0),
229+
)
230+
# assert fraction
231+
npt.assert_array_equal(
232+
haz_fcst_quantile.fraction.toarray().squeeze(),
233+
np.quantile(haz_fc.fraction.toarray(), q, axis=0),
234+
)
235+
236+
# check that attributes where reduced correctly
237+
npt.assert_array_equal(
238+
haz_fcst_quantile.lead_time, np.array([np.timedelta64("NaT")])
239+
)
240+
npt.assert_array_equal(haz_fcst_quantile.member, np.array([-1]))
241+
npt.assert_array_equal(
242+
haz_fcst_quantile.event_name, np.array([f"quantile_{q}"])
243+
)
244+
npt.assert_array_equal(haz_fcst_quantile.event_id, np.array([0]))
245+
npt.assert_array_equal(haz_fcst_quantile.frequency, np.array([1]))
246+
npt.assert_array_equal(haz_fcst_quantile.date, np.array([0]))
247+
npt.assert_array_equal(haz_fcst_quantile.orig, np.array([True]))

0 commit comments

Comments
 (0)