get_coord_manager

function of dascore.core.coordmanager source

get_coord_manager(
    coords: collections.abc.Mapping[collections.abc.Mapping[str, Any], CoordManager, None] = None,
    dims: collections.abc.Sequence[collections.abc.Sequence[str], 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
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)