Skip to content

Coords that look like ranges are not written in netcdf files. #734

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

Closed
wilhelmsen opened this issue Jan 29, 2016 · 1 comment
Closed

Coords that look like ranges are not written in netcdf files. #734

wilhelmsen opened this issue Jan 29, 2016 · 1 comment

Comments

@wilhelmsen
Copy link

This may be related to #733, but I am not sure, so I create a new one to keep it clean. It was discovered when creating the second example for #722 .

When the coords from #722 are changed to coords=[np.array([0, 1], np.int64)], they are not written to the netcdf file.

Example:

In [1]: import xray as xr

In [2]: import numpy as np

In [3]: var1 = xr.DataArray(np.array([1, 2], np.float64), coords=[np.array([0, 1], np.int64)], dims=["coor1",], name = "var1")

In [4]: var2 = xr.DataArray(np.array([3, 4], np.float64), dims=["dim1",], name = "var2")

In [5]: ds = xr.Dataset({"var1": var1, "var2": var2})

In [6]: ds
Out[6]: 
<xray.Dataset>
Dimensions:  (coor1: 2, dim1: 2)
Coordinates:
  * coor1    (coor1) int64 0 1
  * dim1     (dim1) int64 0 1
Data variables:
    var1     (coor1) float64 1.0 2.0
    var2     (dim1) float64 3.0 4.0

In [7]:  ds.to_netcdf("/tmp/from_xr_2.nc")

And then, no coor1 data variable in the file:

$ ncdump /tmp/from_xr_2.nc
netcdf from_xr_2 {
dimensions:
    coor1 = 2 ;
    dim1 = 2 ;
variables:
    double var1(coor1) ;
    double var2(dim1) ;
data:

 var1 = 1, 2 ;

 var2 = 3, 4 ;
}

Change it back:

In [8]: var1 = xr.DataArray(np.array([1, 2], np.float64), coords=[np.array([1, 2], np.int64)], dims=["coor1",], name = "var1")

In [9]: ds = xr.Dataset({"var1": var1, "var2": var2})

In [10]: ds.to_netcdf("/tmp/from_xr_3.nc")

and coor1 is back in the file:

$ ncdump /tmp/from_xr_3.nc
netcdf from_xr_3 {
dimensions:
    coor1 = 2 ;
    dim1 = 2 ;
variables:
    int64 coor1(coor1) ;
    double var1(coor1) ;
    double var2(dim1) ;
data:

 coor1 = 1, 2 ;

 var1 = 1, 2 ;

 var2 = 3, 4 ;
}

That is, when the coords seem like they are similar to a range.

@shoyer
Copy link
Member

shoyer commented Jan 30, 2016

Yep, this is exactly the same issue as #733... closing this in favor of that issue

@shoyer shoyer closed this as completed Jan 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants