html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue
https://github.com/pydata/xarray/issues/548#issuecomment-134420461,https://api.github.com/repos/pydata/xarray/issues/548,134420461,MDEyOklzc3VlQ29tbWVudDEzNDQyMDQ2MQ==,6063709,2015-08-25T00:05:40Z,2015-08-25T04:09:18Z,CONTRIBUTOR,"Brilliant. Thanks. I looked into the code but thought the encoding information was being stripped out.
So I've confirmed xray will round-trip fine. Shallow copies also round trip. Similarly making a new dataset from a variable with encoding information preserves that information and will output properly.
``` python
% tmp = xray.open_dataset('saved_on_disk_compressed.nc')
% tmp
Dimensions: (time: 3, x: 2, y: 2)
Coordinates:
reference_time datetime64[ns] 2014-09-05
lon (x, y) float64 -99.83 -99.32 -99.79 -99.23
* time (time) datetime64[ns] 2014-09-06 2014-09-07 2014-09-08
lat (x, y) float64 42.25 42.21 42.63 42.59
* x (x) int64 0 1
* y (y) int64 0 1
Data variables:
temperature (x, y, time) float64 10.66 8.539 6.713 8.519 29.07 27.86 ...
precipitation (x, y, time) float64 0.3385 6.773 8.985 0.9651 0.1359 ...
% tmp.temperature.encoding
{'chunksizes': (2, 2, 3),
'complevel': 5,
'contiguous': False,
'dtype': dtype('float64'),
'fletcher32': False,
'shuffle': True,
'source': 'saved_on_disk_compressed.nc',
'zlib': True}
% tmp2 = tmp
% tmp2.to_netcdf('saved_on_disk_comp_tmp2.nc')
% tmp3 = xray.open_dataset('saved_on_disk_comp_tmp2.nc')
% tmp3.temperature.encoding
{'chunksizes': (2, 2, 3),
'complevel': 5,
'contiguous': False,
'dtype': dtype('float64'),
'fletcher32': False,
'shuffle': True,
'source': 'saved_on_disk_comp_xray.nc',
'zlib': True}
```
Setting encoding dictionary works fine too (in this case copying from an existing variable):
``` python
% tmp4 = xray.DataArray(tmp.temperature.values).to_dataset(name='temperature')
% tmp4.temperature.encoding
{}
% tmp4.temperature.encoding = tmp.temperature.encoding
% tmp4.temperature.encoding
{'chunksizes': (2, 2, 3),
'complevel': 5,
'contiguous': False,
'dtype': dtype('float64'),
'fletcher32': False,
'shuffle': True,
'source': 'saved_on_disk_compressed.nc',
'zlib': True}
% tmp4.to_netcdf('saved_on_disk_comp_tmp4.nc')
% tmp5 = xray.open_dataset('saved_on_disk_comp_tmp4.nc')
% tmp.temperature.encoding
{'chunksizes': (2, 2, 3),
'complevel': 5,
'contiguous': False,
'dtype': dtype('float64'),
'fletcher32': False,
'shuffle': True,
'source': 'saved_on_disk_compressed.nc',
'zlib': True}
```
That will do nicely. Thanks.
","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,102703065