Skip to content

Commit

Permalink
Fix QDM with 360_day calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
saschahofmann committed Jan 16, 2025
1 parent d891929 commit 90d8345
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/xclim/sdba/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/xclim/sdba/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 90d8345

Please sign in to comment.