From 3fca60651e407eb918625734aadb06dcab35eae6 Mon Sep 17 00:00:00 2001 From: Joseph Ramsay <joseph.ramsay@stfc.ac.uk> Date: Wed, 18 Oct 2017 10:22:11 +0100 Subject: [PATCH] Re #20603 Convert unsplined vanadium to TOF and system test --- .../tests/analysis/ISIS_PowderPolarisTest.py | 14 +++++++++---- ...S_Powder-POLARIS00098533_unsplined.nxs.md5 | 1 + scripts/Diffraction/isis_powder/polaris.py | 2 +- .../polaris_routines/polaris_algs.py | 20 ++++++++++++++++--- 4 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 Testing/SystemTests/tests/analysis/reference/ISIS_Powder-POLARIS00098533_unsplined.nxs.md5 diff --git a/Testing/SystemTests/tests/analysis/ISIS_PowderPolarisTest.py b/Testing/SystemTests/tests/analysis/ISIS_PowderPolarisTest.py index 31dd2a92559..963075d6e66 100644 --- a/Testing/SystemTests/tests/analysis/ISIS_PowderPolarisTest.py +++ b/Testing/SystemTests/tests/analysis/ISIS_PowderPolarisTest.py @@ -25,6 +25,7 @@ output_folder_name = "output" calibration_folder_name = os.path.join("calibration", inst_name.lower()) calibration_map_rel_path = os.path.join("yaml_files", "polaris_system_test_mapping.yaml") spline_rel_path = os.path.join("17_1", "VanSplined_98532_cycle_16_3_silicon_all_spectra.cal.nxs") +unsplined_van_rel_path = os.path.join("17_1", "Van_98532_cycle_16_3_silicon_all_spectra.cal.nxs") # Generate paths for the tests # This implies DIRS[0] is the system test data folder @@ -36,6 +37,7 @@ output_dir = os.path.join(working_dir, output_folder_name) calibration_map_path = os.path.join(input_dir, calibration_map_rel_path) calibration_dir = os.path.join(input_dir, calibration_folder_name) spline_path = os.path.join(calibration_dir, spline_rel_path) +unsplined_van_path = os.path.join(calibration_dir, unsplined_van_rel_path) class CreateVanadiumTest(stresstesting.MantidStressTest): @@ -110,8 +112,9 @@ def run_vanadium_calibration(): if not os.path.exists(spline_path): raise RuntimeError("Could not find output spline at the following path: " + spline_path) splined_ws = mantid.Load(Filename=spline_path) + unsplined_ws = mantid.Load(Filename=unsplined_van_path) - return splined_ws + return splined_ws, unsplined_ws def run_focus(): @@ -132,9 +135,12 @@ def run_focus(): def calibration_validator(results): + splined_ws, unsplined_ws = results # Get the name of the grouped workspace list - reference_file_name = "ISIS_Powder-POLARIS00098533_splined.nxs" - return _compare_ws(reference_file_name=reference_file_name, results=results) + splined_reference_file_name = "ISIS_Powder-POLARIS00098533_splined.nxs" + unsplined_reference_file_name = "ISIS_Powder-POLARIS00098533_unsplined.nxs" + return _compare_ws(reference_file_name=splined_reference_file_name, results=splined_ws) and \ + _compare_ws(reference_file_name=unsplined_reference_file_name, results=unsplined_ws) def focus_validation(results): @@ -145,7 +151,7 @@ def focus_validation(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-POLARIS00098533_unsplined.nxs.md5 b/Testing/SystemTests/tests/analysis/reference/ISIS_Powder-POLARIS00098533_unsplined.nxs.md5 new file mode 100644 index 00000000000..9516b1abb5b --- /dev/null +++ b/Testing/SystemTests/tests/analysis/reference/ISIS_Powder-POLARIS00098533_unsplined.nxs.md5 @@ -0,0 +1 @@ +a8fb08bb0f2b7fee05ead4691d012895 \ No newline at end of file diff --git a/scripts/Diffraction/isis_powder/polaris.py b/scripts/Diffraction/isis_powder/polaris.py index 70f9f699187..c720dfcd86c 100644 --- a/scripts/Diffraction/isis_powder/polaris.py +++ b/scripts/Diffraction/isis_powder/polaris.py @@ -35,7 +35,7 @@ class Polaris(AbstractInst): self._inst_settings.update_attributes(kwargs=kwargs) vanadium_d = self._create_vanadium(run_number_string=self._inst_settings.run_in_range, do_absorb_corrections=self._inst_settings.do_absorb_corrections) - + run_details = self._get_run_details(run_number_string=self._inst_settings.run_in_range) polaris_algs.save_unsplined_vanadium(vanadium_ws=vanadium_d, output_path=run_details.unsplined_vanadium_file_path) diff --git a/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py b/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py index 4825ba40484..595da208bca 100644 --- a/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py +++ b/scripts/Diffraction/isis_powder/polaris_routines/polaris_algs.py @@ -2,7 +2,8 @@ from __future__ import (absolute_import, division, print_function) import mantid.simpleapi as mantid -from isis_powder.routines import absorb_corrections, common, common_enums +from isis_powder.routines import absorb_corrections, common +from isis_powder.routines.common_enums import WORKSPACE_UNITS from isis_powder.routines.run_details import create_run_details_object, \ CustomFuncForRunDetails, RunDetailsWrappedCommonFuncs from isis_powder.polaris_routines import polaris_advanced_config @@ -58,8 +59,21 @@ def process_vanadium_for_focusing(bank_spectra, mask_path, spline_number): def save_unsplined_vanadium(vanadium_ws, output_path): - # TODO: convert vanadium_ws to TOF - mantid.SaveNexus(InputWorkspace=vanadium_ws, Filename=output_path, Append=False) + converted_workspaces = [] + + for ws_index in range(vanadium_ws.getNumberOfEntries()): + ws = vanadium_ws.getItem(ws_index) + previous_units = ws.getAxis(0).getUnit().unitID() + + if previous_units != WORKSPACE_UNITS.tof: + ws = mantid.ConvertUnits(InputWorkspace=ws, Target=WORKSPACE_UNITS.tof) + + ws = mantid.RenameWorkspace(InputWorkspace=ws, OutputWorkspace="van_bank_{}".format(ws_index + 1)) + converted_workspaces.append(ws) + + converted_group = mantid.GroupWorkspaces(",".join(ws.getName() for ws in converted_workspaces)) + mantid.SaveNexus(InputWorkspace=converted_group, Filename=output_path, Append=False) + mantid.DeleteWorkspace(converted_group) def _apply_bragg_peaks_masking(workspaces_to_mask, mask_list): -- GitLab