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
I try to save the result of ds.resample("time": "Q-FEB").mean() with a 360_day calendar as netcdf. Thus, my first date is cftime.Datetime360Day(2000-02-30) (note the day). xarray then tries to use units='days since 2000-02-30' which fails with ValueError: day is out of range for month.
encoding= {}
encoding['time'] = {'units': 'days since 1850-01-01'}
ds.to_netcdf(filename, encoding=encoding)
The text was updated successfully, but these errors were encountered:
mathause
changed the title
encode_cf_datetime: reference_date must be a valid date
encode_cf_datetime: reference_date can not be "2000-02-30"
Oct 15, 2020
In [1]: import xarray as xr
In [2]: import cftime
In [3]: import numpy as np
In [4]: time = xr.cftime_range("2000-02-30", "2001-01-01", freq="3M", calendar="360_day")
In [5]: dates = np.asarray(time)
In [6]: reference_date = xr.coding.times.infer_datetime_units(dates)
In [7]: xr.coding.times.encode_cf_datetime(time)
Out[7]:
(array([ 0, 90, 180, 270]),
'days since 2000-02-30 00:00:00.000000',
'360_day')
As a general point I think we should strive to be able to handle reference dates that might not be valid in all calendars (they might occur in the wild). Would we be ok labeling this as an upstream issue?
What happened:
I try to save the result of
ds.resample("time": "Q-FEB").mean()
with a360_day
calendar as netcdf. Thus, my first date iscftime.Datetime360Day(2000-02-30)
(note the day). xarray then tries to useunits='days since 2000-02-30'
which fails withValueError: day is out of range for month
.What you expected to happen:
The dataset can be saved.
Minimal Complete Verifiable Example:
Traceback:
Anything else we need to know?:
This goes wrong here:
xarray/xarray/coding/times.py
Lines 249 to 250 in 1553749
A possible fix is to add the following lines:
To workaround set the encoding manually:
The text was updated successfully, but these errors were encountered: