Skip to content

Commit 977e559

Browse files
authored
Merge pull request #170 from scipp/subtract-empty-can
Move empty can subtraction to end
2 parents 2fba55e + 7e2ab29 commit 977e559

File tree

12 files changed

+246
-203
lines changed

12 files changed

+246
-203
lines changed

docs/user-guide/dream/dream-advanced-powder-reduction.ipynb

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"metadata": {},
112112
"outputs": [],
113113
"source": [
114-
"workflow.visualize(IofDspacingTwoTheta, graph_attr={\"rankdir\": \"LR\"})"
114+
"workflow.visualize(IofDspacingTwoTheta[SampleRun], graph_attr={\"rankdir\": \"LR\"})"
115115
]
116116
},
117117
{
@@ -129,7 +129,7 @@
129129
"metadata": {},
130130
"outputs": [],
131131
"source": [
132-
"grouped_dspacing = workflow.compute(IofDspacingTwoTheta)\n",
132+
"grouped_dspacing = workflow.compute(IofDspacingTwoTheta[SampleRun])\n",
133133
"grouped_dspacing"
134134
]
135135
},
@@ -209,7 +209,7 @@
209209
"metadata": {},
210210
"outputs": [],
211211
"source": [
212-
"workflow.visualize(IofDspacing, graph_attr={\"rankdir\": \"LR\"})"
212+
"workflow.visualize(IofDspacing[SampleRun], graph_attr={\"rankdir\": \"LR\"})"
213213
]
214214
},
215215
{
@@ -227,7 +227,7 @@
227227
"metadata": {},
228228
"outputs": [],
229229
"source": [
230-
"result = workflow.compute(IofDspacing)\n",
230+
"result = workflow.compute(IofDspacing[SampleRun])\n",
231231
"result.hist().plot(title=result.coords['detector'].value.capitalize())"
232232
]
233233
},
@@ -285,7 +285,7 @@
285285
"metadata": {},
286286
"outputs": [],
287287
"source": [
288-
"workflow.visualize(IofDspacing, graph_attr={\"rankdir\": \"LR\"})"
288+
"workflow.visualize(IofDspacing[SampleRun], graph_attr={\"rankdir\": \"LR\"})"
289289
]
290290
},
291291
{
@@ -303,7 +303,7 @@
303303
"metadata": {},
304304
"outputs": [],
305305
"source": [
306-
"result = workflow.compute(IofDspacing)\n",
306+
"result = workflow.compute(IofDspacing[SampleRun])\n",
307307
"result.hist().plot(title=result.coords['detector'].value.capitalize())"
308308
]
309309
},
@@ -424,8 +424,10 @@
424424
").rename_axis(index='detector')\n",
425425
"\n",
426426
"all_detector_workflow = workflow.copy()\n",
427-
"mapped = all_detector_workflow[IofDspacing].map(parameter_table)\n",
428-
"all_detector_workflow[IofDspacing] = mapped.reduce(func=powder.grouping.collect_detectors)"
427+
"mapped = all_detector_workflow[EmptyCanSubtractedIofDspacing[SampleRun]].map(parameter_table)\n",
428+
"all_detector_workflow[EmptyCanSubtractedIofDspacing[SampleRun]] = mapped.reduce(\n",
429+
" func=powder.grouping.collect_detectors\n",
430+
")"
429431
]
430432
},
431433
{
@@ -443,7 +445,11 @@
443445
"metadata": {},
444446
"outputs": [],
445447
"source": [
446-
"all_detector_workflow.visualize(IofDspacing, graph_attr={\"rankdir\": \"LR\"}, compact=True)"
448+
"all_detector_workflow.visualize(\n",
449+
" EmptyCanSubtractedIofDspacing[SampleRun],\n",
450+
" graph_attr={\"rankdir\": \"LR\"},\n",
451+
" compact=True\n",
452+
")"
447453
]
448454
},
449455
{
@@ -461,7 +467,7 @@
461467
"metadata": {},
462468
"outputs": [],
463469
"source": [
464-
"result = all_detector_workflow.compute(IofDspacing)"
470+
"result = all_detector_workflow.compute(EmptyCanSubtractedIofDspacing[SampleRun])"
465471
]
466472
},
467473
{
@@ -534,8 +540,10 @@
534540
").rename_axis(index='detector')\n",
535541
"\n",
536542
"all_detector_workflow = workflow.copy()\n",
537-
"mapped = all_detector_workflow[IofDspacingTwoTheta].map(parameter_table)\n",
538-
"all_detector_workflow[IofDspacingTwoTheta] = mapped.reduce(func=powder.grouping.collect_detectors)"
543+
"mapped = all_detector_workflow[EmptyCanSubtractedIofDspacingTwoTheta[SampleRun]].map(parameter_table)\n",
544+
"all_detector_workflow[EmptyCanSubtractedIofDspacingTwoTheta[SampleRun]] = mapped.reduce(\n",
545+
" func=powder.grouping.collect_detectors\n",
546+
")"
539547
]
540548
},
541549
{
@@ -545,7 +553,11 @@
545553
"metadata": {},
546554
"outputs": [],
547555
"source": [
548-
"all_detector_workflow.visualize(IofDspacing, graph_attr={\"rankdir\": \"LR\"}, compact=True)"
556+
"all_detector_workflow.visualize(\n",
557+
" EmptyCanSubtractedIofDspacingTwoTheta[SampleRun],\n",
558+
" graph_attr={\"rankdir\": \"LR\"},\n",
559+
" compact=True\n",
560+
")"
549561
]
550562
},
551563
{
@@ -555,7 +567,7 @@
555567
"metadata": {},
556568
"outputs": [],
557569
"source": [
558-
"result = all_detector_workflow.compute(IofDspacingTwoTheta)"
570+
"result = all_detector_workflow.compute(EmptyCanSubtractedIofDspacingTwoTheta[SampleRun])"
559571
]
560572
},
561573
{
@@ -592,7 +604,12 @@
592604
"metadata": {},
593605
"outputs": [],
594606
"source": [
595-
"pp.imagefigure(*(pp.Node(da.hist()) for da in result.values()), norm='log', cbar=True)"
607+
"pp.imagefigure(\n",
608+
" *(pp.Node(da.hist()) for da in result.values()),\n",
609+
" norm='log',\n",
610+
" cbar=True,\n",
611+
" vmin=1e-3,\n",
612+
")"
596613
]
597614
}
598615
],

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"source": [
5959
"workflow = dream.DreamGeant4Workflow(\n",
6060
" run_norm=powder.RunNormalization.monitor_histogram,\n",
61-
" subtract_empty_can=True,\n",
6261
")"
6362
]
6463
},
@@ -108,8 +107,11 @@
108107
"## Use the reduction workflow\n",
109108
"\n",
110109
"We then call [workflow.compute(target)](https://scipp.github.io/sciline/generated/classes/sciline.Pipeline.html#sciline.Pipeline.compute) to compute the result.\n",
111-
"`IofDspacing` is the normalized intensity as a function of $d$-spacing.\n",
112-
"`ReducedTofCIF` encode the same data but converted back to time-of-flight and ready to be written to a CIF file."
110+
"\n",
111+
"- `EmptyCanSubtractedIofDspacing` is the normalized intensity as a function of $d$-spacing.\n",
112+
"- `ReducedEmptyCanSubtractedTofCIF` encode the same data but converted back to time-of-flight and ready to be written to a CIF file.\n",
113+
"\n",
114+
"If we didn't want to subtract an empty can measurement from the sample measurement, we would instead request `IofDspacing[SampleRun]` and `ReducedTofCIF`."
113115
]
114116
},
115117
{
@@ -119,9 +121,12 @@
119121
"metadata": {},
120122
"outputs": [],
121123
"source": [
122-
"results = workflow.compute([IofDspacing, ReducedTofCIF])\n",
123-
"intensity = results[IofDspacing]\n",
124-
"cif_data = results[ReducedTofCIF]"
124+
"results = workflow.compute([\n",
125+
" EmptyCanSubtractedIofDspacing[SampleRun],\n",
126+
" ReducedEmptyCanSubtractedTofCIF\n",
127+
"])\n",
128+
"intensity = results[EmptyCanSubtractedIofDspacing[SampleRun]]\n",
129+
"cif_data = results[ReducedEmptyCanSubtractedTofCIF]"
125130
]
126131
},
127132
{
@@ -185,7 +190,7 @@
185190
"metadata": {},
186191
"outputs": [],
187192
"source": [
188-
"workflow.visualize(ReducedTofCIF, graph_attr={\"rankdir\": \"LR\"})"
193+
"workflow.visualize(ReducedEmptyCanSubtractedTofCIF, graph_attr={\"rankdir\": \"LR\"})"
189194
]
190195
},
191196
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"wfw = widget.children[1].children[0]\n",
6060
"outputs = wfw.output_selection_box.typical_outputs_widget\n",
6161
"keys, values = zip(*outputs.options, strict=True)\n",
62-
"ind = keys.index(\"IofTof\")\n",
62+
"ind = keys.index(\"IofDspacing[SampleRun]\")\n",
6363
"outputs.value = (values[ind],)\n",
6464
"# Refresh parameters\n",
6565
"pbox = wfw.parameter_box\n",
@@ -116,7 +116,7 @@
116116
"outputs": [],
117117
"source": [
118118
"(da,) = results.values()\n",
119-
"da.hist(tof=200).plot()"
119+
"da.hist(dspacing=200).plot()"
120120
]
121121
}
122122
],

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
"metadata": {},
107107
"outputs": [],
108108
"source": [
109-
"IofDspacing in workflow.get(IofDspacing).keys()"
109+
"IofDspacing[SampleRun] in workflow.get(IofDspacing[SampleRun]).keys()"
110110
]
111111
},
112112
{
@@ -116,7 +116,7 @@
116116
"metadata": {},
117117
"outputs": [],
118118
"source": [
119-
"workflow.visualize(IofDspacing, graph_attr={\"rankdir\": \"LR\"})"
119+
"workflow.visualize(IofDspacing[SampleRun], graph_attr={\"rankdir\": \"LR\"})"
120120
]
121121
},
122122
{
@@ -134,7 +134,7 @@
134134
"metadata": {},
135135
"outputs": [],
136136
"source": [
137-
"result = workflow.compute(IofDspacing)\n",
137+
"result = workflow.compute(IofDspacing[SampleRun])\n",
138138
"result"
139139
]
140140
},
@@ -172,7 +172,7 @@
172172
"outputs": [],
173173
"source": [
174174
"def save_xye(\n",
175-
" reduced_data: IofDspacing,\n",
175+
" reduced_data: IofDspacing[SampleRun],\n",
176176
" out_filename: OutFilename,\n",
177177
") -> None:\n",
178178
" data = reduced_data.hist()\n",
@@ -319,7 +319,7 @@
319319
"metadata": {},
320320
"outputs": [],
321321
"source": [
322-
"workflow.visualize(IofDspacingTwoTheta, graph_attr={\"rankdir\": \"LR\"})"
322+
"workflow.visualize(IofDspacingTwoTheta[SampleRun], graph_attr={\"rankdir\": \"LR\"})"
323323
]
324324
},
325325
{
@@ -337,7 +337,7 @@
337337
"metadata": {},
338338
"outputs": [],
339339
"source": [
340-
"grouped_dspacing = workflow.compute(IofDspacingTwoTheta)\n",
340+
"grouped_dspacing = workflow.compute(IofDspacingTwoTheta[SampleRun])\n",
341341
"grouped_dspacing"
342342
]
343343
},

src/ess/dream/io/cif.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
from ess.powder.types import (
1111
Beamline,
1212
CIFAuthors,
13+
EmptyCanSubtractedIofTof,
1314
IofTof,
15+
ReducedEmptyCanSubtractedTofCIF,
1416
ReducedTofCIF,
1517
ReducerSoftwares,
1618
Source,
@@ -53,6 +55,71 @@ def prepare_reduced_tof_cif(
5355
An object that contains the reduced data and metadata.
5456
Us its ``save`` method to write the CIF file.
5557
"""
58+
return _prepare_reduced_tof_cif_impl(
59+
da,
60+
authors=authors,
61+
beamline=beamline,
62+
source=source,
63+
reducers=reducers,
64+
calibration=calibration,
65+
)
66+
67+
68+
def prepare_reduced_empty_can_subtracted_tof_cif(
69+
da: EmptyCanSubtractedIofTof,
70+
*,
71+
authors: CIFAuthors,
72+
beamline: Beamline,
73+
source: Source,
74+
reducers: ReducerSoftwares,
75+
calibration: OutputCalibrationData,
76+
) -> ReducedEmptyCanSubtractedTofCIF:
77+
"""Construct a CIF builder with reduced data in d-spacing.
78+
79+
The object contains the d-spacing coordinate, intensities,
80+
and some metadata.
81+
82+
Parameters
83+
----------
84+
da:
85+
Reduced 1d data with a ``'tof'`` dimension and coordinate.
86+
authors:
87+
List of authors to write to the file.
88+
beamline:
89+
Information about the beamline that the data was produced at.
90+
source:
91+
Information about the neutron source.
92+
reducers:
93+
List of software pieces used to reduce the data.
94+
calibration:
95+
Coefficients for conversion between d-spacing and final ToF.
96+
See :meth:`scippneutron.io.cif.CIF.with_powder_calibration`.
97+
98+
Returns
99+
-------
100+
:
101+
An object that contains the reduced data and metadata.
102+
Us its ``save`` method to write the CIF file.
103+
"""
104+
return _prepare_reduced_tof_cif_impl(
105+
da,
106+
authors=authors,
107+
beamline=beamline,
108+
source=source,
109+
reducers=reducers,
110+
calibration=calibration,
111+
)
112+
113+
114+
def _prepare_reduced_tof_cif_impl(
115+
da: IofTof,
116+
*,
117+
authors: CIFAuthors,
118+
beamline: Beamline,
119+
source: Source,
120+
reducers: ReducerSoftwares,
121+
calibration: OutputCalibrationData,
122+
) -> ReducedTofCIF:
56123
to_save = _prepare_data(da)
57124
return ReducedTofCIF(
58125
cif.CIF('reduced_tof')

src/ess/dream/parameters.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
CalibrationFilename,
1010
DspacingBins,
1111
Filename,
12+
IofDspacing,
1213
IofDspacingTwoTheta,
13-
IofTof,
1414
MonitorFilename,
1515
NeXusDetectorName,
1616
PixelMaskFilename,
@@ -68,4 +68,8 @@
6868
# that allows to define a python function in the notebook and pass it to the workflow.
6969
# We defer this to later; the masks are set to None by default in the workflow for now.
7070

71-
typical_outputs = (IofTof, IofDspacingTwoTheta, ReducedTofCIF)
71+
typical_outputs = (
72+
IofDspacing[SampleRun],
73+
IofDspacingTwoTheta[SampleRun],
74+
ReducedTofCIF,
75+
)

0 commit comments

Comments
 (0)