squeeze_coords

function of dascore.proc.coords source

squeeze_coords(
    self ,
    *coords: str | collections.abc.Iterable[str, collections.abc.Iterable[str]] ,
)-> ‘Self’

Move non-dimensional coordinates holding one value into the attrs.

Each coordinate is dropped and its value stored as an attribute of the same name; units are not kept and dimensions are never touched.

Parameters

Parameter Description
*coords The coordinates to squeeze, as names or sequences of them. If none
are given, every non-dimensional coordinate whose values are all one
non-null value is squeezed, skipping private coordinates and names
the attrs reserve.

Raises

CoordError If a named coordinate is absent, a dimension, private, reserved by the attrs, or not one non-null value throughout.

Examples

import numpy as np
import dascore as dc
patch = dc.get_example_patch()
ones = np.ones(patch.coord_shapes["distance"])
patch = patch.update_coords(quality=("distance", ones))
out = patch.squeeze_coords()
assert "quality" not in out.coords.coord_map
assert out.attrs["quality"] == 1