Skip to content

Commit 94a9f99

Browse files
committed
doc
1 parent 781456f commit 94a9f99

File tree

2 files changed

+49
-31
lines changed

2 files changed

+49
-31
lines changed

doc/devices/dae.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -285,42 +285,43 @@ as a list, and `units` (μs/microseconds for time of flight bounding, and angstr
285285

286286
If you don't specify either of these options, they will default to summing over the entire spectrum.
287287

288-
### Polarisation/Asymmetry
288+
{#polarisationasymmetry}
289+
### Polarisation & Asymmetry
289290

290-
ibex_bluesky_core provides a helper method,
291-
{py:obj}`ibex_bluesky_core.utils.calculate_polarisation`, for calculating the quantity (a-b)/(a+b). This quantity is used, for example, in neutron polarisation measurements, and in calculating asymmetry for muon measurements.
291+
A helper method, {py:obj}`calculate_polarisation <ibex_bluesky_core.utils.calculate_polarisation>`, is provided
292+
for calculating the quantity {math}`\frac{a-\alpha b}{a+\alpha b}`, where {math}`\alpha` is a scalar constant which is
293+
assumed not to have a variance.
294+
This quantity is used, for example, in neutron polarisation measurements, and in calculating asymmetry for muon measurements.
292295

293-
For this expression, scipp's default uncertainty propagation rules cannot be used as the uncertainties on (a-b) are correlated with those of (a+b) in the division step - but scipp assumes uncorrelated data. This helper method calculates the uncertainties following linear error propagation theory, using the partial derivatives of the above expression.
296+
For this expression, scipp's default uncertainty propagation rules cannot be used as the uncertainties on
297+
{math}`(a-\alpha b)` are correlated with those of {math}`(a+\alpha b)` in the division step - but
298+
{external+scipp:doc}`scipp's uncertainty propagation mechanism <reference/error-propagation>` assumes
299+
uncorrelated data. This helper method calculates
300+
the uncertainties following linear error propagation theory, using the partial derivatives of the above expression:
294301

295-
The partial derivatives are:
302+
```{math}
303+
\frac{\delta}{\delta a}(\frac{a - \alpha b}{a + \alpha b}) = \frac{2b\alpha}{(a+b\alpha)^2}
296304
297-
$ \frac{\delta}{\delta a}\Big(\frac{a - b}{a + b}) = \frac{2b}{(a+b)^2} $
305+
\frac{\delta}{\delta b}(\frac{a - \alpha b}{a + \alpha b}) = -\frac{2a\alpha}{(a+b\alpha)^2}
298306
299-
$ \frac{\delta}{\delta b}\Big(\frac{a - b}{a + b}) = -\frac{2a}{(a+b)^2} $
300-
301-
302-
Which then means the variances computed by this helper function are:
303-
304-
$ Variance = (\frac{\delta}{\delta a}^2 * variance_a) + (\frac{\delta}{\delta b}^2 * variance_b) $
305-
306-
307-
The polarisation function provided will calculate the polarisation between two values, A and B, which
308-
have different definitions based on the instrument context.
307+
\sigma^2_f = (\frac{\delta f}{\delta a})^2 \sigma^2_a + (\frac{\delta f}{\delta b})^2 \sigma^2_b
308+
```
309309

310-
Instrument-Specific Interpretations
311-
SANS Instruments (e.g., LARMOR)
312-
A: Intensity in DAE period before switching a flipper.
313-
B: Intensity in DAE period after switching a flipper.
310+
The polarisation function provided will calculate the polarisation between two values, {math}`a` and {math}`b`, which
311+
have different interpretations based on the instrument context:
314312

315-
Reflectometry Instruments (e.g., POLREF)
316-
Similar to LARMOR, A and B represent intensities before and after flipper switching.
313+
**SANS Instruments (e.g., LARMOR) & Reflectometry Instruments (e.g. POLREF)**
317314

318-
Muon Instruments
319-
A and B refer to Measurements from different detector banks.
315+
{math}`a` & {math}`b` represent intensity (detector counts over monitor counts) before and after switching a
316+
spin-flipper device. This is implemented by
317+
{py:obj}`PolarisationReducer <ibex_bluesky_core.devices.polarisingdae.PolarisationReducer>`.
318+
For this use case, {math}`\alpha` is always equal to {math}`1`.
320319

321-
{py:obj}`ibex_bluesky_core.utils.calculate_polarisation`
320+
**Muon Instruments**
322321

323-
See [`PolarisationReducer`](#PolarisationReducer) for how this is integrated into DAE behaviour.
322+
A and B refer to Measurements from different detector banks. Muon instruments use the additional {math}`\alpha`
323+
term, which might not be equal to {math}`1`. A reducer which exposes muon spin asymmetry as a measured quantity
324+
is implemented by the {py:obj}`MuonAsymmetryReducer <ibex_bluesky_core.devices.muon.MuonAsymmetryReducer>` class.
324325

325326
## Waiters
326327

src/ibex_bluesky_core/devices/muon.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323

2424
logger = logging.getLogger(__name__)
2525

26+
__all__ = [
27+
"MuonAsymmetryReducer",
28+
"damped_oscillator",
29+
"double_damped_oscillator",
30+
]
31+
2632

2733
def damped_oscillator(
2834
t: NDArray[np.floating],
@@ -31,8 +37,13 @@ def damped_oscillator(
3137
omega_0: float,
3238
phi_0: float,
3339
lambda_0: float,
34-
) -> NDArray[np.float64]:
35-
r"""Equation for a damped oscillations with an offset (B)."""
40+
) -> NDArray[np.floating]:
41+
r"""Equation for a damped oscillator with an offset, as a function of time :math:`t`.
42+
43+
.. math::
44+
45+
B + A_0 \cos(\omega_0 t + \phi_0) e^{-\lambda_0 t}
46+
"""
3647
return B + A_0 * np.cos(omega_0 * t + phi_0) * np.exp(-t * lambda_0)
3748

3849

@@ -47,8 +58,14 @@ def double_damped_oscillator( # noqa: PLR0913 PLR0917 (model is just this compl
4758
omega_1: float,
4859
phi_1: float,
4960
lambda_1: float,
50-
) -> NDArray[np.float64]:
51-
r"""Equation for multiple component damped oscillations with an offset (B)."""
61+
) -> NDArray[np.floating]:
62+
r"""Equation for two damped oscillators with an offset, as a function of time :math:`t`.
63+
64+
.. math::
65+
66+
B + A_0 \cos(\omega_0 t + \phi_0) e^{-\lambda_0 t}
67+
+ A_1 \cos(\omega_1 t + \phi_1) e^{-\lambda_1 t}
68+
"""
5269
return (
5370
B
5471
+ A_0 * np.cos(omega_0 * t + phi_0) * np.exp(-t * lambda_0)
@@ -57,7 +74,7 @@ def double_damped_oscillator( # noqa: PLR0913 PLR0917 (model is just this compl
5774

5875

5976
class MuonAsymmetryReducer(Reducer, StandardReadable):
60-
r"""DAE reducer which exposes a computed asymmetry quantity.
77+
r"""DAE reducer which exposes a fitted asymmetry quantity.
6178
6279
This reducer takes two lists of detectors; a forward scattering set of detectors,
6380
:math:`F`, and a backward scattering set, :math:`B`.

0 commit comments

Comments
 (0)