You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding a variable that's not a 1d "dimension coordinate" with the same name as a dimension is an error. This makes sense. However, if I have a .nc file that has such a variable, is there any workaround to get the badly-named variable into xarray short of altering the .nc file or loading it separately with netCDF4? I.e. to make the following work somehow
import xarray as xr
import netCDF4
f = netCDF4.Dataset()
f = netCDF4.Dataset("test.nc", "w")
f.createDimension("x", 2)
f.createDimension("y", 3)
f["y"] = np.ones([2,3])
f["y"][...] = 1.0
f.close()
ds = xr.open_dataset('test.nc')
rather than getting the current error MissingDimensionsError: 'y' has more than 1-dimension and the same name as one of its dimensions ('x', 'y'). xarray disallows such variables because they conflict with the coordinates used to label dimensions.
I think it might be nice to have something like a rename_vars argument to open_dataset(). Similar to how drop_vars ignores a list of variables, rename_vars could rename a dict of variables so the example above could do
Is there any news on that topic? Has something being implemented already, to solve that issue? I'm wondering if roundtripping might be possible at all. As those files are valid nc-files, shouldn't xarray be capable of handling them?
Thanks @johnomotani me neither. I wonder if xarray could just invent the same as netcdf4 did, prepending the variables internally with some prefix. But this might only get confusing.
Adding a variable that's not a 1d "dimension coordinate" with the same name as a dimension is an error. This makes sense. However, if I have a
.nc
file that has such a variable, is there any workaround to get the badly-named variable intoxarray
short of altering the.nc
file or loading it separately withnetCDF4
? I.e. to make the following work somehowrather than getting the current error
MissingDimensionsError: 'y' has more than 1-dimension and the same name as one of its dimensions ('x', 'y'). xarray disallows such variables because they conflict with the coordinates used to label dimensions.
I think it might be nice to have something like a
rename_vars
argument toopen_dataset()
. Similar to howdrop_vars
ignores a list of variables,rename_vars
could rename a dict of variables so the example above could doand get a Dataset with a dimension
"y"
and a variable"y_not_dimension"
.The text was updated successfully, but these errors were encountered: