Skip to content

Commit 8e7045e

Browse files
committed
Distinguish between raw and parsed choppers
1 parent 7b6d5d6 commit 8e7045e

File tree

5 files changed

+36
-19
lines changed

5 files changed

+36
-19
lines changed

src/ess/reduce/nexus/types.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import scipp as sc
99
import scippnexus as snx
1010
from scippneutron import metadata as scn_meta
11+
from scippneutron.chopper import DiskChopper
1112

1213
FilePath = NewType('FilePath', Path)
1314
"""Full path to a NeXus file on disk."""
@@ -293,8 +294,15 @@ def from_chain(
293294
return NeXusTransformation(value=transform)
294295

295296

296-
class Choppers(
297+
class RawChoppers(
297298
sciline.Scope[RunType, sc.DataGroup[sc.DataGroup[Any]]],
298299
sc.DataGroup[sc.DataGroup[Any]],
299300
):
300301
"""All choppers in a NeXus file."""
302+
303+
304+
class DiskChoppers(
305+
sciline.Scope[RunType, sc.DataGroup[DiskChopper]],
306+
sc.DataGroup[DiskChopper],
307+
):
308+
"""All disk choppers parsed from a NeXus file."""

src/ess/reduce/nexus/workflow.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
CalibratedBeamline,
2424
CalibratedDetector,
2525
CalibratedMonitor,
26-
Choppers,
2726
Component,
2827
DetectorBankSizes,
2928
DetectorData,
@@ -46,6 +45,7 @@
4645
NeXusTransformationChain,
4746
Position,
4847
PreopenNeXusFile,
48+
RawChoppers,
4949
RunType,
5050
SampleRun,
5151
TimeInterval,
@@ -513,9 +513,18 @@ def assemble_monitor_data(
513513

514514
def parse_disk_choppers(
515515
choppers: AllNeXusComponents[snx.NXdisk_chopper, RunType],
516-
) -> Choppers[RunType]:
517-
"""Convert the NeXus representation of a chopper to ours."""
518-
return Choppers[RunType](
516+
) -> RawChoppers[RunType]:
517+
"""Convert the NeXus representation of a chopper to ours.
518+
519+
Returns
520+
-------
521+
:
522+
A nested data group containing the loaded choppers.
523+
The elements may be time-dependent arrays that first need to be processed
524+
before they can be passed to other functions as
525+
:class:`ess.reduce.nexus.types.DiskChoppers`.
526+
"""
527+
return RawChoppers[RunType](
519528
choppers.apply(
520529
lambda chopper: extract_chopper_from_nexus(
521530
nexus.compute_component_position(chopper)

src/ess/reduce/time_of_flight/simulation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import scippnexus as snx
77
from scippneutron.chopper import DiskChopper
88

9-
from ..nexus.types import Choppers, Position, SampleRun
9+
from ..nexus.types import DiskChoppers, Position, SampleRun
1010
from .types import NumberOfSimulatedNeutrons, SimulationResults
1111

1212

@@ -87,7 +87,7 @@ def simulate_beamline(
8787

8888

8989
def simulate_chopper_cascade_using_tof(
90-
choppers: Choppers[SampleRun],
90+
choppers: DiskChoppers[SampleRun],
9191
neutrons: NumberOfSimulatedNeutrons,
9292
source_position: Position[snx.NXsource, SampleRun],
9393
) -> SimulationResults:

tests/nexus/workflow_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from ess.reduce.nexus.types import (
1313
BackgroundRun,
1414
Beamline,
15-
Choppers,
1615
DetectorData,
1716
EmptyBeamRun,
1817
Filename,
@@ -26,6 +25,7 @@
2625
NeXusName,
2726
NeXusTransformation,
2827
PreopenNeXusFile,
28+
RawChoppers,
2929
RunType,
3030
SampleRun,
3131
TimeInterval,
@@ -556,7 +556,7 @@ def test_generic_nexus_workflow(preopen: bool) -> None:
556556
def test_generic_nexus_workflow_load_choppers() -> None:
557557
wf = GenericNeXusWorkflow(run_types=[SampleRun], monitor_types=[])
558558
wf[Filename[SampleRun]] = data.bifrost_simulated_elastic()
559-
choppers = wf.compute(Choppers[SampleRun])
559+
choppers = wf.compute(RawChoppers[SampleRun])
560560

561561
assert choppers.keys() == {
562562
'005_PulseShapingChopper',
@@ -613,8 +613,8 @@ def test_generic_nexus_workflow_includes_only_given_run_and_monitor_types() -> N
613613
assert MonitorData[BackgroundRun, FrameMonitor0] not in graph
614614
assert MonitorData[BackgroundRun, FrameMonitor1] not in graph
615615
assert MonitorData[BackgroundRun, FrameMonitor2] not in graph
616-
assert Choppers[SampleRun] in graph
617-
assert Choppers[BackgroundRun] not in graph
616+
assert RawChoppers[SampleRun] in graph
617+
assert RawChoppers[BackgroundRun] not in graph
618618

619619
assert NeXusComponentLocationSpec[FrameMonitor0, SampleRun] in graph
620620
assert NeXusComponentLocationSpec[FrameMonitor1, SampleRun] in graph
@@ -655,8 +655,8 @@ def test_generic_nexus_workflow_includes_only_given_run_types() -> None:
655655
assert MonitorData[SampleRun, FrameMonitor1] not in graph
656656
assert MonitorData[SampleRun, FrameMonitor2] not in graph
657657
assert MonitorData[SampleRun, FrameMonitor0] not in graph
658-
assert Choppers[EmptyBeamRun] in graph
659-
assert Choppers[SampleRun] not in graph
658+
assert RawChoppers[EmptyBeamRun] in graph
659+
assert RawChoppers[SampleRun] not in graph
660660

661661
excluded_run_types = set(RunType.__constraints__) - {EmptyBeamRun}
662662
for node in graph:
@@ -681,8 +681,8 @@ def test_generic_nexus_workflow_includes_only_given_monitor_types() -> None:
681681
assert MonitorData[BackgroundRun, FrameMonitor1] in graph
682682
assert MonitorData[BackgroundRun, FrameMonitor2] not in graph
683683
assert MonitorData[BackgroundRun, FrameMonitor0] not in graph
684-
assert Choppers[SampleRun] in graph
685-
assert Choppers[BackgroundRun] in graph
684+
assert RawChoppers[SampleRun] in graph
685+
assert RawChoppers[BackgroundRun] in graph
686686

687687
excluded_monitor_types = set(MonitorType.__constraints__) - {
688688
FrameMonitor1,

tests/time_of_flight/workflow_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from ess.reduce import time_of_flight
1111
from ess.reduce.nexus.types import (
1212
CalibratedBeamline,
13-
Choppers,
1413
DetectorData,
14+
DiskChoppers,
1515
NeXusData,
1616
Position,
1717
SampleRun,
@@ -62,7 +62,7 @@ def test_GenericTofWorkflow_can_compute_tof_lut_without_nexus_file_or_detector_i
6262
run_types=[SampleRun],
6363
monitor_types=[],
6464
)
65-
wf[Choppers[SampleRun]] = fakes.psc_choppers()
65+
wf[DiskChoppers[SampleRun]] = fakes.psc_choppers()
6666
wf[time_of_flight.types.NumberOfSimulatedNeutrons] = 10_000
6767
wf[time_of_flight.types.LtotalRange] = (
6868
sc.scalar(0.0, unit="m"),
@@ -93,7 +93,7 @@ def test_GenericTofWorkflow_with_tof_lut_from_tof_simulation(
9393
with pytest.raises(sciline.UnsatisfiedRequirement):
9494
_ = wf.compute(time_of_flight.DetectorTofData[SampleRun])
9595

96-
wf[Choppers[SampleRun]] = fakes.psc_choppers()
96+
wf[DiskChoppers[SampleRun]] = fakes.psc_choppers()
9797
wf[time_of_flight.types.NumberOfSimulatedNeutrons] = 10_000
9898
wf[time_of_flight.types.LtotalRange] = (
9999
sc.scalar(0.0, unit="m"),
@@ -128,7 +128,7 @@ def test_GenericTofWorkflow_with_tof_lut_from_file(
128128
run_types=[SampleRun],
129129
monitor_types=[],
130130
)
131-
make_lut_wf[Choppers[SampleRun]] = fakes.psc_choppers()
131+
make_lut_wf[DiskChoppers[SampleRun]] = fakes.psc_choppers()
132132
make_lut_wf[time_of_flight.types.NumberOfSimulatedNeutrons] = 10_000
133133
make_lut_wf[time_of_flight.types.LtotalRange] = (
134134
sc.scalar(0.0, unit="m"),

0 commit comments

Comments
 (0)