feat: support aligned writing on NetCDF->Zarr path#95
Merged
Conversation
Remove `ShardSpec` for `ChunkSpec | None`
Because NetCDF chunks can have irregular internal gridding across blocks when auto-selected by the compressor...
input_aligned_chunks parameter to dataset_to_zarrThere was a problem hiding this comment.
Pull request overview
This PR enhances the NetCDF → Zarr conversion pipeline by adding an “input-aligned” writing mode for Zarr output and a NetCDF read option to ignore per-file internal chunking, aiming to preserve/align chunk grids and avoid expensive rechunking.
Changes:
- Add
input_aligned_chunkstodataset_to_zarr()and refactor writer layout resolution to an internalchunks/subchunksmodel, with optional skip-rechunk behavior. - Add
ignore_block_chunksto NetCDF reading to optionally treat each NetCDF file/block as a single Dask chunk (useful for irregular internal NetCDF chunking across blocks). - Update CLI to default to the new behavior (NetCDF→Zarr), add worker control and optional Dask graph visualization support; add a
lintjust recipe.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/anu_ctlab_io/zarr/_writer.py |
Adds input_aligned_chunks, introduces chunks/subchunks internal layout, and conditionally skips rechunking before storing. |
src/anu_ctlab_io/netcdf/__init__.py |
Adds ignore_block_chunks and sets xarray chunking defaults to respect internal chunks unless overridden. |
cli/src/anu_ctlab_io_cli/_cli.py |
Uses ignore_block_chunks on NetCDF→Zarr, enables aligned writing for Zarr output, adds --workers and --dask-graph. |
tests/test_zarr_write.py |
Updates layout tests for the chunks/subchunks refactor and adds coverage for input-aligned writing behavior. |
tests/test_netcdf.py |
Adds tests validating default internal-chunk respect and the new “ignore block chunks” behavior. |
cli/pyproject.toml |
Adds graphviz dependency for Dask graph visualization. |
uv.lock |
Locks the new graphviz dependency. |
justfile |
Adds lint recipe (pre-commit run --all-files). |
CHANGELOG.md |
Documents the new input_aligned_chunks parameter. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
Author
Evaluation -
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Used by default in the CLI when converting to Zarr.
Add
input_aligned_chunksparameter todataset_to_zarrandignore_block_chunksto NetCDF reader, both defaulting to false. Used by default in the CLI on the NetCDF->Zarr path.Ignoring block chunks is necessary because sometimes the internal chunking in our NetCDF datasets be irregularly gridded between blocks. With
input_aligned_chunks, the Zarr output will just match the NetCDF blocking (but will use subchunking).lintrecipezarr/_writer.py. Makes the logic much clearer to me (and LLMs?)Note
This is all severely overcomplicated by the fact that we are not utilising
rectilineargrids yet (waiting on ecosystem support) and that the sharding codec requires subchunks to evenly divide the chunk shape. I am working on lifting that restriction in the spec. Also, I would ultimately prefer to go a virtualisation path in the future for NetCDF -> Zarr so that we can avoid rewriting any chunk data.