xarray.Dataset.dggs.decode

xarray.Dataset.dggs.decode#

Dataset.dggs.decode(grid_info=None, *, name='cell_ids', convention=None, index_options=None, **index_kwargs)#

decode the DGGS cell ids

Parameters:
  • grid_info (dict or xdggs.DGGSInfo, optional) – Override the grid parameters on the dataset. Useful to set attributes on the dataset.

  • name (str, optional) – The name of the coordinate containing the cell ids. The default name depends on the convention.

  • convention (str, optional) – The name of the metadata convention. Built-in conventions are:

    • “zarr”: the zarr dggs convention. All metadata is contained in a single nested JSON object that lives in the group attributes.

    • “cf”: the DGGS section from the CF conventions. While the convention extension is specialized on healpix for now, the decoder can work with other DGGS as well. For this, all metadata lives on a variable with a grid_mapping_name attribute, and the cell ids coordinate is indicated by the coordinates attribute on data variables / other coordinates (this can be overridden by the name parameter).

    • “xdggs”: the existing xdggs convention. name points to the coordinate containing cell ids, and which has all the grid metadata. The name parameter defaults to "cell_ids".

    If not passed, will try to infer the convention in the order listed here.

  • index_options, **index_kwargs (dict, optional) – Additional options to forward to the index.

Returns:

obj (xarray.DataArray or xarray.Dataset) – The object with a DGGS index on the cell id coordinate.

Examples

>>> import xdggs
>>> import xarray as xr
>>> import numpy as np

Dataset following the xdggs convention:

>>> ds = xr.Dataset(
...     {"a": ("cells", list("abcdefghijkl"))},
...     coords={
...         "cell_ids": (
...             "cells",
...             np.arange(12, dtype="uint64"),
...             {
...                 "grid_name": "healpix",
...                 "level": 0,
...                 "indexing_scheme": "nested",
...             },
...         )
...     },
... )
>>> ds.dggs.decode()
<xarray.Dataset> Size: 144B
Dimensions:   (cells: 12)
Coordinates:
  * cell_ids  (cells) uint64 96B 0 1 2 3 4 5 6 7 8 9 10 11
Dimensions without coordinates: cells
Data variables:
    a         (cells) <U1 48B 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l'
Indexes:
    cell_ids  HealpixIndex(level=0, indexing_scheme=nested, kind=pandas)