Skip to content

Commit

Permalink
fix {hot|cold}_spell_max_length
Browse files Browse the repository at this point in the history
  • Loading branch information
coxipi committed Jun 11, 2024
1 parent edf1e13 commit 3e83bb9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down
2 changes: 1 addition & 1 deletion tests/test_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 4 additions & 6 deletions xclim/indices/_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down Expand Up @@ -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")


Expand Down

0 comments on commit 3e83bb9

Please sign in to comment.