ibex_bluesky_core.devices.simpledae

A simple interface to the DAE for bluesky.

Members

SimpleDae

Configurable DAE with pluggable strategies for data collection, waiting, and reduction.

check_dae_strategies

Check that the provided dae instance has appropriate controller/reducer/waiter configured.

monitor_normalising_dae

Create a simple DAE which normalises using a monitor and waits for frames.

class ibex_bluesky_core.devices.simpledae.Controller[source]

Bases: ProvidesExtraReadables

Controller specifies how DAE runs should be started & stopped.

async setup(dae: SimpleDae) None[source]

Pre-scan setup.

async start_counting(dae: SimpleDae) None[source]

Start counting for a single scan point.

async stop_counting(dae: SimpleDae) None[source]

Stop counting for a single scan point.

async teardown(dae: SimpleDae) None[source]

Post-scan teardown.

class ibex_bluesky_core.devices.simpledae.GoodFramesNormalizer(prefix: str, detector_spectra: ~collections.abc.Sequence[int], sum_detector: ~collections.abc.Callable[[~collections.abc.Collection[~ibex_bluesky_core.devices.dae._spectra.DaeSpectra]], ~collections.abc.Awaitable[~scipp._scipp.core.Variable | ~scipp._scipp.core.DataArray]] = <function sum_spectra>)[source]

Bases: ScalarNormalizer

Sum a set of user-specified spectra, then normalize by total good frames.

Init.

Parameters:
  • prefix – the PV prefix of the instrument to get spectra from (e.g. IN:DEMO:)

  • detector_spectra – a sequence of spectra numbers (detectors) to sum.

  • sum_detector – takes spectra objects, reads from them, and returns a scipp scalar describing the detector intensity. Defaults to summing over the entire spectrum.

denominator(dae: SimpleDae) SignalR[int][source]

Get normalization denominator (total good frames).

class ibex_bluesky_core.devices.simpledae.GoodFramesWaiter(value: T)[source]

Bases: SimpleWaiter[int]

Wait for good frames to reach a user-specified value.

Wait for a value to be at least equal to the specified value.

Parameters:

value – the value to wait for

get_signal(dae: SimpleDae) SignalR[int][source]

Wait for good frames.

class ibex_bluesky_core.devices.simpledae.GoodUahWaiter(value: T)[source]

Bases: SimpleWaiter[float]

Wait for good microamp-hours to reach a user-specified value.

Wait for a value to be at least equal to the specified value.

Parameters:

value – the value to wait for

get_signal(dae: SimpleDae) SignalR[float][source]

Wait for good uah.

class ibex_bluesky_core.devices.simpledae.MEventsWaiter(value: T)[source]

Bases: SimpleWaiter[float]

Wait for a user-specified number of millions of events.

Wait for a value to be at least equal to the specified value.

Parameters:

value – the value to wait for

get_signal(dae: SimpleDae) SignalR[float][source]

Wait for mevents.

class ibex_bluesky_core.devices.simpledae.MonitorNormalizer(prefix: str, detector_spectra: ~collections.abc.Sequence[int], monitor_spectra: ~collections.abc.Sequence[int], sum_detector: ~collections.abc.Callable[[~collections.abc.Collection[~ibex_bluesky_core.devices.dae._spectra.DaeSpectra]], ~collections.abc.Awaitable[~scipp._scipp.core.Variable | ~scipp._scipp.core.DataArray]] = <function sum_spectra>, sum_monitor: ~collections.abc.Callable[[~collections.abc.Collection[~ibex_bluesky_core.devices.dae._spectra.DaeSpectra]], ~collections.abc.Awaitable[~scipp._scipp.core.Variable | ~scipp._scipp.core.DataArray]] = <function sum_spectra>)[source]

Bases: Reducer, StandardReadable

Normalize a set of user-specified detector spectra by user-specified monitor spectra.

Init.

Parameters:
  • prefix – the PV prefix of the instrument to get spectra from (e.g. IN:DEMO:)

  • detector_spectra – a sequence of spectra numbers (detectors) to sum.

  • monitor_spectra – a sequence of spectra number (monitors) to sum and normalize by.

  • sum_detector – takes spectra objects, reads from them, and returns a scipp scalar describing the detector intensity. Defaults to summing over the entire spectrum.

  • sum_monitor – takes spectra objects, reads from them, and returns a scipp scalar describing the monitor intensity. Defaults to summing over the entire spectrum.

Scipp scalars are described in further detail here: https://scipp.github.io/generated/functions/scipp.scalar.html

additional_readable_signals(dae: SimpleDae) list[Device][source]

Publish interesting signals derived or used by this reducer.

async reduce_data(dae: SimpleDae) None[source]

Apply the normalization.

class ibex_bluesky_core.devices.simpledae.PeriodGoodFramesNormalizer(prefix: str, detector_spectra: ~collections.abc.Sequence[int], sum_detector: ~collections.abc.Callable[[~collections.abc.Collection[~ibex_bluesky_core.devices.dae._spectra.DaeSpectra]], ~collections.abc.Awaitable[~scipp._scipp.core.Variable | ~scipp._scipp.core.DataArray]] = <function sum_spectra>)[source]

Bases: ScalarNormalizer

Sum a set of user-specified spectra, then normalize by period good frames.

Init.

Parameters:
  • prefix – the PV prefix of the instrument to get spectra from (e.g. IN:DEMO:)

  • detector_spectra – a sequence of spectra numbers (detectors) to sum.

  • sum_detector – takes spectra objects, reads from them, and returns a scipp scalar describing the detector intensity. Defaults to summing over the entire spectrum.

denominator(dae: SimpleDae) SignalR[int][source]

Get normalization denominator (period good frames).

class ibex_bluesky_core.devices.simpledae.PeriodGoodFramesWaiter(value: T)[source]

Bases: SimpleWaiter[int]

Wait for period good frames to reach a user-specified value.

Wait for a value to be at least equal to the specified value.

Parameters:

value – the value to wait for

get_signal(dae: SimpleDae) SignalR[int][source]

Wait for period good frames.

class ibex_bluesky_core.devices.simpledae.PeriodPerPointController(save_run: bool)[source]

Bases: Controller

Controller for a SimpleDae which counts using a period per point.

A single run is opened during stage(), and then each new point will count into a new DAE period (starting from 1). The run will be either ended or aborted in unstage, depending on the value of the save_run parameter.

Period-per-point DAE controller.

Parameters:

save_run – True to terminate runs using end(), saving the data. False to terminate runs using abort(), discarding the data.

additional_readable_signals(dae: SimpleDae) list[Device][source]

period_num is always an interesting signal if using this controller.

async setup(dae: SimpleDae) None[source]

Pre-scan setup (begin a new run in paused mode).

async start_counting(dae: SimpleDae) None[source]

Start counting a scan point.

Increments the period by 1, then unpauses the run.

async stop_counting(dae: SimpleDae) None[source]

Stop counting a scan point, by pausing the run.

async teardown(dae: SimpleDae) None[source]

Finish taking data, ending or aborting the run.

class ibex_bluesky_core.devices.simpledae.PeriodSpecIntegralsReducer(*, monitors: ndarray[tuple[int, ...], dtype[int64]], detectors: ndarray[tuple[int, ...], dtype[int64]])[source]

Bases: Reducer, StandardReadable

A DAE Reducer which simultaneously exposes integrals of many spectra in the current period.

Two types of integrals are available: detectors and monitors. Other than defaults, their behaviour is identical. No normalization is performed in this reducer - exactly how the detector and monitor integrals are used is defined downstream.

By itself, the data from this reducer is not suitable for use in a scan - but it provides raw data which may be useful for further processing as part of callbacks (e.g. LiveDispatchers).

Init.

Parameters:
  • monitors – an array representing the mapping of monitors to acquire integrals from. For example, passing np.array([1]) selects spectrum 1.

  • detectors – an array representing the mapping of detectors to acquire integrals from. For example, passing np.array([5, 6, 7, 8]) would select detector spectra 5-8 inclusive, and so the output of this reducer would be an array of dimension 4.

additional_readable_signals(dae: SimpleDae) list[Device][source]

Publish interesting signals derived or used by this reducer.

property detectors: ndarray[tuple[int, ...], dtype[int64]]

Get the detectors used by this reducer.

property monitors: ndarray[tuple[int, ...], dtype[int64]]

Get the monitors used by this reducer.

async reduce_data(dae: SimpleDae) None[source]

Expose detector & monitor integrals.

After this method returns, it is valid to read from det_integrals and mon_integrals.

Note

Could use SPECINTEGRALS PV here, which seems more efficient initially, but it gets bounded by some areadetector settings under-the-hood which may be a bit surprising on some instruments.

We can’t just change these settings in this reducer, as they only apply to new events that come in.

class ibex_bluesky_core.devices.simpledae.ProvidesExtraReadables[source]

Bases: object

Strategies may specify interesting DAE signals using this method.

Those signals will then be added to read() and describe() on the top-level SimpleDae object.

additional_readable_signals(dae: SimpleDae) list[Device][source]

Define signals that this strategy considers important.

These will be added to the dae’s default-read signals and made available by read() on the DAE object.

class ibex_bluesky_core.devices.simpledae.Reducer[source]

Bases: ProvidesExtraReadables

Reducer specifies any post-processing which needs to be done after a scan point completes.

async reduce_data(dae: SimpleDae) None[source]

Triggers a reduction of DAE data after a scan point has been measured.

Data that should be published by this reducer should be added as soft signals, in a class which both implements this protocol and derives from StandardReadable.

class ibex_bluesky_core.devices.simpledae.RunPerPointController(save_run: bool)[source]

Bases: Controller, StandardReadable

Controller for a SimpleDae which counts using a DAE run per point.

The runs can be either ended or aborted once counting is finished.

Init.

Parameters:

save_run – whether to end the run (True) or abort the run (False) on completion.

additional_readable_signals(dae: SimpleDae) list[Device][source]

Run number is an interesting signal only if saving runs.

async start_counting(dae: SimpleDae) None[source]

Start counting a scan point, by starting a DAE run.

async stop_counting(dae: SimpleDae) None[source]

Stop counting a scan point, by ending or aborting the run.

class ibex_bluesky_core.devices.simpledae.ScalarNormalizer(prefix: str, detector_spectra: ~collections.abc.Sequence[int], sum_detector: ~collections.abc.Callable[[~collections.abc.Collection[~ibex_bluesky_core.devices.dae._spectra.DaeSpectra]], ~collections.abc.Awaitable[~scipp._scipp.core.Variable | ~scipp._scipp.core.DataArray]] = <function sum_spectra>)[source]

Bases: Reducer, StandardReadable, ABC

Sum a set of user-specified spectra, then normalize by a scalar signal.

Init.

Parameters:
  • prefix – the PV prefix of the instrument to get spectra from (e.g. IN:DEMO:)

  • detector_spectra – a sequence of spectra numbers (detectors) to sum.

  • sum_detector – takes spectra objects, reads from them, and returns a scipp scalar describing the detector intensity. Defaults to summing over the entire spectrum.

additional_readable_signals(dae: SimpleDae) list[Device][source]

Publish interesting signals derived or used by this reducer.

abstractmethod denominator(dae: SimpleDae) SignalR[int] | SignalR[float][source]

Get the normalization denominator, which is assumed to be a scalar signal.

async reduce_data(dae: SimpleDae) None[source]

Apply the normalization.

class ibex_bluesky_core.devices.simpledae.SimpleDae(*, prefix: str, name: str = 'DAE', controller: TController_co, waiter: TWaiter_co, reducer: TReducer_co)[source]

Bases: Dae, Triggerable, AsyncStageable, Generic[TController_co, TWaiter_co, TReducer_co]

Configurable DAE with pluggable strategies for data collection, waiting, and reduction.

This class should cover many simple DAE use-cases, but for complex use-cases a custom Dae subclass may still be required to give maximum flexibility.

Initialize a simple DAE interface.

Parameters:
  • prefix – the PV prefix of the instrument being controlled.

  • name – A friendly name for this DAE object.

  • controller – A DAE control strategy, defines how the DAE begins and ends data acquisition Pre-defined strategies in the ibex_bluesky_core.devices.controllers module

  • waiter – A waiting strategy, defines how the DAE waits for an acquisition to be complete Pre-defined strategies in the ibex_bluesky_core.devices.waiters module

  • reducer – A data reduction strategy, defines the post-processing on raw DAE data, for example normalization or unit conversion. Pre-defined strategies in the ibex_bluesky_core.devices.reducers module

stage() None[source]

Pre-scan setup. Delegate to the controller.

trigger() None[source]

Take a single measurement and prepare it for subsequent reading.

This waits for the acquisition and any defined reduction to be complete, such that after this coroutine completes all relevant data is available via read()

unstage() None[source]

Post-scan teardown, delegate to the controller.

class ibex_bluesky_core.devices.simpledae.SimpleWaiter(value: T)[source]

Bases: Waiter, Generic[T], ABC

Wait for a single DAE variable to be greater or equal to a specified numeric value.

Wait for a value to be at least equal to the specified value.

Parameters:

value – the value to wait for

additional_readable_signals(dae: SimpleDae) list[Device][source]

Publish the signal we’re waiting on as an interesting signal.

abstractmethod get_signal(dae: SimpleDae) SignalR[T][source]

Get the numeric signal to wait for.

async wait(dae: SimpleDae) None[source]

Wait for signal to reach the user-specified value.

class ibex_bluesky_core.devices.simpledae.TimeWaiter(*, seconds: float)[source]

Bases: Waiter

Wait for a user-specified time duration.

Init.

Parameters:

seconds – number of seconds to wait for.

async wait(dae: SimpleDae) None[source]

Wait for the specified time duration.

class ibex_bluesky_core.devices.simpledae.Waiter[source]

Bases: ProvidesExtraReadables

Waiter specifies how the dae will wait for a scan point to complete counting.

async wait(dae: SimpleDae) None[source]

Wait for the acquisition to complete.

ibex_bluesky_core.devices.simpledae.check_dae_strategies(dae: SimpleDae, *, expected_controller: type[Controller] | None = None, expected_waiter: type[Waiter] | None = None, expected_reducer: type[Reducer] | None = None) None[source]

Check that the provided dae instance has appropriate controller/reducer/waiter configured.

Parameters:
  • dae – The simpledae instance to check.

  • expected_controller – The expected controller type, on None to not check.

  • expected_waiter – The expected controller type, on None to not check.

  • expected_reducer – The expected controller type, on None to not check.

ibex_bluesky_core.devices.simpledae.monitor_normalising_dae(*, det_pixels: list[int], frames: int, periods: bool = True, monitor: int = 1, save_run: bool = False) SimpleDae[source]

Create a simple DAE which normalises using a monitor and waits for frames.

This is really a shortcut to reduce code in plans used on the majority of instruments that normalise using a monitor, wait for a number of frames and optionally use software periods.

Parameters:
  • det_pixels – list of detector pixel to use for scanning.

  • frames – number of frames to wait for.

  • periods – whether or not to use software periods.

  • monitor – the monitor spectra number.

  • save_run – whether or not to save the run of the DAE.

ibex_bluesky_core.devices.simpledae.tof_bounded_spectra(bounds: Variable) Callable[[Collection[DaeSpectra]], Awaitable[Variable | DataArray]][source]

Sum a set of neutron spectra between the specified time of flight bounds.

Parameters:

bounds – A scipp array of size 2, no variances, unit of us, where the second element must be larger than the first.

Returns a scipp scalar, which has .value and .variance properties for accessing the sum and variance respectively of the summed counts.

More info on scipp arrays and scalars can be found here: https://scipp.github.io/generated/functions/scipp.scalar.html

ibex_bluesky_core.devices.simpledae.wavelength_bounded_spectra(bounds: Variable, total_flight_path_length: Variable) Callable[[Collection[DaeSpectra]], Awaitable[Variable | DataArray]][source]

Sum a set of neutron spectra between the specified wavelength bounds.

Parameters:
  • bounds – A scipp array of size 2 of wavelength bounds, in units of angstrom, where the second element must be larger than the first.

  • total_flight_path_length – A scipp scalar of Ltotal (total flight path length), the path length from neutron source to detector or monitor, in units of meters.

Time of flight is converted to wavelength using scipp neutron’s library function

wavelength_from_tof, more info on which can be found here: https://scipp.github.io/scippneutron/generated/modules/scippneutron.conversion.tof.wavelength_from_tof.html

Returns a scipp scalar, which has .value and .variance properties for accessing the sum and variance respectively of the summed counts.