-
Hello, I have a dataset of .nc format which contains the following variables: When trying to load the file, I get the following error. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
unfortunately, this is not possible with In [1]: import netCDF4
...: import xarray as xr
...:
...: # create the file
...: with netCDF4.Dataset("test.nc", mode="w") as nc:
...: nc.createDimension("time", size=1)
...: nc.createDimension("lat", size=2)
...: nc.createDimension("lon", size=2)
...:
...: nc.createVariable("lon", "float64", dimensions=("time", "lat", "lon"))
...: nc.variables["lon"][:] = [[[0, 1], [2, 3]]]
...:
...: # fails
...: #xr.open_dataset("test.nc")
...:
...: # rename variables
...: with netCDF4.Dataset("test.nc", mode="r+") as nc:
...: display(nc)
...:
...: nc.renameVariable("lon", "lon_")
...: display(nc)
...:
...: with xr.open_dataset("test.nc") as ds:
...: display(ds)
<class 'netCDF4._netCDF4.Dataset'>
root group (NETCDF4 data model, file format HDF5):
dimensions(sizes): time(1), lat(2), lon(2)
variables(dimensions): float64 lon(time, lat, lon)
groups:
<class 'netCDF4._netCDF4.Dataset'>
root group (NETCDF4 data model, file format HDF5):
dimensions(sizes): time(1), lat(2), lon(2)
variables(dimensions): float64 lon_(time, lat, lon)
groups:
<xarray.Dataset>
Dimensions: (lat: 2, lon_: 2, time: 1)
Dimensions without coordinates: lat, lon_, time
Data variables:
lon (time, lat, lon_) float64 ... |
Beta Was this translation helpful? Give feedback.
unfortunately, this is not possible with
xarray
, yet (see #2368). You will have to use thenetCDF4
library (or any other netcdf reading library, or thencrename
executable) to rename the conflicting variables: