|
def | __init__ (self, name, aliases=(), defaults=None) |
|
def | from_context (cls, context, **defaults) |
|
def | from_lines (cls, lines, to_base_func=None) |
|
def | add_transformation (self, src, dst, func) |
|
def | remove_transformation (self, src, dst) |
|
def | transform (self, src, dst, registry, value) |
|
A specialized container that defines transformation functions from
one dimension to another. Each Dimension are specified using a UnitsContainer.
Simple transformation are given with a function taking a single parameter.
>>> timedim = UnitsContainer({'[time]': 1})
>>> spacedim = UnitsContainer({'[length]': 1})
>>> def f(time):
... 'Time to length converter'
... return 3. * time
>>> c = Context()
>>> c.add_transformation(timedim, spacedim, f)
>>> c.transform(timedim, spacedim, 2)
6
Conversion functions may take optional keyword arguments and the context can
have default values for these arguments.
>>> def f(time, n):
... 'Time to length converter, n is the index of refraction of the material'
... return 3. * time / n
>>> c = Context(n=3)
>>> c.add_transformation(timedim, spacedim, f)
>>> c.transform(timedim, spacedim, 2)
2