import numpy as np
import dascore as dc
from dascore.core.coordmanager import get_coord_manager
# initialize coordinates from dict of arrays
= np.arange(0, 100)
distance = dc.to_datetime64(np.arange(0, 100_000, 1_000))
time = {"distance": distance, "time": time}
coords = ("time", "distance")
dims = get_coord_manager(coords=coords, dims=dims)
cm # 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.
= np.random.random(distance.shape)
latitude 'latitude'] = ('distance', latitude)
coords[= get_coord_manager(coords=coords, dims=dims)
cm # Add two-D non-dimensional coord.
= np.random.random((len(distance), len(time)))
quality 'quality'] = (("distance", "time"), quality)
coords[= get_coord_manager(coords=coords, dims=dims)
cm # Get coordinate manager from typical patch attribute dict
= dc.get_example_patch().attrs
attrs = get_coord_manager(attrs=attrs) cm
get_coord_manager
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. |