Callbacks#

Receive documents from the bluesky RunEngine. File Writers are a specialized type of callback.

Callbacks

DocumentCollectorCallback

Bluesky callback to collect all documents from most-recent plan

document_contents_callback

prints document contents -- use for diagnosing a document stream

SignalStatsCallback

Callback: Collect peak (& other) statistics during a scan.

File Writing Callbacks

NXWriterAPS(*args, **kwargs)

Customize NXWriter with APS-specific content.

NXWriter(*args, **kwargs)

General class for writing HDF5/NeXus file (using only NeXus base classes).

SpecWriterCallback([filename, auto_write, ...])

Deprecated: Use SpecWriterCallback2.

SpecWriterCallback2(*args, **kwargs)

Write SPEC data file as data is collected, line-by-line.

Document Collector#

DocumentCollectorCallback()

Bluesky callback to collect all documents from most-recent plan

document_contents_callback(key, doc)

prints document contents -- use for diagnosing a document stream

class apstools.callbacks.doc_collector.DocumentCollectorCallback[source]#

Bluesky callback to collect all documents from most-recent plan

Will reset when it receives a start document.

EXAMPLE:

from apstools.callbacks import DocumentCollectorCallback
doc_collector = DocumentCollectorCallback()
RE.subscribe(doc_collector.receiver)
...
RE(some_plan())
print(doc_collector.uids)
print(doc_collector.documents["stop"])
receiver(key, document)[source]#

keep all documents from recent plan in memory

apstools.callbacks.doc_collector.document_contents_callback(key, doc)[source]#

prints document contents – use for diagnosing a document stream

Collect statistics on the first detector used in 1-D scans.#

SignalStatsCallback()

Callback: Collect peak (& other) statistics during a scan.

class apstools.callbacks.scan_signal_statistics.SignalStatsCallback[source]#

Callback: Collect peak (& other) statistics during a scan.

Caution

This is an early draft and is subject to change!

Subscribe the receiver() method. Use with step scan plans such as bp.scan() and bp.rel_scan().

Caution

It is recommended to subscribe this callback to specific plans. It should not be run with just any plan (it could easily raise exceptions).

Basic example

 1from bluesky import plans as bp
 2from bluesky import preprocessors as bpp
 3from apstools.callbacks import SignalStatsCallback
 4
 5signal_stats = SignalStatsCallback()
 6
 7def my_plan(detectors, mover, rel_start, rel_stop, points, md={}):
 8
 9    @bpp.subs_decorator(signal_stats.receiver)  # collect the data
10    def _inner():
11        yield from bp.rel_scan(detectors, mover, rel_start, rel_end, points, md)
12
13    yield from _inner()  # run the scan
14    signal_stats.report()  # print the statistics

Public API

receiver(key, document)

Client method used to subscribe to the RunEngine.

report()

Print a table with the collected statistics for each signal.

data_stream

RunEngine document with signals to to watch.

reporting

If True (default), call the report() method when a stop document is received.

Internal API

clear()

Clear the internal memory for the next run.

descriptor(doc)

Receives 'descriptor' documents from the RunEngine.

event(doc)

Receives 'event' documents from the RunEngine.

start(doc)

Receives 'start' documents from the RunEngine.

stop(doc)

Receives 'stop' documents from the RunEngine.

analysis

Dictionary of statistical array analyses.

_data

Arrays of x & y data

_scanning

Is a run in progress?

_registers

Deprecated: Use 'analysis' instead, will remove in next major release.

_data: dict = {}#

Arrays of x & y data

_registers: dict = {}#

Deprecated: Use ‘analysis’ instead, will remove in next major release.

Dictionary (keyed on Signal name) of SummationRegister() objects.

_scanning: bool = False#

Is a run in progress?

analysis: object = None#

Dictionary of statistical array analyses.

clear()[source]#

Clear the internal memory for the next run.

data_stream: str = 'primary'#

RunEngine document with signals to to watch.

descriptor(doc)[source]#

Receives ‘descriptor’ documents from the RunEngine.

event(doc)[source]#

Receives ‘event’ documents from the RunEngine.

receiver(key, document)[source]#

Client method used to subscribe to the RunEngine.

report()[source]#

Print a table with the collected statistics for each signal.

reporting: bool = True#

If True (default), call the report() method when a stop document is received.

start(doc)[source]#

Receives ‘start’ documents from the RunEngine.

stop(doc)[source]#

Receives ‘stop’ documents from the RunEngine.