Skip to content

Commit e72fa06

Browse files
committed
rename alpha with more meaningful name
1 parent fef3a51 commit e72fa06

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

docs/utilities/utilities.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ Modules
1010

1111
logging
1212
nexus
13+
uncertainty

src/ess/sans/i_of_q.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def to_I_of_Q(data: sc.DataArray,
225225
gravity: bool = False,
226226
wavelength_mask: Optional[sc.DataArray] = None,
227227
wavelength_bands: Optional[sc.Variable] = None,
228-
alpha_threshold: float = 0.1) -> sc.DataArray:
228+
signal_over_monitor_threshold: float = 0.1) -> sc.DataArray:
229229
"""
230230
Compute the scattering cross-section I(Q) for a SANS experimental run, performing
231231
binning in Q and a normalization based on monitor data and a direct beam function.
@@ -271,7 +271,7 @@ def to_I_of_Q(data: sc.DataArray,
271271
If defined, return the data as a set of bands in the wavelength dimension. This
272272
is useful for separating different wavelength ranges that contribute to
273273
different regions in Q space.
274-
alpha_threshold:
274+
signal_over_monitor_threshold:
275275
The threshold for the ratio of detector counts to monitor counts above which
276276
an error is raised because it is not safe to drop the variances of the monitor.
277277
@@ -311,7 +311,7 @@ def to_I_of_Q(data: sc.DataArray,
311311
direct_incident_monitor=direct_monitors['incident'],
312312
direct_transmission_monitor=direct_monitors['transmission'],
313313
direct_beam=direct_beam,
314-
alpha_threshold=alpha_threshold)
314+
signal_over_monitor_threshold=signal_over_monitor_threshold)
315315

316316
# Insert a copy of coords needed for conversion to Q.
317317
# TODO: can this be avoided by copying the Q coords from the converted numerator?

src/ess/sans/normalization.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import scippneutron as scn
88

99
from ..logging import get_logger
10-
from ..uncertainty import alpha_ratio
10+
from ..uncertainty import variance_normalized_signal_over_monitor
1111

1212

1313
def solid_angle_of_rectangular_pixels(data: sc.DataArray, pixel_width: sc.Variable,
@@ -80,32 +80,33 @@ def transmission_fraction(data_monitors: Dict[str, sc.DataArray],
8080

8181
def _verify_normalization_alpha(numerator: sc.DataArray,
8282
denominator: sc.DataArray,
83-
alpha_threshold: float = 0.1):
83+
signal_over_monitor_threshold: float = 0.1):
8484
"""
8585
Verify that the ratio of sample detector counts to monitor counts is small, so
8686
we can safely drop the variances of the monitor to avoid broadcasting issues.
8787
See Heybrock et al. (2023).
8888
"""
89-
alpha = alpha_ratio(numerator, denominator)
90-
if alpha > 0.25 * alpha_threshold:
89+
alpha = variance_normalized_signal_over_monitor(numerator, denominator)
90+
if alpha > 0.25 * signal_over_monitor_threshold:
9191
logger = get_logger('sans')
9292
logger.warning(
93-
f'alpha = {alpha} is close to the specified threshold of '
94-
f'{alpha_threshold}. This means we are close to the regime where it is no '
95-
'longer safe to drop the variances of the normalization term.')
96-
if alpha > alpha_threshold:
93+
f'signal_over_monitor = {alpha} is close to the specified threshold of '
94+
f'{signal_over_monitor_threshold}. This means we are close to the regime '
95+
'where it is no longer safe to drop the variances of the normalization '
96+
'term.')
97+
if alpha > signal_over_monitor_threshold:
9798
raise ValueError(
98-
f'alpha = {alpha} > {alpha_threshold}! This means that the ratio of '
99-
'detector counts to monitor counts is too high, and the variances of the '
100-
'monitor data cannot be safely dropped.')
99+
f'signal_over_monitor = {alpha} > {signal_over_monitor_threshold}! '
100+
'This means that the ratio of detector counts to monitor counts is too '
101+
'high, and the variances of the monitor data cannot be safely dropped.')
101102

102103

103104
def iofq_denominator(data: sc.DataArray,
104105
data_transmission_monitor: sc.DataArray,
105106
direct_incident_monitor: sc.DataArray,
106107
direct_transmission_monitor: sc.DataArray,
107108
direct_beam: Optional[sc.DataArray] = None,
108-
alpha_threshold: float = 0.1) -> sc.DataArray:
109+
signal_over_monitor_threshold: float = 0.1) -> sc.DataArray:
109110
"""
110111
Compute the denominator term for the I(Q) normalization. This is basically:
111112
``solid_angle * direct_beam * data_transmission_monitor * direct_incident_monitor / direct_transmission_monitor``
@@ -131,7 +132,7 @@ def iofq_denominator(data: sc.DataArray,
131132
The transmission monitor counts from the direct run (depends on wavelength).
132133
direct_beam:
133134
The DataArray containing the direct beam function (depends on wavelength).
134-
alpha_threshold:
135+
signal_over_monitor_threshold:
135136
The threshold for the ratio of detector counts to monitor counts above which
136137
an error is raised because it is not safe to drop the variances of the monitor.
137138
@@ -153,7 +154,7 @@ def iofq_denominator(data: sc.DataArray,
153154
_verify_normalization_alpha(
154155
numerator=data.hist(wavelength=denominator.coords['wavelength']),
155156
denominator=denominator,
156-
alpha_threshold=alpha_threshold)
157+
signal_over_monitor_threshold=signal_over_monitor_threshold)
157158

158159
solid_angle = solid_angle_of_rectangular_pixels(
159160
data,

src/ess/uncertainty.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
T = TypeVar("T", bound=Union[sc.Variable, sc.DataArray])
1010

1111

12-
def alpha_ratio(numerator: T, denominator: T) -> float:
12+
def variance_normalized_signal_over_monitor(numerator: T, denominator: T) -> float:
1313
"""
14+
Calculates the ratio of detector variance-normalized counts over monitor
15+
variance-normalized counts:
16+
1417
.. math::
1518
\\alpha = \\frac{\\sum_{i} \\text{var}_{i}(b) a_{i}^{2}}{\\text{var}_{i}(a) b_{i}^{2}}
1619
1720
where :math:`a` is the numerator and :math:`b` the denominator.
21+
See Heybrock et al. (2023) for more details.
1822
1923
Parameters
2024
----------

0 commit comments

Comments
 (0)