Skip to content
Snippets Groups Projects
Commit fc98f195 authored by Conor Finn's avatar Conor Finn
Browse files

RE #27187 Add full calibration functionality

Currently, there is no way to load a CSV file (which is the format
that the full calibration is in) into mantid to be used by the GUI.
Until that is added, the option to select the full calibration has been
hidden from the user.
The functionality is there, so once the loading works for large CSVs the
hide() call can be removed.
parent 8ec0b318
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,9 @@ class SettingsView(QtWidgets.QDialog, Ui_settings):
self.finder_fullCalib.setLabelText("Full Calibration")
self.finder_fullCalib.isForRunFiles(False)
# TODO: Once it becomes possible to load the .csv containing the full calibration into mantid,
# this can be used. Until then, this option is hidden from the user.
self.finder_fullCalib.hide()
# ===============
# Slot Connectors
......
......@@ -18,6 +18,7 @@ from mantid.simpleapi import Load, EnggCalibrate, DeleteWorkspace, CloneWorkspac
from Engineering.EnggUtils import write_ENGINX_GSAS_iparam_file
from Engineering.gui.engineering_diffraction.tabs.common import vanadium_corrections
from Engineering.gui.engineering_diffraction.tabs.common import path_handling
from Engineering.gui.engineering_diffraction.settings.settings_helper import get_setting
VANADIUM_INPUT_WORKSPACE_NAME = "engggui_vanadium_ws"
CURVES_WORKSPACE_NAME = "engggui_vanadium_curves"
......@@ -45,8 +46,14 @@ class CalibrationModel(object):
"""
van_integration, van_curves = vanadium_corrections.fetch_correction_workspaces(
vanadium_path, instrument, rb_num=rb_num)
sample_workspace = self.load_sample(sample_path)
output = self.run_calibration(sample_workspace, van_integration, van_curves)
sample_workspace = self.load_workspace(sample_path)
full_calib_path = get_setting(path_handling.INTERFACES_SETTINGS_GROUP,
path_handling.ENGINEERING_PREFIX, "full_calibration")
if full_calib_path is not None and path.exists(full_calib_path):
full_calib = self.load_workspace(full_calib_path)
output = self.run_calibration(sample_workspace, van_integration, van_curves, full_calib_ws=full_calib)
else:
output = self.run_calibration(sample_workspace, van_integration, van_curves)
if plot_output:
self._plot_vanadium_curves()
for i in range(2):
......@@ -179,32 +186,41 @@ class CalibrationModel(object):
fig.show()
@staticmethod
def load_sample(sample_run_no):
def load_workspace(sample_run_no):
try:
return Load(Filename=sample_run_no, OutputWorkspace="engggui_calibration_sample_ws")
except Exception as e:
logger.error("Error while loading calibration sample data. "
"Could not run the algorithm Load successfully for the calibration sample "
"(run number: " + str(sample_run_no) + "). Error description: " + str(e) +
logger.error("Error while loading workspace. "
"Could not run the algorithm Load successfully for the data file "
"(path: " + str(sample_run_no) + "). Error description: " + str(e) +
" Please check also the previous log messages for details.")
raise RuntimeError
def run_calibration(self, sample_ws, van_integration, van_curves):
def run_calibration(self, sample_ws, van_integration, van_curves, full_calib_ws=None):
"""
Runs the main Engineering calibration algorithm.
:param sample_ws: The workspace with the sample data.
:param van_integration: The integration values from the vanadium corrections
:param van_curves: The curves from the vanadium corrections.
:param full_calib_ws: Full pixel calibration of the detector (optional)
:return: The output of the algorithm.
"""
output = [None] * 2
for i in range(2):
table_name = self._generate_table_workspace_name(i)
output[i] = EnggCalibrate(InputWorkspace=sample_ws,
VanIntegrationWorkspace=van_integration,
VanCurvesWorkspace=van_curves,
Bank=str(i + 1),
FittedPeaks=table_name)
if full_calib_ws is not None:
output[i] = EnggCalibrate(InputWorkspace=sample_ws,
VanIntegrationWorkspace=van_integration,
VanCurvesWorkspace=van_curves,
Bank=str(i + 1),
FittedPeaks=table_name)
else:
output[i] = EnggCalibrate(InputWorkspace=sample_ws,
VanIntegrationWorkspace=van_integration,
VanCurvesWorkspace=van_curves,
Bank=str(i + 1),
FittedPeaks=table_name,
DetectorPositions=full_calib_ws)
return output
def create_output_files(self, calibration_dir, difc, tzero, sample_path, vanadium_path,
......
......@@ -34,7 +34,7 @@ class CalibrationModelTest(unittest.TestCase):
@patch(class_path + '.update_calibration_params_table')
@patch(class_path + '.create_output_files')
@patch(class_path + '.run_calibration')
@patch(class_path + '.load_sample')
@patch(class_path + '.load_workspace')
@patch(file_path + '.vanadium_corrections.fetch_correction_workspaces')
def test_EnggVanadiumCorrections_algorithm_is_called(self, van, load_sample, calib,
output_files, update_table):
......@@ -44,7 +44,7 @@ class CalibrationModelTest(unittest.TestCase):
@patch(class_path + '.update_calibration_params_table')
@patch(class_path + '.create_output_files')
@patch(class_path + '.load_sample')
@patch(class_path + '.load_workspace')
@patch(class_path + '.run_calibration')
@patch(file_path + '.vanadium_corrections.fetch_correction_workspaces')
def test_fetch_vanadium_is_called(self, van_corr, calibrate_alg, load_sample, output_files,
......@@ -53,9 +53,26 @@ class CalibrationModelTest(unittest.TestCase):
self.model.create_new_calibration(VANADIUM_NUMBER, CERIUM_NUMBER, False, "ENGINX")
self.assertEqual(van_corr.call_count, 1)
@patch(file_path + '.path.exists')
@patch(file_path + '.get_setting')
@patch(class_path + '.update_calibration_params_table')
@patch(class_path + '.create_output_files')
@patch(class_path + '.load_sample')
@patch(class_path + '.load_workspace')
@patch(class_path + '.run_calibration')
@patch(file_path + '.vanadium_corrections.fetch_correction_workspaces')
def test_having_full_calib_set_uses_file(self, van_corr, calibrate_alg, load_workspace, output_files,
update_table, setting, path):
path.return_value = True
setting.return_value = "mocked/out/path"
van_corr.return_value = ("mocked_integration", "mocked_curves")
load_workspace.return_value = "mocked_workspace"
self.model.create_new_calibration(VANADIUM_NUMBER, CERIUM_NUMBER, False, "ENGINX")
calibrate_alg.assert_called_with("mocked_workspace", "mocked_integration", "mocked_curves",
full_calib_ws="mocked_workspace")
@patch(class_path + '.update_calibration_params_table')
@patch(class_path + '.create_output_files')
@patch(class_path + '.load_workspace')
@patch(file_path + '.vanadium_corrections.fetch_correction_workspaces')
@patch(class_path + '._plot_vanadium_curves')
@patch(class_path + '._generate_difc_tzero_workspace')
......@@ -75,7 +92,7 @@ class CalibrationModelTest(unittest.TestCase):
@patch(class_path + '.update_calibration_params_table')
@patch(class_path + '.create_output_files')
@patch(class_path + '.load_sample')
@patch(class_path + '.load_workspace')
@patch(file_path + '.vanadium_corrections.fetch_correction_workspaces')
@patch(class_path + '._plot_vanadium_curves')
@patch(class_path + '._plot_difc_tzero')
......@@ -93,7 +110,7 @@ class CalibrationModelTest(unittest.TestCase):
@patch(class_path + '.update_calibration_params_table')
@patch(class_path + '.create_output_files')
@patch(class_path + '.load_sample')
@patch(class_path + '.load_workspace')
@patch(file_path + '.vanadium_corrections.fetch_correction_workspaces')
@patch(class_path + '._plot_vanadium_curves')
@patch(class_path + '._plot_difc_tzero')
......@@ -107,7 +124,7 @@ class CalibrationModelTest(unittest.TestCase):
@patch(class_path + '.update_calibration_params_table')
@patch(class_path + '.create_output_files')
@patch(class_path + '.load_sample')
@patch(class_path + '.load_workspace')
@patch(file_path + '.vanadium_corrections.fetch_correction_workspaces')
@patch(class_path + '.run_calibration')
def test_calibration_params_table_is_updated(self, calibrate_alg, vanadium_alg, load_sample,
......
......@@ -12,6 +12,7 @@ from matplotlib import gridspec
import matplotlib.pyplot as plt
from Engineering.gui.engineering_diffraction.tabs.common import vanadium_corrections, path_handling
from Engineering.gui.engineering_diffraction.settings.settings_helper import get_setting
from mantid.simpleapi import EnggFocus, Load, logger, AnalysisDataService as Ads, SaveNexus, SaveGSS, SaveFocusedXYE
SAMPLE_RUN_WORKSPACE_NAME = "engggui_focusing_input_ws"
......@@ -35,10 +36,16 @@ class FocusModel(object):
curves_workspace = Ads.retrieve(vanadium_corrections.CURVES_WORKSPACE_NAME)
sample_workspace = self._load_focus_sample_run(sample_path)
output_workspaces = []
full_calib_path = get_setting(path_handling.INTERFACES_SETTINGS_GROUP,
path_handling.ENGINEERING_PREFIX, "full_calibration")
if full_calib_path is not None and path.exists(full_calib_path):
full_calib_workspace = self._load_focus_sample_run(full_calib_path)
else:
full_calib_workspace = None
for name in banks:
output_workspace_name = FOCUSED_OUTPUT_WORKSPACE_NAME + str(name)
self._run_focus(sample_workspace, output_workspace_name, integration_workspace,
curves_workspace, name)
curves_workspace, name, full_calib_workspace)
output_workspaces.append(output_workspace_name)
# Save the output to the file system.
self._save_output(instrument, sample_path, name, output_workspace_name, rb_num)
......@@ -47,14 +54,26 @@ class FocusModel(object):
self._plot_focused_workspaces(output_workspaces)
@staticmethod
def _run_focus(input_workspace, output_workspace, vanadium_integration_ws, vanadium_curves_ws,
bank):
def _run_focus(input_workspace,
output_workspace,
vanadium_integration_ws,
vanadium_curves_ws,
bank,
full_calib_ws=None):
try:
return EnggFocus(InputWorkspace=input_workspace,
OutputWorkspace=output_workspace,
VanIntegrationWorkspace=vanadium_integration_ws,
VanCurvesWorkspace=vanadium_curves_ws,
Bank=bank)
if full_calib_ws is not None:
return EnggFocus(InputWorkspace=input_workspace,
OutputWorkspace=output_workspace,
VanIntegrationWorkspace=vanadium_integration_ws,
VanCurvesWorkspace=vanadium_curves_ws,
Bank=bank,
DetectorPositions=full_calib_ws)
else:
return EnggFocus(InputWorkspace=input_workspace,
OutputWorkspace=output_workspace,
VanIntegrationWorkspace=vanadium_integration_ws,
VanCurvesWorkspace=vanadium_curves_ws,
Bank=bank)
except RuntimeError as e:
logger.error(
"Error in focusing, Could not run the EnggFocus algorithm successfully for bank " +
......
......@@ -45,7 +45,7 @@ class FocusModelTest(unittest.TestCase):
self.assertEqual(len(banks), run_focus.call_count)
run_focus.assert_called_with("mocked_sample",
model.FOCUSED_OUTPUT_WORKSPACE_NAME + banks[-1], "test_wsp",
"test_wsp", banks[-1])
"test_wsp", banks[-1], None)
@patch(file_path + ".Ads")
@patch(file_path + ".FocusModel._save_output")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment