From 29e735345f0d6651c0c338f1cc4f8c6399d9bfbf Mon Sep 17 00:00:00 2001 From: Ross Whitfield Date: Fri, 14 Jun 2024 15:11:40 +1000 Subject: [PATCH] Update SNSPowderReduction to be able to use new compression options --- .../plugins/algorithms/SNSPowderReduction.py | 37 ++++++++--- .../tests/framework/SNSPowderRedux.py | 63 +++++++++++++++++++ .../Diffraction/Powder/New_features/37517.rst | 1 + 3 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 docs/source/release/v6.11.0/Diffraction/Powder/New_features/37517.rst diff --git a/Framework/PythonInterface/plugins/algorithms/SNSPowderReduction.py b/Framework/PythonInterface/plugins/algorithms/SNSPowderReduction.py index cd925af304eb..7c6b7c0ea366 100644 --- a/Framework/PythonInterface/plugins/algorithms/SNSPowderReduction.py +++ b/Framework/PythonInterface/plugins/algorithms/SNSPowderReduction.py @@ -129,6 +129,7 @@ def getBasename(filename): class SNSPowderReduction(DataProcessorAlgorithm): COMPRESS_TOL_TOF = 0.01 + _compressBinningMode = None _resampleX = None _binning = None _bin_in_dspace = None @@ -325,6 +326,7 @@ def PyInit(self): self.declareProperty("NormalizeByCurrent", True, "Normalize by current") self.declareProperty("CompressTOFTolerance", 0.01, "Tolerance to compress events in TOF.") + self.copyProperties("AlignAndFocusPowderFromFiles", ["CompressBinningMode"]) # reduce logs being loaded self.declareProperty( @@ -455,10 +457,9 @@ def PyExec(self): # noqa self._normalisebycurrent = self.getProperty("NormalizeByCurrent").value - # Tolerance for compress TOF event. If given a negative value, then use default 0.01 + # Tolerance for compress TOF event. self.COMPRESS_TOL_TOF = float(self.getProperty("CompressTOFTolerance").value) - if self.COMPRESS_TOL_TOF < -0.0: - self.COMPRESS_TOL_TOF = 0.01 + self._compressBinningMode = self.getProperty("CompressBinningMode").value # Clean the cache directory if so requested if self._clean_cache: @@ -637,8 +638,13 @@ def PyExec(self): # noqa api.Scale(InputWorkspace=can_run_ws_name, OutputWorkspace=can_run_ws_name, Factor=self._containerScaleFactor) api.Minus(LHSWorkspace=sam_ws_name, RHSWorkspace=can_run_ws_name, OutputWorkspace=sam_ws_name) # compress event if the sample run workspace is EventWorkspace - if is_event_workspace(sam_ws_name) and self.COMPRESS_TOL_TOF > 0.0: - api.CompressEvents(InputWorkspace=sam_ws_name, OutputWorkspace=sam_ws_name, Tolerance=self.COMPRESS_TOL_TOF) # 10ns + if is_event_workspace(sam_ws_name) and self.COMPRESS_TOL_TOF != 0.0: + api.CompressEvents( + InputWorkspace=sam_ws_name, + OutputWorkspace=sam_ws_name, + Tolerance=self.COMPRESS_TOL_TOF, + BinningMode=self._compressBinningMode, + ) # 10ns # canRun = str(canRun) if van_run_ws_name is not None: @@ -659,8 +665,13 @@ def PyExec(self): # noqa normalized = False # Compress the event again - if is_event_workspace(sam_ws_name) and self.COMPRESS_TOL_TOF > 0.0: - api.CompressEvents(InputWorkspace=sam_ws_name, OutputWorkspace=sam_ws_name, Tolerance=self.COMPRESS_TOL_TOF) # 5ns/ + if is_event_workspace(sam_ws_name) and self.COMPRESS_TOL_TOF != 0.0: + api.CompressEvents( + InputWorkspace=sam_ws_name, + OutputWorkspace=sam_ws_name, + Tolerance=self.COMPRESS_TOL_TOF, + BinningMode=self._compressBinningMode, + ) # 5ns if self._scaleFactor != 1.0: api.Scale(sam_ws_name, Factor=self._scaleFactor, OutputWorkspace=sam_ws_name) @@ -905,6 +916,7 @@ def _focusAndSum(self, filenames, preserveEvents=True, final_name=None, absorpti PreserveEvents=preserveEvents, RemovePromptPulseWidth=self._removePromptPulseWidth, CompressTolerance=self.COMPRESS_TOL_TOF, + CompressBinningMode=self._compressBinningMode, LorentzCorrection=self._lorentz, UnwrapRef=self._LRef, LowResRef=self._DIFCref, @@ -1019,6 +1031,7 @@ def _focusChunks(self, filename, filter_wall=(0.0, 0.0), splitwksp=None, preserv PreserveEvents=preserveEvents, RemovePromptPulseWidth=self._removePromptPulseWidth, CompressTolerance=self.COMPRESS_TOL_TOF, + CompressBinningMode=self._compressBinningMode, LorentzCorrection=self._lorentz, UnwrapRef=self._LRef, LowResRef=self._DIFCref, @@ -1081,11 +1094,12 @@ def _focusChunks(self, filename, filter_wall=(0.0, 0.0), splitwksp=None, preserv # Compress events for split_index in range(num_out_wksp): - if is_event_workspace(output_wksp_list[split_index]) and self.COMPRESS_TOL_TOF > 0.0: + if is_event_workspace(output_wksp_list[split_index]) and self.COMPRESS_TOL_TOF != 0.0: api.CompressEvents( InputWorkspace=output_wksp_list[split_index], OutputWorkspace=output_wksp_list[split_index], Tolerance=self.COMPRESS_TOL_TOF, + BinningMode=self._compressBinningMode, ) # 100ns try: if self._normalisebycurrent is True: @@ -1580,9 +1594,12 @@ def _process_vanadium_runs(self, van_run_number_list, samRunIndex, **dummy_focus ) # compress events - if is_event_workspace(van_run_ws_name) and self.COMPRESS_TOL_TOF > 0.0: + if is_event_workspace(van_run_ws_name) and self.COMPRESS_TOL_TOF != 0.0: api.CompressEvents( - InputWorkspace=van_run_ws_name, OutputWorkspace=van_run_ws_name, Tolerance=self.COMPRESS_TOL_TOF + InputWorkspace=van_run_ws_name, + OutputWorkspace=van_run_ws_name, + Tolerance=self.COMPRESS_TOL_TOF, + BinningMode=self._compressBinningMode, ) # 10ns except RuntimeError as e: self.log().warning("Failed to process vanadium background. Skipping: {}".format(e)) diff --git a/Testing/SystemTests/tests/framework/SNSPowderRedux.py b/Testing/SystemTests/tests/framework/SNSPowderRedux.py index 68c68f5885b1..931830f36851 100644 --- a/Testing/SystemTests/tests/framework/SNSPowderRedux.py +++ b/Testing/SystemTests/tests/framework/SNSPowderRedux.py @@ -489,3 +489,66 @@ def runTest(self): # Check volume using height value from log - pi*(r^2)*h, r and h in meters assert mtd["PG3_46577"].sample().getShape().volume() == np.pi * np.square(0.00295) * 0.020 + + +class LogarithmicTest(systemtesting.MantidSystemTest): + cal_file = "PG3_FERNS_d4832_2011_08_24.cal" + char_file = "PG3_characterization_2012_02_23-HR-ILL.txt" + ref_file = "PG3_9829_sum_reference.gsa" + data_file = "PG3_9829_event.nxs" + expected_ws_name = "sns_powder_expected" + + def cleanup(self): + return True + + def requiredMemoryMB(self): + """Requires 2Gb""" + return 2000 + + def requiredFiles(self): + files = [self.cal_file, self.char_file, self.ref_file, self.data_file] + return files + + def runTest(self): + savedir = getSaveDir() + + results = PDLoadCharacterizations(Filename=self.char_file, OutputWorkspace="characterizations") + + AlignAndFocusPowderFromFiles( + Filename=self.data_file, + FilterBadPulses=95.0, + OutputWorkspace=self.expected_ws_name, + Characterizations="characterizations", + CalFileName=self.cal_file, + Params=0.01, + CompressTolerance=-0.001, + CompressBinningMode="Logarithmic", + PrimaryFlightPath=results.PrimaryFlightPath, + SpectrumIDs=results.SpectrumIDs, + L2=results.L2, + Polar=results.Polar, + Azimuthal=results.Azimuthal, + ) + CompressEvents( + InputWorkspace=self.expected_ws_name, OutputWorkspace=self.expected_ws_name, Tolerance=-0.001, BinningMode="Logarithmic" + ) + ConvertUnits(InputWorkspace=self.expected_ws_name, OutputWorkspace=self.expected_ws_name, Target="dSpacing") + + SNSPowderReduction( + Filename="PG3_9829", + VanadiumNumber=-1, + CalibrationFile=self.cal_file, + CharacterizationRunsFile=self.char_file, + Binning=0.01, + CompressTOFTolerance=-0.001, + CompressBinningMode="Logarithmic", + OutputDirectory=savedir, + NormalizeByCurrent=False, + ) + + def validateMethod(self): + self.tolerance = 1.0e-5 + return "ValidateWorkspaceToWorkspace" + + def validate(self): + return ("PG3_9829", self.expected_ws_name) diff --git a/docs/source/release/v6.11.0/Diffraction/Powder/New_features/37517.rst b/docs/source/release/v6.11.0/Diffraction/Powder/New_features/37517.rst new file mode 100644 index 000000000000..84426e0d658e --- /dev/null +++ b/docs/source/release/v6.11.0/Diffraction/Powder/New_features/37517.rst @@ -0,0 +1 @@ +- :ref:`SNSPowderReduction ` has been updated to take advantage of new capabilities in :ref:`AlignAndFocusPowderFromFiles ` and :ref:`AlignAndFocusPowder `