From dd96ae1880ad09e1ac489ca6c8a9de3b9c18d8c6 Mon Sep 17 00:00:00 2001 From: Joseph Ramsay <joseph.ramsay@stfc.ac.uk> Date: Tue, 24 Oct 2017 15:27:00 +0100 Subject: [PATCH] Re #20877 Implemented unit test for PEARL create cal --- .../ISIS_Powder/input/PEARL00098494.nxs.md5 | 1 + .../tests/analysis/ISIS_PowderPearlTest.py | 40 ++++++++++++++++++- .../ISIS_Powder-PEARL98494_grouped.nxs.md5 | 1 + .../pearl_routines/pearl_calibration_algs.py | 13 +++--- 4 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 Testing/Data/SystemTest/ISIS_Powder/input/PEARL00098494.nxs.md5 create mode 100644 Testing/SystemTests/tests/analysis/reference/ISIS_Powder-PEARL98494_grouped.nxs.md5 diff --git a/Testing/Data/SystemTest/ISIS_Powder/input/PEARL00098494.nxs.md5 b/Testing/Data/SystemTest/ISIS_Powder/input/PEARL00098494.nxs.md5 new file mode 100644 index 00000000000..bb209053d4c --- /dev/null +++ b/Testing/Data/SystemTest/ISIS_Powder/input/PEARL00098494.nxs.md5 @@ -0,0 +1 @@ +c13f59f8155dc56e59d0412511b80b5d \ No newline at end of file diff --git a/Testing/SystemTests/tests/analysis/ISIS_PowderPearlTest.py b/Testing/SystemTests/tests/analysis/ISIS_PowderPearlTest.py index 98ae85c2bdf..28581866f3d 100644 --- a/Testing/SystemTests/tests/analysis/ISIS_PowderPearlTest.py +++ b/Testing/SystemTests/tests/analysis/ISIS_PowderPearlTest.py @@ -87,9 +87,34 @@ class FocusTest(stresstesting.MantidStressTest): mantid.mtd.clear() +class CreateCalTest(stresstesting.MantidStressTest): + + calibration_results = None + existing_config = config["datasearch.directories"] + + def requiredFiles(self): + return _gen_required_files() + + def runTest(self): + setup_mantid_paths() + self.calibration_results = run_create_cal() + + def valid(self): + return ceria_validator(self.calibration_results) + + def cleanup(self): + try: + _try_delete(spline_path) + _try_delete(output_dir) + finally: + config['datasearch.directories'] = self.existing_config + mantid.mtd.clear() + + def _gen_required_files(): required_run_numbers = ["98472", "98485", # create_van - "98507", "98472_splined"] # Focus (Si) + "98507", "98472_splined", # Focus (Si) + "98494"] # create_cal (Ce) # Generate file names of form "INSTxxxxx.nxs" - PEARL requires 000 padding input_files = [os.path.join(input_dir, (inst_name + "000" + number + ".nxs")) for number in required_run_numbers] @@ -97,6 +122,12 @@ def _gen_required_files(): return input_files +def run_create_cal(): + ceria_run = 98494 + inst_obj = setup_inst_object(mode="tt88") + return inst_obj.create_cal(run_number=ceria_run) + + def run_vanadium_calibration(): vanadium_run = 98507 # Choose arbitrary run in the cycle 17_1 @@ -141,10 +172,15 @@ def focus_validation(results): return _compare_ws(reference_file_name=reference_file_name, results=results) +def ceria_validator(results): + reference_file_name = "ISIS_Powder-PEARL00098494_grouped.nxs" + return _compare_ws(reference_file_name=reference_file_name, results=results) + + def _compare_ws(reference_file_name, results): ref_ws = mantid.Load(Filename=reference_file_name) - is_valid = True if len(results) > 0 else False + is_valid = len(results) > 0 for ws, ref in zip(results, ref_ws): if not (mantid.CompareWorkspaces(Workspace1=ws, Workspace2=ref)): diff --git a/Testing/SystemTests/tests/analysis/reference/ISIS_Powder-PEARL98494_grouped.nxs.md5 b/Testing/SystemTests/tests/analysis/reference/ISIS_Powder-PEARL98494_grouped.nxs.md5 new file mode 100644 index 00000000000..85159fd3ae5 --- /dev/null +++ b/Testing/SystemTests/tests/analysis/reference/ISIS_Powder-PEARL98494_grouped.nxs.md5 @@ -0,0 +1 @@ +b957a6b0928e12a8c86284ea010df429 \ No newline at end of file diff --git a/scripts/Diffraction/isis_powder/pearl_routines/pearl_calibration_algs.py b/scripts/Diffraction/isis_powder/pearl_routines/pearl_calibration_algs.py index 095fbfd1657..9a7d7138362 100644 --- a/scripts/Diffraction/isis_powder/pearl_routines/pearl_calibration_algs.py +++ b/scripts/Diffraction/isis_powder/pearl_routines/pearl_calibration_algs.py @@ -33,10 +33,10 @@ def create_calibration(calibration_runs, instrument, offset_file_name, grouping_ cross_correlated = mantid.CrossCorrelate(InputWorkspace=rebinned, **cross_correlate_params) offset_file = os.path.join(calibration_dir, offset_file_name) - offset_ws = "offsets" - # Name must be given as a string so it can be deleted later, as simpleapi doesn't recognise offsets as a workspace - mantid.GetDetectorOffsets(InputWorkspace=cross_correlated, GroupingFileName=offset_file, OutputWorkspace=offset_ws, - **get_det_offset_params) + # Offsets workspace must be referenced as string so it can be deleted, as simpleapi doesn't recognise it as a ws + offsets_ws_name = "offsets" + offsets = mantid.GetDetectorOffsets(InputWorkspace=cross_correlated, GroupingFileName=offset_file, + OutputWorkspace=offsets_ws_name, **get_det_offset_params) rebinned_tof = mantid.ConvertUnits(InputWorkspace=rebinned, Target="TOF") aligned = mantid.AlignDetectors(InputWorkspace=rebinned_tof, CalibrationFile=offset_file) @@ -46,5 +46,6 @@ def create_calibration(calibration_runs, instrument, offset_file_name, grouping_ OutputWorkspace=instrument._generate_output_file_name(calibration_runs) + "_grouped") - common.remove_intermediate_workspace([calibration_ws, rebinned, cross_correlated, - offset_ws, rebinned_tof, aligned]) + common.remove_intermediate_workspace([calibration_ws, rebinned, cross_correlated, rebinned_tof, aligned, + offsets_ws_name]) + return focused -- GitLab