-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coordinate attributes as DataArray type doesn't export to netcdf #1906
Comments
This is not a workaround, this is what the CF conventions say to do: cell bounds need to be defined as variables, while the |
Also |
I agree totally, but when writing to netcdf, I was expecting xarray to take out the DataArrays out of attributes, replace them with their name, and save them as separate array in the netcdf files. But maybe that's not xarray's job do deal with ? |
The way to do this with xarray is: arr = xr.DataArray([[1, 2, 3]], dims=['time', 'x'])
arr['time'] = np.array([1])
time_bnds = xr.DataArray([[0, 1]], dims=('time', 'nv'))
arr['time'].attrs['bounds'] = 'time_bnds'
dataset = xr.Dataset({'arr': arr,
'time_bnds': time_bnds})
dataset.info()
Note this is the same number of lines of code and is CF compliant. I personally don't see us going down the path of nesting xarray objects inside of Is there more to discuss here or should we close this? |
I'm satisfied with this answer, thanks for taking the time ! |
Code Sample, a copy-pastable example if possible
Problem description
This code produces a TypeError
This is a problem for me because we need to provide attributes to the coordinate variables and save the to netcdf in order to be CF compliant. There are workarounds (like saving the
time_bnds
as a regular variable and putting its name as an attribute of thetime
variable) , but the provided code seems to be the most intuitive way to do it.Expected output
I would expect an output like this (ncdump -h):
Output of
xr.show_versions()
INSTALLED VERSIONS
commit: None
python: 2.7.5.final.0
python-bits: 64
OS: Linux
OS-release: 3.10.0-693.11.6.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: None.None
xarray: 0.10.0
pandas: 0.21.0
numpy: 1.13.3
scipy: 0.18.1
netCDF4: 1.1.8
h5netcdf: 0.4.2
Nio: None
bottleneck: 1.2.1
cyordereddict: None
dask: 0.16.1
matplotlib: 2.1.0
cartopy: None
seaborn: None
setuptools: 38.4.0
pip: 9.0.1
conda: None
pytest: 3.1.3
IPython: 5.5.0
sphinx: 1.6.6
The text was updated successfully, but these errors were encountered: