Skip to content

Commit 20b553a

Browse files
authored
fix: replace mask function by limits (#204)
1 parent bc0623f commit 20b553a

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/ess/beer/io.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Filename,
1111
ModulationPeriod,
1212
SampleRun,
13-
TwoThetaMaskFunction,
13+
TwoThetaLimits,
1414
WavelengthDefinitionChopperDelay,
1515
)
1616

@@ -122,19 +122,27 @@ def load_beer_mcstas(f: str | Path | h5py.File) -> sc.DataGroup:
122122
)
123123

124124

125+
def _not_between(x, a, b):
126+
return (x < a) | (b < x)
127+
128+
125129
def load_beer_mcstas_provider(
126-
fname: Filename[SampleRun], two_theta_mask: TwoThetaMaskFunction
130+
fname: Filename[SampleRun], two_theta_limits: TwoThetaLimits
127131
) -> DetectorData[SampleRun]:
128132
da = load_beer_mcstas(fname)
129133
da = (
130134
sc.DataGroup(
131135
{
132-
k: v.assign_masks(two_theta=two_theta_mask(v.coords['two_theta']))
136+
k: v.assign_masks(
137+
two_theta=_not_between(v.coords['two_theta'], *two_theta_limits)
138+
)
133139
for k, v in da.items()
134140
}
135141
)
136142
if isinstance(da, sc.DataGroup)
137-
else da.assign_masks(two_theta=two_theta_mask(da.coords['two_theta']))
143+
else da.assign_masks(
144+
two_theta=_not_between(da.coords['two_theta'], *two_theta_limits)
145+
)
138146
)
139147
return DetectorData[SampleRun](da)
140148

src/ess/beer/types.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections.abc import Callable
21
from typing import NewType
32

43
import sciline
@@ -18,9 +17,7 @@ class StreakClusteredData(sciline.Scope[RunType, sc.DataArray], sc.DataArray):
1817
DetectorTofData = DetectorTofData
1918

2019

21-
TwoThetaMaskFunction = NewType(
22-
'TwoThetaMaskFunction', Callable[[sc.Variable], sc.Variable]
23-
)
20+
TwoThetaLimits = NewType('TwoThetaLimits', tuple[sc.Variable, sc.Variable])
2421

2522
TofCoordTransformGraph = NewType("TofCoordTransformGraph", dict)
2623

src/ess/beer/workflow.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
PulseLength,
1212
RunType,
1313
SampleRun,
14-
TwoThetaMaskFunction,
14+
TwoThetaLimits,
1515
)
1616

1717
default_parameters = {
1818
PulseLength: sc.scalar(0.003, unit='s'),
19-
TwoThetaMaskFunction: lambda two_theta: (
20-
(two_theta >= sc.scalar(105, unit='deg').to(unit='rad', dtype='float64'))
21-
| (two_theta <= sc.scalar(75, unit='deg').to(unit='rad', dtype='float64'))
19+
TwoThetaLimits: (
20+
sc.scalar(75, unit='deg').to(unit='rad', dtype='float64'),
21+
sc.scalar(105, unit='deg').to(unit='rad', dtype='float64'),
2222
),
2323
}
2424

0 commit comments

Comments
 (0)