Skip to content

Add structured and curvilinear grid support for Zarr#22

Merged
koldunovn merged 1 commit intomainfrom
zarr-structured-grid
Mar 25, 2026
Merged

Add structured and curvilinear grid support for Zarr#22
koldunovn merged 1 commit intomainfrom
zarr-structured-grid

Conversation

@koldunovn
Copy link
Copy Markdown
Collaborator

@koldunovn koldunovn commented Mar 25, 2026

Summary

  • Zarr stores with structured grids (1D lat/lon of different sizes) and curvilinear grids (2D lat/lon arrays) now work the same as NetCDF files
  • read_zarr_coord rewritten to handle N-dimensional coordinate arrays with proper multi-dimensional chunk paths
  • mesh_create_from_zarr detects three coordinate types: 1D unstructured, 1D structured (meshgrid expansion), and 2D curvilinear
  • New zarr_read_spatial_slice helper supports both single and dual spatial dimensions with multi-chunk iteration
  • zarr_scan_variables updated to detect structured grids by matching lat/lon dimension sizes

Closes #20

Test plan

  • 7 new tests added covering structured and curvilinear grids (mesh creation, variable scanning, data reading, multi-chunk)
  • All 32 zarr tests pass (`make test-zarr WITH_ZARR=1`)
  • Tested against real dataset at `/work/ab0995/a270088/samudra/output_fesom/data.zarr` (shape [3285, 180, 360])

🤖 Generated with Claude Code

Zarr stores with structured grids (1D lat/lon of different sizes) and
curvilinear grids (2D lat/lon arrays) now work the same as NetCDF files.

Changes:
- mesh.c: Rewrite read_zarr_coord to handle N-dimensional coordinate
  arrays with proper multi-dimensional chunk paths and row-by-row
  copying for 2D chunks. Rewrite mesh_create_from_zarr to detect and
  handle three coordinate types: 1D unstructured (same-size), 1D
  structured (different-size with meshgrid expansion), and 2D
  curvilinear.
- file_zarr.c: Add zarr_read_spatial_slice helper that supports both
  single and dual spatial dimensions with multi-chunk iteration and
  stride-based indexing. Update zarr_scan_variables to detect structured
  grids by matching lat/lon dimension sizes against orig_nx/orig_ny.
  Use matches_name_list() for coordinate skip lists.
- tests/test_file_zarr.c: Add 7 tests for structured grid support
  covering mesh creation, variable scanning, data reading, and
  multi-chunk spatial dimensions for both 1D structured and 2D
  curvilinear grids.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@koldunovn koldunovn merged commit fab72c2 into main Mar 25, 2026
4 checks passed
@koldunovn
Copy link
Copy Markdown
Collaborator Author

closes #20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to read meshes that has 1d lon/lat along sides.

1 participant