Skip to content

Commit

Permalink
Add more tests for heat_wave_magnitude
Browse files Browse the repository at this point in the history
  • Loading branch information
seblehner committed Sep 16, 2024
1 parent 6eb6394 commit 532da97
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
26 changes: 26 additions & 0 deletions tests/test_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,32 @@ def test_nan_presence(self, tasmax_series):
np.testing.assert_array_equal(hwi, [np.nan])


class TestHeatWaveMagnitude:
def test_simple(self, tasmax_series):
tx = np.zeros(366)
tx[:5] = np.array([30, 30, 30, 30, 30])
tx = tasmax_series(tx + K2C, start="1/1/2000")
hwm = atmos.heat_wave_magnitude(tx, freq="YS")
np.testing.assert_array_equal(hwm, [25])

def test_convert_units(self, tasmax_series):
tx = np.zeros(366)
tx[:5] = np.array([30, 30, 30, 30, 30])
tx = tasmax_series(tx, start="1/1/2000")
tx.attrs["units"] = "C"
hwm = atmos.heat_wave_magnitude(tx, freq="YS")
np.testing.assert_array_equal(hwm, [25])

def test_nan_presence(self, tasmax_series):
tx = np.zeros(366)
tx[:5] = np.array([30, 30, 30, 30, 30])
tx[-1] = np.nan
tx = tasmax_series(tx + K2C, start="1/1/2000")

hwm = atmos.heat_wave_magnitude(tx, freq="YS")
np.testing.assert_array_equal(hwm, [np.nan])


class TestDailyFreezeThaw:
nc_tasmax = os.path.join("NRCANdaily", "nrcan_canada_daily_tasmax_1990.nc")
nc_tasmin = os.path.join("NRCANdaily", "nrcan_canada_daily_tasmin_1990.nc")
Expand Down
6 changes: 3 additions & 3 deletions xclim/indicators/atmos/_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ class TempWithIndexing(ResamplingIndicatorWithIndexing):
title="Heat wave magnitude",
identifier="heat_wave_magnitude",
units="degC",
long_name="Maximum difference between daily maximum temperature and {thresh_tasmax} for days within a heat wave. "
long_name="Maximum difference between daily maximum temperature and {thresh} for days within a heat wave. "
"A heat wave is defined as a series of at least {window} consecutive days with daily maximum temperature above "
"{thresh_tasmax}.",
"{thresh}.",
description="Magnitude of the most intensive heat wave per {freq} as accumulated deg C above a given threshold "
"A heat wave occurs when daily maximum temperatures exceed {thresh_tasmax} for {window} days.",
"A heat wave occurs when daily maximum temperatures exceed {thresh} for {window} days.",
abstract="Magnitude of the most intensive heat wave per {freq}. A heat wave occurs when daily maximum "
"temperatures exceed given thresholds for a number of days.",
cell_methods="",
Expand Down
2 changes: 1 addition & 1 deletion xclim/indices/_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ def heat_wave_magnitude(
out = rl.resample_and_rl(
over_values,
resample_before_rl,
rl.windowed_run_sum,
rl.windowed_max_run_sum,
window=window,
freq=freq,
)
Expand Down

0 comments on commit 532da97

Please sign in to comment.