ChainMap

ChainMap(maps, *, uid=None, name=None)

Composition of multiple maps: f(g(h(x))).

The maps are applied in sequence from first to last. The output unit of one map must match the input unit of the next (if specified).

Attributes

Name Type Description
maps list[ConversionMap[Any]] The sequence of maps to apply.

Examples

>>> # Ticks -> Seconds -> Milliseconds
>>> ticks_to_secs = ScalarMap(scalar=1/480, source_unit="ticks", target_unit="seconds")
>>> secs_to_ms = ScalarMap(scalar=1000, source_unit="seconds", target_unit="milliseconds")
>>> chain = ChainMap([ticks_to_secs, secs_to_ms])
>>> chain(480)
1000.0

Methods

Name Description
from_dict Deserialize from dictionary.
inverse Return the inverse chain.
to_dict Serialize to dictionary.

from_dict

ChainMap.from_dict(data)

Deserialize from dictionary.

inverse

ChainMap.inverse()

Return the inverse chain.

This reverses the order of maps and inverts each one. (f(g(x)))^-1 = g-1(f-1(x))

to_dict

ChainMap.to_dict()

Serialize to dictionary.