-
-
Notifications
You must be signed in to change notification settings - Fork 364
docs: replace getting_started page with quickstart #2590
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
01bc352
docs: split tutorial into multiple user guide sections
jhamman d2bdb64
docs: replace getting_started page with quickstart
jhamman 63118f5
Apply suggestions from code review
jhamman 1bf3306
update quickstart
jhamman cac32c0
docs: replace getting_started page with quickstart
jhamman df593ea
Apply suggestions from code review
jhamman f6be517
update quickstart
jhamman 4238567
Use docstests
dstansby 8440aca
Merge branch 'main' into docs/3.0-quickstart
jhamman 4932ab3
Merge branch 'docs/3.0-quickstart' of https://github.com/zarr-develop…
jhamman 5344f2c
update link to storage guide
jhamman 391c76f
remove ipython
jhamman 163737d
add redirect
jhamman 74a365b
Merge branch 'main' of https://github.com/zarr-developers/zarr-python…
jhamman 1725424
reorg storage
jhamman 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
This file was deleted.
Oops, something went wrong.
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,190 @@ | ||
.. only:: doctest | ||
|
||
>>> import shutil | ||
>>> shutil.rmtree('data', ignore_errors=True) | ||
>>> | ||
>>> import numpy as np | ||
>>> np.random.seed(0) | ||
|
||
Quickstart | ||
========== | ||
|
||
Welcome to the Zarr-Python Quickstart guide! This page will help you get up and running with | ||
the Zarr library in Python to efficiently manage and analyze multi-dimensional arrays. | ||
|
||
Zarr is a powerful library for storage of n-dimensional arrays, supporting chunking, | ||
compression, and various backends, making it a versatile choice for scientific and | ||
large-scale data. | ||
|
||
Installation | ||
------------ | ||
|
||
Zarr requires Python 3.11 or higher. You can install it via `pip`: | ||
|
||
.. code-block:: bash | ||
|
||
pip install zarr | ||
|
||
or `conda`: | ||
|
||
.. code-block:: bash | ||
|
||
conda install --channel conda-forge zarr | ||
|
||
Creating an Array | ||
----------------- | ||
|
||
To get started, you can create a simple Zarr array:: | ||
|
||
>>> import zarr | ||
>>> import numpy as np | ||
>>> | ||
>>> # Create a 2D Zarr array | ||
>>> z = zarr.create_array( | ||
... store="data/example-1.zarr", | ||
... shape=(100, 100), | ||
... chunks=(10, 10), | ||
... dtype="f4" | ||
... ) | ||
>>> | ||
>>> # Assign data to the array | ||
>>> z[:, :] = np.random.random((100, 100)) | ||
>>> z.info | ||
Type : Array | ||
Zarr format : 3 | ||
Data type : DataType.float32 | ||
Shape : (100, 100) | ||
Chunk shape : (10, 10) | ||
Order : C | ||
Read-only : False | ||
Store type : LocalStore | ||
Codecs : [{'endian': <Endian.little: 'little'>}, {'level': 0, 'checksum': False}] | ||
No. bytes : 40000 (39.1K) | ||
|
||
Here, we created a 2D array of shape ``(100, 100)``, chunked into blocks of | ||
``(10, 10)``, and filled it with random floating-point data. This array was | ||
written to a ``LocalStore`` in the ``data/example-1.zarr`` directory. | ||
|
||
Compression and Filters | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Zarr supports data compression and filters. For example, to use Blosc compression:: | ||
|
||
>>> z = zarr.create_array( | ||
... "data/example-3.zarr", | ||
... mode="w", shape=(100, 100), | ||
... chunks=(10, 10), dtype="f4", | ||
... compressor=zarr.codecs.BloscCodec(cname="zstd", clevel=3, shuffle=zarr.codecs.BloscShuffle.SHUFFLE) | ||
... ) | ||
>>> z[:, :] = np.random.random((100, 100)) | ||
>>> | ||
>>> z.info | ||
Type : Array | ||
Zarr format : 3 | ||
Data type : DataType.float32 | ||
Shape : (100, 100) | ||
Chunk shape : (10, 10) | ||
Order : C | ||
Read-only : False | ||
Store type : LocalStore | ||
Codecs : [{'endian': <Endian.little: 'little'>}, {'level': 0, 'checksum': False}] | ||
No. bytes : 40000 (39.1K) | ||
|
||
This compresses the data using the Zstandard codec with shuffle enabled for better compression. | ||
|
||
Hierarchical Groups | ||
------------------- | ||
|
||
Zarr allows you to create hierarchical groups, similar to directories:: | ||
|
||
>>> # Create nested groups and add arrays | ||
>>> root = zarr.group("data/example-2.zarr") | ||
>>> foo = root.create_group(name="foo") | ||
>>> bar = root.create_array( | ||
... name="bar", shape=(100, 10), chunks=(10, 10) | ||
... ) | ||
>>> spam = foo.create_array(name="spam", shape=(10,), dtype="i4") | ||
>>> | ||
>>> # Assign values | ||
>>> bar[:, :] = np.random.random((100, 10)) | ||
>>> spam[:] = np.arange(10) | ||
>>> | ||
>>> # print the hierarchy | ||
>>> root.tree() | ||
/ | ||
└── foo | ||
└── spam (10,) int32 | ||
<BLANKLINE> | ||
|
||
This creates a group with two datasets: ``foo`` and ``bar``. | ||
|
||
Persistent Storage | ||
------------------ | ||
|
||
Zarr supports persistent storage to disk or cloud-compatible backends. While examples above | ||
utilized a :class:`zarr.storage.LocalStore`, a number of other storage options are available, | ||
including the :class:`zarr.storage.ZipStore` and :class:`zarr.storage.FsspecStore`:: | ||
|
||
>>> # Store the array in a ZIP file | ||
>>> store = zarr.storage.ZipStore("data/example-3.zip", mode='w') | ||
>>> | ||
>>> z = zarr.create_array( | ||
... store=store, | ||
... mode="w", | ||
... shape=(100, 100), | ||
... chunks=(10, 10), | ||
... dtype="f4" | ||
... ) | ||
>>> | ||
>>> # write to the array | ||
>>> z[:, :] = np.random.random((100, 100)) | ||
>>> | ||
>>> # the ZipStore must be explicitly closed | ||
>>> store.close() | ||
|
||
To open an existing array:: | ||
|
||
>>> # Open the ZipStore in read-only mode | ||
>>> store = zarr.storage.ZipStore("data/example-3.zip", read_only=True) | ||
>>> | ||
>>> z = zarr.open_array(store, mode='r') | ||
>>> | ||
>>> # read the data as a NumPy Array | ||
>>> z[:] | ||
array([[0.66734236, 0.15667458, 0.98720884, ..., 0.36229587, 0.67443246, | ||
0.34315267], | ||
[0.65787303, 0.9544212 , 0.4830079 , ..., 0.33097172, 0.60423803, | ||
0.45621237], | ||
[0.27632037, 0.9947008 , 0.42434934, ..., 0.94860053, 0.6226942 , | ||
0.6386924 ], | ||
..., | ||
[0.12854576, 0.934397 , 0.19524333, ..., 0.11838563, 0.4967675 , | ||
0.43074256], | ||
[0.82029045, 0.4671437 , 0.8090906 , ..., 0.7814118 , 0.42650765, | ||
0.95929915], | ||
[0.4335856 , 0.7565437 , 0.7828931 , ..., 0.48119593, 0.66220033, | ||
0.6652362 ]], shape=(100, 100), dtype=float32) | ||
|
||
Cloud Storage Backends | ||
~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Zarr integrates seamlessly with cloud storage such as Amazon S3 and Google Cloud Storage | ||
using external libraries like `s3fs <https://s3fs.readthedocs.io>`_ or | ||
`gcsfs <https://gcsfs.readthedocs.io>`_. | ||
|
||
For example, to use S3:: | ||
|
||
>>> import s3fs # doctest: +SKIP | ||
>>> | ||
>>> z = zarr.create_array("s3://example-bucket/foo", mode="w", shape=(100, 100), chunks=(10, 10)) # doctest: +SKIP | ||
>>> z[:, :] = np.random.random((100, 100)) # doctest: +SKIP | ||
|
||
Read more about Zarr's storage options in the :ref:`User Guide <user-guide-storage>`. | ||
|
||
Next Steps | ||
---------- | ||
|
||
Now that you're familiar with the basics, explore the following resources: | ||
|
||
- `User Guide <user-guide>`_ | ||
- `API Reference <api>`_ |
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.
I would merge with the previous section or at least talk about it before ZipStore