issues: 865003095
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
865003095 | MDU6SXNzdWU4NjUwMDMwOTU= | 5208 | DataArray attributes not present in DataSet. Coherency problem between DataSet and NetCDF file | 2853966 | open | 0 | 4 | 2021-04-22T14:14:15Z | 2021-04-29T22:33:05Z | NONE | When I create a DataSet from DataArrays, attributes are lost. When are create attributes in a DataSet, they are know shown by Below is python code showing the xarray behaviour in details. My requests :
* When creating a DataSet from DataArrays, DataArrays attributes should be incorporated in the DataSet. (maybe optional)
* Attributes present in a DataSet should appear with a Thanks, Olivier ```python !/usr/bin/env pythoncoding: utf-8import numpy as np import xarray as xr Creates DataArraysnt = 4 time = np.arange (nt) * 86400.0 time = xr.DataArray (time, coords=[time,], dims=["time",]) aa = time * 2.0 Adding attributes to DataArraystime.attrs['units'] = "second" aa.attrs['units'] = "whatever" Attributes are visible in the DataArraysprint ('----------> time DataArray: ') print (time) print ('----------> aa DataArray : ' ) print (aa) print ('----------> aa attributes : ') print (aa.attrs ) Creating a Datasetds = xr.Dataset( { "aa": (["time",], aa), }, coords={"time": (["time",], time), }, ) Attributes are not visible in the Datasetprint ('----------> DataSet before setting attributes') print (ds) My request #1 : attributes of the DataArrays should be added to the DataSet (may be optional)print ('----------> Attributes of aa in DataSet : none') print ( ds['aa'].attrs ) print ('----------> Attributes of aa outside DataSet : still here') print ( aa.attrs ) print ('----------> Attributes are not written to the NetCDF file') ds.to_netcdf ('sample1.nc') Adding attributes directly to the Datasetds['time'].attrs['units'] = "second" ds['aa'].attrs['units'] = "whatever" Attributes are still not visible in the Datasetprint ('----------> DataSet after setting attributes : attributes not shown' ) print (ds) My request #2 : attributes added to the DataSet should be printedprint ('----------> But they are written in the NetCDF file') ds.to_netcdf ('sample2.nc') MyRequest : coherency between the DataSet and the NetCDF fileWhat if I read a NetCDF filedt = xr.open_dataset ( 'sample2.nc') print ('----------> DataSet read in a NetCDF file : Attributes are not shown') print (dt) print ('----------> Attributes of aa in DataSet : present') print ( dt['aa'].attrs ) ``` |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/5208/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
13221727 | issue |