Python Netcdf Ioerror: Netcdf: Netcdf: Invalid Dimension Id Or Name
Solution 1:
This may be a case of a library trying to be "helpful" (see the end of my post for details, but I can't confirm it). To fix this, you should explicitly create dimensions for atom_number and step_number, by using the following before you create the variables (assuming I am understanding nSteps and nAtoms correctly):
ofl.createDimension("step_number", nSteps) ofl.createDimension("atom_number", nAtoms)
If you are new to netCDF, I might suggest looking at either the netcdf4-python package,
http://unidata.github.io/netcdf4-python/
of the netCDF package found in scipy:
http://docs.scipy.org/doc/scipy/reference/io.html
What might be going on: it looks like the issue is that when you create the variable step_number, the library is trying to be helpful by creating a step_number dimension with unlimited length. However, you can only have one unlimited dimension in a netcdf-3 file, so the helpful "trick" does not work.
Solution 2:
atomNumber_var.standard_name = "atom__number"
The atom__number has two "__" instead of one "_". I am not sure if this is your problem, but it may be something to look at.
I would also suggest making your netcdf file steps clearer. I like to break them down into 3 steps. I used an example of scientific data using ocean sst. You also have a section for creating dimensions, but you don't actually do it. This is more correctly create variable section.
Create Dimensions
Create Variable
Fill the variable
from netCDF4 import Dataset ncfile = Dataset('temp.nc','w') lonsdim = latdata.shape #Set dimension lengths latsdim = londata.shape ################Create Dimensions############### latdim = ncfile.createDimension('latitude', latsdim) londim = ncfile.createDimension('longitude', lonsdim) ################Create Variables################# The variables contain the dimensions previously set latitude = ncfile.createVariable('latitude','f8',('latitude')) longitude = ncfile.createVariable('longitude','f8',('longitude')) oceantemp = ncfile.createVariable('SST','f4' ('latitude','longitude'),fill_value=-99999.0) ############### Fill Variables ################ latitude[:] = latdata #lat data to fill in longitude[:] = londata #lon data to fill in oceantemp[:,:] = sst[:,:] #some variable previous calculated
I hope this is helpful.
Post a Comment for "Python Netcdf Ioerror: Netcdf: Netcdf: Invalid Dimension Id Or Name"