xarray-tutorial icon indicating copy to clipboard operation
xarray-tutorial copied to clipboard

dask chunking tutorial outline

Open dcherian opened this issue 2 years ago • 3 comments

from the pangeo working meeting discussion with @mgrover1 @jmunroe @norlandrhagen

Here's an outline for an intermediate tutorial talking about dask chunking specifically for Xarray users


Motivation: why care about chunk size?

  • demonstrate relation between chunk size and computation time / number of tasks with a simple example?
    • maybe even memory usage
  • https://tutorial.dask.org/02_array.html#Choosing-good-chunk-sizes
  • https://docs.dask.org/en/stable/array-chunks.html

Keeping track

  • monitoring chunk sizes and num tasks throughout the pipeline using the repr
    • use some images
  • while output blocks may be small (say after a big reduction), intermediate blocks need not be.
  • So keep monitoring chunksizes (and tasks) throughout the pipeline.

Why is it important to choose appropriate chunks early in the pipeline?

  • Demonstrate that rechunking is not cheap in most cases

Specify chunks when reading data

  1. Avoid chunks="auto".
    • https://docs.dask.org/en/stable/array-chunks.html#automatic-chunking
  2. Specifying chunks during data read
    • open_dataset
    • open_mfdataset
  3. Analysis vs storage chunks:
    • Dask chunks should be a multiple of chunks on disk
    • talk about aligning chunks with files stored on disk
    • @djhoese example

dcherian avatar Jan 31 '23 21:01 dcherian

Agreed this would be great to document thoroughly. See also this relevant issue + discussion in rioxarray https://github.com/corteva/rioxarray/issues/253

scottyhq avatar Jan 31 '23 23:01 scottyhq

demonstrate relation between chunk size and computation time / number of tasks with a simple example?

  • maybe even memory usage

This would be huge! This comes up often in Satpy where users want to process satellite images on their local machine but they only have 8GB or 16GB of memory. If someone can make a good diagram showing chunks being processed by a worker thread/process and how changing the size of all chunks or number of workers contributes to the overall memory usage that would be such a help when explaining this to users.

djhoese avatar Feb 01 '23 15:02 djhoese

forgot to cc @rybchuk!

dcherian avatar Feb 02 '23 16:02 dcherian