Skip to content

Commit

Permalink
Merge branch 'main' into check_matching_times
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeitsperre authored Dec 9, 2024
2 parents 1b0b1d4 + 6c554fa commit ed0905f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ target-version = [
]

[tool.bumpversion]
current_version = "0.53.3-dev.8"
current_version = "0.53.3-dev.9"
commit = true
commit_args = "--no-verify"
tag = false
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
2 changes: 1 addition & 1 deletion xclim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

__author__ = """Travis Logan"""
__email__ = "[email protected]"
__version__ = "0.53.3-dev.8"
__version__ = "0.53.3-dev.9"


with _resources.as_file(_resources.files("xclim.data")) as _module_data:
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 ed0905f

Please sign in to comment.