Skip to content

Commit 230a52f

Browse files
committed
Properly use generic DiskChoppers
1 parent 437345c commit 230a52f

File tree

9 files changed

+38
-24
lines changed

9 files changed

+38
-24
lines changed

docs/user-guide/tof/dream.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"import plopp as pp\n",
2525
"import scipp as sc\n",
2626
"from scippneutron.chopper import DiskChopper\n",
27-
"from ess.reduce.nexus.types import DetectorData, SampleRun\n",
27+
"from ess.reduce.nexus.types import AnyRun, DetectorData, SampleRun\n",
2828
"from ess.reduce.time_of_flight import *"
2929
]
3030
},
@@ -340,7 +340,7 @@
340340
"outputs": [],
341341
"source": [
342342
"lut_wf = TofLookupTableWorkflow()\n",
343-
"lut_wf[DiskChoppers] = disk_choppers\n",
343+
"lut_wf[DiskChoppers[AnyRun]] = disk_choppers\n",
344344
"lut_wf[SourcePosition] = source_position\n",
345345
"lut_wf[LtotalRange] = (\n",
346346
" sc.scalar(75.5, unit=\"m\"),\n",
@@ -713,7 +713,7 @@
713713
"outputs": [],
714714
"source": [
715715
"# Update workflow\n",
716-
"lut_wf[DiskChoppers] = disk_choppers\n",
716+
"lut_wf[DiskChoppers[AnyRun]] = disk_choppers\n",
717717
"\n",
718718
"sim = lut_wf.compute(SimulationResults)\n",
719719
"\n",

docs/user-guide/tof/frame-unwrapping.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"import plopp as pp\n",
3333
"import scipp as sc\n",
3434
"from scippneutron.chopper import DiskChopper\n",
35-
"from ess.reduce.nexus.types import DetectorData, SampleRun\n",
35+
"from ess.reduce.nexus.types import AnyRun, DetectorData, SampleRun\n",
3636
"from ess.reduce.time_of_flight import *\n",
3737
"import tof\n",
3838
"\n",
@@ -212,7 +212,7 @@
212212
"source": [
213213
"lut_wf = TofLookupTableWorkflow()\n",
214214
"lut_wf[LtotalRange] = detectors[0].distance, detectors[-1].distance\n",
215-
"lut_wf[DiskChoppers] = {\n",
215+
"lut_wf[DiskChoppers[AnyRun]] = {\n",
216216
" \"chopper\": DiskChopper(\n",
217217
" frequency=-chopper.frequency,\n",
218218
" beam_position=sc.scalar(0.0, unit=\"deg\"),\n",
@@ -399,7 +399,7 @@
399399
"lut_wf = TofLookupTableWorkflow()\n",
400400
"lut_wf[PulseStride] = 2\n",
401401
"lut_wf[LtotalRange] = detectors[0].distance, detectors[-1].distance\n",
402-
"lut_wf[DiskChoppers] = {\n",
402+
"lut_wf[DiskChoppers[AnyRun]] = {\n",
403403
" ch.name: DiskChopper(\n",
404404
" frequency=-ch.frequency,\n",
405405
" beam_position=sc.scalar(0.0, unit=\"deg\"),\n",

docs/user-guide/tof/wfm.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"import plopp as pp\n",
2626
"import scipp as sc\n",
2727
"from scippneutron.chopper import DiskChopper\n",
28-
"from ess.reduce.nexus.types import DetectorData, SampleRun\n",
28+
"from ess.reduce.nexus.types import AnyRun, DetectorData, SampleRun\n",
2929
"from ess.reduce.time_of_flight import *"
3030
]
3131
},
@@ -361,7 +361,7 @@
361361
"outputs": [],
362362
"source": [
363363
"lut_wf = TofLookupTableWorkflow()\n",
364-
"lut_wf[DiskChoppers] = disk_choppers\n",
364+
"lut_wf[DiskChoppers[AnyRun]] = disk_choppers\n",
365365
"lut_wf[SourcePosition] = source_position\n",
366366
"lut_wf[LtotalRange] = Ltotal, Ltotal\n",
367367
"lut_wf[LookupTableRelativeErrorThreshold] = 0.1\n",

src/ess/reduce/nexus/types.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
# 1 TypeVars used to parametrize the generic parts of the workflow
4141

4242
# 1.1 Run types
43+
44+
AnyRun = NewType("AnyRun", int)
45+
"""RunType that does not represent a specific measurement run.
46+
47+
This can be used in cases where it makes no sense to use an 'actual' run type
48+
like ``SampleRun`` or ``BackgroundRun``.
49+
"""
50+
4351
BackgroundRun = NewType('BackgroundRun', int)
4452
"""Background run such as a run with only a solvent which the sample is placed in."""
4553
EmptyBeamRun = NewType('EmptyBeamRun', int)

src/ess/reduce/time_of_flight/lut.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import sciline as sl
1313
import scipp as sc
1414

15-
from ..nexus.types import DiskChoppers
15+
from ..nexus.types import AnyRun, DiskChoppers
1616
from .types import TimeOfFlightLookupTable
1717

1818

@@ -380,7 +380,7 @@ def make_tof_lookup_table(
380380

381381

382382
def simulate_chopper_cascade_using_tof(
383-
choppers: DiskChoppers,
383+
choppers: DiskChoppers[AnyRun],
384384
source_position: SourcePosition,
385385
neutrons: NumberOfSimulatedNeutrons,
386386
pulse_stride: PulseStride,

tests/time_of_flight/lut_test.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import scipp as sc
55

66
from ess.reduce import time_of_flight
7+
from ess.reduce.nexus.types import AnyRun
78
from ess.reduce.time_of_flight import TofLookupTableWorkflow
89

910
sl = pytest.importorskip("sciline")
1011

1112

1213
def test_lut_workflow_computes_table():
1314
wf = TofLookupTableWorkflow()
14-
wf[time_of_flight.DiskChoppers] = {}
15+
wf[time_of_flight.DiskChoppers[AnyRun]] = {}
1516
wf[time_of_flight.SourcePosition] = sc.vector([0, 0, 0], unit='m')
1617
wf[time_of_flight.NumberOfSimulatedNeutrons] = 100_000
1718
wf[time_of_flight.SimulationSeed] = 60
@@ -40,7 +41,7 @@ def test_lut_workflow_computes_table():
4041

4142
def test_lut_workflow_computes_table_in_chunks():
4243
wf = TofLookupTableWorkflow()
43-
wf[time_of_flight.DiskChoppers] = {}
44+
wf[time_of_flight.DiskChoppers[AnyRun]] = {}
4445
wf[time_of_flight.SourcePosition] = sc.vector([0, 0, 0], unit='m')
4546
# Lots of neutrons activates chunking
4647
wf[time_of_flight.NumberOfSimulatedNeutrons] = 1_000_000
@@ -70,7 +71,7 @@ def test_lut_workflow_computes_table_in_chunks():
7071

7172
def test_lut_workflow_pulse_skipping():
7273
wf = TofLookupTableWorkflow()
73-
wf[time_of_flight.DiskChoppers] = {}
74+
wf[time_of_flight.DiskChoppers[AnyRun]] = {}
7475
wf[time_of_flight.SourcePosition] = sc.vector([0, 0, 0], unit='m')
7576
wf[time_of_flight.NumberOfSimulatedNeutrons] = 100_000
7677
wf[time_of_flight.SimulationSeed] = 62
@@ -93,7 +94,7 @@ def test_lut_workflow_pulse_skipping():
9394

9495
def test_lut_workflow_non_exact_distance_range():
9596
wf = TofLookupTableWorkflow()
96-
wf[time_of_flight.DiskChoppers] = {}
97+
wf[time_of_flight.DiskChoppers[AnyRun]] = {}
9798
wf[time_of_flight.SourcePosition] = sc.vector([0, 0, 0], unit='m')
9899
wf[time_of_flight.NumberOfSimulatedNeutrons] = 100_000
99100
wf[time_of_flight.SimulationSeed] = 63

tests/time_of_flight/unwrap_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
from scippneutron.conversion.graph.tof import elastic as elastic_graph
99

1010
from ess.reduce import time_of_flight
11-
from ess.reduce.nexus.types import DetectorData, SampleRun
11+
from ess.reduce.nexus.types import AnyRun, DetectorData, SampleRun
1212
from ess.reduce.time_of_flight import GenericTofWorkflow, TofLookupTableWorkflow, fakes
1313

1414
sl = pytest.importorskip("sciline")
1515

1616

1717
def make_lut_workflow(choppers, neutrons, seed, pulse_stride):
1818
lut_wf = TofLookupTableWorkflow()
19-
lut_wf[time_of_flight.DiskChoppers] = choppers
19+
lut_wf[time_of_flight.DiskChoppers[AnyRun]] = choppers
2020
lut_wf[time_of_flight.SourcePosition] = fakes.source_position()
2121
lut_wf[time_of_flight.NumberOfSimulatedNeutrons] = neutrons
2222
lut_wf[time_of_flight.SimulationSeed] = seed

tests/time_of_flight/wfm_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from scippneutron.conversion.graph.tof import elastic as elastic_graph
1010

1111
from ess.reduce import time_of_flight
12-
from ess.reduce.nexus.types import DetectorData, SampleRun
12+
from ess.reduce.nexus.types import AnyRun, DetectorData, SampleRun
1313
from ess.reduce.time_of_flight import GenericTofWorkflow, TofLookupTableWorkflow, fakes
1414

1515
sl = pytest.importorskip("sciline")
@@ -112,7 +112,7 @@ def dream_source_position() -> sc.Variable:
112112
@pytest.fixture(scope="module")
113113
def lut_workflow_dream_choppers() -> sl.Pipeline:
114114
lut_wf = TofLookupTableWorkflow()
115-
lut_wf[time_of_flight.DiskChoppers] = dream_choppers()
115+
lut_wf[time_of_flight.DiskChoppers[AnyRun]] = dream_choppers()
116116
lut_wf[time_of_flight.SourcePosition] = dream_source_position()
117117
lut_wf[time_of_flight.NumberOfSimulatedNeutrons] = 100_000
118118
lut_wf[time_of_flight.SimulationSeed] = 432
@@ -213,7 +213,7 @@ def test_dream_wfm(
213213
@pytest.fixture(scope="module")
214214
def lut_workflow_dream_choppers_time_overlap():
215215
lut_wf = TofLookupTableWorkflow()
216-
lut_wf[time_of_flight.DiskChoppers] = dream_choppers_with_frame_overlap()
216+
lut_wf[time_of_flight.DiskChoppers[AnyRun]] = dream_choppers_with_frame_overlap()
217217
lut_wf[time_of_flight.SourcePosition] = dream_source_position()
218218
lut_wf[time_of_flight.NumberOfSimulatedNeutrons] = 100_000
219219
lut_wf[time_of_flight.SimulationSeed] = 432
@@ -405,7 +405,7 @@ def v20_source_position():
405405
@pytest.fixture(scope="module")
406406
def lut_workflow_v20_choppers():
407407
lut_wf = TofLookupTableWorkflow()
408-
lut_wf[time_of_flight.DiskChoppers] = v20_choppers()
408+
lut_wf[time_of_flight.DiskChoppers[AnyRun]] = v20_choppers()
409409
lut_wf[time_of_flight.SourcePosition] = v20_source_position()
410410
lut_wf[time_of_flight.NumberOfSimulatedNeutrons] = 300_000
411411
lut_wf[time_of_flight.SimulationSeed] = 431

tests/time_of_flight/workflow_test.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99

1010
from ess.reduce import time_of_flight
1111
from ess.reduce.nexus.types import (
12+
AnyRun,
1213
CalibratedBeamline,
1314
DetectorData,
1415
DiskChoppers,
1516
NeXusData,
1617
SampleRun,
1718
)
18-
from ess.reduce.time_of_flight import GenericTofWorkflow, TofLookupTableWorkflow, fakes
19+
from ess.reduce.time_of_flight import (
20+
GenericTofWorkflow,
21+
TofLookupTableWorkflow,
22+
fakes,
23+
)
1924

2025
sl = pytest.importorskip("sciline")
2126

@@ -57,7 +62,7 @@ def nexus_data():
5762

5863
def test_TofLookupTableWorkflow_can_compute_tof_lut():
5964
wf = TofLookupTableWorkflow()
60-
wf[DiskChoppers] = fakes.psc_choppers()
65+
wf[DiskChoppers[AnyRun]] = fakes.psc_choppers()
6166
wf[time_of_flight.NumberOfSimulatedNeutrons] = 10_000
6267
wf[time_of_flight.LtotalRange] = (
6368
sc.scalar(0.0, unit="m"),
@@ -85,7 +90,7 @@ def test_GenericTofWorkflow_with_tof_lut_from_tof_simulation(
8590
_ = wf.compute(time_of_flight.DetectorTofData[SampleRun])
8691

8792
lut_wf = TofLookupTableWorkflow()
88-
lut_wf[DiskChoppers] = fakes.psc_choppers()
93+
lut_wf[DiskChoppers[AnyRun]] = fakes.psc_choppers()
8994
lut_wf[time_of_flight.NumberOfSimulatedNeutrons] = 10_000
9095
lut_wf[time_of_flight.LtotalRange] = (
9196
sc.scalar(0.0, unit="m"),
@@ -106,7 +111,7 @@ def test_GenericTofWorkflow_with_tof_lut_from_file(
106111
tmp_path: pytest.TempPathFactory,
107112
):
108113
lut_wf = TofLookupTableWorkflow()
109-
lut_wf[DiskChoppers] = fakes.psc_choppers()
114+
lut_wf[DiskChoppers[AnyRun]] = fakes.psc_choppers()
110115
lut_wf[time_of_flight.NumberOfSimulatedNeutrons] = 10_000
111116
lut_wf[time_of_flight.LtotalRange] = (
112117
sc.scalar(0.0, unit="m"),

0 commit comments

Comments
 (0)