-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
Problem
Here is the dump of a NetCDF file (download):
netcdf cesm.TREFHT.160001-200512.selection {
dimensions:
time = UNLIMITED ; // (4872 currently)
lat = 3 ;
lon = 3 ;
nbnd = 2 ;
variables:
float TREFHT(time, lat, lon) ;
TREFHT:units = "K" ;
TREFHT:long_name = "Reference height temperature" ;
TREFHT:cell_methods = "time: mean" ;
double lat(lat) ;
lat:long_name = "latitude" ;
lat:units = "degrees_north" ;
double lon(lon) ;
lon:long_name = "longitude" ;
lon:units = "degrees_east" ;
double time(time) ;
time:long_name = "time" ;
time:units = "days since 0850-01-01 00:00:00" ;
time:calendar = "noleap" ;
time:bounds = "time_bnds" ;
double time_bnds(time, nbnd) ;
time_bnds:long_name = "time interval endpoints" ;
// global attributes:
:Conventions = "CF-1.0" ;
:source = "CAM" ;
...
}
When xarray decodes the time coordinates it also deletes the time:units attribute (this kind of makes sense, because the unit has no meaning when the time is converted to a CFTime object):
import xarray as xr
ds = xr.open_dataset(f)
ds.time
<xarray.DataArray 'time' (time: 4872)>
array([cftime.DatetimeNoLeap(1600, 2, 1, 0, 0, 0, 0, 0, 32),
cftime.DatetimeNoLeap(1600, 3, 1, 0, 0, 0, 0, 0, 60),
cftime.DatetimeNoLeap(1600, 4, 1, 0, 0, 0, 0, 3, 91), ...,
cftime.DatetimeNoLeap(2005, 11, 1, 0, 0, 0, 0, 6, 305),
cftime.DatetimeNoLeap(2005, 12, 1, 0, 0, 0, 0, 1, 335),
cftime.DatetimeNoLeap(2006, 1, 1, 0, 0, 0, 0, 4, 1)], dtype=object)
Coordinates:
* time (time) object 1600-02-01 00:00:00 ... 2006-01-01 00:00:00
Attributes:
long_name: time
bounds: time_bndsThe problem is that I have no way to actually decode the time_bnds variable from xarray alone now, because the time_bnds variable doesn't store the time units. First, I thought that my file was not CF compliant but I've looked into the CF conventions and it looks like they are not prescribing that time_bnds should also have a units attribute.
Solution
I actually don't know what we should do here. I see a couple of ways:
- we don't care and leave it to the user (here: me) to open the file with netCDF4 to decode the time bounds
- we don't delete the
time:unitsattribute after decoding - we start to also decode the
time_bndswhen available, like we do withtime
Thoughts? cc @spencerkclark @jhamman