Skip to content

Commit bcd4e48

Browse files
authored
Merge pull request #125 from scipp/tof-workflow
Use time-of-flight workflow in Dream data reduction
2 parents eca4561 + 5c4b3f8 commit bcd4e48

23 files changed

+748
-102
lines changed

.copier-answers.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Diffraction data reduction for the European Spallation Source
55
max_python: '3.13'
66
min_python: '3.10'
77
namespace_package: ess
8-
nightly_deps: scipp,scippnexus,sciline,plopp,scippneutron,essreduce
8+
nightly_deps: scipp,scippnexus,sciline,plopp,scippneutron,essreduce,tof
99
orgname: scipp
1010
prettyname: ESSdiffraction
1111
projectname: essdiffraction

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

+26-50
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"outputs": [],
2121
"source": [
2222
"import scipp as sc\n",
23-
"\n",
2423
"from ess import dream, powder\n",
2524
"import ess.dream.data # noqa: F401\n",
2625
"from ess.powder.types import *"
@@ -71,22 +70,22 @@
7170
"workflow[UncertaintyBroadcastMode] = UncertaintyBroadcastMode.drop\n",
7271
"# Edges for binning in d-spacing\n",
7372
"workflow[DspacingBins] = sc.linspace(\"dspacing\", 0.0, 2.3434, 201, unit=\"angstrom\")\n",
74-
"# Mask in time-of-flight to crop to valid range\n",
75-
"workflow[TofMask] = lambda x: (x < sc.scalar(0.0, unit=\"ns\")) | (\n",
76-
" x > sc.scalar(86e6, unit=\"ns\")\n",
77-
")\n",
73+
"# Empty masks by default\n",
74+
"workflow[TofMask] = None\n",
7875
"workflow[TwoThetaMask] = None\n",
7976
"workflow[WavelengthMask] = None\n",
8077
"# No pixel masks\n",
81-
"workflow = powder.with_pixel_mask_filenames(workflow, [])"
78+
"workflow = powder.with_pixel_mask_filenames(workflow, [])\n",
79+
"# Time-of-flight lookup table\n",
80+
"workflow[TimeOfFlightLookupTableFilename] = dream.data.tof_lookup_table_high_flux()"
8281
]
8382
},
8483
{
8584
"cell_type": "markdown",
8685
"id": "6",
8786
"metadata": {},
8887
"source": [
89-
"## Use the workflow\n",
88+
"## Use the reduction workflow\n",
9089
"\n",
9190
"We can visualize the graph for computing the final normalized result for intensity as a function of time-of-flight:"
9291
]
@@ -152,7 +151,7 @@
152151
"in the documentation of ESSdiffraction.\n",
153152
"See https://scipp.github.io/essdiffraction/\n",
154153
"\"\"\"\n",
155-
"cif_data.save('reduced.cif')"
154+
"cif_data.save(\"reduced.cif\")"
156155
]
157156
},
158157
{
@@ -192,9 +191,9 @@
192191
"outputs": [],
193192
"source": [
194193
"two_theta = sc.linspace(\"two_theta\", 0.8, 2.4, 301, unit=\"rad\")\n",
195-
"intermediates[MaskedData[SampleRun]].hist(two_theta=two_theta, wavelength=300).plot(\n",
196-
" norm=\"log\"\n",
197-
")"
194+
"intermediates[MaskedData[SampleRun]].hist(\n",
195+
" two_theta=two_theta, wavelength=300\n",
196+
").plot(norm=\"log\")"
198197
]
199198
},
200199
{
@@ -216,7 +215,7 @@
216215
"outputs": [],
217216
"source": [
218217
"workflow[TwoThetaBins] = sc.linspace(\n",
219-
" dim=\"two_theta\", unit=\"rad\", start=0.8, stop=2.4, num=17\n",
218+
" dim=\"two_theta\", unit=\"rad\", start=0.8, stop=2.4, num=201\n",
220219
")"
221220
]
222221
},
@@ -237,31 +236,13 @@
237236
"id": "19",
238237
"metadata": {},
239238
"outputs": [],
240-
"source": [
241-
"angle = sc.midpoints(grouped_dspacing.coords[\"two_theta\"])\n",
242-
"sc.plot(\n",
243-
" {\n",
244-
" f\"{angle[group].value:.3f} {angle[group].unit}\": grouped_dspacing[\n",
245-
" \"two_theta\", group\n",
246-
" ].hist()\n",
247-
" for group in range(2, 6)\n",
248-
" }\n",
249-
")"
250-
]
251-
},
252-
{
253-
"cell_type": "code",
254-
"execution_count": null,
255-
"id": "20",
256-
"metadata": {},
257-
"outputs": [],
258239
"source": [
259240
"grouped_dspacing.hist().plot(norm=\"log\")"
260241
]
261242
},
262243
{
263244
"cell_type": "markdown",
264-
"id": "21",
245+
"id": "20",
265246
"metadata": {},
266247
"source": [
267248
"## Normalizing by monitor\n",
@@ -283,7 +264,7 @@
283264
{
284265
"cell_type": "code",
285266
"execution_count": null,
286-
"id": "22",
267+
"id": "21",
287268
"metadata": {},
288269
"outputs": [],
289270
"source": [
@@ -292,7 +273,7 @@
292273
},
293274
{
294275
"cell_type": "markdown",
295-
"id": "23",
276+
"id": "22",
296277
"metadata": {},
297278
"source": [
298279
"In addition to the parameters used before, we also need to provide filenames for monitor data and a position of the monitor as that is not saved in the simulation files:"
@@ -301,14 +282,14 @@
301282
{
302283
"cell_type": "code",
303284
"execution_count": null,
304-
"id": "24",
285+
"id": "23",
305286
"metadata": {},
306287
"outputs": [],
307288
"source": [
308289
"workflow[MonitorFilename[SampleRun]] = dream.data.simulated_monitor_diamond_sample()\n",
309290
"workflow[MonitorFilename[VanadiumRun]] = dream.data.simulated_monitor_vanadium_sample()\n",
310291
"workflow[MonitorFilename[BackgroundRun]] = dream.data.simulated_monitor_empty_can()\n",
311-
"workflow[CaveMonitorPosition] = sc.vector([0.0, 0.0, -4220.0], unit='mm')\n",
292+
"workflow[CaveMonitorPosition] = sc.vector([0.0, 0.0, -4220.0], unit=\"mm\")\n",
312293
"\n",
313294
"# These are the same as at the top of the notebook:\n",
314295
"workflow[Filename[SampleRun]] = dream.data.simulated_diamond_sample()\n",
@@ -318,18 +299,17 @@
318299
"workflow[NeXusDetectorName] = \"mantle\"\n",
319300
"workflow[UncertaintyBroadcastMode] = UncertaintyBroadcastMode.drop\n",
320301
"workflow[DspacingBins] = sc.linspace(\"dspacing\", 0.0, 2.3434, 201, unit=\"angstrom\")\n",
321-
"workflow[TofMask] = lambda x: (x < sc.scalar(0.0, unit=\"ns\")) | (\n",
322-
" x > sc.scalar(86e6, unit=\"ns\")\n",
323-
")\n",
302+
"workflow[TofMask] = None\n",
324303
"workflow[TwoThetaMask] = None\n",
325304
"workflow[WavelengthMask] = None\n",
326-
"workflow = powder.with_pixel_mask_filenames(workflow, [])"
305+
"workflow = powder.with_pixel_mask_filenames(workflow, [])\n",
306+
"workflow[TimeOfFlightLookupTableFilename] = dream.data.tof_lookup_table_high_flux()"
327307
]
328308
},
329309
{
330310
"cell_type": "code",
331311
"execution_count": null,
332-
"id": "25",
312+
"id": "24",
333313
"metadata": {},
334314
"outputs": [],
335315
"source": [
@@ -339,7 +319,7 @@
339319
{
340320
"cell_type": "code",
341321
"execution_count": null,
342-
"id": "26",
322+
"id": "25",
343323
"metadata": {},
344324
"outputs": [],
345325
"source": [
@@ -352,7 +332,7 @@
352332
{
353333
"cell_type": "code",
354334
"execution_count": null,
355-
"id": "27",
335+
"id": "26",
356336
"metadata": {},
357337
"outputs": [],
358338
"source": [
@@ -361,7 +341,7 @@
361341
},
362342
{
363343
"cell_type": "markdown",
364-
"id": "28",
344+
"id": "27",
365345
"metadata": {},
366346
"source": [
367347
"Comparing the final, normalized result shows that it agrees with the data that was normalized by proton-charge:"
@@ -370,14 +350,11 @@
370350
{
371351
"cell_type": "code",
372352
"execution_count": null,
373-
"id": "29",
353+
"id": "28",
374354
"metadata": {},
375355
"outputs": [],
376356
"source": [
377-
"sc.plot({\n",
378-
" 'By proton charge': histogram,\n",
379-
" 'By monitor': normalized_by_monitor.hist()\n",
380-
"})"
357+
"sc.plot({\"By proton charge\": histogram, \"By monitor\": normalized_by_monitor.hist()})"
381358
]
382359
}
383360
],
@@ -396,8 +373,7 @@
396373
"mimetype": "text/x-python",
397374
"name": "python",
398375
"nbconvert_exporter": "python",
399-
"pygments_lexer": "ipython3",
400-
"version": "3.10.14"
376+
"pygments_lexer": "ipython3"
401377
}
402378
},
403379
"nbformat": 4,

docs/user-guide/dream/workflow-widget-dream.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
},
4848
"outputs": [],
4949
"source": [
50-
"from ess.powder.types import DspacingBins, Filename, SampleRun, VanadiumRun\n",
50+
"from ess.powder.types import DspacingBins, Filename, SampleRun, TimeOfFlightLookupTableFilename, VanadiumRun\n",
5151
"import ess.dream.data # noqa: F401\n",
5252
"\n",
5353
"select = widget.children[0].children[0]\n",
@@ -66,6 +66,7 @@
6666
"# Set parameters\n",
6767
"pbox._input_widgets[Filename[SampleRun]].children[0].value = dream.data.simulated_diamond_sample()\n",
6868
"pbox._input_widgets[Filename[VanadiumRun]].children[0].value = dream.data.simulated_vanadium_sample()\n",
69+
"pbox._input_widgets[TimeOfFlightLookupTableFilename].children[0].value = dream.data.tof_lookup_table_high_flux()\n",
6970
"pbox._input_widgets[DspacingBins].fields[\"stop\"].value = 2.3434\n",
7071
"# Run the workflow\n",
7172
"rbox = wfw.result_box\n",
@@ -133,8 +134,7 @@
133134
"mimetype": "text/x-python",
134135
"name": "python",
135136
"nbconvert_exporter": "python",
136-
"pygments_lexer": "ipython3",
137-
"version": "3.10.14"
137+
"pygments_lexer": "ipython3"
138138
}
139139
},
140140
"nbformat": 4,

docs/user-guide/sns-instruments/POWGEN_data_reduction.ipynb

+3-4
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239
"source": [
240240
"results = workflow.compute(\n",
241241
" (\n",
242-
" DetectorData[SampleRun],\n",
242+
" TofData[SampleRun],\n",
243243
" MaskedData[SampleRun],\n",
244244
" FilteredData[SampleRun],\n",
245245
" FilteredData[VanadiumRun],\n",
@@ -254,7 +254,7 @@
254254
"metadata": {},
255255
"outputs": [],
256256
"source": [
257-
"results[DetectorData[SampleRun]]"
257+
"results[TofData[SampleRun]]"
258258
]
259259
},
260260
{
@@ -393,8 +393,7 @@
393393
"mimetype": "text/x-python",
394394
"name": "python",
395395
"nbconvert_exporter": "python",
396-
"pygments_lexer": "ipython3",
397-
"version": "3.10.14"
396+
"pygments_lexer": "ipython3"
398397
}
399398
},
400399
"nbformat": 4,

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ dependencies = [
4141
"scipp>=24.09.1",
4242
"scippneutron>=25.02.0",
4343
"scippnexus>=23.12.0",
44+
"tof>=25.01.2",
4445
]
4546

4647
dynamic = ["version"]

requirements/base.in

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ sciline>=24.06.0
1212
scipp>=24.09.1
1313
scippneutron>=25.02.0
1414
scippnexus>=23.12.0
15+
tof>=25.01.2

requirements/base.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SHA1:4b779f60b811ecde0982bc9dc5df5ed5b296b876
1+
# SHA1:bd57e2addebc398f9de7064eb2a5c993a359ba46
22
#
33
# This file is autogenerated by pip-compile-multi
44
# To update, run:
@@ -45,6 +45,8 @@ h5py==3.12.1
4545
# scippnexus
4646
idna==3.10
4747
# via email-validator
48+
importlib-resources==6.5.2
49+
# via tof
4850
ipydatawidgets==4.3.5
4951
# via pythreejs
5052
ipython==8.32.0
@@ -102,6 +104,7 @@ plopp==24.10.0
102104
# via
103105
# -r base.in
104106
# scippneutron
107+
# tof
105108
prompt-toolkit==3.0.50
106109
# via ipython
107110
ptyprocess==0.7.0
@@ -135,6 +138,7 @@ scipp==25.2.0
135138
# essreduce
136139
# scippneutron
137140
# scippnexus
141+
# tof
138142
scippneutron==25.2.0
139143
# via
140144
# -r base.in
@@ -148,10 +152,13 @@ scipy==1.15.2
148152
# via
149153
# scippneutron
150154
# scippnexus
155+
# tof
151156
six==1.17.0
152157
# via python-dateutil
153158
stack-data==0.6.3
154159
# via ipython
160+
tof==25.2.0
161+
# via -r base.in
155162
toolz==1.0.0
156163
# via
157164
# dask

requirements/nightly.in

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ sciline @ git+https://github.com/scipp/sciline@main
1717
plopp @ git+https://github.com/scipp/plopp@main
1818
scippneutron @ git+https://github.com/scipp/scippneutron@main
1919
essreduce @ git+https://github.com/scipp/essreduce@main
20+
tof @ git+https://github.com/scipp/tof@main

requirements/nightly.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SHA1:b20670ae7cbdca0a2dae7facc845a0a636ee537c
1+
# SHA1:366263fa92dc0eb9f81d46f056e0c80a931f671e
22
#
33
# This file is autogenerated by pip-compile-multi
44
# To update, run:
@@ -54,6 +54,8 @@ idna==3.10
5454
# via
5555
# email-validator
5656
# requests
57+
importlib-resources==6.5.2
58+
# via tof
5759
iniconfig==2.0.0
5860
# via pytest
5961
ipydatawidgets==4.3.5
@@ -122,6 +124,7 @@ plopp @ git+https://github.com/scipp/plopp@main
122124
# via
123125
# -r nightly.in
124126
# scippneutron
127+
# tof
125128
pluggy==1.5.0
126129
# via pytest
127130
pooch==1.8.2
@@ -166,6 +169,7 @@ scipp==100.0.0.dev0
166169
# essreduce
167170
# scippneutron
168171
# scippnexus
172+
# tof
169173
scippneutron @ git+https://github.com/scipp/scippneutron@main
170174
# via
171175
# -r nightly.in
@@ -179,10 +183,13 @@ scipy==1.15.2
179183
# via
180184
# scippneutron
181185
# scippnexus
186+
# tof
182187
six==1.17.0
183188
# via python-dateutil
184189
stack-data==0.6.3
185190
# via ipython
191+
tof @ git+https://github.com/scipp/tof@main
192+
# via -r nightly.in
186193
toolz==1.0.0
187194
# via
188195
# dask

0 commit comments

Comments
 (0)