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

RE #27187 Use save location in GUI functionality

parent db24ee83
No related branches found
No related tags found
No related merge requests found
......@@ -8,12 +8,10 @@
from __future__ import (absolute_import, division, print_function)
from Engineering.gui.engineering_diffraction.settings.settings_helper import get_setting, set_setting
from Engineering.gui.engineering_diffraction.tabs.common import path_handling
class SettingsModel(object):
INTERFACES_SETTINGS_GROUP = "CustomInterfaces"
ENGINEERING_PREFIX = "EngineeringDiffraction2/"
def get_settings_dict(self, keys):
settings = {}
for setting_name in keys:
......@@ -24,8 +22,10 @@ class SettingsModel(object):
for key in settings:
self.set_setting(key, settings[key])
def get_setting(self, name):
return get_setting(self.INTERFACES_SETTINGS_GROUP, self.ENGINEERING_PREFIX, name)
@staticmethod
def get_setting(name):
return get_setting(path_handling.INTERFACES_SETTINGS_GROUP, path_handling.ENGINEERING_PREFIX, name)
def set_setting(self, name, value):
set_setting(self.INTERFACES_SETTINGS_GROUP, self.ENGINEERING_PREFIX, name, value)
\ No newline at end of file
@staticmethod
def set_setting(name, value):
set_setting(path_handling.INTERFACES_SETTINGS_GROUP, path_handling.ENGINEERING_PREFIX, name, value)
......@@ -70,8 +70,11 @@ class SettingsPresenter(object):
@staticmethod
def _validate_settings(settings):
all_keys = settings.keys() == SETTINGS_LIST
save_location = str(settings["save_location"])
save_valid = save_location is not "" and save_location is not None
recalc_valid = settings["recalc_vanadium"] is not None
return all_keys and save_valid and recalc_valid
try:
all_keys = settings.keys() == SETTINGS_LIST
save_location = str(settings["save_location"])
save_valid = save_location is not "" and save_location is not None
recalc_valid = settings["recalc_vanadium"] is not None
return all_keys and save_valid and recalc_valid
except KeyError: # Settings contained invalid key.
return False
......@@ -24,8 +24,6 @@ CURVES_WORKSPACE_NAME = "engggui_vanadium_curves"
INTEGRATED_WORKSPACE_NAME = "engggui_vanadium_integration"
CALIB_PARAMS_WORKSPACE_NAME = "engggui_calibration_banks_parameters"
CALIBRATION_DIR = path.join(path_handling.OUT_FILES_ROOT_DIR, "Calibration", "")
NORTH_BANK_TEMPLATE_FILE = "template_ENGINX_241391_236516_North_bank.prm"
SOUTH_BANK_TEMPLATE_FILE = "template_ENGINX_241391_236516_South_bank.prm"
......@@ -64,10 +62,10 @@ class CalibrationModel(object):
params_table.append([i, difc[i], 0.0, tzero[i]])
self.update_calibration_params_table(params_table)
self.create_output_files(CALIBRATION_DIR, difc, tzero, sample_path, vanadium_path,
instrument)
calib_dir = path.join(path_handling.get_output_path(), "Calibration", "")
self.create_output_files(calib_dir, difc, tzero, sample_path, vanadium_path, instrument)
if rb_num:
user_calib_dir = path.join(path_handling.OUT_FILES_ROOT_DIR, "User", rb_num,
user_calib_dir = path.join(path_handling.get_output_path(), "User", rb_num,
"Calibration", "")
self.create_output_files(user_calib_dir, difc, tzero, sample_path, vanadium_path,
instrument)
......
......@@ -8,9 +8,16 @@
from __future__ import (absolute_import, division, print_function)
from os import path
from Engineering.gui.engineering_diffraction.settings.settings_helper import get_setting
OUT_FILES_ROOT_DIR = path.join(path.expanduser("~"), "Engineering_Mantid")
INTERFACES_SETTINGS_GROUP = "CustomInterfaces"
ENGINEERING_PREFIX = "EngineeringDiffraction2/"
def get_run_number_from_path(run_path, instrument):
return path.splitext(path.basename(run_path))[0].replace(instrument, '').lstrip('0')
def get_output_path():
location = get_setting(INTERFACES_SETTINGS_GROUP, ENGINEERING_PREFIX, "save_location")
return location if location is not None else ""
......@@ -59,17 +59,19 @@ class VanadiumCorrectionsTest(unittest.TestCase):
self.assertEqual(0, van_correction.call_count)
self.assertEqual(0, save.call_count)
@patch(dir_path + ".vanadium_corrections.path_handling.get_output_path")
@patch(dir_path + ".vanadium_corrections.makedirs")
def test_file_path_generation(self, makedirs):
def test_file_path_generation(self, makedirs, out_path):
out_path.return_value = path.join(path.expanduser("~"), "Test_Directory")
vanadium_run_number = "1234"
engineering_path = path.join(path.expanduser("~"), "Engineering_Mantid")
engineering_path = path.join(path.expanduser("~"), "Test_Directory")
if path.exists(engineering_path):
rmtree(engineering_path)
output = vanadium_corrections._generate_saved_workspace_file_paths(vanadium_run_number)
self.assertEqual(output,
(path.join(path.expanduser("~"), "Engineering_Mantid", "Vanadium_Runs",
(path.join(path.expanduser("~"), "Test_Directory", "Vanadium_Runs",
"1234_precalculated_vanadium_run_integration.nxs"),
path.join(path.expanduser("~"), "Engineering_Mantid", "Vanadium_Runs",
path.join(path.expanduser("~"), "Test_Directory", "Vanadium_Runs",
"1234_precalculated_vanadium_run_bank_curves.nxs")))
self.assertEqual(1, makedirs.call_count)
......
......@@ -113,10 +113,10 @@ def _generate_saved_workspace_file_paths(vanadium_number, rb_num=""):
integrated_filename = vanadium_number + SAVED_FILE_INTEG_SUFFIX
curves_filename = vanadium_number + SAVED_FILE_CURVE_SUFFIX
if rb_num:
vanadium_dir = path.join(path_handling.OUT_FILES_ROOT_DIR, "User", rb_num,
vanadium_dir = path.join(path_handling.get_output_path(), "User", rb_num,
VANADIUM_DIRECTORY_NAME)
else:
vanadium_dir = path.join(path_handling.OUT_FILES_ROOT_DIR, VANADIUM_DIRECTORY_NAME)
vanadium_dir = path.join(path_handling.get_output_path(), VANADIUM_DIRECTORY_NAME)
if not path.exists(vanadium_dir):
makedirs(vanadium_dir)
return path.join(vanadium_dir, integrated_filename), path.join(vanadium_dir, curves_filename)
......@@ -104,36 +104,36 @@ class FocusModel(object):
def _save_focused_output_files_as_gss(self, instrument, sample_path, bank, sample_workspace,
rb_num):
gss_output_path = path.join(
path_handling.OUT_FILES_ROOT_DIR, "Focus",
path_handling.get_output_path(), "Focus",
self._generate_output_file_name(instrument, sample_path, bank, ".gss"))
SaveGSS(InputWorkspace=sample_workspace, Filename=gss_output_path)
if rb_num is not None:
gss_output_path = path.join(
path_handling.OUT_FILES_ROOT_DIR, "User", rb_num, "Focus",
path_handling.get_output_path(), "User", rb_num, "Focus",
self._generate_output_file_name(instrument, sample_path, bank, ".gss"))
SaveGSS(InputWorkspace=sample_workspace, Filename=gss_output_path)
def _save_focused_output_files_as_nexus(self, instrument, sample_path, bank, sample_workspace,
rb_num):
nexus_output_path = path.join(
path_handling.OUT_FILES_ROOT_DIR, "Focus",
path_handling.get_output_path(), "Focus",
self._generate_output_file_name(instrument, sample_path, bank, ".nxs"))
SaveNexus(InputWorkspace=sample_workspace, Filename=nexus_output_path)
if rb_num is not None:
nexus_output_path = path.join(
path_handling.OUT_FILES_ROOT_DIR, "User", rb_num, "Focus",
path_handling.get_output_path(), "User", rb_num, "Focus",
self._generate_output_file_name(instrument, sample_path, bank, ".nxs"))
SaveNexus(InputWorkspace=sample_workspace, Filename=nexus_output_path)
def _save_focused_output_files_as_xye(self, instrument, sample_path, bank, sample_workspace,
rb_num):
xye_output_path = path.join(
path_handling.OUT_FILES_ROOT_DIR, "Focus",
path_handling.get_output_path(), "Focus",
self._generate_output_file_name(instrument, sample_path, bank, ".dat"))
SaveFocusedXYE(InputWorkspace=sample_workspace, Filename=xye_output_path, SplitFiles=False)
if rb_num is not None:
xye_output_path = path.join(
path_handling.OUT_FILES_ROOT_DIR, "User", rb_num, "Focus",
path_handling.get_output_path(), "User", rb_num, "Focus",
self._generate_output_file_name(instrument, sample_path, bank, ".dat"))
SaveFocusedXYE(InputWorkspace=sample_workspace,
Filename=xye_output_path,
......
......@@ -83,7 +83,7 @@ class FocusModelTest(unittest.TestCase):
@patch(file_path + ".SaveNexus")
def test_save_output_files_with_no_RB_number(self, nexus, gss, xye):
mocked_workspace = "mocked-workspace"
output_file = path.join(path_handling.OUT_FILES_ROOT_DIR, "Focus",
output_file = path.join(path_handling.get_output_path(), "Focus",
"ENGINX_123_bank_North.nxs")
self.model._save_output("ENGINX", "Path/To/ENGINX000123.whatever", "North",
......
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