我有一个包含多个变量的大型netcdf文件。我需要沿着一个维度进行离散积分,以及具有尺寸(时间,深度,节点)的变量即形状温度(80,100,300000)。因此,我尝试将大数据集分成带有xarray的块,然后尝试应用函数scipy.integrate.simps,但失败了。
import xarray as xr
import scipy.integrate as sci
ds = xr.open_dataset('./temperature.nc',chunks={'time':5, 'nodes':1000})
temp = ds.temperature
请帮助我沿着chunked变量的第二维应用simps函数,然后将块保存到netcdf文件,而不是将整个数据转储到RAM中。我想做这样的事情
temp.apply(sci.simps,{'dx':5}).to_netcdf('./temperature_integrated.nc')
答案 0 :(得分:0)
我认为您正在寻找xarray.apply_ufunc
也许以下内容适合您(未经测试):
import xarray as xr
xr.apply_ufunc(scipy.integrate, ds.temperature)