Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/ess/beer/io.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for now. But we probably need to generalise and allow functions again in the future.
Note also the implementation in ESSimaging: https://scipp.github.io/essimaging/odin/odin-data-reduction.html#Select-region-of-interest-by-masking-outer-regions We should unify this in ESSreduce soon.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Filename,
ModulationPeriod,
SampleRun,
TwoThetaMaskFunction,
TwoThetaLimits,
WavelengthDefinitionChopperDelay,
)

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


def _not_between(x, a, b):
return (x < a) | (b < x)


def load_beer_mcstas_provider(
fname: Filename[SampleRun], two_theta_mask: TwoThetaMaskFunction
fname: Filename[SampleRun], two_theta_limits: TwoThetaLimits
) -> DetectorData[SampleRun]:
da = load_beer_mcstas(fname)
da = (
sc.DataGroup(
{
k: v.assign_masks(two_theta=two_theta_mask(v.coords['two_theta']))
k: v.assign_masks(
two_theta=_not_between(v.coords['two_theta'], *two_theta_limits)
)
for k, v in da.items()
}
)
if isinstance(da, sc.DataGroup)
else da.assign_masks(two_theta=two_theta_mask(da.coords['two_theta']))
else da.assign_masks(
two_theta=_not_between(da.coords['two_theta'], *two_theta_limits)
)
)
return DetectorData[SampleRun](da)

Expand Down
5 changes: 1 addition & 4 deletions src/ess/beer/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from collections.abc import Callable
from typing import NewType

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


TwoThetaMaskFunction = NewType(
'TwoThetaMaskFunction', Callable[[sc.Variable], sc.Variable]
)
TwoThetaLimits = NewType('TwoThetaLimits', tuple[sc.Variable, sc.Variable])

TofCoordTransformGraph = NewType("TofCoordTransformGraph", dict)

Expand Down
8 changes: 4 additions & 4 deletions src/ess/beer/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
PulseLength,
RunType,
SampleRun,
TwoThetaMaskFunction,
TwoThetaLimits,
)

default_parameters = {
PulseLength: sc.scalar(0.003, unit='s'),
TwoThetaMaskFunction: lambda two_theta: (
(two_theta >= sc.scalar(105, unit='deg').to(unit='rad', dtype='float64'))
| (two_theta <= sc.scalar(75, unit='deg').to(unit='rad', dtype='float64'))
TwoThetaLimits: (
sc.scalar(75, unit='deg').to(unit='rad', dtype='float64'),
sc.scalar(105, unit='deg').to(unit='rad', dtype='float64'),
),
}

Expand Down
Loading