earthkit.data.xr_engine.accessor

Encoding/decoding utilities for the _earthkit xarray attribute and the EarthkitAttrsBuilder that constructs it from GRIB field metadata.

Attributes

Classes

Functions

decode_earthkit_attrs(s)

Decode an _earthkit attribute value back to a dict.

encode_earthkit_attrs(d)

Encode a dict into a JSON string suitable for storage in xarray attrs.

Module Contents

earthkit.data.xr_engine.accessor.ACCESSOR_KEY = '_earthkit'
class earthkit.data.xr_engine.accessor.EarthkitAttrsBuilder
build(field)

Build the _earthkit attribute dict for a field and encode it to JSON.

Returns a dict {ACCESSOR_KEY: <json_string>} suitable for merging into da.attrs.

set_field(field, da_attrs)

Update the _earthkit attribute with a new field’s metadata.

set_grid_spec(grid_spec, da_attrs)

Update only the grid_spec in the _earthkit attribute.

earthkit.data.xr_engine.accessor.decode_earthkit_attrs(s)

Decode an _earthkit attribute value back to a dict. Restores base64-encoded bytes to their original form.

Parameters:

s (str) – The attribute value to decode.

Returns:

The decoded dictionary, or None if decoding fails.

Return type:

dict or None

earthkit.data.xr_engine.accessor.encode_earthkit_attrs(d)

Encode a dict into a JSON string suitable for storage in xarray attrs.

Handles bytes values (via base64), nested dicts, and other JSON-serializable types.

Parameters:

d (dict) – The dictionary to encode.

Returns:

A JSON string representation of the dictionary.

Return type:

str