ConversionMap
ConversionMap(source_unit=None, target_unit=None, uid=None, name=None)Abstract base class for coordinate conversion maps.
A ConversionMap transforms coordinates from one representation to another. Maps are callable and support both scalar and array inputs.
The key methods are: - call(value): Convert a single value or array - inverse(): Get the inverse map (if invertible)
Attributes: id: Unique identifier for this map instance. source_unit: The unit of input coordinates (optional). target_unit: The unit of output coordinates (optional).
Examples: >>> # Create a map that doubles values >>> linear = LinearMap(scalar=2.0) >>> linear(5.0) 10.0
>>> # Maps are callable
>>> linear(np.array([1.0, 2.0, 3.0]))
array([2., 4., 6.])
>>> # Get the inverse
>>> inv = linear.inverse()
>>> inv(10.0)
5.0
Attributes
| Name | Description |
|---|---|
| id | Unique identifier for this map. |
| is_invertible | Whether this map has a well-defined inverse. |
| name | Human-readable name for this map. |
| source_unit | The unit of input coordinates, if specified. |
| target_unit | The unit of output coordinates, if specified. |
Methods
| Name | Description |
|---|---|
| convert_array | Convert an array of values. |
| from_dict | Deserialize a map from a dictionary. |
| inverse | Return the inverse of this map. |
| then | Compose this map with another (this first, then other). |
| to_dict | Serialize the map to a dictionary. |
convert_array
ConversionMap.convert_array(values, **kwargs)Convert an array of values.
This is the public API for array conversion, used by the timestamp system and other batch operations. It delegates to _convert_array().
All ConversionMap subclasses support efficient array operations through this method. Linear maps use NumPy broadcasting, TableMaps use np.interp, and composite maps delegate to their sub-maps.
Args: values: NumPy array of values to convert. **kwargs: Subclass-specific arguments.
Returns: NumPy array of converted values with same shape as input.
Examples: >>> linear = LinearMap(scalar=2.0, offset=1.0) >>> linear.convert_array(np.array([0.0, 1.0, 2.0])) array([1., 3., 5.])
>>> tempo_map = TableMap.from_tempo_changes([0, 960], [120, 60], 480)
>>> tempo_map.convert_array(np.array([0, 480, 960]))
array([0. , 0.5 , 1.5])
from_dict
ConversionMap.from_dict(data)Deserialize a map from a dictionary.
Args: data: Dictionary representation.
Returns: A ConversionMap instance.
Raises: ValueError: If the type is unknown.
inverse
ConversionMap.inverse()Return the inverse of this map.
Returns: A new ConversionMap that reverses this transformation.
Raises: NotImplementedError: If the map is not invertible.
then
ConversionMap.then(other)Compose this map with another (this first, then other).
Args: other: The map to apply after this one.
Returns: A ChainMap that applies both maps in sequence.
to_dict
ConversionMap.to_dict()Serialize the map to a dictionary.
Subclasses should call super().to_dict() and add their parameters.
Returns: Dictionary representation of the map.