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

RE #27635 Integrate changes into eng diff 2 gui

parent b7e3eff1
No related branches found
No related tags found
No related merge requests found
...@@ -74,31 +74,33 @@ class CalibrationModel(object): ...@@ -74,31 +74,33 @@ class CalibrationModel(object):
bank_name = str(i + 1) bank_name = str(i + 1)
else: else:
bank_name = bank bank_name = bank
difa = output[i].DIFA
difc = output[i].DIFC difc = output[i].DIFC
tzero = output[i].TZERO tzero = output[i].TZERO
self._generate_difc_tzero_workspace(difc, tzero, bank_name) self._generate_tof_fit_workspace(difa, difc, tzero, bank_name)
if bank is None and spectrum_numbers is None: if bank is None and spectrum_numbers is None:
self._plot_difc_tzero() self._plot_tof_fit()
elif spectrum_numbers is None: elif spectrum_numbers is None:
self._plot_difc_tzero_single_bank_or_custom(bank) self._plot_tof_fit_single_bank_or_custom(bank)
else: else:
self._plot_difc_tzero_single_bank_or_custom("cropped") self._plot_tof_fit_single_bank_or_custom("cropped")
difa = [i.DIFC for i in output]
difc = [i.DIFC for i in output] difc = [i.DIFC for i in output]
tzero = [i.TZERO for i in output] tzero = [i.TZERO for i in output]
params_table = [] params_table = []
for i in range(len(difc)): for i in range(len(difc)):
params_table.append([i, difc[i], 0.0, tzero[i]]) params_table.append([i, difc[i], difa[i], tzero[i]])
self.update_calibration_params_table(params_table) self.update_calibration_params_table(params_table)
calib_dir = path.join(path_handling.get_output_path(), "Calibration", "") calib_dir = path.join(path_handling.get_output_path(), "Calibration", "")
self.create_output_files(calib_dir, difc, tzero, sample_path, vanadium_path, instrument, self.create_output_files(calib_dir, difa, difc, tzero, sample_path, vanadium_path, instrument,
bank, spectrum_numbers) bank, spectrum_numbers)
if rb_num: if rb_num:
user_calib_dir = path.join(path_handling.get_output_path(), "User", rb_num, user_calib_dir = path.join(path_handling.get_output_path(), "User", rb_num,
"Calibration", "") "Calibration", "")
self.create_output_files(user_calib_dir, difc, tzero, sample_path, vanadium_path, self.create_output_files(user_calib_dir, difa, difc, tzero, sample_path, vanadium_path,
instrument, bank, spectrum_numbers) instrument, bank, spectrum_numbers)
def load_existing_gsas_parameters(self, file_path): def load_existing_gsas_parameters(self, file_path):
...@@ -162,20 +164,21 @@ class CalibrationModel(object): ...@@ -162,20 +164,21 @@ class CalibrationModel(object):
fig.show() fig.show()
@staticmethod @staticmethod
def _generate_difc_tzero_workspace(difc, tzero, bank): def _generate_tof_fit_workspace(difa, difc, tzero, bank):
bank_ws = Ads.retrieve(CalibrationModel._generate_table_workspace_name(bank)) bank_ws = Ads.retrieve(CalibrationModel._generate_table_workspace_name(bank))
x_val = [] x_val = []
y_val = [] y_val = []
y2_val = [] y2_val = []
difa_to_plot = difa
difc_to_plot = difc difc_to_plot = difc
tzero_to_plot = tzero tzero_to_plot = tzero
for irow in range(0, bank_ws.rowCount()): for irow in range(0, bank_ws.rowCount()):
x_val.append(bank_ws.cell(irow, 0)) x_val.append(bank_ws.cell(irow, 0))
y_val.append(bank_ws.cell(irow, 5)) y_val.append(bank_ws.cell(irow, 5))
y2_val.append(x_val[irow] * difc_to_plot + tzero_to_plot) y2_val.append(pow(x_val[irow], 2) * difa_to_plot + x_val[irow] * difc_to_plot + tzero_to_plot)
ws1 = CreateWorkspace(DataX=x_val, ws1 = CreateWorkspace(DataX=x_val,
DataY=y_val, DataY=y_val,
...@@ -183,7 +186,7 @@ class CalibrationModel(object): ...@@ -183,7 +186,7 @@ class CalibrationModel(object):
YUnitLabel="Fitted Peaks Centre(TOF, us)") YUnitLabel="Fitted Peaks Centre(TOF, us)")
ws2 = CreateWorkspace(DataX=x_val, DataY=y2_val) ws2 = CreateWorkspace(DataX=x_val, DataY=y2_val)
output_ws = "engggui_difc_zero_peaks_bank_" + str(bank) output_ws = "engggui_tof_peaks_bank_" + str(bank)
if Ads.doesExist(output_ws): if Ads.doesExist(output_ws):
DeleteWorkspace(output_ws) DeleteWorkspace(output_ws)
...@@ -192,9 +195,9 @@ class CalibrationModel(object): ...@@ -192,9 +195,9 @@ class CalibrationModel(object):
DeleteWorkspace(ws2) DeleteWorkspace(ws2)
@staticmethod @staticmethod
def _plot_difc_tzero(): def _plot_tof_fit():
bank_1_ws = Ads.retrieve("engggui_difc_zero_peaks_bank_1") bank_1_ws = Ads.retrieve("engggui_tof_peaks_bank_1")
bank_2_ws = Ads.retrieve("engggui_difc_zero_peaks_bank_2") bank_2_ws = Ads.retrieve("engggui_tof_peaks_bank_2")
# Create plot # Create plot
fig = plt.figure() fig = plt.figure()
gs = gridspec.GridSpec(1, 2) gs = gridspec.GridSpec(1, 2)
...@@ -204,13 +207,14 @@ class CalibrationModel(object): ...@@ -204,13 +207,14 @@ class CalibrationModel(object):
for ax, ws, bank in zip([plot_bank_1, plot_bank_2], [bank_1_ws, bank_2_ws], [1, 2]): for ax, ws, bank in zip([plot_bank_1, plot_bank_2], [bank_1_ws, bank_2_ws], [1, 2]):
ax.plot(ws, wkspIndex=0, linestyle="--", marker="o", markersize="3") ax.plot(ws, wkspIndex=0, linestyle="--", marker="o", markersize="3")
ax.plot(ws, wkspIndex=1, linestyle="--", marker="o", markersize="3") ax.plot(ws, wkspIndex=1, linestyle="--", marker="o", markersize="3")
ax.set_title("Engg Gui Difc Zero Peaks Bank " + str(bank)) ax.set_title("Engg Gui TOF Peaks Bank " + str(bank))
ax.legend(("Peaks Fitted", "DifC/TZero Fitted Straight Line")) ax.legend(("Peaks Fitted", "TOF Quadratic Fit"))
ax.set_xlabel("Expected Peaks Centre(dSpacing, A)") ax.set_xlabel("Expected Peaks Centre(dSpacing, A)")
ax.set_ylabel("Fitted Peaks Centre(TOF, us")
fig.show() fig.show()
@staticmethod @staticmethod
def _plot_difc_tzero_single_bank_or_custom(bank): def _plot_tof_fit_single_bank_or_custom(bank):
bank_ws = Ads.retrieve("engggui_difc_zero_peaks_bank_" + str(bank)) bank_ws = Ads.retrieve("engggui_difc_zero_peaks_bank_" + str(bank))
ax = plot([bank_ws], [0, 1], ax = plot([bank_ws], [0, 1],
...@@ -271,11 +275,12 @@ class CalibrationModel(object): ...@@ -271,11 +275,12 @@ class CalibrationModel(object):
output[0] = run_engg_calibrate(kwargs) output[0] = run_engg_calibrate(kwargs)
return output return output
def create_output_files(self, calibration_dir, difc, tzero, sample_path, vanadium_path, def create_output_files(self, calibration_dir, difa, difc, tzero, sample_path, vanadium_path,
instrument, bank, spectrum_numbers): instrument, bank, spectrum_numbers):
""" """
Create output files from the algorithms in the specified directory Create output files from the algorithms in the specified directory
:param calibration_dir: The directory to save the files into. :param calibration_dir: The directory to save the files into.
:param difa: DIFA values from calibration algorithm
:param difc: DIFC values from the calibration algorithm. :param difc: DIFC values from the calibration algorithm.
:param tzero: TZERO values from the calibration algorithm. :param tzero: TZERO values from the calibration algorithm.
:param sample_path: The path to the sample data file. :param sample_path: The path to the sample data file.
...@@ -294,29 +299,29 @@ class CalibrationModel(object): ...@@ -294,29 +299,29 @@ class CalibrationModel(object):
kwargs["template_file"] = NORTH_BANK_TEMPLATE_FILE kwargs["template_file"] = NORTH_BANK_TEMPLATE_FILE
kwargs["bank_names"] = ["North"] kwargs["bank_names"] = ["North"]
def generate_output_file(difc_list, tzero_list, bank_name, kwargs_to_pass): def generate_output_file(difa_list, difc_list, tzero_list, bank_name, kwargs_to_pass):
file_path = calibration_dir + self._generate_output_file_name(vanadium_path, sample_path, instrument, file_path = calibration_dir + self._generate_output_file_name(vanadium_path, sample_path, instrument,
bank=bank_name) bank=bank_name)
write_ENGINX_GSAS_iparam_file(file_path, difc_list, tzero_list, **kwargs_to_pass) write_ENGINX_GSAS_iparam_file(file_path, difa_list, difc_list, tzero_list, **kwargs_to_pass)
if not path.exists(calibration_dir): if not path.exists(calibration_dir):
makedirs(calibration_dir) makedirs(calibration_dir)
if bank is None and spectrum_numbers is None: if bank is None and spectrum_numbers is None:
generate_output_file(difc, tzero, "all", kwargs) generate_output_file(difa, difc, tzero, "all", kwargs)
north_kwargs() north_kwargs()
generate_output_file([difc[0]], [tzero[0]], "north", kwargs) generate_output_file([difa[0]], [difc[0]], [tzero[0]], "north", kwargs)
south_kwargs() south_kwargs()
generate_output_file([difc[1]], [tzero[1]], "south", kwargs) generate_output_file([difa[1]], [difc[1]], [tzero[1]], "south", kwargs)
elif bank == "1": elif bank == "1":
north_kwargs() north_kwargs()
generate_output_file([difc[0]], [tzero[0]], "north", kwargs) generate_output_file([difa[0]], [difc[0]], [tzero[0]], "north", kwargs)
elif bank == "2": elif bank == "2":
south_kwargs() south_kwargs()
generate_output_file([difc[0]], [tzero[0]], "south", kwargs) generate_output_file([difa[0]], [difc[0]], [tzero[0]], "south", kwargs)
elif bank is None: # Custom cropped files use the north bank template. elif bank is None: # Custom cropped files use the north bank template.
north_kwargs() north_kwargs()
generate_output_file([difc[0]], [tzero[0]], "cropped", kwargs) generate_output_file([difa[0]], [difc[0]], [tzero[0]], "cropped", kwargs)
@staticmethod @staticmethod
def get_info_from_file(file_path): def get_info_from_file(file_path):
......
...@@ -82,54 +82,54 @@ class CalibrationModelTest(unittest.TestCase): ...@@ -82,54 +82,54 @@ class CalibrationModelTest(unittest.TestCase):
@patch(file_path + ".path_handling.load_workspace") @patch(file_path + ".path_handling.load_workspace")
@patch(file_path + '.vanadium_corrections.fetch_correction_workspaces') @patch(file_path + '.vanadium_corrections.fetch_correction_workspaces')
@patch(class_path + '._plot_vanadium_curves') @patch(class_path + '._plot_vanadium_curves')
@patch(class_path + '._generate_difc_tzero_workspace') @patch(class_path + '._generate_tof_fit_workspace')
@patch(class_path + '._plot_difc_tzero') @patch(class_path + '._plot_tof_fit')
@patch(class_path + '.run_calibration') @patch(class_path + '.run_calibration')
def test_plotting_check(self, calib, plot_difc_zero, gen_difc, plot_van, van, sample, def test_plotting_check(self, calib, plot_tof, gen_tof, plot_van, van, sample,
output_files, update_table): output_files, update_table):
calib.return_value = [MagicMock(), MagicMock()] calib.return_value = [MagicMock(), MagicMock()]
van.return_value = ("A", "B") van.return_value = ("A", "B")
self.model.create_new_calibration(VANADIUM_NUMBER, CERIUM_NUMBER, False, "ENGINX") self.model.create_new_calibration(VANADIUM_NUMBER, CERIUM_NUMBER, False, "ENGINX")
plot_van.assert_not_called() plot_van.assert_not_called()
plot_difc_zero.assert_not_called() plot_tof.assert_not_called()
gen_difc.assert_not_called() gen_tof.assert_not_called()
self.model.create_new_calibration(VANADIUM_NUMBER, CERIUM_NUMBER, True, "ENGINX") self.model.create_new_calibration(VANADIUM_NUMBER, CERIUM_NUMBER, True, "ENGINX")
plot_van.assert_called_once() plot_van.assert_called_once()
self.assertEqual(gen_difc.call_count, 2) self.assertEqual(gen_tof.call_count, 2)
self.assertEqual(plot_difc_zero.call_count, 1) self.assertEqual(plot_tof.call_count, 1)
@patch(class_path + '.update_calibration_params_table') @patch(class_path + '.update_calibration_params_table')
@patch(class_path + '.create_output_files') @patch(class_path + '.create_output_files')
@patch(file_path + ".path_handling.load_workspace") @patch(file_path + ".path_handling.load_workspace")
@patch(file_path + '.vanadium_corrections.fetch_correction_workspaces') @patch(file_path + '.vanadium_corrections.fetch_correction_workspaces')
@patch(class_path + '._plot_vanadium_curves') @patch(class_path + '._plot_vanadium_curves')
@patch(class_path + '._generate_difc_tzero_workspace') @patch(class_path + '._generate_tof_fit_workspace')
@patch(class_path + '._plot_difc_tzero') @patch(class_path + '._plot_tof_fit')
@patch(class_path + '._plot_difc_tzero_single_bank_or_custom') @patch(class_path + '._plot_tof_fit_single_bank_or_custom')
@patch(class_path + '.run_calibration') @patch(class_path + '.run_calibration')
def test_plotting_check_cropped(self, calib, plot_difc_zero_cus, plot_difc_zero, gen_difc, def test_plotting_check_cropped(self, calib, plot_tof_cus, plot_tof_fit, gen_tof,
plot_van, van, sample, output_files, update_table): plot_van, van, sample, output_files, update_table):
calib.return_value = [MagicMock()] calib.return_value = [MagicMock()]
van.return_value = ("A", "B") van.return_value = ("A", "B")
self.model.create_new_calibration(VANADIUM_NUMBER, CERIUM_NUMBER, False, "ENGINX") self.model.create_new_calibration(VANADIUM_NUMBER, CERIUM_NUMBER, False, "ENGINX")
plot_van.assert_not_called() plot_van.assert_not_called()
plot_difc_zero_cus.assert_not_called() plot_tof_cus.assert_not_called()
plot_difc_zero.assert_not_called() plot_tof_fit.assert_not_called()
gen_difc.assert_not_called() gen_tof.assert_not_called()
self.model.create_new_calibration(VANADIUM_NUMBER, CERIUM_NUMBER, True, "ENGINX", bank=1) self.model.create_new_calibration(VANADIUM_NUMBER, CERIUM_NUMBER, True, "ENGINX", bank=1)
plot_van.assert_called_once() plot_van.assert_called_once()
self.assertEqual(gen_difc.call_count, 1) self.assertEqual(gen_tof.call_count, 1)
plot_difc_zero.assert_not_called() plot_tof_fit.assert_not_called()
self.assertEqual(plot_difc_zero_cus.call_count, 1) self.assertEqual(plot_tof_cus.call_count, 1)
@patch(class_path + '.update_calibration_params_table') @patch(class_path + '.update_calibration_params_table')
@patch(class_path + '.create_output_files') @patch(class_path + '.create_output_files')
@patch(file_path + ".path_handling.load_workspace") @patch(file_path + ".path_handling.load_workspace")
@patch(file_path + '.vanadium_corrections.fetch_correction_workspaces') @patch(file_path + '.vanadium_corrections.fetch_correction_workspaces')
@patch(class_path + '._plot_vanadium_curves') @patch(class_path + '._plot_vanadium_curves')
@patch(class_path + '._plot_difc_tzero') @patch(class_path + '._plot_tof_fit')
@patch(class_path + '.run_calibration') @patch(class_path + '.run_calibration')
def test_present_RB_number_results_in_user_output_files(self, calib, plot_difc_zero, plot_van, def test_present_RB_number_results_in_user_output_files(self, calib, plot_tof, plot_van,
van, sample, output_files, van, sample, output_files,
update_table): update_table):
van.return_value = ("A", "B") van.return_value = ("A", "B")
...@@ -145,9 +145,9 @@ class CalibrationModelTest(unittest.TestCase): ...@@ -145,9 +145,9 @@ class CalibrationModelTest(unittest.TestCase):
@patch(file_path + ".path_handling.load_workspace") @patch(file_path + ".path_handling.load_workspace")
@patch(file_path + '.vanadium_corrections.fetch_correction_workspaces') @patch(file_path + '.vanadium_corrections.fetch_correction_workspaces')
@patch(class_path + '._plot_vanadium_curves') @patch(class_path + '._plot_vanadium_curves')
@patch(class_path + '._plot_difc_tzero') @patch(class_path + '._plot_tof_fit')
@patch(class_path + '.run_calibration') @patch(class_path + '.run_calibration')
def test_absent_run_number_results_in_no_user_output_files(self, calib, plot_difc_zero, def test_absent_run_number_results_in_no_user_output_files(self, calib, plot_tof,
plot_van, van, sample, output_files, plot_van, van, sample, output_files,
update_table): update_table):
van.return_value = ("A", "B") van.return_value = ("A", "B")
...@@ -176,7 +176,7 @@ class CalibrationModelTest(unittest.TestCase): ...@@ -176,7 +176,7 @@ class CalibrationModelTest(unittest.TestCase):
filename = "output" filename = "output"
output_name.return_value = filename output_name.return_value = filename
self.model.create_output_files("test/", [0, 0], [1, 1], self.model.create_output_files("test/", [2, 2], [0, 0], [1, 1],
sample_path, sample_path,
vanadium_path, vanadium_path,
"ENGINX", "ENGINX",
...@@ -185,7 +185,7 @@ class CalibrationModelTest(unittest.TestCase): ...@@ -185,7 +185,7 @@ class CalibrationModelTest(unittest.TestCase):
self.assertEqual(make_dirs.call_count, 1) self.assertEqual(make_dirs.call_count, 1)
self.assertEqual(write_file.call_count, 3) self.assertEqual(write_file.call_count, 3)
write_file.assert_called_with("test/" + filename, [0], [1], write_file.assert_called_with("test/" + filename, [2], [0], [1],
bank_names=['South'], bank_names=['South'],
ceria_run=sample_path, ceria_run=sample_path,
template_file="template_ENGINX_241391_236516_South_bank.prm", template_file="template_ENGINX_241391_236516_South_bank.prm",
......
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