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 signals used in 1-D scans.#

factor_fwhm

FWHM \(=2\sqrt{2\ln{2}}\cdot\sigma_c\)

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
 3
 4signal_stats = SignalStatsCallback()
 5
 6def my_plan(detectors, mover, rel_start, rel_stop, points, md={}):
 7
 8    @bpp.subs_decorator(signal_stats.receiver)  # collect the data
 9    def _inner():
10        yield from bp.rel_scan(detectors, mover, rel_start, rel_end, points, md)
11
12    yield from _inner()  # run the scan
13    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.

stop_report

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.

_scanning

Is a run in progress?

_registers

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

_registers: dict = {}#

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

_scanning: bool = False#

Is a run in progress?

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.

start(doc)[source]#

Receives ‘start’ documents from the RunEngine.

stop(doc)[source]#

Receives ‘stop’ documents from the RunEngine.

stop_report: bool = True#

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

apstools.callbacks.scan_signal_statistics.factor_fwhm = 2.3548200450309493#

FWHM \(=2\sqrt{2\ln{2}}\cdot\sigma_c\)

see: https://statproofbook.github.io/P/norm-fwhm.html