From 90d834509953a0b16c6455be99a9ae38a9376de6 Mon Sep 17 00:00:00 2001 From: saschahofmann Date: Thu, 16 Jan 2025 10:45:08 +0100 Subject: [PATCH] Fix QDM with 360_day calendar --- src/xclim/sdba/base.py | 7 ++++--- src/xclim/sdba/utils.py | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/xclim/sdba/base.py b/src/xclim/sdba/base.py index 352d170ae..094ebcca5 100644 --- a/src/xclim/sdba/base.py +++ b/src/xclim/sdba/base.py @@ -179,7 +179,9 @@ def prop_name(self): """Create a significant name for the grouping.""" return "year" if self.prop == "group" else self.prop - def get_coordinate(self, ds: xr.Dataset | None = None) -> xr.DataArray: + def get_coordinate( + self, ds: xr.Dataset | xr.DataArray | None = None + ) -> xr.DataArray: """Return the coordinate as in the output of group.apply. Currently, only implemented for groupings with prop == `month` or `dayofyear`. @@ -196,8 +198,7 @@ def get_coordinate(self, ds: xr.Dataset | None = None) -> xr.DataArray: if ds is not None: cal = get_calendar(ds, dim=self.dim) mdoy = max( - xr.coding.calendar_ops._days_in_year(yr, cal) - for yr in np.unique(ds[self.dim].dt.year) + xr.coding.calendar_ops._days_in_year(ds[self.dim].dt.year, cal) ) else: mdoy = 365 diff --git a/src/xclim/sdba/utils.py b/src/xclim/sdba/utils.py index f8c2a6d2f..3a40a4858 100644 --- a/src/xclim/sdba/utils.py +++ b/src/xclim/sdba/utils.py @@ -475,9 +475,10 @@ def interp_on_quantiles( return out if prop not in xq.dims: - xq = xq.expand_dims({prop: group.get_coordinate()}) + prop_coords = group.get_coordinate(newx) + xq = xq.expand_dims({prop: prop_coords}) if prop not in yq.dims: - yq = yq.expand_dims({prop: group.get_coordinate()}) + yq = yq.expand_dims({prop: prop_coords}) # Adding the cyclic bounds fails for string coordinates like seasons # That's why we map the seasons to integers