Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref & hist times in bias adjustment methods must match #1995

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 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`).
Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Pascal Bourgault (:user:`aulemahal`), Éric Dupuis (:user:`coxipi`).

Breaking changes
----------------
Expand All @@ -17,6 +17,7 @@ Bug fixes
Internal changes
^^^^^^^^^^^^^^^^
* Changed french translations with word "pluvieux" to "avec précipitations". (:issue:`1960`, :pull:`1994`).
* Using different time for `ref` and `hist` is now explicitly forbidden in many bias adjustment methods (e.g. `EmpiricalQuantileMapping`). (:issue:`1903`, :pull:`1995`)

v0.53.2 (2024-10-31)
--------------------
Expand Down
11 changes: 11 additions & 0 deletions xclim/sdba/adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ def __convert_units_to(_input_da, _internal_dim, _internal_target):
convert_units_to(inda, target, context="infer") for inda in inputs
), target

@classmethod
def _check_matching_time(cls, ref, hist):
"""Raise an error ref and hist times don't match."""
if all(ref.time == hist.time) is False:
raise ValueError("`ref` and `hist` should have the same time arrays.")

@classmethod
def _train(cls, ref, hist, **kwargs):
raise NotImplementedError()
Expand Down Expand Up @@ -258,6 +264,9 @@ def train(cls, ref: DataArray, hist: DataArray, **kwargs) -> TrainAdjust:
else:
train_units = ""

if cls._allow_diff_calendars is False:
cls._check_matching_time(ref, hist)

Comment on lines +267 to +269
Copy link
Contributor Author

@coxipi coxipi Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aulemahal was this more or less the intent behind _allow_diff_calendars? Or is this just a condition so that map_groups is easier to operate? It seems to be applied pretty broadly, e.g. in Scaling where we would in principle not need such a constraint in this case.

Perhaps I should add a new variable _allow_diff_training_time that would be True for Scaling, but False for the Quantile methods (instead of re-using _allow_diff_calendars?

ds, params = cls._train(ref, hist, **kwargs)
obj = cls(
_trained=True,
Expand Down Expand Up @@ -1737,6 +1746,8 @@ class MBCn(TrainAdjust):
Only "time" and "time.dayofyear" (with a suitable window) are implemented as possible values for `group`.
"""

_allow_diff_calendars = False

@classmethod
def _train(
cls,
Expand Down
Loading