Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Cutting a big cube into bricks
A year of daily global temperature maps is a 3-D block of numbers: time × latitude × longitude. Storing it as one huge piece means you load everything even to look at one day; storing it as chunks (bricks) lets you fetch only the bricks you need. The catch: the best brick shape depends on how you will read the data, a whole map at one time or a long history at one place.
Weather and climate model output, satellite imagery, CFD and structural simulation results, and spectrometer cubes are all stored this way. Choosing chunks well can turn a 50-second read into a 50-millisecond one.
- 1. A chunk is…
- 2. Chunks of one full map per time step are good for…
- 3. Reading part of a chunk fetches…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.One data model, three containers
All three store arrays (typed, n-dimensional, chunked, compressed) organised in groups with attributes (key/value metadata).
| HDF5 | NetCDF-4 | Zarr | |
|---|---|---|---|
| Container | one binary file | one HDF5 file | directory / object-store prefix of many objects |
| Adds | groups, datasets, attributes | named dimensions, coordinate variables, CF conventions | JSON metadata, one object per chunk |
| Parallel writes | MPI-IO (parallel HDF5) | via HDF5 | independent chunks, no locking |
| Cloud | needs range requests | same | native |
import xarray as xr
ds = xr.open_dataset("era5_2024.nc", chunks={"time": 30}) # lazy, Dask-backed
t2m = ds["t2m"].sel(time="2024-07", latitude=slice(60, 30)).mean("time")
ds.to_zarr("s3://bucket/era5_2024.zarr", encoding={"t2m": {"chunks": (30, 90, 90)}})h5py gives NumPy-like access to HDF5 datasets (f["/sim/pressure"][100, :, :]); xarray adds labelled dimensions and CF decoding on top of NetCDF or Zarr.
- 1. NetCDF-4 is built on…
- 2. Zarr stores each chunk as…
- 3. xarray's .sel(time='2024-07') selects by…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.Chunks and compression
An array of shape (365, 90, 180) with chunks (30, 45, 45) has ⌈365/30⌉ × 2 × 4 = 104 chunks. Element (100, 45, 90) lives in chunk (3, 1, 2) at offset (10, 0, 0). A read fetches and decompresses every chunk its selection overlaps; a partial write must read-modify-write the chunks it touches. Filters (shuffle, delta) and codecs (zlib, Zstd, Blosc, LZ4) apply per chunk. Chunks never written are not stored and read as the fill value, so sparse arrays are cheap.
CF conventions
unitsandstandard_nameon every variable; coordinate variables (time,lat,lon) with the same name as their dimension.- Packing: store int16
pwithscale_factors andadd_offseto; value = p·s + o. Precision is s/2, and 16 bits span 65 535·s. - Missing data:
_FillValue(ormissing_value) decoded to NaN. - Time: numbers with units like
days since 2000-01-01and acalendarattribute (standard, noleap, 360_day in climate models).
- 1. Chunks touched by rows 30–39, cols 0–9 with 32×32 chunks?
- 2. Packing precision with scale_factor 0.01?
- 3. An unwritten Zarr chunk reads as…
Level 3: Advanced
★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.Choosing chunks
- Match chunks to the dominant access pattern; for mixed patterns use balanced chunks over all dimensions.
- Aim for chunks of roughly 1–100 MB uncompressed (smaller for local random access, larger for cloud stores where each request costs tens of milliseconds).
- Avoid millions of tiny chunks: object-store request overhead and metadata dominate.
- If two very different access patterns are both critical, store two copies with different chunking (rechunking with the
rechunkerlibrary orxarray+ Dask). - For Zarr v3, sharding packs many small chunks into one object, decoupling read granularity from object count.
- For existing HDF5/NetCDF files in the cloud, Kerchunk/VirtualiZarr index the chunk byte ranges so they can be read like Zarr without converting.
- 1. Why are tiny chunks bad on object storage?
- 2. Zarr v3 sharding…
- 3. Two critical but opposite access patterns: best option?
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Chunking, measured
Exercise 1. A 100 × 120 float32 array with 32 × 32 chunks has 16 chunks; reading rows 30–39, columns 50–69 fetches 4. Before any write, reads return the fill value and the store holds no chunk objects. Overwriting a 3 × 3 patch at (31–33, 31–33) rewrites 4 chunks and leaves their other values intact. CF packing at 0.01 K stays within 0.005 K and maps NaN to the fill value; “days since 2000-01-01” decodes 59.5 to 2000-02-29 12:00.
Exercise 2: one year of daily global temperature (365 × 90 × 180, 2° grid, int16 at 0.01 K = 11.83 MB raw, zlib level 5 per chunk). Storage models: local SSD (0.1 ms per request, 2 GB/s) and object storage (50 ms per request, 16 in flight, 500 MB/s).
| Chunking | Chunks | Stored | Map of one day | One point, all year | 30 days, 10 × 10 box | Worst case (object store) |
|---|---|---|---|---|---|---|
| map (1, 90, 180) | 365 | 9.01 MB | 1 chunk, 25 kB | 365 chunks, 9.0 MB | 30 chunks, 745 kB | 1.17 s |
| time series (365, 1, 1) | 16 200 | 10.27 MB | 16 200 chunks, 10.3 MB | 1 chunk, 0.6 kB | 100 chunks, 61 kB | 50.7 s |
| pencil (365, 15, 15) | 72 | 8.76 MB | 72 chunks, 8.8 MB | 1 chunk, 120 kB | 1 chunk, 120 kB | 0.27 s |
| cube (30, 45, 45) | 104 | 9.27 MB | 8 chunks, 764 kB | 13 chunks, 1.16 MB | 1 chunk, 97 kB | 52 ms |
| one chunk | 1 | 9.08 MB | 9.1 MB | 9.1 MB | 9.1 MB | 68 ms |
Each specialised layout is ideal for its own query and terrible for the other (over 10× more bytes, or 16 200 requests); tiny chunks also compress worst (10.27 MB). The balanced cube chunking has the best worst case on object storage. The single chunk looks competitive here only because the cube is small; at real sizes (ERA5 hourly is terabytes) reading everything for every query is impossible. On a local SSD the latency term is small and bytes dominate, so even the map chunking’s time-series read takes only 41 ms. (Compressed sizes can differ slightly between zlib builds.)
Array formats in AI, robotics and aerospace
- Weather and climate: ERA5, CMIP6 and NOAA data in NetCDF and analysis-ready cloud Zarr; ML weather models (GraphCast and successors) train from Zarr archives.
- Earth observation: satellite swaths in HDF5/NetCDF (NASA HDF-EOS, Sentinel products).
- Simulation: CFD and structural codes write HDF5 (often through XDMF or CGNS conventions).
- Lab and instrument data: NeXus/HDF5 at synchrotrons; ML training sets stored as HDF5 or Zarr arrays.
References
- The HDF Group. HDF5 User’s Guide (hdfgroup.org).
- R. Rew, G. Davis (1990). “NetCDF: an interface for scientific data access.” IEEE Computer Graphics and Applications 10(4).
- B. Eaton et al. NetCDF Climate and Forecast (CF) Metadata Conventions, version 1.11 (cfconventions.org).
- Zarr Developers. Zarr storage specification, versions 2 and 3 (zarr-specs.readthedocs.io).
- S. Hoyer, J. Hamman (2017). “xarray: N-D labeled arrays and datasets in Python.” Journal of Open Research Software 5(1).
- R. Abernathey et al. (2021). “Cloud-native repositories for big scientific data.” Computing in Science & Engineering 23(2).