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
Unexpected behaviour of climpred.utils.add_time_from_init_lead()
#698
Comments
P.S. other combinations of init and lead frequencies also produce unusual results, e.g. monthly init and "seasons" lead (what is a seasonal lead time anyway? Is it 3 months?) |
Thanks for the bug report. Yes. Seasonal means 3 months. |
Instead of lead attrs years pleas try months and range(0,12*5,12). Cftimeindex.shift on init causes the problems I think and I should implement it better. |
I will look into your example tomorrow. Thanks for trying to use climpred and the reproducible issue with sample code @dougiesquire |
The freq is strange: xr.cftime_range(start="2000-01-01", end="2002-01-01", freq="6MS")
CFTimeIndex([2000-01-01 00:00:00, 2000-07-01 00:00:00, 2001-01-01 00:00:00,
2001-07-01 00:00:00, 2002-01-01 00:00:00],
dtype='object', length=5, calendar='gregorian', freq='2QS-OCT') totally unrelated to |
pandas version
|
Yes that does seem odd - good catch. Perhaps worth opening an xarray issue? |
|
Thanks, I'll post an issue, but probably won't get to it till Monday |
I started digging into do you mind if I post the issue? |
removing i = pd.date_range(start="2000-01-01", end="2002-01-01", freq="6MS")
i
DatetimeIndex(['2000-01-01', '2000-07-01', '2001-01-01', '2001-07-01',
'2002-01-01'],
dtype='datetime64[ns]', freq='6MS')
from xarray.coding.frequencies import (
_CFTimeFrequencyInferer,
_ONE_DAY,
_is_multiple,
_MONTH_ABBREVIATIONS,
_maybe_add_count,
)
fi = _CFTimeFrequencyInferer(i)
fi.month_deltas # array([6])
fi.get_freq() # 2QS-OCT
fi._infer_daily_rule() # 2QS-OCT
_is_multiple(fi.deltas, _ONE_DAY) # TRUE
fi._get_annual_rule() # None
quartely_rule = fi._get_quartely_rule() # QS
nquarters = fi.month_deltas[0] / 3 # 2
mod_dict = {0: 12, 2: 11, 1: 10}
month = _MONTH_ABBREVIATIONS[mod_dict[fi.index[0].month % 3]] # OCT
alias = f"{quartely_rule}-{month}"
_maybe_add_count(alias, nquarters) # 2QS-OCT
fi.index[0].month # 1
fi.index[0].month % 3 # 1
_MONTH_ABBREVIATIONS[fi.index[0].month % 3] # JAN when removing mod_dict |
ok. the above should be an xarray issue, but there is still an unrelated issue in climpred. Line 546 in 7440d7c
|
Please go ahead |
very likely not an nevertheless I found a fix in #700 |
Describe the bug
The function
climpred.utils.add_time_from_init_lead
(which adds the "valid_time" coordinate) seems to return unusual values when the lead frequency is "yearly" and the init frequency is higher than annual (e.g. 6 monthly). The "valid_time" coordinate is used heavily by climpred internals so this causes strange behaviour/bugs further downstream.Code Sample
Returns
You can see that the "valid_time"s at the first two leads are identical and that all "valid_times" are at month 10, regardless of initialisation month (which alternates between 1 and 7).
Expected behavior
"valid_time"s should correspond to L years after the initialisation date, where L is the lead.
Output of
climpred.show_versions()
climpred: 2.1.7.dev10+gb8bf61b
xarray: 0.20.1
pandas: 1.3.4
numpy: 1.21.4
scipy: 1.6.3
cftime: 1.5.0
netcdf4: None
nc_time_axis: 1.4.0
matplotlib: 3.4.2
cf_xarray: 0.6.1
xclim: 0.31.0
dask: 2021.11.2
distributed: 2021.11.2
setuptools: 49.6.0.post20210108
pip: 21.1.2
conda: 4.11.0
IPython: 7.24.0
sphinx: None
The text was updated successfully, but these errors were encountered: