xarray-contrib / xdggs

Xarray extension for DGGS
https://xdggs.readthedocs.io
Apache License 2.0
80 stars 14 forks source link

decoder function #47

Closed keewis closed 7 months ago

keewis commented 7 months ago

The current way of creating the DGGS index is pretty verbose:

ds.set_xindex("cell_ids", xdggs.DGGSIndex)

In this PR, I'm proposing to add a top-level function that hides that detail. You'd call it like this:

ds.pipe(xdggs.decode)

Should we ever get the custom decoder machinery in xarray, we could have it call xdggs.decode.

We could alternatively use ds.dggs.decode(), but so far all methods in the dggs namespace require the index to exist, and this would be an exception to that.

At the moment the variable name is hard-coded to cell_ids, but we could just as well use filter_by_attrs instead.

This would fix #13 without being too specific (as create_index would be) nor having somewhat confusing names (from_x, to_x), with the downside that we'd be reusing the term decode with a slightly different meaning: so far decode would take attributes, modify the data and move the attributes to .encoding (and encode does the inverse). By "decoding" a dggs index we're not actually invalidating the attributes, which is why this does not fit exactly (but I think it is close enough).

keewis commented 7 months ago

merging since I think it helps a lot already, and if we find something better, we can just deprecate this method.