-
-
Notifications
You must be signed in to change notification settings - Fork 423
Add 'From Zero to Zarr' beginner guide to the Zarr data model #4077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chuckwondo
wants to merge
3
commits into
zarr-developers:main
Choose a base branch
from
chuckwondo:docs/from-zero-to-zarr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+918
−1
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added a beginner-oriented "From Zero to Zarr" page to the user guide. It motivates why Zarr exists, then builds up the Zarr data model — arrays, chunking, stores as key/byte maps, metadata, the specification, codecs, sharding, and groups — for readers new to chunked array formats, ending with a short runnable example. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # From Zero to Zarr | ||
|
|
||
| *From a NumPy array to stored bytes, chunk by chunk.* | ||
|
|
||
| This page is for people who are new to Zarr. You don't need to know NumPy, HDF5, | ||
| or anything about file formats. We begin with *why* Zarr exists, then build up | ||
| the *how* one idea at a time, until you understand **how Zarr stores an array**, | ||
| **why** that layout is defined by a written specification, and **how a library | ||
| turns those stored bytes back into an array you can use**. | ||
|
|
||
| This guide comes in three parts: | ||
|
|
||
| - **[Part I: The core idea](data_model_core_idea.md).** The happy path, with | ||
| pictures and no code. | ||
| - **[Part II: Under the hood](data_model_under_the_hood.md).** A few deeper | ||
| sections that go *off* the happy path. Each one is signposted, so you can read | ||
| on or skip ahead. | ||
| - **[Part III: Seeing it for real](data_model_in_action.md).** A short hands-on | ||
| section with runnable code that ties everything together. | ||
|
|
||
| But before the *how*, a word on the *why*. | ||
|
|
||
| --- | ||
|
|
||
| ## Why we need Zarr | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If possible, it would be nice to have a tl;dr (maybe a note admonition) at the top of this section |
||
|
|
||
| !!! note "In short" | ||
| Modern instruments and simulations produce arrays of numbers far too big to | ||
| fit in memory, and that data needs to be stored durably and shared widely. | ||
| Zarr stores these giant arrays so a reader can cheaply fetch just the piece | ||
| they want, and so the work of reading them can run in parallel across many | ||
| CPU cores. | ||
|
|
||
| Across science and industry, our instruments and simulations have become | ||
| extraordinary firehoses of numbers. A satellite streams images of the Earth. A | ||
| microscope captures gigapixel scans. A gene sequencer reads thousands of genomes. | ||
| A climate model writes out temperature and wind for every point on the globe, hour | ||
| after hour. In each case the result has the same shape: a vast grid of numbers, | ||
| far more than fits in any single computer's memory, and often arriving as a | ||
| continuous stream. | ||
|
|
||
| That data is worth little sitting on one machine. It has to be stored somewhere | ||
| **durable** and **shareable**, so that many people (often scattered across the | ||
| world) can read and analyze it. Increasingly that somewhere is **cloud object | ||
| storage** (such as Amazon S3, Google Cloud Storage, or Azure Blob Storage): cheap, | ||
| effectively unlimited, and reachable from anywhere. But sheer size makes this | ||
| hard. Nobody wants to download terabytes just to inspect one corner. What's needed | ||
| is a way to store these giant grids so a reader can efficiently and cheaply fetch | ||
| **just the piece they want**. | ||
|
|
||
| Zarr was built to solve exactly this, though it didn't begin with the cloud. It | ||
| grew out of **genomics**. Around 2015, Alistair Miles needed to analyze arrays of | ||
| genetic variation across thousands of malaria-carrying mosquitoes (the | ||
| [*Anopheles gambiae* 1000 Genomes Project](https://www.malariagen.net/)), arrays | ||
| far too big to fit in memory. His real frustration was *speed*, and to see why, it | ||
| helps to understand two things the array formats of the day were already doing: | ||
| chunking and compression. | ||
|
|
||
| First, **chunking**. To store an array bigger than memory, formats like HDF5 and | ||
|
maxrjones marked this conversation as resolved.
|
||
| netCDF already split it into blocks (called *chunks*) and compress each one. That's | ||
| what lets you read part of an array without loading all of it: you only fetch and | ||
| decompress the chunks that cover the part you want. None of this is Zarr's | ||
| invention. Chunking and compression were well-established ideas, and Zarr | ||
| deliberately reuses them. The catch with the existing tools was *speed*: | ||
| **decompression takes CPU work**, and for a big analysis that scans millions of | ||
| values, that work adds up fast. | ||
|
|
||
| Here's where speed came in. Reading a chunk means decompressing it, so reading | ||
| *many* chunks is a pile of independent decompression jobs, exactly the kind of work | ||
| you'd want to spread across all your CPU cores at once. But the tools of the day | ||
| wouldn't let him. In Python, the **global interpreter lock** (GIL) limits how much | ||
| work threads can do at the same time, so reading through HDF5 couldn't keep all the | ||
| cores busy. And the other chunked format he tried could split an array along only | ||
| its **first dimension**, while scientific arrays usually have *several* dimensions. | ||
| His analyses kept needing pieces that cut across those dimensions, and chunking | ||
| along just one of them made that painfully slow. One core did all the work while | ||
| the rest sat idle. | ||
|
|
||
| So he built Zarr. It didn't introduce new storage concepts so much as **recombine | ||
| familiar ones** (chunks, compression, metadata) in a way that frees the CPU cores to | ||
| work in parallel: cut an array into chunks across **all its dimensions at once**, | ||
| not just one, and decompress them concurrently. Now a read becomes many | ||
| chunk-decompressions running **at the same time**, across every core on the machine | ||
| (and, with tools like [Dask](https://www.dask.org/), across many machines), so an | ||
| analysis that crunches the whole array finishes in a fraction of the time. (He | ||
| tells the story in his early | ||
| [Zarr blog posts](http://alimanfoo.github.io/2016/05/16/cpu-blues.html).) | ||
|
|
||
| Storing data in the cloud came **later**, and turned out to be a superpower. | ||
| Because each chunk is simply one key/value entry (as we'll see), Zarr maps | ||
| naturally onto object storage like S3, which made it a backbone of cloud-native | ||
| science. Today Zarr is used far beyond genomics: in **Earth and climate science** | ||
| (satellite imagery and weather and climate model output, via the | ||
| [Pangeo](https://www.pangeo.io/) community), **bio-imaging** (huge microscopy | ||
| volumes, via [OME-Zarr](https://ngff.openmicroscopy.org/)), **astronomy**, and | ||
| **machine learning**, anywhere people wrestle with large, multi-dimensional grids | ||
| of numbers. | ||
|
|
||
| Strip away the domain (mosquitoes, galaxies, hurricanes) and the object at the | ||
| center is always the same: an **array**, a big grid of numbers. So that's where | ||
| we'll begin. In [Part I](data_model_core_idea.md) we'll look at what an array is, | ||
| then at what happens when one grows too big to fit in memory, and build up from | ||
| there to how Zarr stores it. | ||
|
|
||
| --- | ||
|
|
||
| Continue to **[Part I: The core idea](data_model_core_idea.md)**. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit about consistent use of bold text