Skip to content

Commit f63c622

Browse files
generate unfocussed after the preprocessingrecipe, as well as rebin it (#656)
* generate unfocussed after the preprocessingrecipe, as well as rebin it * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update unit tests --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d3751cf commit f63c622

File tree

5 files changed

+151
-28
lines changed

5 files changed

+151
-28
lines changed

pixi.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/snapred/backend/recipe/ReductionRecipe.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,29 @@ def _prepareUnfocusedData(
158158
OutputWorkspace=preOutputUnfocWs,
159159
)
160160

161+
self.mantidSnapper.ConvertUnits(
162+
"Converting unfocused data to TOF",
163+
InputWorkspace=preOutputUnfocWs,
164+
OutputWorkspace=preOutputUnfocWs,
165+
Target="TOF",
166+
)
167+
168+
self.mantidSnapper.Rebin(
169+
"Rebin in log TOF",
170+
InputWorkspace=preOutputUnfocWs,
171+
Params=Config["constants.ReductionRecipe.unfocussed.Rebin.Params"],
172+
PreserveEvents=Config["constants.ReductionRecipe.unfocussed.Rebin.PreserveEvents"],
173+
OutputWorkspace=preOutputUnfocWs,
174+
BinningMode="Logarithmic",
175+
)
176+
177+
self.mantidSnapper.ConvertUnits(
178+
"Converting unfocused data to dSpacing",
179+
InputWorkspace=preOutputUnfocWs,
180+
OutputWorkspace=preOutputUnfocWs,
181+
Target="dSpacing",
182+
)
183+
161184
self.mantidSnapper.ConvertUnits(
162185
f"Converting unfocused data to {units}",
163186
InputWorkspace=preOutputUnfocWs,
@@ -266,10 +289,6 @@ def queueAlgos(self):
266289
def execute(self):
267290
data: Dict[str, Any] = {"result": False}
268291

269-
# Retain unfocused data for comparison.
270-
if self.keepUnfocused:
271-
data["unfocusedWS"] = self._prepareUnfocusedData(self.sampleWs, self.maskWs, self.convertUnitsTo)
272-
273292
outputs = []
274293

275294
if bool(self.maskWs) and all(
@@ -306,6 +325,10 @@ def execute(self):
306325
)
307326
self._cloneIntermediateWorkspace(self.sampleWs, "sample_preprocessed")
308327

328+
# Retain unfocused data for comparison.
329+
if self.keepUnfocused:
330+
data["unfocusedWS"] = self._prepareUnfocusedData(self.sampleWs, None, self.convertUnitsTo)
331+
309332
if self.normalizationWs:
310333
# If artificial normalization is being used, there won't be any incoming normalization workspace.
311334
# NOTE: This MASKS the ws, this is not reversible.

src/snapred/resources/application.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ constants:
336336
RawVanadiumCorrection:
337337
numberOfSlices: 10
338338
numberOfAnnuli: 10
339+
ReductionRecipe:
340+
unfocussed:
341+
Rebin:
342+
Params: "-0.002"
343+
PreserveEvents: true
339344
ResampleX:
340345
NumberBins: 1500
341346

tests/resources/application.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ constants:
323323
m2cm: 10000.0 # conversion factor for m^2 to cm^2
324324
maskedPixelThreshold: 0.15
325325

326+
ReductionRecipe:
327+
unfocussed:
328+
Rebin:
329+
Params: "-0.002"
330+
PreserveEvents: true
331+
326332
CrystallographicInfo:
327333
crystalDMin: 0.4
328334
crystalDMax: 100.0

tests/unit/backend/recipe/test_ReductionRecipe.py

Lines changed: 107 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -152,49 +152,121 @@ def test_prepareUnfocusedData(self):
152152

153153
# TODO: All units are tested here for now, this will be changed when EWM 6615 is completed
154154
units = "dSpacing"
155-
msg = f"Converting unfocused data to {units}"
156155
recipe._prepareUnfocusedData(workspace, None, units)
157156
outputWs = (
158157
wng.run().runNumber("555").lite(True).unit(wng.Units.DSP).group(wng.Groups.UNFOC).hidden(True).build()
159158
)
160-
recipe.mantidSnapper.ConvertUnits.assert_called_once_with(
161-
msg, InputWorkspace=outputWs, OutputWorkspace=outputWs, Target=units
159+
recipe.mantidSnapper.ConvertUnits.assert_has_calls(
160+
[
161+
mock.call(
162+
"Converting unfocused data to TOF",
163+
InputWorkspace=outputWs,
164+
OutputWorkspace=outputWs,
165+
Target="TOF",
166+
),
167+
mock.call(
168+
"Converting unfocused data to dSpacing",
169+
InputWorkspace=outputWs,
170+
OutputWorkspace=outputWs,
171+
Target="dSpacing",
172+
),
173+
mock.call(
174+
f"Converting unfocused data to {units}",
175+
InputWorkspace=outputWs,
176+
OutputWorkspace=outputWs,
177+
Target=units,
178+
),
179+
]
162180
)
163181
recipe.mantidSnapper.executeQueue.assert_called()
164182
recipe.mantidSnapper.reset_mock()
165183

166184
units = "MomentumTransfer"
167-
msg = f"Converting unfocused data to {units}"
168185
recipe._prepareUnfocusedData(workspace, None, units)
169186
outputWs = (
170187
wng.run().runNumber("555").lite(True).unit(wng.Units.QSP).group(wng.Groups.UNFOC).hidden(True).build()
171188
)
172-
recipe.mantidSnapper.ConvertUnits.assert_called_once_with(
173-
msg, InputWorkspace=outputWs, OutputWorkspace=outputWs, Target=units
189+
recipe.mantidSnapper.ConvertUnits.assert_has_calls(
190+
[
191+
mock.call(
192+
"Converting unfocused data to TOF",
193+
InputWorkspace=outputWs,
194+
OutputWorkspace=outputWs,
195+
Target="TOF",
196+
),
197+
mock.call(
198+
"Converting unfocused data to dSpacing",
199+
InputWorkspace=outputWs,
200+
OutputWorkspace=outputWs,
201+
Target="dSpacing",
202+
),
203+
mock.call(
204+
f"Converting unfocused data to {units}",
205+
InputWorkspace=outputWs,
206+
OutputWorkspace=outputWs,
207+
Target=units,
208+
),
209+
]
174210
)
175211
recipe.mantidSnapper.executeQueue.assert_called()
176212
recipe.mantidSnapper.reset_mock()
177213

178214
units = "Wavelength"
179-
msg = f"Converting unfocused data to {units}"
180215
recipe._prepareUnfocusedData(workspace, None, units)
181216
outputWs = (
182217
wng.run().runNumber("555").lite(True).unit(wng.Units.LAM).group(wng.Groups.UNFOC).hidden(True).build()
183218
)
184-
recipe.mantidSnapper.ConvertUnits.assert_called_once_with(
185-
msg, InputWorkspace=outputWs, OutputWorkspace=outputWs, Target=units
219+
recipe.mantidSnapper.ConvertUnits.assert_has_calls(
220+
[
221+
mock.call(
222+
"Converting unfocused data to TOF",
223+
InputWorkspace=outputWs,
224+
OutputWorkspace=outputWs,
225+
Target="TOF",
226+
),
227+
mock.call(
228+
"Converting unfocused data to dSpacing",
229+
InputWorkspace=outputWs,
230+
OutputWorkspace=outputWs,
231+
Target="dSpacing",
232+
),
233+
mock.call(
234+
f"Converting unfocused data to {units}",
235+
InputWorkspace=outputWs,
236+
OutputWorkspace=outputWs,
237+
Target=units,
238+
),
239+
]
186240
)
187241
recipe.mantidSnapper.executeQueue.assert_called()
188242
recipe.mantidSnapper.reset_mock()
189243

190244
units = "TOF"
191-
msg = f"Converting unfocused data to {units}"
192245
recipe._prepareUnfocusedData(workspace, None, units)
193246
outputWs = (
194247
wng.run().runNumber("555").lite(True).unit(wng.Units.TOF).group(wng.Groups.UNFOC).hidden(True).build()
195248
)
196-
recipe.mantidSnapper.ConvertUnits.assert_called_once_with(
197-
msg, InputWorkspace=outputWs, OutputWorkspace=outputWs, Target=units
249+
recipe.mantidSnapper.ConvertUnits.assert_has_calls(
250+
[
251+
mock.call(
252+
"Converting unfocused data to TOF",
253+
InputWorkspace=outputWs,
254+
OutputWorkspace=outputWs,
255+
Target="TOF",
256+
),
257+
mock.call(
258+
"Converting unfocused data to dSpacing",
259+
InputWorkspace=outputWs,
260+
OutputWorkspace=outputWs,
261+
Target="dSpacing",
262+
),
263+
mock.call(
264+
f"Converting unfocused data to {units}",
265+
InputWorkspace=outputWs,
266+
OutputWorkspace=outputWs,
267+
Target=units,
268+
),
269+
]
198270
)
199271
recipe.mantidSnapper.executeQueue.assert_called()
200272
recipe.mantidSnapper.reset_mock()
@@ -228,11 +300,28 @@ def test_prepareUnfocusedData_masking(self):
228300
recipe.mantidSnapper.MaskDetectorFlags.assert_called_once_with(
229301
"Applying pixel mask to unfocused data", MaskWorkspace=maskWs, OutputWorkspace=preOutputWs
230302
)
231-
recipe.mantidSnapper.ConvertUnits.assert_called_once_with(
232-
f"Converting unfocused data to {units}",
233-
InputWorkspace=preOutputWs,
234-
OutputWorkspace=preOutputWs,
235-
Target=units,
303+
304+
recipe.mantidSnapper.ConvertUnits.assert_has_calls(
305+
[
306+
mock.call(
307+
"Converting unfocused data to TOF",
308+
InputWorkspace=preOutputWs,
309+
OutputWorkspace=preOutputWs,
310+
Target="TOF",
311+
),
312+
mock.call(
313+
"Converting unfocused data to dSpacing",
314+
InputWorkspace=preOutputWs,
315+
OutputWorkspace=preOutputWs,
316+
Target="dSpacing",
317+
),
318+
mock.call(
319+
f"Converting unfocused data to {units}",
320+
InputWorkspace=preOutputWs,
321+
OutputWorkspace=preOutputWs,
322+
Target=units,
323+
),
324+
]
236325
)
237326

238327
# Test the output add-or-replace sequence.
@@ -320,7 +409,7 @@ def test_keepUnfocusedData(self, mockMtd):
320409
result = recipe.execute()
321410

322411
# Assertions
323-
recipe._prepareUnfocusedData.assert_called_once_with("sample", "mask", "dSpacing")
412+
recipe._prepareUnfocusedData.assert_called_once_with("sample", None, "dSpacing")
324413
# Delete the group clones (sample + norm), and the masked normalization clone.
325414
assert recipe._deleteWorkspace.call_count == 3
326415
recipe._deleteWorkspace.assert_called_with(recipe.normalizationWsMasked)

0 commit comments

Comments
 (0)