Skip to content

Commit

Permalink
fix {hot|cold}_spell_max_length (#1777)
Browse files Browse the repository at this point in the history
### What kind of change does this PR introduce?

* Fixes a bug. `{hot|cold}_spell_max_length` were not properly using
`window` to only count spells with at least `window` time steps, now
they do.

### Does this PR introduce a breaking change?
* Yes, output of functions will sometimes change (and work as expected)
  • Loading branch information
Zeitsperre authored Jun 11, 2024
2 parents 24b8971 + e3f04cd commit c9847db
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,7 +4,7 @@ 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`).

Breaking changes
^^^^^^^^^^^^^^^^
Expand All @@ -18,6 +18,10 @@ Internal changes
* Fixed some previously uncaught errors raised from recent versions of `pylint` and `codespell`. (:pull:`1772`).
* Set the `doctest` examples to all use `h5netcdf` with worker-separated caches to load datasets. (:pull:`1772`).

Bug fixes
^^^^^^^^^
* ``xclim.indices.{cold|hot}_spell_total_length`` now properly uses the argument `window` to only count spells with at least `window` time steps. (:issue:`1765`, :pull:`1777`).

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 c9847db

Please sign in to comment.