Repository navigation
Creates Zarr to b2nd conversion utility - #738
Conversation
There was a problem hiding this comment.
I like this PR. It is well-designed, effectively eliminates duplicate code between b2nd_to_zarr.py and zarr_to_b2nd.py, and maps Zarr shards → b2nd chunks and Zarr inner chunks → b2nd blocks cleanly (great!). The test coverage is comprehensive too.
Some requests for improvements:
- Add an
zarr-to-blosc2alias in pyproject.toml - Include Blocks in
print_summary()(both in rich and text outputs) - Defensive attribute access on Zarr arrays: in Zarr v2 array objects (e.g. if opened with older Zarr versions or custom store wrappers), .shards does not exist and raises
AttributeError. Similarly, Zarr v2 uses.compressor(singular) rather than.compressors(plural). - Please use type annotation on output_path in zarr_to_b2nd (like
output_path: str | Path | None = None). - Warn on dropped attributes in verbose mode. Silently suppressing exceptions can lead to unexpected metadata loss (e.g. unstorable types). Suggestion: pass
verbose: bool = Falsetocopy_attrs()and emit a notification if an attribute cannot be stored.
Keep the good work!
|
Thank you for your feedback @FrancescAlted. I found three other bugs
I also added the change for 5 to |
|
Do a rebase please. |
|
Thanks for addressing these, and for catching the additional bugs! You’re right about point 3: I conflated the Zarr package version with the on-disk format version. With zarr>=3.0.9 as our supported dependency, there’s no need to support the Zarr 2 Python API. Reading both v2 and v3 datasets through Zarr 3 is what matters. A clear version check is fine. The C-contiguous batch conversion, dtype-aware verification, and early rejection of variable-length strings all sound sensible. Thanks also for applying the metadata warnings to both converters. Please ensure the regression tests cover:
After the rebase, I’ll take another look. Thanks for the careful work! |
Summary
This PR adds a new command-line tool, zarr-to-b2nd, for converting Zarr arrays to Blosc2 .b2nd files. I created a file for utility functions shared between the b2nd-to-zarr and zarr-to-b2nd tools. The new tool works by determining the shape of the input in terms of the chunks and shards (if they exist) used in the Zarr dataset and its compression settings. Then data is copied in batches, sized by
--buffer-size. When shards are present in the Zarr dataset, shards become b2nd chunks and inner chunks become b2nd blocks. When shards are not present, Zarr chunks become b2nd chunks and the blocks are chosen by Blosc2.Closes #721. I plan to write docs in a separate PR for #714.
Changes
zarr_to_b2ndcommand registered in pyproject.toml--forceCompression handling
--codec/--clevel/--shuffleoverride all of the aboveTesting
I tested the utility on the 2-metre air temperature dataset from NOAA published as Zarr on AWS. It is a Zarr v2 dataset compressed with Blosc (lz4, level 9, shuffle) and carries attributes such as
units: "K"andlong_name.I downloaded the dataset with the following commands:
I tested the conversion utility with the following command and got these results:
Not included
AI tool usage
I used AI to make edits of the code and tests after I wrote an initial version. I have read through the code and understand how it works.