drop_coords

function of dascore.proc.coords source

drop_coords(
    self ,
    *coords: str | collections.abc.Iterable[str, collections.abc.Iterable[str]] ,
    to_attrs: bool = False,
)-> ‘Self’

Drop one or more non-dimensional coordinates.

Parameters

Parameter Description
*coords One or more coordinates to drop. Each can be a coordinate name or
a sequence of them.
to_attrs If True, store each dropped coordinate’s value as an attribute of
the same name; each must hold one non-null value throughout, and
its units are not kept. With no names given, every non-dimensional
coordinate holding one value moves, skipping private coordinates
and names the attrs reserve.

Raises

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

Examples

import numpy as np
import dascore as dc
pa = dc.get_example_patch("random_patch_with_lat_lon")
# Drop non-dimensional coordinate latitude
pa_no_lat = pa.drop_coords("latitude")
# A sequence of names works as well.
pa_no_lat = pa.drop_coords(["latitude"])
# Move a coordinate holding one value into the attrs.
ones = np.ones(pa.coord_shapes["distance"])
out = pa.update_coords(quality=("distance", ones)).drop_coords(
    "quality", to_attrs=True
)
assert out.attrs["quality"] == 1