Skip to content

fix zarr convention - #260

Open
carloshorn wants to merge 10 commits into
xarray-contrib:mainfrom
carloshorn:fix_zarr_convention
Open

fix zarr convention#260
carloshorn wants to merge 10 commits into
xarray-contrib:mainfrom
carloshorn:fix_zarr_convention

Conversation

@carloshorn

@carloshorn carloshorn commented Sep 7, 2026

Copy link
Copy Markdown
  • closes zarr convention #256
  • Tests added
  • User visible changes (including notable bug fixes) are documented in changelog.md
  • New functions/methods are listed in api.rst

I went through the Zarr DGGS spec and introduced few changes which I also covered with tests.

  1. The ellipsoid attribute semi_major_axis and semi_minor_axis is now translated correctly.
  2. The required attribute refinement_level is now checked.
  3. It can handle a missing coordinate.

@keewis keewis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR, @carloshorn!

Looks good to me, except I'd move the treatment of the missing coordinate to the specific index implementation (e.g. HealpixIndex). Which feels like it's going to be quite a bit of work, so you may want to move that to a separate PR.

Comment thread xdggs/conventions/zarr.py Outdated
Comment thread xdggs/tests/test_conventions.py Outdated
Comment thread pyproject.toml
@carloshorn

Copy link
Copy Markdown
Author

Before fixing the merge conflict. What do you think about this change?
I have moved the domain spanning index creation into the respective indexes.
There are also some tests missing to cover all branching logic (e.g. no coordinate given but name), but I wanted to get your feedback first.

@keewis keewis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good to me in general. Just a caveat, I've almost finished supporting compression types in the zarr convention, so there might be more merge conflicts soon (but also this may simplify a lot of the code here). In particular, though, I just realized I also have a fix for the ellipsoid naming.

I'm not sure how I'll manage these differences, but if you're game we can try to merge this first and then I'll resolve the merge conflicts in my PR.

Edit: see #262

So yes, I'm pretty happy with the direction of this PR, I just have a few small suggestions after a quick first pass.

Comment thread xdggs/healpix.py Outdated
Comment on lines +779 to +784
elif indexing_scheme == "nuniq":
start = 4 ** (1 + level)
stop = start + size
cell_ids = xr.indexes.PandasIndex(
pd.RangeIndex(start, stop, name=name), dim
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we support "nuniq" in healpix-geo yet, so naturally this will fail for now (but possibly we can keep it commented out)

Comment thread xdggs/healpix.py Outdated
return cls(var.data, dim, name, grid_info, index_kind=index_kind)

@classmethod
def from_level(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe call this full_domain (or at least, that's what I've called this for the RangeMOCIndex)?

This will also need to account for index_kind="moc", which I believe should just forward to the moc index and RangeMOCIndex.full_domain.

Comment thread xdggs/healpix.py Outdated

@classmethod
def from_level(
cls: type[DGGSIndex],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to https://typing.python.org/en/latest/spec/annotations.html#annotating-instance-and-class-methods you don't need to annotate cls, or if you do you can annotate it as type[Self] (and annotate the return type of the class method as Self)

@keewis

keewis commented Sep 11, 2026

Copy link
Copy Markdown
Member

I've decided to instead merge #262 first and adapt here. To make this easier on you I've resolved the merge conflicts for you. This does mean however that this PR does not need to translate the ellipsoid parameter names anymore, but the additional test coverage is definitely nice (but it looks like we'll need even more tests, which I'll add in a separate PR).

@carloshorn

Copy link
Copy Markdown
Author

Thanks for the initiative @keewis. I will look into it early next week.

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.

zarr convention

3 participants