Skip to content

Commit

Permalink
Add positive chill units (#2003)
Browse files Browse the repository at this point in the history
### What kind of change does this PR introduce?

* Adds a new argument to `chill_unit` `positive_only` to compute the
daily positive chill units
  • Loading branch information
Zeitsperre authored Dec 9, 2024
2 parents 959308c + c02e5b2 commit 1190aad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^
Expand All @@ -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`).
Expand Down
4 changes: 4 additions & 0 deletions tests/test_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
12 changes: 10 additions & 2 deletions xclim/indices/_agro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down Expand Up @@ -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="")

0 comments on commit 1190aad

Please sign in to comment.