Skip to content

Commit ffb46a9

Browse files
authored
Merge pull request #81 from scipp/use-generic-tof-wf
Use the generic Tof workflow for TBL
2 parents 37365f7 + 625ca0f commit ffb46a9

File tree

15 files changed

+166
-307
lines changed

15 files changed

+166
-307
lines changed

docs/user-guide/odin/odin_simulation.ipynb

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@
132132
"metadata": {},
133133
"outputs": [],
134134
"source": [
135-
"import sciline as sl\n",
136135
"from odin_mcstas_helper import DISK_CHOPPERS\n",
137136
"\n",
138137
"disk_choppers = DISK_CHOPPERS.copy() # Copy to avoid modifying the original dictionary"
@@ -228,22 +227,25 @@
228227
"outputs": [],
229228
"source": [
230229
"from ess.reduce import time_of_flight\n",
230+
"from ess.reduce.nexus.types import CalibratedBeamline, DetectorData, SampleRun\n",
231231
"\n",
232-
"workflow = sl.Pipeline(\n",
233-
" time_of_flight.providers(), params=time_of_flight.default_parameters()\n",
232+
"wf = time_of_flight.GenericTofWorkflow(\n",
233+
" tof_lut_provider=time_of_flight.TofLutProvider.TOF,\n",
234+
" run_types=[SampleRun],\n",
235+
" monitor_types=[],\n",
234236
")\n",
235-
"workflow[time_of_flight.RawData] = sample_nexus\n",
236-
"workflow[time_of_flight.Ltotal] = sample_nexus.coords['Ltotal']\n",
237-
"workflow[time_of_flight.LtotalRange] = (\n",
237+
"wf[DetectorData[SampleRun]] = sample_nexus\n",
238+
"wf[CalibratedBeamline[SampleRun]] = sample_nexus\n",
239+
"wf[time_of_flight.LtotalRange] = (\n",
238240
" sc.scalar(55.0, unit=\"m\"),\n",
239241
" sc.scalar(65.0, unit=\"m\"),\n",
240242
")\n",
241-
"workflow[time_of_flight.PulseStride] = 2 # Need for pulse-skipping\n",
242-
"workflow[time_of_flight.SimulationResults] = time_of_flight.simulate_beamline(\n",
243+
"wf[time_of_flight.PulseStride] = 2 # Need for pulse-skipping\n",
244+
"wf[time_of_flight.SimulationResults] = time_of_flight.simulate_beamline(\n",
243245
" choppers=disk_choppers, neutrons=2_000_000, source_position=sc.vector([0, 0, 0], unit='m')\n",
244246
")\n",
245247
"\n",
246-
"workflow.visualize(time_of_flight.TofData)"
248+
"wf.visualize(time_of_flight.DetectorTofData[SampleRun])"
247249
]
248250
},
249251
{
@@ -261,9 +263,9 @@
261263
"metadata": {},
262264
"outputs": [],
263265
"source": [
264-
"table = workflow.compute(time_of_flight.TimeOfFlightLookupTable).squeeze()\n",
266+
"table = wf.compute(time_of_flight.TimeOfFlightLookupTable)\n",
265267
"\n",
266-
"table['pulse', 0].plot(title='Pulse 0') + table['pulse', 1].plot(title='Pulse 1')"
268+
"table.plot(figsize=(9, 4))"
267269
]
268270
},
269271
{
@@ -281,7 +283,7 @@
281283
"metadata": {},
282284
"outputs": [],
283285
"source": [
284-
"sample_tofs = workflow.compute(time_of_flight.TofData)\n",
286+
"sample_tofs = wf.compute(time_of_flight.DetectorTofData[SampleRun])\n",
285287
"sample_tofs"
286288
]
287289
},
@@ -395,10 +397,10 @@
395397
" {key: sample_nexus.coords[key] for key in ('position', 'Ltotal')}\n",
396398
")\n",
397399
"\n",
398-
"workflow[time_of_flight.Ltotal] = ob_nexus.coords['Ltotal']\n",
399-
"workflow[time_of_flight.RawData] = ob_nexus\n",
400+
"wf[DetectorData[SampleRun]] = ob_nexus\n",
401+
"wf[CalibratedBeamline[SampleRun]] = ob_nexus\n",
400402
"\n",
401-
"ob_tofs = workflow.compute(time_of_flight.TofData)\n",
403+
"ob_tofs = wf.compute(time_of_flight.DetectorTofData[SampleRun])\n",
402404
"ob_wavs = ob_tofs.transform_coords('wavelength', graph=PLAIN_GRAPH)\n",
403405
"ob_folded = ob_wavs.fold(dim='pixel_id', sizes={'y': 128, 'x': 128})\n",
404406
"ob_cropped = ob_folded['y', sel]['x', sel]"
@@ -484,8 +486,7 @@
484486
"mimetype": "text/x-python",
485487
"name": "python",
486488
"nbconvert_exporter": "python",
487-
"pygments_lexer": "ipython3",
488-
"version": "3.12.9"
489+
"pygments_lexer": "ipython3"
489490
}
490491
},
491492
"nbformat": 4,

docs/user-guide/tbl/tbl-data-reduction.ipynb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"metadata": {},
3838
"outputs": [],
3939
"source": [
40-
"wf = tbl.TblWorkflow()\n",
40+
"wf = tbl.TblWorkflow(tof_lut_provider=time_of_flight.TofLutProvider.TOF)\n",
41+
"wf[DiskChoppers[SampleRun]] = {}\n",
4142
"\n",
4243
"wf[Filename[SampleRun]] = tbl.data.tutorial_sample_data()"
4344
]
@@ -80,7 +81,7 @@
8081
"metadata": {},
8182
"outputs": [],
8283
"source": [
83-
"ngem['dim_0', 0].hist().plot(aspect='equal') + ngem['dim_0', 1].hist().plot(aspect='equal')"
84+
"ngem['dim_0', 0].hist().plot(aspect='equal', title='First detection') + ngem['dim_0', 1].hist().plot(aspect='equal', title='Last detection')"
8485
]
8586
},
8687
{
@@ -98,7 +99,7 @@
9899
"metadata": {},
99100
"outputs": [],
100101
"source": [
101-
"wf.visualize(TofData[SampleRun], graph_attr={\"rankdir\": \"LR\"})"
102+
"wf.visualize(DetectorTofData[SampleRun], graph_attr={\"rankdir\": \"LR\"})"
102103
]
103104
},
104105
{
@@ -117,7 +118,7 @@
117118
"outputs": [],
118119
"source": [
119120
"table = wf.compute(time_of_flight.TimeOfFlightLookupTable)\n",
120-
"table.squeeze().plot()"
121+
"table.plot()"
121122
]
122123
},
123124
{
@@ -145,8 +146,8 @@
145146
"metadata": {},
146147
"outputs": [],
147148
"source": [
148-
"ngem_tofs = wf.compute(TofData[SampleRun])\n",
149-
"ngem_wavs = wf.compute(WavelengthData[SampleRun])\n",
149+
"ngem_tofs = wf.compute(DetectorTofData[SampleRun])\n",
150+
"ngem_wavs = wf.compute(DetectorWavelengthData[SampleRun])\n",
150151
"\n",
151152
"ngem_tofs.bins.concat().hist(tof=100).plot() + ngem_wavs.bins.concat().hist(wavelength=100).plot()"
152153
]
@@ -206,8 +207,8 @@
206207
"\n",
207208
"for bank in ('he3_detector_bank0', 'he3_detector_bank1'):\n",
208209
" he3_wf[NeXusDetectorName] = bank\n",
209-
" he3_tofs[bank] = he3_wf.compute(TofData[SampleRun]).bins.concat().hist(tof=100)\n",
210-
" he3_wavs[bank] = he3_wf.compute(WavelengthData[SampleRun]).bins.concat().hist(wavelength=100)\n",
210+
" he3_tofs[bank] = he3_wf.compute(DetectorTofData[SampleRun]).bins.concat().hist(tof=100)\n",
211+
" he3_wavs[bank] = he3_wf.compute(DetectorWavelengthData[SampleRun]).bins.concat().hist(wavelength=100)\n",
211212
"\n",
212213
"pp.plot(he3_tofs) + pp.plot(he3_wavs)"
213214
]

requirements/base.txt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ annotated-types==0.7.0
99
# via pydantic
1010
asttokens==3.0.0
1111
# via stack-data
12-
click==8.1.8
12+
click==8.2.1
1313
# via dask
1414
cloudpickle==3.1.1
1515
# via dask
@@ -21,23 +21,23 @@ cyclebane==24.10.0
2121
# via sciline
2222
cycler==0.12.1
2323
# via matplotlib
24-
dask==2025.3.0
24+
dask==2025.5.1
2525
# via -r base.in
2626
decorator==5.2.1
2727
# via ipython
2828
dnspython==2.7.0
2929
# via email-validator
3030
email-validator==2.2.0
3131
# via scippneutron
32-
essreduce==25.4.1
32+
essreduce==25.5.3
3333
# via -r base.in
34-
exceptiongroup==1.2.2
34+
exceptiongroup==1.3.0
3535
# via ipython
3636
executing==2.2.0
3737
# via stack-data
38-
fonttools==4.57.0
38+
fonttools==4.58.1
3939
# via matplotlib
40-
fsspec==2025.3.2
40+
fsspec==2025.5.1
4141
# via dask
4242
graphviz==0.20.3
4343
# via
@@ -49,25 +49,25 @@ h5py==3.13.0
4949
# scippnexus
5050
idna==3.10
5151
# via email-validator
52-
importlib-metadata==8.6.1
52+
importlib-metadata==8.7.0
5353
# via dask
5454
ipydatawidgets==4.3.5
5555
# via pythreejs
5656
ipympl==0.9.7
5757
# via plopp
58-
ipython==8.35.0
58+
ipython==8.37.0
5959
# via
6060
# ipympl
6161
# ipywidgets
62-
ipywidgets==8.1.6
62+
ipywidgets==8.1.7
6363
# via
6464
# ipydatawidgets
6565
# ipympl
6666
# plopp
6767
# pythreejs
6868
jedi==0.19.2
6969
# via ipython
70-
jupyterlab-widgets==3.0.14
70+
jupyterlab-widgets==3.0.15
7171
# via ipywidgets
7272
kiwisolver==1.4.8
7373
# via matplotlib
@@ -77,27 +77,26 @@ lazy-loader==0.4
7777
# scippneutron
7878
locket==1.0.0
7979
# via partd
80-
matplotlib==3.10.1
80+
matplotlib==3.10.3
8181
# via
8282
# ipympl
8383
# mpltoolbox
8484
# plopp
8585
matplotlib-inline==0.1.7
8686
# via ipython
87-
mpltoolbox==24.5.1
87+
mpltoolbox==25.5.0
8888
# via
8989
# plopp
9090
# scippneutron
9191
networkx==3.4.2
9292
# via cyclebane
93-
numpy==2.2.5
93+
numpy==2.2.6
9494
# via
9595
# contourpy
9696
# h5py
9797
# ipydatawidgets
9898
# ipympl
9999
# matplotlib
100-
# mpltoolbox
101100
# pythreejs
102101
# scipp
103102
# scippneutron
@@ -118,7 +117,7 @@ pillow==11.2.1
118117
# via
119118
# ipympl
120119
# matplotlib
121-
plopp[all]==25.4.0
120+
plopp[all]==25.6.0
122121
# via
123122
# -r base.in
124123
# scippneutron
@@ -128,9 +127,9 @@ ptyprocess==0.7.0
128127
# via pexpect
129128
pure-eval==0.2.3
130129
# via stack-data
131-
pydantic==2.11.3
130+
pydantic==2.11.5
132131
# via scippneutron
133-
pydantic-core==2.33.1
132+
pydantic-core==2.33.2
134133
# via pydantic
135134
pygments==2.19.1
136135
# via ipython
@@ -145,7 +144,7 @@ pythreejs==2.4.2
145144
# via plopp
146145
pyyaml==6.0.2
147146
# via dask
148-
sciline==25.4.1
147+
sciline==25.5.2
149148
# via
150149
# -r base.in
151150
# essreduce
@@ -156,7 +155,7 @@ scipp==25.5.1
156155
# plopp
157156
# scippneutron
158157
# scippnexus
159-
scippneutron==25.2.1
158+
scippneutron==25.5.0
160159
# via
161160
# -r base.in
162161
# essreduce
@@ -165,15 +164,15 @@ scippnexus==25.4.0
165164
# -r base.in
166165
# essreduce
167166
# scippneutron
168-
scipy==1.15.2
167+
scipy==1.15.3
169168
# via
170169
# scippneutron
171170
# scippnexus
172171
six==1.17.0
173172
# via python-dateutil
174173
stack-data==0.6.3
175174
# via ipython
176-
tifffile==2025.3.30
175+
tifffile==2025.5.10
177176
# via -r base.in
178177
toolz==1.0.0
179178
# via
@@ -190,18 +189,19 @@ traitlets==5.14.3
190189
# traittypes
191190
traittypes==0.2.1
192191
# via ipydatawidgets
193-
typing-extensions==4.13.2
192+
typing-extensions==4.14.0
194193
# via
194+
# exceptiongroup
195195
# ipython
196196
# pydantic
197197
# pydantic-core
198198
# sciline
199199
# typing-inspection
200-
typing-inspection==0.4.0
200+
typing-inspection==0.4.1
201201
# via pydantic
202202
wcwidth==0.2.13
203203
# via prompt-toolkit
204204
widgetsnbextension==4.0.14
205205
# via ipywidgets
206-
zipp==3.21.0
206+
zipp==3.22.0
207207
# via importlib-metadata

0 commit comments

Comments
 (0)