I am a little confused by this error, I am opening a CMIP3 netcdf file with what appears to be valid data, however, cftime is throwing errors with what appear to be numbers that are within the 64 bit signed integer range.
The file is a 1.1GiB file downloadable from here
Below is the example reproducing the error:
Python 3.10.5 | packaged by conda-forge | (main, Jun 14 2022, 07:04:59) [GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import xarray as xr
>>> xr.__version__
'2022.6.0'
>>> import cftime as cft
>>> cft.__version__
'1.6.1'
>>> ds = xr.open_dataset("rhopoto_O1.PIcntrl_2.CCSM.ocnm.0585-01_cat_0589-12.nc", use_cftime=True)
Traceback (most recent call last):
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/coding/times.py", line 180, in _decode_cf_datetime_dtype
result = decode_cf_datetime(example_value, units, calendar, use_cftime)
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/coding/times.py", line 293, in decode_cf_datetime
dates = _decode_datetime_with_cftime(flat_num_dates, units, calendar)
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/coding/times.py", line 201, in _decode_datetime_with_cftime
cftime.num2date(num_dates, units, calendar, only_use_cftime_datetimes=True)
File "src/cftime/_cftime.pyx", line 586, in cftime._cftime.num2date
File "src/cftime/_cftime.pyx", line 385, in cftime._cftime.cast_to_int
OverflowError: time values outside range of 64 bit signed integers
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/backends/api.py", line 531, in open_dataset
backend_ds = backend.open_dataset(
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/backends/netCDF4_.py", line 569, in open_dataset
ds = store_entrypoint.open_dataset(
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/backends/store.py", line 29, in open_dataset
vars, attrs, coord_names = conventions.decode_cf_variables(
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/conventions.py", line 521, in decode_cf_variables
new_vars[k] = decode_cf_variable(
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/conventions.py", line 369, in decode_cf_variable
var = times.CFDatetimeCoder(use_cftime=use_cftime).decode(var, name=name)
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/coding/times.py", line 682, in decode
dtype = _decode_cf_datetime_dtype(data, units, calendar, self.use_cftime)
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/coding/times.py", line 190, in _decode_cf_datetime_dtype
raise ValueError(msg)
ValueError: unable to decode time units 'days since 0000-1-1' with "calendar 'noleap'". Try opening your dataset with decode_times=False or installing cftime if it is not installed.
>>> ds = xr.open_dataset("rhopoto_O1.PIcntrl_2.CCSM.ocnm.0585-01_cat_0589-12.nc", decode_times=False)
>>> ds.time
<xarray.DataArray 'time' (time: 60)>
array([213540.5, 213570. , 213599.5, 213630. , 213660.5, 213691. , 213721.5,
213752.5, 213783. , 213813.5, 213844. , 213874.5, 213905.5, 213935. ,
213964.5, 213995. , 214025.5, 214056. , 214086.5, 214117.5, 214148. ,
214178.5, 214209. , 214239.5, 214270.5, 214300. , 214329.5, 214360. ,
214390.5, 214421. , 214451.5, 214482.5, 214513. , 214543.5, 214574. ,
214604.5, 214635.5, 214665. , 214694.5, 214725. , 214755.5, 214786. ,
214816.5, 214847.5, 214878. , 214908.5, 214939. , 214969.5, 215000.5,
215030. , 215059.5, 215090. , 215120.5, 215151. , 215181.5, 215212.5,
215243. , 215273.5, 215304. , 215334.5])
Coordinates:
* time (time) float64 2.135e+05 2.136e+05 ... 2.153e+05 2.153e+05
Attributes:
calendar: noleap
standard_name: time
axis: T
units: days since 0000-1-1
bounds: time_bnds
>>>
I have also tried to fix the quirky calendar "days since 0000-1-1" -> "days since 0001-01-01" but this doesn't seem to get me any further:
>>> ds.time.attrs["units"] = "days since 0001-01-01"
>>> ds.time
<xarray.DataArray 'time' (time: 60)>
array([213540.5, 213570. , 213599.5, 213630. , 213660.5, 213691. , 213721.5,
213752.5, 213783. , 213813.5, 213844. , 213874.5, 213905.5, 213935. ,
213964.5, 213995. , 214025.5, 214056. , 214086.5, 214117.5, 214148. ,
214178.5, 214209. , 214239.5, 214270.5, 214300. , 214329.5, 214360. ,
214390.5, 214421. , 214451.5, 214482.5, 214513. , 214543.5, 214574. ,
214604.5, 214635.5, 214665. , 214694.5, 214725. , 214755.5, 214786. ,
214816.5, 214847.5, 214878. , 214908.5, 214939. , 214969.5, 215000.5,
215030. , 215059.5, 215090. , 215120.5, 215151. , 215181.5, 215212.5,
215243. , 215273.5, 215304. , 215334.5])
Coordinates:
* time (time) float64 2.135e+05 2.136e+05 ... 2.153e+05 2.153e+05
Attributes:
calendar: noleap
standard_name: time
axis: T
units: days since 0001-01-01
bounds: time_bnds
>>> ds = xr.decode_cf(ds)
Traceback (most recent call last):
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/coding/times.py", line 270, in decode_cf_datetime
dates = _decode_datetime_with_pandas(flat_num_dates, units, calendar)
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/coding/times.py", line 207, in _decode_datetime_with_pandas
raise OutOfBoundsDatetime(
pandas._libs.tslibs.np_datetime.OutOfBoundsDatetime: Cannot decode times from a non-standard calendar, 'noleap', using pandas.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/coding/times.py", line 180, in _decode_cf_datetime_dtype
result = decode_cf_datetime(example_value, units, calendar, use_cftime)
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/coding/times.py", line 272, in decode_cf_datetime
dates = _decode_datetime_with_cftime(
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/coding/times.py", line 201, in _decode_datetime_with_cftime
cftime.num2date(num_dates, units, calendar, only_use_cftime_datetimes=True)
File "src/cftime/_cftime.pyx", line 586, in cftime._cftime.num2date
File "src/cftime/_cftime.pyx", line 385, in cftime._cftime.cast_to_int
OverflowError: time values outside range of 64 bit signed integers
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/conventions.py", line 655, in decode_cf
vars, attrs, coord_names = decode_cf_variables(
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/conventions.py", line 521, in decode_cf_variables
new_vars[k] = decode_cf_variable(
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/conventions.py", line 369, in decode_cf_variable
var = times.CFDatetimeCoder(use_cftime=use_cftime).decode(var, name=name)
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/coding/times.py", line 682, in decode
dtype = _decode_cf_datetime_dtype(data, units, calendar, self.use_cftime)
File "~/mambaforge/envs/xcd031spy532mat353/lib/python3.10/site-packages/xarray/coding/times.py", line 190, in _decode_cf_datetime_dtype
raise ValueError(msg)
ValueError: unable to decode time units 'days since 0001-01-01' with "calendar 'noleap'". Try opening your dataset with decode_times=False or installing cftime if it is not installed.
>>>
I'd appreciate a heads up about how to solve this issue, it seems like it should work - does for adjacent (earlier and later timesteps) in the same dataset.
I am a little confused by this error, I am opening a CMIP3 netcdf file with what appears to be valid data, however,
cftimeis throwing errors with what appear to be numbers that are within the 64 bit signed integer range.The file is a 1.1GiB file downloadable from here
Below is the example reproducing the error:
I have also tried to fix the quirky calendar
"days since 0000-1-1" -> "days since 0001-01-01"but this doesn't seem to get me any further:I'd appreciate a heads up about how to solve this issue, it seems like it should work - does for adjacent (earlier and later timesteps) in the same dataset.