issues: 279832457
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
279832457 | MDU6SXNzdWUyNzk4MzI0NTc= | 1763 | Multi-dimensional coordinate mixup when writing to netCDF | 1554921 | closed | 0 | 4 | 2017-12-06T17:05:36Z | 2018-01-11T16:54:48Z | 2018-01-11T16:54:48Z | CONTRIBUTOR | Problem descriptionUnder certain conditions, the netCDF files produced by Test DatasetSome sample code to generate a problematic Dataset: ```python import xarray as xr import numpy as np zeros1 = np.zeros((5,3))
zeros2 = np.zeros((6,3))
zeros3 = np.zeros((5,4))
d = xr.Dataset({
'lon1': (['x1','y1'], zeros1, {}),
'lon2': (['x2','y1'], zeros2, {}),
'lon3': (['x1','y2'], zeros3, {}),
'lat1': (['x1','y1'], zeros1, {}),
'lat2': (['x2','y1'], zeros2, {}),
'lat3': (['x1','y2'], zeros3, {}),
'foo1': (['x1','y1'], zeros1, {'coordinates': 'lon1 lat1'}),
'foo2': (['x2','y1'], zeros2, {'coordinates': 'lon2 lat2'}),
'foo3': (['x1','y2'], zeros3, {'coordinates': 'lon3 lat3'}),
})
d = xr.conventions.decode_cf(d)
<xarray.Dataset>
Dimensions: (x1: 5, x2: 6, y1: 3, y2: 4)
Coordinates:
lat1 (x1, y1) float64 ...
lat3 (x1, y2) float64 ...
lat2 (x2, y1) float64 ...
lon1 (x1, y1) float64 ...
lon3 (x1, y2) float64 ...
lon2 (x2, y1) float64 ...
Dimensions without coordinates: x1, x2, y1, y2
Data variables:
foo1 (x1, y1) float64 ...
foo2 (x2, y1) float64 ...
foo3 (x1, y2) float64 ...
<xarray.DataArray 'foo1' (x1: 5, y1: 3)> array([[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]]) Coordinates: lat1 (x1, y1) float64 ... lon1 (x1, y1) float64 ... Dimensions without coordinates: x1, y1
<xarray.DataArray 'foo2' (x2: 6, y1: 3)> array([[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]]) Coordinates: lat2 (x2, y1) float64 ... lon2 (x2, y1) float64 ... Dimensions without coordinates: x2, y1
<xarray.DataArray 'foo3' (x1: 5, y2: 4)> array([[ 0., 0., 0., 0.], [ 0., 0., 0., 0.], [ 0., 0., 0., 0.], [ 0., 0., 0., 0.], [ 0., 0., 0., 0.]]) Coordinates: lat3 (x1, y2) float64 ... lon3 (x1, y2) float64 ... Dimensions without coordinates: x1, y2 ``` The problemThe problem happens when I try to write this to netCDF (using either the netCDF4 or scipy engines):
// global attributes: :_NCProperties = "version=1|netcdflibversion=4.4.1.1|hdf5libversion=1.8.18" ; } ``` Here, foo1, foo2, and foo3 have extra coordinates associated with them. Interestingly, if I re-open this netCDF file with Expected OutputI would expect the netCDF file to have a single pair of lat/lon for each variable:
Output of
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/1763/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |