Bidirectional coordinate warping derived from alignment data.
A WarpMap converts coordinates from a source timeline to a target timeline (and back) using linear interpolation between anchor points extracted from a timetoalign.MatchLine.
Internally it delegates to an timetoalign.maps.interpolation.InterpolationMap for O(log n) lookup. The materialise() method produces a complete copy of a source timetoalign.Timeline with all coordinates warped to the target’s coordinate space.
This lower-level constructor is useful when coordinate pairs are already available (e.g. from a Parquet file or external alignment tool) and do not need to be extracted from a MatchLine.
Parameters
Name
Type
Description
Default
source_timeline_id
str
ID of the source timeline.
required
target_timeline_id
str
ID of the target timeline.
required
source_coords
list[float] | NDArray[np.floating[Any]]
Source coordinates. Duplicate coordinates are averaged when their targets are compatible; otherwise they raise an ambiguity error. Remaining coordinates must be strictly increasing.
required
target_coords
list[float] | NDArray[np.floating[Any]]
Corresponding target coordinates.
required
source_unit
'TimeUnit | None'
Unit of the source timeline (optional).
None
target_unit
'TimeUnit | None'
Unit of the target timeline (optional).
None
Returns
Name
Type
Description
'WarpMap'
A new WarpMap.
Raises
Name
Type
Description
ValueError
If fewer than 2 coordinate pairs, if source coordinates are ambiguous, or if the remaining source coordinates are not strictly increasing.
Build a WarpMap from a MatchLine’s coordinate pairs.
Extracts (source_coord, target_coord) pairs from the MatchLine for the given target timeline, deduplicates compatible chord coordinates, and constructs the interpolation map. A repeated source coordinate with materially different targets is rejected.
Parameters
Name
Type
Description
Default
match_line
'MatchLine'
The MatchLine providing ordered stamps.
required
target_timeline_id
str
The target timeline to warp towards.
required
source_unit
'TimeUnit | None'
Unit of the source timeline (optional).
None
target_unit
'TimeUnit | None'
Unit of the target timeline (optional).
None
Returns
Name
Type
Description
'WarpMap'
A new WarpMap.
Raises
Name
Type
Description
ValueError
If fewer than 2 coordinate pairs are available.
ValueError
If target_timeline_id is not in the MatchLine’s target timelines.
inverse
alignment.WarpMap.inverse()
Return the cached inverse map with source and target swapped.
Returns
Name
Type
Description
'WarpMap'
A WarpMap converting target coordinates back to source coordinates.
Raises
Name
Type
Description
ValueError
If the target coordinates are not strictly monotonic (map is not invertible).
materialise
alignment.WarpMap.materialise(source_timeline)
Produce a new Timeline with all contents warped to target coordinates.
Creates a complete copy of the source timeline where every coordinate (events, children, regions) is converted by calling this map. The resulting timeline:
Has length equal to the mapped source_timeline.length
Preserves the source’s unit (unless target_unit differs)
Contains warped copies of all events
Contains warped copies of all children (recursively)
Contains warped copies of all regions
Carries an inverse WarpMap as a ConversionMap for traceability
Parameters
Name
Type
Description
Default
source_timeline
'Timeline'
The timeline to warp.
required
Returns
Name
Type
Description
'Timeline'
A new Timeline with warped coordinates.
Raises
Name
Type
Description
ValueError
If source_timeline.id does not match self.source_timeline_id.
to_dict
alignment.WarpMap.to_dict()
Serialize to dictionary.
Returns
Name
Type
Description
dict[str, Any]
Dict with timeline IDs, units, and coordinate arrays.