coordmanager

module of dascore.core source

Module for managing coordinates.

The coordmanager is a simple class for tracking multidimensional coordinates and labels of ndarrays. Various methods exist for trimming, sorting, and filtering the managed arrays based on coordinates.

Initializing CoordinateManagers

Coordinate managers are initialized using the get_coord_manager function. They take a combination of coordinate dictionaries, dimensions, and attributes. They can also be extracted from example patches.

import dascore as dc
from rich import print

patch = dc.get_example_patch()
data = patch.data
cm = patch.coords
print(cm)
Coordinates (distance: 300, time: 2000)
    *distance: CoordRange( min: 0 max: 299 step: 1 shape: (300,) dtype: int64 units: m )
    *time: CoordRange( min: 2017-09-18 max: 2017-09-18T00:00:07.996 step: 0.004s shape: (2000,) dtype: 
datetime64[ns] units: s )
import numpy as np
# Get array of coordinate values
time = cm['time']

# Filter data array
# this gets a new coord manager and a view of the trimmed data.
_sorted_time = np.sort(time)
t1 = _sorted_time[5]
t2 = _sorted_time[-5]
new_cm, new_data = cm.select(time=(t1, t2), array=data)
print(f"Old data shape: {data.shape}")
print(f"New data shape: {new_data.shape}")
print(new_cm)
Old data shape: (300, 2000)
New data shape: (300, 1991)
Coordinates (distance: 300, time: 1991)
    *distance: CoordRange( min: 0 max: 299 step: 1 shape: (300,) dtype: int64 units: m )
    *time: CoordRange( min: 2017-09-18T00:00:00.02 max: 2017-09-18T00:00:07.98 step: 0.004s shape: (1991,) dtype: 
datetime64[ns] units: s )

Functions

Name Description
get_coord_manager Create a coordinate manager.
merge_coord_managers Merger coordinate managers along a specified dimension.

Classes

Name Description
CoordManager Class for managing coordinates.