def get_active_ws_sorted_by_primary_log(self): active_ws_dict = self._data_workspaces.get_active_ws_dict() tof_ws_inds = [ ind for ind, ws in enumerate(active_ws_dict.values()) if ws.getAxis(0).getUnit().caption() == 'Time-of-flight' ] primary_log = get_setting(output_settings.INTERFACES_SETTINGS_GROUP, output_settings.ENGINEERING_PREFIX, "primary_log") sort_ascending = get_setting(output_settings.INTERFACES_SETTINGS_GROUP, output_settings.ENGINEERING_PREFIX, "sort_ascending") ws_name_list = list(active_ws_dict.keys()) if primary_log: log_table = ADS.retrieve(primary_log) isort = argsort(array(log_table.column('avg'))) ws_list_tof = [ ws_name_list[iws] for iws in isort if iws in tof_ws_inds ] else: ws_list_tof = ws_name_list if sort_ascending == 'false': # settings can only be saved as text ws_list_tof = ws_list_tof[::-1] return ws_list_tof
def test_get_setting_with_int(self): settings = QSettings() settings.beginGroup(GROUP) settings.setValue(PREFIX + "something", 10) settings.endGroup() self.assertEqual(get_setting(GROUP, PREFIX, "something", return_type=int), 10)
def test_get_setting_with_bool_true(self): settings = QSettings() settings.beginGroup(GROUP) settings.setValue(PREFIX + "something", True) settings.endGroup() self.assertEqual(get_setting(GROUP, PREFIX, "something", return_type=bool), True)
def test_get_setting_with_string(self): settings = QSettings() settings.beginGroup(GROUP) settings.setValue(PREFIX + "something", "value") settings.endGroup() self.assertEqual(get_setting(GROUP, PREFIX, "something"), "value")
def test_get_setting_bool_without_specifying_type(self): settings = QSettings() settings.beginGroup(GROUP) settings.setValue(PREFIX + "something", True) settings.endGroup() self.assertEqual(get_setting(GROUP, PREFIX, "something"), "true")
def __init__(self, canvas, toolbar_manager, parent=None): super(EngDiffFitPropertyBrowser, self).__init__(canvas, toolbar_manager, parent) # overwrite default peak with that in settings (gets init when UI opened) default_peak = get_setting(output_settings.INTERFACES_SETTINGS_GROUP, output_settings.ENGINEERING_PREFIX, "default_peak") self.setDefaultPeakType(default_peak) self.fit_notifier = GenericObservable() self.fit_enabled_notifier = GenericObservable()
def load_last_calibration(self) -> None: """ Loads the most recently created or loaded calibration into the interface instance. To be used on interface startup. """ last_cal_path = get_setting(output_settings.INTERFACES_SETTINGS_GROUP, output_settings.ENGINEERING_PREFIX, "last_calibration_path") if last_cal_path: self.view.set_load_checked(True) self.view.set_file_text_with_search(last_cal_path)
def create_log_workspace_group(self): # run information table run_info = self.make_runinfo_table() self._log_workspaces = GroupWorkspaces([run_info], OutputWorkspace='logs') # a table per logs logs = get_setting(output_settings.INTERFACES_SETTINGS_GROUP, output_settings.ENGINEERING_PREFIX, "logs") if logs: self._log_names = logs.split(',') for log in self._log_names: self.make_log_table(log) self._log_workspaces.add(log)
def load_full_instrument_calibration(): if ADS.doesExist("full_inst_calib"): full_calib = ADS.retrieve("full_inst_calib") else: full_calib_path = get_setting( output_settings.INTERFACES_SETTINGS_GROUP, output_settings.ENGINEERING_PREFIX, "full_calibration") try: full_calib = Load(full_calib_path, OutputWorkspace="full_inst_calib") except ValueError: logger.error( "Error loading Full instrument calibration - this is set in the interface settings." ) return return full_calib
def __init__(self, model, view): self.model = model self.view = view self.worker = None self.calibration_observer = CalibrationObserver(self) # Observable Setup self.focus_run_notifier = GenericObservable() # Connect view signals to local methods. self.view.set_on_focus_clicked(self.on_focus_clicked) self.view.set_enable_controls_connection(self.set_focus_controls_enabled) # Variables from other GUI tabs. self.current_calibration = CalibrationInfo() self.instrument = "ENGINX" self.rb_num = None last_van_path = get_setting(output_settings.INTERFACES_SETTINGS_GROUP, output_settings.ENGINEERING_PREFIX, "last_vanadium_run") if last_van_path: self.view.set_van_file_text_with_search(last_van_path)
def create_vanadium_corrections(vanadium_path: str, instrument: str): # -> Workspace, Workspace """ Runs the vanadium correction algorithm. :param vanadium_path: The path to the vanadium data. :return: The integrated workspace and the processed instrument workspace generated. """ try: run_no = path_handling.get_run_number_from_path( vanadium_path, instrument) van_ws = Load(Filename=vanadium_path, OutputWorkspace=str(run_no) + '_' + VANADIUM_INPUT_WORKSPACE_NAME) except Exception as e: logger.error( "Error when loading vanadium sample data. " "Could not run Load algorithm with vanadium run number: " + str(vanadium_path) + ". Error description: " + str(e)) raise RuntimeError # get full instrument calibration for instrument processing calculation if Ads.doesExist("full_inst_calib"): full_calib_ws = Ads.retrieve("full_inst_calib") else: full_calib_path = get_setting( output_settings.INTERFACES_SETTINGS_GROUP, output_settings.ENGINEERING_PREFIX, "full_calibration") try: full_calib_ws = Load(full_calib_path, OutputWorkspace="full_inst_calib") except ValueError: logger.error( "Error loading Full instrument calibration - this is set in the interface settings." ) return integral_ws = _calculate_vanadium_integral(van_ws, run_no) processed_ws = _calculate_vanadium_processed_instrument( van_ws, full_calib_ws, integral_ws, run_no) return integral_ws, processed_ws
def create_new_calibration(self, ceria_path, plot_output, instrument, rb_num=None, bank=None, calfile=None, spectrum_numbers=None): """ Create a new calibration from a ceria run :param ceria_path: Path to ceria (CeO2) data file :param plot_output: Whether the output should be plotted. :param instrument: The instrument the data relates to. :param rb_num: The RB number for file creation. :param bank: Optional parameter to crop by bank :param calfile: Optional parameter to crop using a custom calfile :param spectrum_numbers: Optional parameter to crop using spectrum numbers. """ ceria_workspace = path_handling.load_workspace(ceria_path) if Ads.doesExist("full_inst_calib"): full_calib = Ads.retrieve("full_inst_calib") else: full_calib_path = get_setting( output_settings.INTERFACES_SETTINGS_GROUP, output_settings.ENGINEERING_PREFIX, "full_calibration") try: full_calib = Load(full_calib_path, OutputWorkspace="full_inst_calib") except ValueError: logger.error( "Error loading Full instrument calibration - this is set in the interface settings." ) return cal_params, ceria_raw, grp_ws = self.run_calibration( ceria_workspace, bank, calfile, spectrum_numbers, full_calib) if plot_output: plot_dicts = list() if len(cal_params) == 1: if calfile: bank_name = "Custom" elif spectrum_numbers: bank_name = "Cropped" else: bank_name = bank plot_dicts.append( EnggUtils.generate_tof_fit_dictionary(bank_name)) EnggUtils.plot_tof_fit(plot_dicts, [bank_name]) else: plot_dicts.append( EnggUtils.generate_tof_fit_dictionary("bank_1")) plot_dicts.append( EnggUtils.generate_tof_fit_dictionary("bank_2")) EnggUtils.plot_tof_fit(plot_dicts, ["bank_1", "bank_2"]) difa = [row['difa'] for row in cal_params] difc = [row['difc'] for row in cal_params] tzero = [row['tzero'] for row in cal_params] bk2bk_params = self.extract_b2b_params(ceria_raw) DeleteWorkspace(ceria_raw) params_table = [] for i in range(len(difc)): params_table.append([i, difc[i], difa[i], tzero[i]]) self.update_calibration_params_table(params_table) calib_dir = path.join(output_settings.get_output_path(), "Calibration", "") if calfile: EnggUtils.save_grouping_workspace(grp_ws, calib_dir, ceria_path, instrument, calfile=calfile) elif spectrum_numbers: EnggUtils.save_grouping_workspace(grp_ws, calib_dir, ceria_path, instrument, spec_nos=spectrum_numbers) self.create_output_files(calib_dir, difa, difc, tzero, bk2bk_params, ceria_path, instrument, bank, spectrum_numbers, calfile) if rb_num: user_calib_dir = path.join(output_settings.get_output_path(), "User", rb_num, "Calibration", "") self.create_output_files(user_calib_dir, difa, difc, tzero, bk2bk_params, ceria_path, instrument, bank, spectrum_numbers, calfile)
def get_setting(name, return_type=str): return get_setting(output_settings.INTERFACES_SETTINGS_GROUP, output_settings.ENGINEERING_PREFIX, name, return_type=return_type)
def get_output_path(): location = get_setting(INTERFACES_SETTINGS_GROUP, ENGINEERING_PREFIX, "save_location") return location if location is not None else ""
def test_get_setting_with_invalid(self): self.assertEqual(get_setting(GROUP, PREFIX, "something"), "")