1

I am currently using ubuntu 22.04. I have installed anaconda3 on it, run everythong on the base environment and installed netcdf4 using the command

pip install netcdf4

I have coded a script visu_choc.py, which uses the Dataset function of netcdf4, yet, when I run my script, I get the following error during the execution of this Dataset function :

File "/home/vboxgrad/test/./visu_choc.py", line 88, in <module> ds=nc.Dataset(input_file) File "src/netCDF4/_netCDF4.pyx", line 2449, in netCDF4._netCDF4.Dataset.__init__ File "src/netCDF4/_netCDF4.pyx", line 2012, in netCDF4._netCDF4._ensure_nc_success OSError: [Errno -51] NetCDF: Unknown file format: '0x0choc_stat.nc'

0x0choc_stat.nc is the file I am trying to open.

I have searched for a solution on internet unsuccessfully.

Could anyone help me to know what to do to make netcdf4 work on python?

I am expecting not to have any error and that the function Dataset opens the file.

ventsyv
  • 3,316
  • 3
  • 27
  • 49
astrorobot
  • 11
  • 2
  • 1
    It appears the file you are trying to open is not a valid netCDF file. Try opening it up in a netcdf viewer (ncview, Panoply, or NetCDF Viewer on Windows, etc) or command line utility. NetCDF4 is a subset of HDF5. There is also the older netcdf 3.x format. Make sure the file is in the format you expect it to be. It's also possible the file is corrupt. – ventsyv Apr 03 '23 at 13:59
  • 1
    Also, can you post a minimal example demonstrating the problem. I'm pretty sure it's a bad file, but it can't hurt to see your code. – ventsyv Apr 03 '23 at 14:07
  • Indeed. I have regenerated my NetCDF file and everything works. Thank you! – astrorobot Apr 03 '23 at 14:21
  • @astrobot I'll make it an answer. – ventsyv Apr 03 '23 at 14:57

1 Answers1

0

It appears the file you are trying to open is not a valid netCDF file. Try opening it up in a netcdf viewer (ncview, Panoply, or NetCDF Viewer on Windows, etc) or command line utility. NetCDF4 is a subset of HDF5. There is also the older netcdf 3.x format. Make sure the file is in the format you expect it to be. If it's not, there is a possibility that the netCDF4 library is unable to read it.

It's also possible the file is corrupt.

On Ubuntu, you can try the following:

sudo apt install ncview
ncview <myFile>
ventsyv
  • 3,316
  • 3
  • 27
  • 49