breezeintopl breezeintopl - 15 days ago 5
Python Question

how to read netcdf4 data if I only have netcdf3 tool?



    1. My school cluster admin said: if we load netcdf4 module, then we cannot load netcdf3 module. So he refused to update netcdf4



    1. I have a
      .nc
      file, which is a netcdf4 file, I think and I need to load it in R.



    1. In R on our cluster, only
      RNetCDF
      package is installed. And it cannot read the above .nc file. The
      ncdf4
      package is not there. (I try to install it, it says it requires netcdf library of version 4. And of course I do not have
      sudo
      )



    1. In python, (I don't know why) I can load
      netcdf4
      file. I don't know if I can use this to (save it in netcdf 3 format?) help me load that data in R.




So, how should I do?


  • The admin don't want to switch to netcdf4 module, and so it seems I(or he) cannot install
    ncdf4
    package in R.

  • Some of the
    nc
    data are directly downloaded from some website, and some of the
    nc
    files are from the output of the
    xarray
    package in python (and the netcdf output of xarray is in version 4).


Answer

With xarray you can control the version of files saved by specifying format='NETCDF3_CLASSIC' when calling to_netcdf. So a simple solution might be to use xarray, e.g.,

ds = xarray.open_dataset(path)
ds.to_netcdf(dest, format='NETCDF3_CLASSIC')
Comments