อาร์เรย์หลายมิติ

Parallel Programming with Dask in Python

James Fulton

Climate Informatics Researcher

ประเภทของข้อมูลหลายมิติ

  • พยากรณ์อากาศ/ข้อมูลการสังเกตการณ์
  • ภาพสแกนชีวการแพทย์แบบ 3 มิติ
  • ภาพถ่ายดาวเทียม
  • ข้อมูลจากเครื่องมือวิทยาศาสตร์อื่นๆ
Parallel Programming with Dask in Python

HDF5

โลโก้ HDF

  • Hierarchical Data Format
  • จัดเก็บในรูปแบบลำดับชั้น คล้ายกับโครงสร้างไดเรกทอรี (และไดเรกทอรีย่อย)
Parallel Programming with Dask in Python

ไฟล์ HDF5 มีหน้าตาอย่างไร?

โฟลเดอร์เดี่ยว

Parallel Programming with Dask in Python

ไฟล์ HDF5 มีหน้าตาอย่างไร?

โฟลเดอร์เดี่ยวที่มีชุดข้อมูลสี่ชุดและข้อมูลเมตาบางส่วน

Parallel Programming with Dask in Python

นำทางไฟล์ HDF5 ด้วย h5py

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']>
Parallel Programming with Dask in Python

นำทางไฟล์ HDF5 ด้วย h5py

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">
Parallel Programming with Dask in Python

โหลดข้อมูลจาก 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>
Parallel Programming with Dask in Python

Zarr

  • ชุดข้อมูลแบบลำดับชั้นเหมือน HDF5
  • ออกแบบมาให้แบ่งเป็น chunk
  • เหมาะสำหรับการสตรีมผ่านบริการ cloud computing เช่น AWS, Google Cloud
  • โครงสร้างไฟล์ที่นำทางได้ง่าย
Parallel Programming with Dask in Python

โหลดข้อมูลจาก 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>
Parallel Programming with Dask in Python

มาฝึกกันเถอะ!

Parallel Programming with Dask in Python

Preparing Video For Download...