我正在使用 URL 从 opendap 服务器(数据的子集)打开 netcdf 数据。当我打开它时,数据(据我所知)在请求变量之前实际上并未加载。我想将数据保存到磁盘上的文件中,我该怎么做?
我目前有:
import numpy as np
import netCDF4 as NC
url = u'http://etc/etc/hourly?varname[0:1:10][0:1:30]'
set = NC.Dataset(url) # I think data is not yet loaded here, only the "layout"
varData = set.variables['varname'][:,:] # I think data is loaded here
# now i want to save this data to a file (for example test.nc), set.close() obviously wont work
希望有人帮忙,谢谢!
最佳答案
如果你可以使用 xarray,这应该工作如下:
import xarray as xr
url = u'http://etc/etc/hourly?varname[0:1:10][0:1:30]'
ds = xr.open_dataset(url, engine='netcdf4') # or engine='pydap'
ds.to_netcdf('test.nc')
xarray documentation还有另一个示例说明如何执行此操作。
关于python 将 OpenDap 加载到 NetcdfFile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44947031/