xarray: time decoding error with "days since"
I am trying to use xray with some CESM POP model netCDF output, which supposedly follows CF-1.0 conventions. It is failing because the models time units are “'days since 0000-01-01 00:00:00”. When calling open_dataset, I get the following error:
ValueError: unable to decode time units u'days since 0000-01-01 00:00:00' with the default calendar. Try opening your dataset with decode_times=False. Full traceback:
Traceback (most recent call last):
File "/home/rpa/xray/xray/conventions.py", line 372, in __init__
# Otherwise, tracebacks end up swallowed by Dataset.__repr__ when users
File "/home/rpa/xray/xray/conventions.py", line 145, in decode_cf_datetime
dates = _decode_datetime_with_netcdf4(flat_num_dates, units, calendar)
File "/home/rpa/xray/xray/conventions.py", line 97, in _decode_datetime_with_netcdf4
dates = np.asarray(nc4.num2date(num_dates, units, calendar))
File "netCDF4/_netCDF4.pyx", line 4522, in netCDF4._netCDF4.num2date (netCDF4/_netCDF4.c:50388)
File "netCDF4/_netCDF4.pyx", line 4337, in netCDF4._netCDF4._dateparse (netCDF4/_netCDF4.c:48234)
ValueError: year is out of range
Full metadata for the time variable:
double time(time) ;
time:long_name = "time" ;
time:units = "days since 0000-01-01 00:00:00" ;
time:bounds = "time_bound" ;
time:calendar = "noleap" ;
I guess this is a problem with the underlying netCDF4 num2date package?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 20 (13 by maintainers)
Commits related to this issue
- Fixes #521 — committed to rabernat/xarray by rabernat 9 years ago
@rabernat -
Yes - this is all coming from the
netCDF4.netcdftime
module.The work around with xray is to use
ds = xray.open_dataset(filename, decode_times=False)
then to fix up the time variable “manually”. You can usexray.decode_cf()
or simply assign a new pandas time index to your time variable.As an aside, I also work with CESM output and this is a common problem with its netCDF output.