Skip to content

Having problems loading a ".nc" file #5105

Answered by keewis
AvitayGT asked this question in Q&A
Discussion options

You must be logged in to vote

unfortunately, this is not possible with xarray, yet (see #2368). You will have to use the netCDF4 library (or any other netcdf reading library, or the ncrename executable) to rename the conflicting variables:

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")

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@AvitayGT
Comment options

Answer selected by AvitayGT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants