get_coord_manager

function of dascore.core.coordmanager source

get_coord_manager(
    coords: collections.abc.Mapping[collections.abc.Mapping[str, dascore.core.coords.BaseCoord | numpy.ndarray[BaseCoord, ndarray]], CoordManager, None] = None,
    dims: tuple[tuple[str, …], None] = None,
    attrs: dascore.core.attrs.PatchAttrs | dict[PatchAttrs, dict[str, Any], None] = None,
    shape = None,
)-> ‘CoordManager’

Create a coordinate manager.

Parameters

Parameter Description
coords Information about coordinates. These can be a mapping of the
form: {name, array}, {name: (dim_name, array)}, or
{name: ((dim_names,) array). Can also be a
CoordManager.
dims Tuple specify dimension names
attrs Attributes which can be used to create coordinates.
Cannot be used with coords argument.
If you want to update CoordManager
use update_from_attrs.
shape The data array shape which will be managed by coord manager. This
allows non-coordinate dimensions to be initiated.

Examples

import numpy as np
import dascore as dc
from dascore.core.coordmanager import get_coord_manager
# initialize coordinates from dict of arrays
distance = np.arange(0, 100)
time = dc.to_datetime64(np.arange(0, 100_000, 1_000))
coords = {"distance": distance, "time": time}
dims = ("time", "distance")
cm = get_coord_manager(coords=coords, dims=dims)
# add non-dimension 1D coordinate. Note the coord dict must be a tuple
# with the first element specifying the dimensional coord the
# non-dimensional coord is attached to.
latitude = np.random.random(distance.shape)
coords['latitude'] = ('distance', latitude)
cm = get_coord_manager(coords=coords, dims=dims)
# Add two-D non-dimensional coord.
quality = np.random.random((len(distance), len(time)))
coords['quality'] = (("distance", "time"), quality)
cm = get_coord_manager(coords=coords, dims=dims)
# Get coordinate manager from typical patch attribute dict
attrs = dc.get_example_patch().attrs
cm = get_coord_manager(attrs=attrs)