Skip to content

Commit

Permalink
Merge branch 'main' into dynamic-time-selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeitsperre authored Feb 11, 2025
2 parents fccf1b5 + 2a44a74 commit 0cea4d1
Show file tree
Hide file tree
Showing 9 changed files with 456 additions and 463 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ Changelog

v0.55.0 (unreleased)
--------------------
Contributors to this version: Juliette Lavoie (:user:`juliettelavoie`), Trevor James Smith (:user:`Zeitsperre`), Sascha Hofmann (:user:`saschahofmann`), Baptiste Hamon (:user:`baptistehamon`), Pascal Bourgault (:user:`aulemahal`).
Contributors to this version: Juliette Lavoie (:user:`juliettelavoie`), Trevor James Smith (:user:`Zeitsperre`), Sascha Hofmann (:user:`saschahofmann`), Pascal Bourgault (:user:`aulemahal`), Baptiste Hamon (:user:`baptistehamon`).

Breaking changes
^^^^^^^^^^^^^^^^
* Missing value method "WMO" was modified to remove the criterion that the timeseries needs to be continuous (without holes). (:pull:`2058`).

Announcements
^^^^^^^^^^^^^
Expand All @@ -23,13 +27,18 @@ New features and enhancements
* `xclim` now tracks energy usage and carbon emissions ("last run", "average", and "total") during CI workflows using the `eco-ci-energy-estimation` GitHub Action. (:pull:`2046`).
* ``xclim.testing.helpers.test_timeseries`` now accepts a `calendar` argument that is forwarded to ``xr.cftime_range``. (:pull:`2019`).
* New ``xclim.indices.fao_allen98``, exporting the FAO-56 Penman-Monteith equation for potential evapotranspiration (:issue:`2004`, :pull:`2067`).
* Time selection in ``xclim.core.calendar.select_time`` and the ``**indexer`` argument of indicators now support day-of-year bounds given as DataArrays with spatial and/or temporal dimensions. (:issue:`1987`, :pull:`2055`).
* Missing values method "pct" and "at_least_n" now accept a new "subfreq" option that allows to compute the missing mask in two steps. When given, the algorithm is applied at this "subfreq" resampling frequency first and then the result is resampled at the target indicator frequency. In the output, a period is invalid if any of its subgroup where flagged as invalid by the chosen method. (:pull:`2058`, :issue:`1820`).
* Time selection in ``xclim.core.calendar.select_time`` and the ``**indexer`` argument of indicators now supports day-of-year bounds given as DataArrays with spatial and/or temporal dimensions. (:issue:`1987`, :pull:`2055`).

Internal changes
^^^^^^^^^^^^^^^^
* `sphinx-codeautolink` and `pygments` have been temporarily pinned due to breaking API changes. (:pull:`2030`).
* Adjusted the ``TestOfficialYaml`` test to use a dynamic method for finding the installed location of `xclim`. (:pull:`2028`).
* Adjusted two tests for better handling when running in Windows environments. (:pull:`2057`).
* Refactor of the ``xclim.core.missing`` module, usage of the ``Missing`` objects has been broken. (:pull:`2058`, :issue:`1820`, :issue:`2000`).
- Objects are initialized with their options and then called with the data, input frequency, target frequency and indexer.
- Subclasses receive non-resampled DataArray in their ``is_missing`` methods.
- ``MissingWMO`` now uses ``xclim.indices.helpers.resample_map`` which should greatly improve performance in a dask context.

Bug fixes
^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ target-version = [
]

[tool.bumpversion]
current_version = "0.54.1-dev.10"
current_version = "0.54.1-dev.11"
commit = true
commit_args = "--no-verify --signoff"
tag = false
Expand Down
2 changes: 1 addition & 1 deletion src/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.54.1-dev.10"
__version__ = "0.54.1-dev.11"


with _resources.as_file(_resources.files("xclim.data")) as _module_data:
Expand Down
20 changes: 9 additions & 11 deletions src/xclim/core/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1529,12 +1529,6 @@ def __init__(self, **kwds):
"Cannot set `missing_options` with `missing` method being from context."
)

# Validate hard-coded missing options
kls = MISSING_METHODS[self.missing]
self._missing = kls.execute
if self.missing_options:
kls.validate(**self.missing_options)

super().__init__(**kwds)

def _history_string(self, das, params):
Expand All @@ -1546,6 +1540,8 @@ def _history_string(self, das, params):

if missing != "skip":
mopts = self.missing_options or OPTIONS[MISSING_OPTIONS].get(missing)
if mopts.get("subfreq", "absent") is None:
mopts.pop("subfreq") # impertinent default
if mopts:
opt_str += f", missing_options={mopts}"

Expand All @@ -1560,17 +1556,19 @@ def _postprocess(self, outs, das, params):
outs = super()._postprocess(outs, das, params)

freq = self._get_missing_freq(params)
if self.missing != "skip" or freq is False:
method = (
self.missing if self.missing != "from_context" else OPTIONS[CHECK_MISSING]
)
if method != "skip" and freq is not False:
# Mask results that do not meet criteria defined by the `missing` method.
# This means all outputs must have the same dimensions as the broadcasted inputs (excluding time)
options = self.missing_options or OPTIONS[MISSING_OPTIONS].get(
self.missing, {}
)
options = self.missing_options or OPTIONS[MISSING_OPTIONS].get(method, {})
misser = MISSING_METHODS[method](**options)

# We flag periods according to the missing method. skip variables without a time coordinate.
src_freq = self.src_freq if isinstance(self.src_freq, str) else None
miss = (
self._missing(da, freq, src_freq, options, params.get("indexer", {}))
misser(da, freq, src_freq, **params.get("indexer", {}))
for da in das.values()
if "time" in da.coords
)
Expand Down
Loading

0 comments on commit 0cea4d1

Please sign in to comment.