ibex_bluesky_core.callbacks
Bluesky callbacks which may be attached to the RunEngine.
Submodules
Reflectometry-specific callbacks. |
Members
ISIS standard callbacks for use within plans. |
- class ibex_bluesky_core.callbacks.ChainedLiveFit(method: FitMethod, y: list[str], x: str, *, yerr: list[str] | None = None, ax: list[Axes] | None = None)[source]
Bases:
CallbackBase
Processes multiple LiveFits, each fit’s results inform the next, with optional plotting.
This callback handles a sequence of LiveFit instances where the parameters from each completed fit serve as the initial guess for the subsequent fit. Optional plotting is built in using LivePlotFits. Note that you should not subscribe to the LiveFit/LiveFitPlot callbacks directly, but rather subscribe just this callback.
Initialise ChainedLiveFit with multiple LiveFits.
- Parameters:
method – FitMethod instance for fitting
y – List of y-axis variable names
x – x-axis variable name
yerr – Optional list of error values corresponding to y variables
ax – A list of axes to plot fits on to. Creates LiveFitPlot instances.
- descriptor(doc: EventDescriptor) None [source]
Process descriptor document for all callbacks.
- Parameters:
doc – EventDescriptor document.
- event(doc: Event) Event [source]
Process event document for all callbacks.
- Parameters:
doc – Event document
- property live_fit_plots: list[LiveFitPlot]
Return a list of the livefitplots.
- 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.
- 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 = '', save_plot_to_png: bool = True, plot_png_output_dir: str | PathLike[str] | None = None, plot_png_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.
save_plot_to_png – whether to save the plot to a PNG file.
plot_png_output_dir – the output directory for plotting PNG files.
plot_png_postfix – the postfix to add to PNG plot files.
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.
- 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.
- 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.
- class ibex_bluesky_core.callbacks.LivePColorMesh(*, y: str, x: str, x_coord: ndarray[tuple[Any, ...], dtype[float64]], ax: Axes, x_name: str | None = None, **kwargs: Any)[source]
Bases:
QtAwareCallback
Live
PColorMesh
-based heatmap.Create a new heatmap.
- Parameters:
y – the name of the signal appearing along the y-axis.
x – the name of the signal appearing along the x-axis. This signal is expected to be an array, representing rows of the heatmap.
x_coord – coordinates along the x-axis. This is expected to have the same length as each row of the heatmap.
ax – a set of matplotlib axes on which to plot.
x_name – A display name for the x-axis. Defaults to the same as
x
if not provided.**kwargs – Arbitrary keyword arguments are passed through to
matplotlib.pyplot.pcolormesh
- 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 a start document (delegate to superclass, then show the plot).
- class ibex_bluesky_core.callbacks.PlotPNGSaver(x: str, y: str, ax: Axes, postfix: str, output_dir: str | PathLike[str] | None)[source]
Bases:
QtAwareCallback
Save plots to PNG files on a run end.
Initialise the PlotPNGSaver callback.
- Parameters:
x – The name of the signal for x.
y – The name of the signal for y.
ax – The subplot to save to a file.
postfix – The file postfix.
output_dir – The output directory for PNGs.