diff --git a/CHANGES.rst b/CHANGES.rst index 6eafde626..96b48b4cc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,12 +4,16 @@ Changelog v0.50.0 (unreleased) -------------------- -Contributors to this version: Trevor James Smith (:user:`Zeitsperre`). +Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Éric Dupuis (:user:`coxipi`). Internal changes ^^^^^^^^^^^^^^^^ * Synchronized tooling versions across ``pyproject.toml`` and ``tox.ini`` and pinned them to the latest stable releases in GitHub Workflows. (:pull:`1744`). +Bug fixes +^^^^^^^^^ +* ``xclim.indices.{cold|hot}_spell_total_length`` now properly use the argument `window` to only count spells with at least `window` time steps . (:issue:`1765`). + v0.49.0 (2024-05-02) -------------------- Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Pascal Bourgault (:user:`aulemahal`), Juliette Lavoie (:user:`juliettelavoie`), David Huard (:user:`huard`), Gabriel Rondeau-Genesse (:user:`RondeauG`), Javier Diez-Sierra (:user:`JavierDiezSierra`), Sarah Gammon (:user:`SarahG-579462`), Éric Dupuis (:user:`coxipi`). diff --git a/tests/test_indices.py b/tests/test_indices.py index e2a8ccc47..0f50b60a0 100644 --- a/tests/test_indices.py +++ b/tests/test_indices.py @@ -1421,7 +1421,7 @@ class TestHotSpellTotalLength: ("29 C", 3, ">", 8), # Two HS ("29 C", 3, ">=", 9), # One long HS, minus a day ("40 C", 3, ">", 0), # No HS - ("30 C", 5, ">", 8), # Windowed + ("30 C", 5, ">", 5), # Windowed ], ) def test_1d(self, tasmax_series, thresh, window, op, expected): diff --git a/xclim/indices/_threshold.py b/xclim/indices/_threshold.py index 150c55b04..604fad520 100644 --- a/xclim/indices/_threshold.py +++ b/xclim/indices/_threshold.py @@ -336,14 +336,13 @@ def cold_spell_total_length( thresh = convert_units_to(thresh, tas) cond = compare(tas, op, thresh, constrain=("<", "<=")) - max_l = rl.resample_and_rl( + out = rl.resample_and_rl( cond, resample_before_rl, rl.windowed_run_count, - window=1, + window=window, freq=freq, ) - out = max_l.where(max_l >= window, 0) return to_agg_units(out, tas, "count") @@ -2112,14 +2111,13 @@ def hot_spell_total_length( thresh = convert_units_to(thresh, tasmax) cond = compare(tasmax, op, thresh, constrain=(">", ">=")) - max_l = rl.resample_and_rl( + out = rl.resample_and_rl( cond, resample_before_rl, rl.windowed_run_count, - window=1, + window=window, freq=freq, ) - out = max_l.where(max_l >= window, 0) return to_agg_units(out, tasmax, "count")