示例#1
0
 def create_new_calibration(calibration,
                            rb_num,
                            plot_output,
                            save_dir=output_settings.get_output_path()):
     full_calib = load_full_instrument_calibration()
     EnggUtils.create_new_calibration(calibration, rb_num, plot_output,
                                      save_dir, full_calib)
示例#2
0
    def test_last_path_updates_with_no_RB_number(self, addlog, nexus, gss,
                                                 xye):
        mocked_workspace = "mocked-workspace"
        output_file = path.join(output_settings.get_output_path(), "Focus",
                                "ENGINX_123_456_North_TOF.nxs")

        self.model._save_output("ENGINX", "123", "456", "North",
                                mocked_workspace, None)

        self.assertEqual(self.model._last_focused_files[0], output_file)
示例#3
0
 def focus_run(
     self,
     sample_paths: list,
     vanadium_path: str,
     plot_output: bool,
     rb_num: str,
     calibration: CalibrationInfo,
     save_dir: Optional[str] = output_settings.get_output_path()
 ) -> None:
     full_calib = load_full_instrument_calibration()
     focused_files = EnggUtils.focus_run(sample_paths, vanadium_path,
                                         plot_output, rb_num, calibration,
                                         save_dir, full_calib)
     self._last_focused_files.extend(focused_files)
示例#4
0
    def test_save_output_files_with_no_RB_number(self, addlog, nexus, gss,
                                                 xye):
        mocked_workspace = "mocked-workspace"
        output_file = path.join(output_settings.get_output_path(), "Focus",
                                "ENGINX_123_456_North_TOF.nxs")

        self.model._save_output("ENGINX", "123", "456", "North",
                                mocked_workspace, None)

        self.assertEqual(1, nexus.call_count)
        self.assertEqual(1, gss.call_count)
        self.assertEqual(1, xye.call_count)
        nexus.assert_called_with(Filename=output_file,
                                 InputWorkspace=mocked_workspace)
示例#5
0
    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)