【问题标题】:Load xarray DataArray in chunks without using dask在不使用 dask 的情况下分块加载 xarray DataArray
【发布时间】:2021-05-15 16:58:57
【问题描述】:

是否可以将 DataArray 的部分块(存储为单个 netcdf 文件)从磁盘加载到内存中(即不一次加载整个数据数组)但没有使用 dask-dataarrays?

问题是我使用 dask 作为我的集群调度程序来提交作业,并且在这些作业中 - 我想将数据数组从磁盘中的小块分页到内存中。不幸的是,Dask 不喜欢嵌套的 dask-scheduler,因此尝试按照 da = xr.open_datarray( file, chunks={'time':1000} ) 不起作用(导致 dask 抛出嵌套的守护进程错误)。

理想情况下,我想做这样的事情 - 不将整个数据数组加载到内存中,而只加载相关部分:

da = xr.open_datarray( my_file )  # lazy open the file
for t in range( 0, len( da ), 1000 ) :
    da_actual = da[t:t+1000].load() # materialize the data into memory
    # do some compute with da_actual

任何关于如何实现这一点的指针/想法将不胜感激

【问题讨论】:

    标签: dask python-xarray


    【解决方案1】:

    delayed 包装它可能会有所帮助:

    import dask
    
    @dask.delayed
    def custom_array_func(my_file):
        da = xr.open_datarray( my_file )  # lazy open the file
            for t in range( 0, len( da ), 1000 ) :
                da_actual = da[t:t+1000].load() # materialize the data into memory
                # do some compute with da_actual
        return final_result # or can return None if nothing is needed
    
    [computed_results] = dask.compute([custom_array_func(my_file) for my_file in list_of_files])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-30
      • 1970-01-01
      • 2022-01-17
      • 2012-12-23
      • 1970-01-01
      • 2021-04-22
      • 1970-01-01
      • 2012-12-23
      相关资源
      最近更新 更多