ibex_bluesky_core.utils
Utilities for plans which are not plan stubs.
Members
Abstract class for type checking that an object is readable, named and movable. |
|
Calculate polarisation or asymmetry, propagating uncertainties. |
|
Compute the centre of mass of the area under a curve defined by a series of (x, y) points. |
|
Given a centre and range, return a contiguous range of pixels around the centre, inclusive. |
|
Return the PV prefix for the current instrument. |
|
Return True if matplotlib is using a qt backend. |
- class ibex_bluesky_core.utils.NamedReadableAndMovable(*args, **kwargs)[source]
Bases:
Readable
[Any
],NamedMovable
[Any
],Protocol
Abstract class for type checking that an object is readable, named and movable.
- ibex_bluesky_core.utils.calculate_polarisation(a: T, b: T, alpha: float = 1.0) T [source]
Calculate polarisation or asymmetry, propagating uncertainties.
The value returned by this function is:
\[f(a, b, \alpha) = \frac{a - \alpha b}{a + \alpha b}\]Where \(a\) and \(b\) are the two input scipp
variables
, which may have corresponding variances, and \(\alpha\) is an optional scalar (float). If \(\alpha\) is not provided, it defaults to 1.The variances are propagated using the partial derivatives of \(f\) with respect to \(a\) and \(b\):
\[ \begin{align}\begin{aligned}\frac{\partial f}{\partial a} = \frac{2 b \alpha}{(a + b \alpha)^2}\\\frac{\partial f}{\partial b} = \frac{-2 a \alpha}{(a + b \alpha)^2}\\\sigma_f^2 = (\frac{\partial f}{\partial a})^2 \sigma_a^2 + (\frac{\partial f}{\partial b})^2 \sigma_b^2\end{aligned}\end{align} \]Note
\(\alpha\) is a scalar constant and is assumed not to have a variance.
On SANS instruments (e.g. LARMOR) and reflectometry instruments (e.g. POLREF), \(a\) and \(b\) correspond to intensity in different DAE periods (before/after switching a flipper) and the output is interpreted as a neutron polarisation ratio. \(\alpha\) is fixed at 1.
On muon instruments, \(a\) and \(b\) correspond to measuring from forward/backward detector banks, and the output is interpreted as a muon asymmetry. \(\alpha\) will not necessarily be 1.
- ibex_bluesky_core.utils.center_of_mass_of_area_under_curve(x: ndarray[tuple[Any, ...], dtype[float64]], y: ndarray[tuple[Any, ...], dtype[float64]]) tuple[float, float] [source]
Compute the centre of mass of the area under a curve defined by a series of (x, y) points.
The “area under the curve” is a shape bounded by: - min(y), along the bottom edge - min(x), on the left-hand edge - max(x), on the right-hand edge - straight lines joining (x, y) data points to their nearest neighbours along the x-axis, along the top edge
This is implemented by geometric decomposition of the shape into a series of trapezoids, which are further decomposed into rectangular and triangular regions.
Returns a tuple of the centre of mass and the total area under the curve.
- ibex_bluesky_core.utils.centred_pixel(centre: int, pixel_range: int) list[int] [source]
Given a centre and range, return a contiguous range of pixels around the centre, inclusive.
ie. a centre of 50 with a range of 3 will give [47, 48, 49, 50, 51, 52, 53]
- Parameters:
Returns a list of pixel numbers.