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

RE #26848 Add load existing functionality to model

parent 6823df2f
No related branches found
No related tags found
No related merge requests found
...@@ -70,12 +70,23 @@ class CalibrationModel(object): ...@@ -70,12 +70,23 @@ class CalibrationModel(object):
self.create_output_files(user_calib_dir, difc, tzero, ceria_path, vanadium_path, self.create_output_files(user_calib_dir, difc, tzero, ceria_path, vanadium_path,
instrument) instrument)
def load_existing_gsas_parameters(self, file_path):
if not path.exists(file_path):
logger.warning("Could not open GSAS calibration file: ", file_path)
return
try:
instrument, van_no, ceria_no = self.get_info_from_file(file_path)
except RuntimeError:
logger.error("Invalid file selected: ", file_path)
return
return instrument, van_no, ceria_no
@staticmethod @staticmethod
def update_calibration_params_table(params_table): def update_calibration_params_table(params_table):
if len(params_table) == 0: if len(params_table) == 0:
return return
# Create blank or clear existing params table. # Create blank, or clear rows from existing, params table.
if Ads.doesExist(CALIB_PARAMS_WORKSPACE_NAME): if Ads.doesExist(CALIB_PARAMS_WORKSPACE_NAME):
workspace = Ads.retrieve(CALIB_PARAMS_WORKSPACE_NAME) workspace = Ads.retrieve(CALIB_PARAMS_WORKSPACE_NAME)
workspace.setRowCount(0) workspace.setRowCount(0)
...@@ -193,34 +204,54 @@ class CalibrationModel(object): ...@@ -193,34 +204,54 @@ class CalibrationModel(object):
""" """
if not path.exists(calibration_dir): if not path.exists(calibration_dir):
makedirs(calibration_dir) makedirs(calibration_dir)
filename, vanadium_no, ceria_no = self._generate_output_file_name(vanadium_path, filename = self._generate_output_file_name(vanadium_path,
ceria_path, ceria_path,
instrument, instrument,
bank="all") bank="all")
# Both Banks # Both Banks
file_path = calibration_dir + filename file_path = calibration_dir + filename
write_ENGINX_GSAS_iparam_file(file_path, write_ENGINX_GSAS_iparam_file(file_path,
difc, difc,
tzero, tzero,
ceria_run=ceria_no, ceria_run=ceria_path,
vanadium_run=vanadium_no) vanadium_run=vanadium_path)
# North Bank # North Bank
file_path = calibration_dir + self._generate_output_file_name( file_path = calibration_dir + self._generate_output_file_name(
vanadium_path, ceria_path, instrument, bank="north")[0] vanadium_path, ceria_path, instrument, bank="north")
write_ENGINX_GSAS_iparam_file(file_path, [difc[0]], [tzero[0]], write_ENGINX_GSAS_iparam_file(file_path, [difc[0]], [tzero[0]],
ceria_run=ceria_no, ceria_run=ceria_path,
vanadium_run=vanadium_no, vanadium_run=vanadium_path,
template_file=NORTH_BANK_TEMPLATE_FILE, template_file=NORTH_BANK_TEMPLATE_FILE,
bank_names=["North"]) bank_names=["North"])
# South Bank # South Bank
file_path = calibration_dir + self._generate_output_file_name( file_path = calibration_dir + self._generate_output_file_name(
vanadium_path, ceria_path, instrument, bank="south")[0] vanadium_path, ceria_path, instrument, bank="south")
write_ENGINX_GSAS_iparam_file(file_path, [difc[1]], [tzero[1]], write_ENGINX_GSAS_iparam_file(file_path, [difc[1]], [tzero[1]],
ceria_run=ceria_no, ceria_run=ceria_path,
vanadium_run=vanadium_no, vanadium_run=vanadium_path,
template_file=SOUTH_BANK_TEMPLATE_FILE, template_file=SOUTH_BANK_TEMPLATE_FILE,
bank_names=["South"]) bank_names=["South"])
@staticmethod
def get_info_from_file(file_path):
# TODO: Find a way to reliably get the instrument from the file without using the filename.
instrument = file_path.split("/")[-1].split("_", 1)[0]
# Get run numbers from file.
run_numbers = ""
with open(file_path) as f:
for line in f:
if line.startswith("INS CALIB"):
run_numbers = line
break
if run_numbers == "":
raise RuntimeError("Invalid file format.")
words = run_numbers.split()
ceria_no = words[2] # Run numbers are stored as the 3rd and 4th word in this line.
van_no = words[3]
return instrument, van_no, ceria_no
@staticmethod @staticmethod
def _generate_table_workspace_name(bank_num): def _generate_table_workspace_name(bank_num):
return "engggui_calibration_bank_" + str(bank_num + 1) return "engggui_calibration_bank_" + str(bank_num + 1)
...@@ -246,4 +277,4 @@ class CalibrationModel(object): ...@@ -246,4 +277,4 @@ class CalibrationModel(object):
filename = filename + "bank_South.prm" filename = filename + "bank_South.prm"
else: else:
raise ValueError("Invalid bank name entered") raise ValueError("Invalid bank name entered")
return filename, vanadium_no, ceria_no return filename
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