【问题标题】:xarray: How to apply a scipy function to a large netcdf datasetxarray:如何将 scipy 函数应用于大型 netcdf 数据集
【发布时间】:2018-04-30 18:31:35
【问题描述】:

我有一个包含多个变量的大型 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')

【问题讨论】:

    标签: python dask h5py xarray


    【解决方案1】:

    我想你在找xarray.apply_ufunc

    也许以下内容对您有用(未经测试):

    import xarray as xr
    xr.apply_ufunc(scipy.integrate, ds.temperature)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-22
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-06
      • 2019-08-19
      • 2020-10-28
      相关资源
      最近更新 更多