contrast.recorders package¶
Module contents¶
Provides the Recorder base class as well as recorder subclasses for
writing, streaming and plotting data.
Submodules¶
contrast.recorders.Recorder module¶
- class contrast.recorders.Recorder.Process(group=None, target=None, name=None, args=(), kwargs={}, *, daemon=None)[source]¶
Bases:
SpawnProcessDummy for cleaning up the inheritance documentation.
- class contrast.recorders.Recorder.RecorderHeader(scannr, path, snapshot=None, description=None, status=None, **kwargs)[source]¶
Bases:
dictHelper class to define a specific dict format to send recorders when a new scan starts.
Bases:
dictHelper class to define a specific dict format to send recorders when a new scan finishes.
- class contrast.recorders.Recorder.Recorder(delay=0.1, **kwargs)[source]¶
-
Base class for Recorders. Provides the multiprocessing and queuing functionality.
- Parameters:
delay (float) – Sleep time for the queue checking loop.
**kwargs – Passed on to base class constructor
- init()[source]¶
Override this. Use this method to Initialize the recorder (open windows, open files, etc.).
- act_on_header(dct)[source]¶
Override this. Performs an action when a new scan is started. The key-value pairs of dct are defined by RecorderHeader.
- act_on_data(dct)[source]¶
Override this. Performs an action when a new data package is received. The keys of dct are detector and motor names, the values are their readings at one particular point in the scan.
Override this. Performs an action when a scan ends.
- class contrast.recorders.Recorder.DummyRecorder(delay=0.1, **kwargs)[source]¶
Bases:
RecorderDummy recorder for practise.
- Parameters:
delay (float) – Sleep time for the queue checking loop.
**kwargs – Passed on to base class constructor
contrast.recorders.Hdf5Recorder module¶
- class contrast.recorders.Hdf5Recorder.Link(*args, universal=False, **kwargs)[source]¶
Bases:
ExternalLinkHelper class which wraps a h5py.ExternalLink, but which also informs the Hdf5Recorder about whether there will be one link per scan (universal=True) or one link per position (universal=False).
contrast.recorders.PlotRecorder module¶
- contrast.recorders.PlotRecorder.dict_lookup(dct, path)[source]¶
Helper to recursively get dct[‘path’][‘to’][‘item’] from dct[‘path/to/item’].
contrast.recorders.StreamRecorder module¶
- contrast.recorders.StreamRecorder.walk_dict(dct)[source]¶
A recursive version of dict.items(), which yields (containing-dict, key, val).
- class contrast.recorders.StreamRecorder.StreamRecorder(name=None, port=5556)[source]¶
Bases:
RecorderRecorder which publishes data to a zmq stream. Try receiving it with:
import zmq context = zmq.Context() socket = context.socket(zmq.SUB) socket.connect ("tcp://localhost:5556") socket.setsockopt(zmq.SUBSCRIBE, b"") # subscribe to all topics while True: messagedata = socket.recv_pyobj() print(messagedata)
The result is a sequence of python objects, of type
dictorOrderedDict. Eachdictcontains a'status'field with one of the following values.heartbeat: a dummy message sent to keep connections alivestarted: indicates the beginning of a scanrunning: indicates that this is a data message from an ongoing scanfinishedorinterrupted: indicates that a scan was either completed or stopped.
Data messages simply contain all gathered motor and detector data, as placed in the
Recorderqueue. For example:$ print(dict(socket.recv_pyobj())) {'sx': 0.8, 'det2': <ExternalLink to "entry/measurement/data" in file "/tmp/Dummy_scan_005_image_004.hdf5", 'det1': 0.024625569499185596, 'dt': 2.3689677715301514, 'status': 'running'}- zmq = <module 'zmq' from '/home/docs/checkouts/readthedocs.org/user_builds/contrast/envs/latest/lib/python3.14/site-packages/zmq/__init__.py'>¶
- act_on_header(dct)[source]¶
Relay information.
Converts RecorderHeader to plain dict so the receiver doesn’t need the contrast library.
- act_on_data(dct, base='entry/measurement/')[source]¶
Relay information, but filter out exotic objects like Links.
Relay information.