问题描述
我正在尝试读取多个NetCDF文件,并且我的代码返回错误:
I am trying to read multiple NetCDF files and my code returns the error:
我查阅了文档,但NetCDF4不支持MFdataset,所以我很困惑从这里开始.
I looked up the documentation and MFdataset is not supported by NetCDF4, so I'm confused where to go from here.
推荐答案
我认为错误很明显,但是有很多方法可以避免它.
I think the error is pretty clear, but there are ways to avoid it.
1/您可以使用以下方法将NetCDF文件从NetCDF4转换为经典格式: nccopy :
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 具有类似的方法(称为open_mfdataset
),它能够处理NetCDF4文件.快速测试:
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'])
这给了我与您同样的错误("MFNetCDF4仅适用于..." ),xarray同样适用,没有任何问题:
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'])
这篇关于Python:如何在netCDF4中使用MFdataset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!