-
Notifications
You must be signed in to change notification settings - Fork 21
convert between different metadata conventions #179
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
base: main
Are you sure you want to change the base?
Conversation
(should this affect `equals`?)
(this avoids import cycles)
|
@benbovy, I've implemented the changes we discussed yesterday (I'll add documentation / type hints to the However, now that we normalize to the "xdggs" convention, we can probably change Otherwise we could have backends call So this clearly needs some more thought to create a clean API, especially if we want people to create their own convention implementations. |
|
actually, there might be an argument for the conventions to work on the objects themselves ( class Convention:
def decode(
self,
ds: xr.Dataset,
*,
grid_info: dict | DGGSInfo | None = None,
name: Hashable | None = None,
index_options: dict | None = None
) -> xr.Dataset:
"""
Decode the dataset according to the convention.
Parameters
----------
ds : xr.Dataset
The encoded dataset.
grid_info : mapping or DGGSInfo, optional
Overrides for the grid metadata.
name : str, optional
The name of the cell ids coordinate.
index_options : mapping of str to Any, optional
Additional options for the index.
Returns
-------
decoded : xr.Dataset
The decoded dataset with a DGGSIndex.
"""
pass
def encode(self, ds: xr.Dataset, *, encoding: dict | None = None) -> xr.Dataset:
"""
Encode according to the convention.
Parameters
----------
ds : xr.Dataset
The dataset to encode. Must have a DGGSIndex.
encoding : mapping of str to Any, optional
Additional options for the convention.
Returns
-------
encoded : xr.Dataset
The encoded dataset. Does not have a DGGSIndex anymore.
"""
pass(the convention shouldn't have to deal with the differences between In theory, the |
(this is more complicated because `coordinates` is a stringified list)
|
with this I'm pretty happy with how the convention support looks. The only weakness I see is in how the coordinate name is duplicated between the underlying index and the |
This adds
as_conventionto the accessor, which allows converting to different conventions. For this to be really useful, we needdecodeto support reading from those conventions (and possibly auto-detect the convention).