ibex_bluesky_core.callbacks

Bluesky callbacks which may be attached to the RunEngine.

Submodules

reflectometry

Reflectometry-specific callbacks.

Members

ISISCallbacks

ISIS standard callbacks for use within plans.

class ibex_bluesky_core.callbacks.DocLoggingCallback[source]

Bases: object

Logs all documents under log_location, with the file name of their UID (.log).

Initialise current_start_document and filename.

class ibex_bluesky_core.callbacks.HumanReadableFileCallback(fields: list[str], *, output_dir: Path | None, postfix: str = '')[source]

Bases: CallbackBase

Outputs bluesky runs to human-readable output files in the specified directory path.

Output human-readable output files of bluesky runs.

If fields are given, just output those, otherwise output all hinted signals.

Parameters:
  • fields – a list of field names to include in output files

  • output_dir – filepath into which to write output files

  • postfix – optional postfix to append to output file names

descriptor(doc: EventDescriptor) None[source]

Add the descriptor data to descriptors.

event(doc: Event) Event[source]

Append an event’s output to the file.

start(doc: RunStart) None[source]

Start writing an output file.

This involves creating the file if it doesn’t already exist then putting the metadata ie. start time, uid in the header.

stop(doc: RunStop) RunStop | None[source]

Clear descriptors.

class ibex_bluesky_core.callbacks.ISISCallbacks(*, x: str, y: str, yerr: str | None = None, measured_fields: list[str] | None = None, add_table_cb: bool = True, fields_for_live_table: list[str] | None = None, add_human_readable_file_cb: bool = True, fields_for_hr_file: list[str] | None = None, human_readable_file_output_dir: str | PathLike[str] | None = None, add_plot_cb: bool = True, ax: Axes | None = None, fit: FitMethod | None = None, show_fit_on_plot: bool = True, add_peak_stats: bool = True, add_live_fit_logger: bool = True, live_fit_logger_output_dir: str | PathLike[str] | None = None, live_fit_logger_postfix: str = '', human_readable_file_postfix: str = '', live_fit_update_every: int | None = 1, live_plot_update_on_every_event: bool = True)[source]

Bases: object

ISIS standard callbacks for use within plans.

A collection of ISIS standard callbacks for use within plans.

By default, this adds:

  • HumanReadableFileCallback

  • LiveTable

  • PeakStats

  • LiveFit

  • LiveFitPlot

  • LivePlot

Results can be accessed from the live_fit and peak_stats properties.

This is to be used as a member and then as a decorator if results are needed ie:

def dae_scan_plan():
    ...
    icc = ISISCallbacks(
        x=block.name,
        y=reducer.intensity.name,
        yerr=reducer.intensity_stddev.name,
        fit=Linear.fit(),
        ...
    )
    ...

    @icc
    def _inner():
        yield from ...
        ...
        print(icc.live_fit.result.fit_report())
        print(f"COM: {icc.peak_stats['com']}")
Parameters:
  • x – The signal name to use for X within plots and fits.

  • y – The signal name to use for Y within plots and fits.

  • yerr – The signal name to use for the Y uncertainty within plots and fits.

  • measured_fields – the fields to use for both the live table and human-readable file.

  • add_table_cb – whether to add a table callback.

  • fields_for_live_table – the fields to measure for the live table (in addition to measured_fields).

  • add_human_readable_file_cb – whether to add a human-readable file callback.

  • fields_for_hr_file – the fields to measure for the human-readable file (in addition to measured_fields).

  • human_readable_file_output_dir – the output directory for human-readable files. can be blank and will default.

  • add_plot_cb – whether to add a plot callback.

  • ax – An optional axes object to use for plotting.

  • fit – The fit method to use when fitting.

  • show_fit_on_plot – whether to show fit on plot.

  • add_peak_stats – whether to add a peak stats callback.

  • add_live_fit_logger – whether to add a live fit logger.

  • live_fit_logger_output_dir – the output directory for live fit logger.

  • live_fit_logger_postfix – the postfix to add to live fit logger.

  • human_readable_file_postfix – optional postfix to add to human-readable file logger.

  • live_fit_update_every – How often, in points, to recompute the fit. If None, do not compute until the end.

  • live_plot_update_on_every_event – whether to show the live plot on every event, or just at the end.

property live_fit: LiveFit

The live fit object containing fitting results.

property peak_stats: PeakStats

The peak stats object containing statistics ie. centre of mass.

property subs: list[CallbackBase]

The list of subscribed callbacks.

class ibex_bluesky_core.callbacks.LiveFit(method: FitMethod, y: str, x: str, *, update_every: int | None = 1, yerr: str | None = None)[source]

Bases: LiveFit

LiveFit, customized for IBEX.

Call Bluesky LiveFit with assumption that there is only one independant variable.

Parameters:
  • method (FitMethod) – The FitMethod (Model & Guess) to use when fitting.

  • y (str) – The name of the dependant variable.

  • x (str) – The name of the independant variable.

  • update_every (int, optional) – How often, in points, to update the fit.

  • yerr (str or None, optional) – Name of field in the Event document that provides standard deviation for each Y value. None meaning do not use uncertainties in fit.

event(doc: Event) None[source]

When an event is received, update caches.

update_fit() None[source]

Use the provided guess function with the most recent x and y values after every update.

Parameters:

None

Returns:

None

update_weight(weight: float | None = 0.0) None[source]

Update uncertainties cache.

class ibex_bluesky_core.callbacks.LiveFitLogger(livefit: LiveFit, y: str, x: str, postfix: str, output_dir: str | PathLike[str] | None, yerr: str | None = None)[source]

Bases: CallbackBase

Generates files as part of a scan that describe the fit(s) which have been performed.

Initialise LiveFitLogger callback.

Parameters:
  • livefit (LiveFit) – A reference to LiveFit callback to collect fit info from.

  • y (str) – The name of the signal pointing to y counts data.

  • x (str) – The name of the signal pointing to x counts data.

  • output_dir (str) – A path to where the fitting file should be stored.

  • postfix (str) – A small string that should be placed at the end of the filename to disambiguate multiple fits and avoid overwriting.

  • yerr (str) – The name of the signal pointing to y count uncertainties data.

event(doc: Event) Event[source]

Start collecting, y, x and yerr data.

Parameters:

doc – (Event): An event document.

start(doc: RunStart) None[source]

Create the output directory if it doesn’t already exist then setting the filename.

Parameters:

doc (RunStart) – The start bluesky document.

stop(doc: RunStop) None[source]

Write to the fitting file.

Parameters:

doc (RunStop) – The stop bluesky document.

write_fields_table() None[source]

Write collected run info to the fitting file.

write_fields_table_uncertainty() None[source]

Write collected run info to the fitting file with uncertainties.

class ibex_bluesky_core.callbacks.LivePlot(y: str, x: str | None = None, yerr: str | None = None, *args: Any, update_on_every_event: bool = True, **kwargs: Any)[source]

Bases: LivePlot

Live plot, customized for IBEX.

Initialise LivePlot.

Parameters:
  • y (str) – The name of the dependant variable.

  • x (str or None, optional) – The name of the independant variable.

  • yerr (str or None, optional) – Name of uncertainties signal. Providing None means do not plot uncertainties.

  • *args – As per mpl_plotting.py

  • update_on_every_event (bool, optional) – Whether to update plot every event, or just at the end.

  • **kwargs – As per mpl_plotting.py

event(doc: Event) None[source]

Process an event document (delegate to superclass, then show the plot).

start(doc: RunStart) None[source]

Process an start document (delegate to superclass, then show the plot).

stop(doc: RunStop) None[source]

Process an start document (delegate to superclass, then show the plot).

update_plot(force: bool = False) None[source]

Create error bars if needed, then update plot.

update_yerr(yerr: float | None) None[source]

Update uncertainties data.

ibex_bluesky_core.callbacks.show_plot() None[source]

Call plt.show().

Play nicely with the “normal” backends too - only force show if we’re actually using our custom backend.