Closed wwicker closed 3 months ago
@wwicker, thanks for raising the issue related to timestamp limitations (limited to approximately 584 years). Your workaround may not be necessary if this xarray's issue would be solved. Otherwise, I would rather suggest the following workaround:
ds = xr.open_dataset(in_netcdf, decode_times=False)
ntime = ds.time.shape[0]
times = pd.period_range(str(s_year)+'-01-01', name='time', periods=ntime, freq='M')
ds['time'] = times
ds['month'] = ('time', times.month)
ds['year'] = ('time', times.year)
climatology = ds.groupby(ds.month).mean('time')
anomalies = ds.groupby(ds.month) - climatology
However, I found out that plotting and netcdf outputting is not possible due to object dtype of time coordinate.
+1 to this issue. I'm struggling big time with an 1800-year climate model dataset that I need to resample in order to make different annual means (June-May). Two remarks.
np.datetime64('0500-01-01')
works fine, Pandas is not: pd.to_datetime(np.datetime64('0500-01-01'))
will fail. Can someone explain that one to me? xarray
should support all operations out-of-the-box for PeriodIndex, which is not the case for cftime
(notably, resampling is missing). But as noted above the support for PeriodIndex is broken, so high priority should IMO be given to addressing https://github.com/pydata/xarray/issues/1565 and https://github.com/pydata/xarray/issues/1270
Hi, xarray is using pandas DateTimeIndex for the time axis of xarrays. Due to the representation of time in nanoseconds the investigated period is limited to something like 550 years. There is much on this issue on the web. A widely recommended workaround is to use PeriodIndex instead. Unfortunately many xarray functionalities are affected by this, e.g. groupby and encoding.
I propose an adaptation like this in eofs_univ_ccmi_xarray.py and something equivalent in the other scripts.
line 96:
line 164: