diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a3e0bc332..9ce8ae9cf 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,7 +4,7 @@ Changelog v0.54.0 (unreleased) -------------------- -Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Pascal Bourgault (:user:`aulemahal`), Éric Dupuis (:user:`coxipi`). +Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Pascal Bourgault (:user:`aulemahal`), Éric Dupuis (:user:`coxipi`), Sascha Hofmann (:user:`saschahofmann`). Breaking changes ^^^^^^^^^^^^^^^^ @@ -30,6 +30,10 @@ CI changes ^^^^^^^^^^ * Added the `green-coding-solutions/eco-ci-energy-estimation` GitHub Action to the workflows to establish energy and carbon usage of CI activity. (:pull:`1863`). +New features and enhancements +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +* ``chill_unit`` now accepts a new argument `positive_only` to compute the daily positive chill units. (:pull:`2003`). + v0.53.2 (2024-10-31) -------------------- Contributors to this version: Éric Dupuis (:user:`coxipi`), Pascal Bourgault (:user:`aulemahal`), Trevor James Smith (:user:`Zeitsperre`). diff --git a/tests/test_indices.py b/tests/test_indices.py index 3fcd31319..22978b49d 100644 --- a/tests/test_indices.py +++ b/tests/test_indices.py @@ -372,6 +372,10 @@ def test_chill_units(self, tas_series): out = xci.chill_units(tas) assert out[0] == 0.5 * num_cu_05 + num_cu_1 - 0.5 * num_cu_min_05 - num_cu_min_1 + out = xci.chill_units(tas, positive_only=True) + # Only the last day contains negative chill units. + assert out[0] == 0.5 * num_cu_05 + num_cu_1 - 0.5 * 3 + def test_cool_night_index(self, open_dataset): ds = open_dataset("cmip5/tas_Amon_CanESM2_rcp85_r1i1p1_200701-200712.nc") ds = ds.rename(dict(tas="tasmin")) diff --git a/xclim/indices/_agro.py b/xclim/indices/_agro.py index 3a9cf0139..4fe48a4e9 100644 --- a/xclim/indices/_agro.py +++ b/xclim/indices/_agro.py @@ -1635,17 +1635,21 @@ def chill_portions( @declare_units(tas="[temperature]") -def chill_units(tas: xarray.DataArray, freq: str = "YS") -> xarray.DataArray: +def chill_units( + tas: xarray.DataArray, positive_only: bool = False, freq: str = "YS" +) -> xarray.DataArray: """Chill units using the Utah model Chill units are a measure to estimate the bud breaking potential of different crop based on Richardson et al. (1974). The Utah model assigns a weight to each hour depending on the temperature recognising that high temperatures can actual decrease, - the potential for bud breaking. + the potential for bud breaking. Providing `positive_only=True` will ignore days with negative chill units. Parameters ---------- tas : xr.DataArray Hourly temperature. + positive_only : bool + If `True`, only positive daily chill units are aggregated. Returns ------- @@ -1680,4 +1684,8 @@ def chill_units(tas: xarray.DataArray, freq: str = "YS") -> xarray.DataArray: ), ) cu = cu.where(tas.notnull()) + + if positive_only: + daily = cu.resample(time="1D").sum() + cu = daily.where(daily > 0) return cu.resample(time=freq).sum().assign_attrs(units="")