多维数组

Python 中的 Dask 并行编程

James Fulton

Climate Informatics Researcher

多维数据类型

  • 天气预报/观测
  • 3D 生物医学扫描
  • 卫星影像
  • 其他科学仪器数据
Python 中的 Dask 并行编程

HDF5

HDF 标志

  • 分层数据格式(Hierarchical Data Format)
  • 以分层方式存储,类似(子)目录
Python 中的 Dask 并行编程

HDF5 文件长什么样?

单个文件夹

Python 中的 Dask 并行编程

HDF5 文件长什么样?

一个文件夹,包含四个数据集和一些元数据。

Python 中的 Dask 并行编程

使用 h5py 浏览 HDF5 文件

import h5py

# Open the HDF5 file
file = h5py.File('data.hdf5')


# Print the available datasets inside the file print(file.keys())
<KeysViewHDF5 ['A', 'B', 'C', 'D']}>
Python 中的 Dask 并行编程

使用 h5py 浏览 HDF5 文件

import h5py

# Open the HDF5 file
file = h5py.File('data.hdf5')


# Select dataset A dataset_a = file['/A']
print(dataset_a)
<HDF5 dataset "A": shape (10000, 100, 100), type "<f4">
Python 中的 Dask 并行编程

从 HDF5 加载

import dask.array as da

# Load dataset into a Dask array a = da.from_array(dataset_a, chunks=(100, 20, 20))
print(a)
dask.array<array, shape=(10000, 100, 100), dtype=float32, chunksize=(100, 20, 20),
    chunktype=numpy.ndarray>
Python 中的 Dask 并行编程

Zarr

  • 类似 HDF5 的分层数据集
  • 天生分块
  • 适合通过 AWS、Google Cloud 等云服务流式处理
  • 可导航的文件结构
Python 中的 Dask 并行编程

从 Zarr 加载

import dask.array as da

a = da.from_zarr("dataset.zarr", component="A")


print(a)
dask.array<from-zarr, shape=(10000, 100, 100), dtype=float32,
    chunksize=(100, 20, 20), chunktype=numpy.ndarray>
Python 中的 Dask 并行编程

Passons à la pratique !

Python 中的 Dask 并行编程

Preparing Video For Download...