API reference

Module contents

contrast.wisdom()[source]

Prints the current meaning of the acronym Contrast.

Submodules

contrast.Gadget module

class contrast.Gadget.Gadget(name=None, userlevel=1)[source]

Bases: object

Base class for motors, detectors, etc. Main purpose is to keep track of instances so that names can be mapped to objects.

This base class keeps a master class attribute holding references to all instances. The class method getinstances() on each subclass then filters and returns instances of that class or its children.

classmethod getinstances()[source]

Returns a generator over all instances of this class and its children.

[g.name for g in Gadget.getinstances()]
    - a list of all motors, detectors, etc.
[m.name for m in Motor.getinstances()]
    - a list of all motors.
[m.name for m in DummyMotor.getinstances()]
    - a list of all dummy motors.

contrast.abbreviations module

Provides meanings of the Contrast acronym.

contrast.utils module

contrast.utils.list_to_table(lst, titles, margins=3, sort=True)[source]

Formats a table from a nested list, where the first index is the row.

contrast.utils.dict_to_table(dct, titles=('col1', 'col2'), margin=3, sort=True)[source]

Formats a dict where key:val is str:str into a two column table.

contrast.utils.str_to_args(line)[source]

Handy function which splits a list of arguments and keyword arguments, translates names of Gadget instances to actual objects, evaluates expressions that can be evaluated, and accepts the rest as strings. For example,

In [1]: from contrast.motors import DummyMotor

In [2]: from contrast.utils import str_to_args

In [3]: samx = DummyMotor(name='samx')

In [4]: str_to_args("samx hej 1./20")
Out[4]: ([<contrast.motors.Motor.DummyMotor at 0x7f6867697f90>, 'hej', 0.05], {})
class contrast.utils.SpecTable[source]

Bases: object

A dyamic table, for use when the column titles and one data row are known.

format_pair(k, v)[source]

Return two title strings and a format string corresponding to the k:v pair.

header_lines(dct)[source]

Takes a dict of {header: value} pairs, and returns a header line. At the same time it calculates the format string for subsequent data lines.

fill_line(dct)[source]

Takes a data dict and returns a data line.