我有一个包含多个变量的大型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
善意地,帮助我沿着分块变量的二维应用simps函数,然后将分块保存到netcdf文件中,而不是将整个数据转储到RAM中。我想做这样的事情
temp.apply(sci.simps,{'dx':5}).to_netcdf('./temperature_integrated.nc')
我认为您正在寻找xarray.apply_ufunc
也许像下面这样的东西对你有用(未经测试(:
import xarray as xr
xr.apply_ufunc(scipy.integrate, ds.temperature)