encode_attrs#
- eoio.serialisation.attrs.encode_attrs(obj: T, *, dict_style: str = 'dot', strict: bool = False, inplace: bool = False) T[source]#
Convert attributes to values that can be written to netCDF or Zarr.
Applies to dataset-level, variable and coordinate attributes, and to every node of a
DataTree. Aneoio:attr_encodingmarker is added to each scope that needed encoding, sodecode_attrs()can reverse it exactly.- Parameters:
obj – Dataset, DataArray or DataTree whose attributes should be encoded.
dict_style –
"dot"to dot-flatten nested dicts, or"json"to encode each as a single JSON blob.strict – If
True, raise on a value no codec handles. IfFalse, fall back tostr()with a warning.inplace – Whether to modify
objrather than a copy.
- Returns:
The object with encoded attributes.
- Raises:
ValueError – If
dict_styleis not"dot"or"json".TypeError – If
strictis set and a value cannot be encoded.