You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
adapt_freq stopped working with 360_day calendar and group 31-doy
What I Did
import xarray as xr
import xclim as xc
from xclim.testing.helpers import test_timeseries as timeseries
import xscen as xs
from xclim import sdba
import numpy as np
group = {"group": "time.dayofyear", "window": 31}
group = sdba.Grouper.from_kwargs(**group)["group"]
dref = timeseries(np.ones(365 * 3), variable="tas", start="2001-01-01", freq="D", as_dataset=True)
dhist = timeseries(
np.concatenate([np.ones(365 * 2) * 2, np.ones(365) * 3]),
variable="tas",
start="2001-01-01",
freq="D",
as_dataset=True,
)
ref=dref.convert_calendar("360_day", align_on='year')['tas']
hist=dhist.convert_calendar("360_day", align_on='year')['tas']
hist_ad, pth, dP0 = sdba.processing.adapt_freq(
ref, hist, thresh="2 K", group=group
)
What I Received
Traceback (most recent call last):
File "/exec/jlavoie/.conda/xscen-dev/lib/python3.12/site-packages/IPython/core/interactiveshell.py", line 3577, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-5-ef5356e36a2f>", line 20, in <module>
hist_ad, pth, dP0 = sdba.processing.adapt_freq(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<boltons.funcutils.FunctionBuilder-288>", line 2, in adapt_freq
File "/exec/jlavoie/.conda/xscen-dev/lib/python3.12/site-packages/xclim/core/formatting.py", line 468, in _call_and_add_history
outs = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/exec/jlavoie/.conda/xscen-dev/lib/python3.12/site-packages/xclim/sdba/processing.py", line 103, in adapt_freq
out = _adapt_freq(xr.Dataset({"sim": sim, "ref": ref}), group=group, thresh=thresh)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<boltons.funcutils.FunctionBuilder-280>", line 2, in _map_blocks
File "/exec/jlavoie/.conda/xscen-dev/lib/python3.12/site-packages/xclim/sdba/base.py", line 485, in _parse_group
return func(*f_args, **f_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/exec/jlavoie/.conda/xscen-dev/lib/python3.12/site-packages/xclim/sdba/base.py", line 639, in _map_blocks
coords[group.prop] = group.get_coordinate(ds=ds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/exec/jlavoie/.conda/xscen-dev/lib/python3.12/site-packages/xclim/sdba/base.py", line 198, in get_coordinate
mdoy = max(
^^^^
File "/exec/jlavoie/.conda/xscen-dev/lib/python3.12/site-packages/xclim/sdba/base.py", line 199, in <genexpr>
xr.coding.calendar_ops._days_in_year(yr, cal)
File "/exec/jlavoie/.conda/xscen-dev/lib/python3.12/site-packages/xarray/coding/calendar_ops.py", line 244, in _days_in_year
return full_like(years, 360)
^^^^^^^^^^^^^^^^^^^^^
File "/exec/jlavoie/.conda/xscen-dev/lib/python3.12/site-packages/xarray/core/common.py", line 1719, in full_like
raise TypeError("Expected DataArray, Dataset, or Variable")
TypeError: Expected DataArray, Dataset, or Variable
But it works if I don't convert the calendar or if group time.
Note: this breaks a xscen test.
Code of Conduct
I agree to follow this project's Code of Conduct
The text was updated successfully, but these errors were encountered:
Generic Issue
Description
adapt_freq
stopped working with 360_day calendar and group 31-doyWhat I Did
What I Received
But it works if I don't convert the calendar or if group time.
Note: this breaks a xscen test.
Code of Conduct
The text was updated successfully, but these errors were encountered: