LinearMap

LinearMap(
    scalar=1.0,
    offset=0.0,
    source_unit=None,
    target_unit=None,
    uid=None,
    name=None,
)

Affine transformation: y = scalar * x + offset.

This is the most general linear map, combining scaling and offset.

Attributes: scalar: The multiplicative factor (default 1.0). offset: The additive offset (default 0.0).

Examples: >>> # Convert ticks to quarters: y = x / 480 >>> tick_to_quarter = LinearMap(scalar=1/480, source_unit=“ticks”, target_unit=“quarters”) >>> tick_to_quarter(480) 1.0

>>> # Temperature conversion: Celsius to Fahrenheit: y = 1.8x + 32
>>> c_to_f = LinearMap(scalar=1.8, offset=32)
>>> c_to_f(0)
32.0
>>> c_to_f(100)
212.0

>>> # Inverse map
>>> f_to_c = c_to_f.inverse()
>>> f_to_c(212.0)
100.0

Attributes

Name Description
is_identity Whether this map is the identity transformation.
offset The additive offset.
scalar The multiplicative factor.

Methods

Name Description
compose_with Compose with another LinearMap: (self then other).
from_dict Deserialize from dictionary.
inverse Return the inverse map: y = (x - b) / a.
to_dict Serialize to dictionary.

compose_with

LinearMap.compose_with(other)

Compose with another LinearMap: (self then other).

For y1 = a1x + b1 and y2 = a2y1 + b2: y2 = a2(a1x + b1) + b2 = (a1a2)x + (a2*b1 + b2)

Args: other: The map to apply after this one.

Returns: A new LinearMap equivalent to applying both in sequence.

from_dict

LinearMap.from_dict(data)

Deserialize from dictionary.

inverse

LinearMap.inverse()

Return the inverse map: y = (x - b) / a.

to_dict

LinearMap.to_dict()

Serialize to dictionary.