diff --git a/tests/test_temperature.py b/tests/test_temperature.py index 45f3c94b7..03fbb1ab4 100644 --- a/tests/test_temperature.py +++ b/tests/test_temperature.py @@ -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") diff --git a/xclim/indicators/atmos/_temperature.py b/xclim/indicators/atmos/_temperature.py index e13f82e07..df540d697 100644 --- a/xclim/indicators/atmos/_temperature.py +++ b/xclim/indicators/atmos/_temperature.py @@ -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="", diff --git a/xclim/indices/_threshold.py b/xclim/indices/_threshold.py index e3e8b1097..ac8add779 100644 --- a/xclim/indices/_threshold.py +++ b/xclim/indices/_threshold.py @@ -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, )