CoordSegmented

class of dascore.core.coords
inherits from: BaseCoord, DascoreBaseModel, pydantic.main.BaseModel, abc.ABC
source

CoordSegmented(
    units: pint.registry.Quantity | str | None[Quantity, str, None] = None,
    step: Any = None,
    shape: tuple[int, …] = (),
    dtype: Any = None,
    segments: tuple[BaseCoord, …] ,
)-> None

A coordinate composed of an ordered sequence of monotonic segments.

Segments are normal coordinates (CoordRange or CoordMonotonicArray); the values of the segmented coordinate are exactly the concatenation of the segment values. Segment boundaries record discontinuities (e.g. data gaps) without altering any value, which makes this the natural coordinate for data merged across nearly-contiguous blocks.

Note
  • Direct construction requires at least two segments after normalization; use concat_coords (or get_coord(segments=...)) which returns a plain coordinate when the inputs fuse into one segment.
  • Normalization promotes exactly evenly sampled array segments to ranges and fuses segments that continue exactly, so equal-valued segmented coordinates compare and fingerprint equal regardless of how they were assembled.
  • step is always None; use simplify to obtain an evenly sampled coordinate with bounded error, or snap to force one.

Examples

import dascore as dc
from dascore.core.coords import concat_coords, get_coord

# Two evenly sampled blocks separated by a gap.
c1 = get_coord(start=0.0, stop=10.0, step=1.0)
c2 = get_coord(start=15.0, stop=25.0, step=1.0)
coord = concat_coords(c1, c2)
assert coord.segment_count == 2
assert coord.min() == 0.0 and coord.max() == 24.0

# Exactly contiguous blocks fuse back to a single range.
c3 = get_coord(start=10.0, stop=20.0, step=1.0)
fused = concat_coords(c1, c3)
assert fused == get_coord(start=0.0, stop=20.0, step=1.0)

Methods

Name Description
align_to Align the coordinate to another coordinate.
approx_equal Return True if the coordinates are approximately equal.
change_length Adjust the length of the coordinate by changing the end value.
check_time_units Ensure time units are s if dtype is time-like.
convert_units Convert units, or set units if none exist.
coord_range Return a scaler value for the coordinate range (e.g., number of seconds).
empty Empty out the coordinate.
fingerprint Return a stable fingerprint whose matches imply coord equality.
from_array Build a coordinate from a monotonic array, detecting uniform runs.
get_discontinuities Return a dataframe describing discontinuities in the coordinate.
get_next_index Get the index a value would have in a coordinate.
get_sample_count Return the number of samples represented by a value.
get_slice_tuple Get a tuple with (start, stop) and perform basic checks.
index Index the coordinate and return new coordinate.
max Return max value.
min Return min value.
new Update coordinate.
order Order coordinate according to array values or samples.
check_time_units Ensure time units are s if dtype is time-like.
reduce_coord Get a reduced coordinate.
select Apply select, return selected coords and index for selecting data.
set_units Set new units on the coordinate and all segments.
simplify Return the simplest coordinate representing the same values.
simplify_units Simplify the coordinate units.
snap Snap the coordinates to evenly sampled grid points.
sort Sort the contents of the coord. Return new coord and slice for sorting.
to_summary Get the summary info about the coord.
update Update parts of the coordinate.
update_data Update the data of the coordinate.
update_limits Update the limits or sampling of the coordinates.