From d715dc0dbc5092f42b34e13ace6d60f79ebf8a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Dupuis?= Date: Thu, 16 Nov 2023 09:52:11 -0500 Subject: [PATCH 1/2] use `_cumsum_reset_on_zero` instead of `rle` --- xclim/indices/run_length.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xclim/indices/run_length.py b/xclim/indices/run_length.py index 3ca9607a0..855f4e4c3 100644 --- a/xclim/indices/run_length.py +++ b/xclim/indices/run_length.py @@ -416,7 +416,7 @@ def _boundary_run( ufunc_1dim: str | bool, position: str, ) -> xr.DataArray: - """Return the index of the first item of the first run of at least a given length. + """Return the index of the first item of the first or last run of at least a given length. Parameters ---------- @@ -493,9 +493,10 @@ def find_boundary_run(runs, position): out = coord_transform(out, da) else: - # for "first" run, return "first" element in the run (and conversely for "last" run) - d = rle(da, dim=dim, index=position) + # _cusum_reset_on_zero() is an intermediate step in rle, which is sufficient here + d = _cumsum_reset_on_zero(da, dim=dim, index=position) d = xr.where(d >= window, 1, 0) + # for "first" run, return "first" element in the run (and conversely for "last" run) if freq is not None: out = d.resample({dim: freq}).map(find_boundary_run, position=position) else: From 66a4a20ce3df83291dd9b434d663f0fd51329f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Dupuis?= Date: Thu, 16 Nov 2023 10:38:41 -0500 Subject: [PATCH 2/2] updates CHANGES --- CHANGES.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 2cdfedfac..7770ff3c0 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,7 @@ Changelog v0.47.0 (unreleased) -------------------- -Contributors to this version: Juliette Lavoie (:user:`juliettelavoie`), Pascal Bourgault (:user:`aulemahal`), Trevor James Smith (:user:`Zeitsperre`). +Contributors to this version: Juliette Lavoie (:user:`juliettelavoie`), Pascal Bourgault (:user:`aulemahal`), Trevor James Smith (:user:`Zeitsperre`), Éric Dupuis (:user:`coxipi`). New features and enhancements ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -17,6 +17,7 @@ Bug fixes Internal changes ^^^^^^^^^^^^^^^^ * Pinned `cf-xarray` below v0.8.5 in Python3.8 installation to further extend legacy support. (:pull:`1519`). +* Use the intermediate step `_cumsum_reset_on_zero` instead of `rle` which is sufficient in `_boundary_run`. (:issue:`1405`, :pull:`1530`). v0.46.0 (2023-10-24) --------------------