Python: How to use MFdataset in netCDF4

百般思念 提交于 2020-01-01 19:55:12

问题


I am trying to read multiple NetCDF files and my code returns the error:

ValueError: MFNetCDF4 only works with NETCDF3_* and NETCDF4_CLASSIC formatted files, not NETCDF4.

I looked up the documentation and MFdataset is not supported by NetCDF4, so I'm confused where to go from here.


回答1:


I think the error is pretty clear, but there are ways to avoid it.

1/ You could convert the NetCDF files from NetCDF4 to the classic format using e.g. nccopy:

nccopy -k classic nc4_file.nc ncclassic_file.nc

2/ xarray has a similar method (called open_mfdataset) which is able to handle NetCDF4 files. A quick test:

import netCDF4 as nc4
test = nc4.MFDataset(['test0.nc','test1.nc'])

This gives me the same error as you get ("MFNetCDF4 only works with..."), the same with xarray works without any problems:

import xarray as xr
test = xr.open_mfdataset(['test0.nc', 'test1.nc'])


来源:https://stackoverflow.com/questions/51290858/python-how-to-use-mfdataset-in-netcdf4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!