IntervalToConstantMap

IntervalToConstantMap(
    boundaries,
    values,
    source_unit=None,
    target_unit=None,
    uid=None,
    name=None,
)

Interval-to-constant map: each interval [x_i, x_{i+1}) maps to value_i.

Unlike TableMap, IntervalToConstantMap does not interpolate. A coordinate x returns the value associated with the interval that contains x.

Values can be any type (string, int, float, etc.). This is NOT a coordinate conversion map when values are non-numeric (e.g., string labels).

This is useful for: - Measure number lookup (quarters -> MN label) - Region/section lookup (coordinate -> section name) - Any step-function relationship

Attributes

Name Type Description
boundaries NDArray[np.floating[Any]] Sorted x-coordinates defining interval starts.
values list[T] Value for each interval (len = len(boundaries)).

Examples

>>> # Map quarters to section names
>>> section_map = IntervalToConstantMap(
...     boundaries=[0, 16, 32, 48],
...     values=["Intro", "Verse", "Chorus", "Outro"],
...     source_unit="quarters",
... )
>>> section_map(20)
'Verse'
>>> section_map(40)
'Chorus'

Methods

Name Description
from_dict Deserialize from dictionary.
inverse IntervalToConstantMap is not invertible.
to_dict Serialize to dictionary.
to_table_map Convert to TableMap for numeric values.

from_dict

IntervalToConstantMap.from_dict(data)

Deserialize from dictionary.

inverse

IntervalToConstantMap.inverse()

IntervalToConstantMap is not invertible.

Raises

Name Type Description
NotImplementedError Always.

to_dict

IntervalToConstantMap.to_dict()

Serialize to dictionary.

to_table_map

IntervalToConstantMap.to_table_map(kind=InterpolationKind.previous)

Convert to TableMap for numeric values.

This allows using TableMap operations on interval data when values are numeric.

Parameters

Name Type Description Default
kind InterpolationKind Interpolation kind. Default is “previous” (step function). InterpolationKind.previous

Returns

Name Type Description
TableMap TableMap with the same boundaries and values.

Raises

Name Type Description
TypeError If values are not numeric.