def test_that_cannot_change_name_when_workspace_in_ADS(self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)

        workspace_handle.show("name1")

        with self.assertRaises(ValueError):
            workspace_handle.name = "new_name"
示例#2
0
 def update_workspaces(self, run, counts_workspace, asymmetry_workspace, rebin):
     if rebin:
         self._counts_workspace_rebin.update({str(run): MuonWorkspaceWrapper(counts_workspace)})
         self._asymmetry_estimate_rebin.update({str(run): MuonWorkspaceWrapper(asymmetry_workspace)})
     else:
         self._counts_workspace.update({str(run): MuonWorkspaceWrapper(counts_workspace)})
         self._asymmetry_estimate.update({str(run): MuonWorkspaceWrapper(asymmetry_workspace)})
示例#3
0
def load_workspace_from_filename(filename,
                                 input_properties=DEFAULT_INPUTS,
                                 output_properties=DEFAULT_OUTPUTS):
    try:
        alg = create_load_algorithm(filename, input_properties)
        alg.execute()
    except:
        alg = create_load_algorithm(filename.split(os.sep)[-1], input_properties)
        alg.execute()

    workspace = alg.getProperty("OutputWorkspace").value
    if is_workspace_group(workspace):
        # handle multi-period data
        load_result = _get_algorithm_properties(alg, output_properties)
        load_result["OutputWorkspace"] = [MuonWorkspaceWrapper(ws) for ws in load_result["OutputWorkspace"]]
        run = get_run_from_multi_period_data(workspace)
        load_result["DataDeadTimeTable"] = copy.copy(load_result["DeadTimeTable"][0])
        load_result["FirstGoodData"] = round(load_result["FirstGoodData"] - load_result['TimeZero'], 2)
    else:
        # single period data
        load_result = _get_algorithm_properties(alg, output_properties)
        load_result["OutputWorkspace"] = [MuonWorkspaceWrapper(load_result["OutputWorkspace"])]
        run = int(workspace.getRunNumber())
        load_result["DataDeadTimeTable"] = load_result["DeadTimeTable"]
        load_result["FirstGoodData"] = round(load_result["FirstGoodData"] - load_result['TimeZero'], 2)

    load_result["DeadTimeTable"] = None

    filename = alg.getProperty("Filename").value

    return load_result, run, filename
示例#4
0
 def add_phase_table_to_ADS(self, base_name):
     run = get_run_numbers_as_string_from_workspace_name(
         base_name, self.context.data_context.instrument)
     directory = get_base_data_directory(self.context, run)
     muon_workspace_wrapper = MuonWorkspaceWrapper(directory + base_name)
     muon_workspace_wrapper.show()
     self.context.phase_context.add_phase_table(muon_workspace_wrapper)
    def test_that_cannot_change_name_when_workspace_in_ADS(self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)

        workspace_handle.show("name1")

        with self.assertRaises(ValueError):
            workspace_handle.name = "new_name"
示例#6
0
    def add_fitting_info_to_ADS_if_required(self, base_name,
                                            fit_workspace_name):
        if not self.view.output_fit_information:
            return

        muon_workspace_wrapper = MuonWorkspaceWrapper(fit_workspace_name)
        muon_workspace_wrapper.show()
示例#7
0
    def add_fft_workspace_to_ADS(self, input_workspace, imaginary_input_workspace, fft_workspace_label):
        run = re.search('[0-9]+', input_workspace).group()
        fft_workspace = mantid.AnalysisDataService.retrieve(fft_workspace_label)
        Im_run = ""
        if imaginary_input_workspace != "":
            Im_run = re.search('[0-9]+', imaginary_input_workspace).group()
        fft_workspace_name = get_fft_workspace_name(input_workspace, imaginary_input_workspace)
        directory = get_fft_workspace_group_name(fft_workspace_name, self.load.data_context.instrument,
                                                 self.load.workspace_suffix)
        Re = get_group_or_pair_from_name(input_workspace)
        Im = get_group_or_pair_from_name(imaginary_input_workspace)
        shift = 3 if fft_workspace.getNumberHistograms() == 6 else 0
        spectra = {"_" + FREQUENCY_EXTENSIONS["RE"]: 0 + shift, "_" + FREQUENCY_EXTENSIONS["IM"]: 1 + shift,
                   "_" + FREQUENCY_EXTENSIONS["MOD"]: 2 + shift}
        for spec_type in list(spectra.keys()):
            extracted_ws = extract_single_spec(fft_workspace, spectra[spec_type], fft_workspace_name + spec_type)

            if 'PhaseQuad' in self.view.workspace:
                self.load._frequency_context.add_FFT(fft_workspace_name + spec_type, run, Re, Im_run, Im,
                                                     phasequad=True)
            else:
                self.load._frequency_context.add_FFT(fft_workspace_name + spec_type, run, Re, Im_run, Im)

            muon_workspace_wrapper = MuonWorkspaceWrapper(extracted_ws)
            muon_workspace_wrapper.show(directory + fft_workspace_name + spec_type)
    def test_that_if_workspace_deleted_from_ADS_then_hide_raises_a_RuntimeWarning(self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)
        workspace_handle.show("name1")

        simpleapi.mtd.clear()

        with self.assertRaises(RuntimeWarning):
            workspace_handle.hide()
示例#9
0
    def add_phase_table_to_ADS(self, base_name, detector_table):
        run = re.search('[0-9]+', base_name).group()

        directory = get_base_data_directory(self.context, run)
        muon_workspace_wrapper = MuonWorkspaceWrapper(detector_table, directory + base_name)
        muon_workspace_wrapper.show()

        self.context.phase_context.add_phase_table(muon_workspace_wrapper)
    def test_that_workspace_added_correctly_for_single_nested_structure(self):
        workspace = create_simple_workspace(data_x=[1, 2, 3, 4], data_y=[10, 10, 10, 10])
        workspace_handle = MuonWorkspaceWrapper(workspace=workspace)

        workspace_handle.show("group1/ws1")

        self.assert_group_workspace_exists("group1")
        self.assert_workspace_in_group("ws1", "group1")
    def test_that_hiding_the_workspace_removes_it_from_ADS(self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)
        workspace_handle.show("test")

        workspace_handle.hide()

        self.assertEqual(workspace_handle.is_hidden, True)
        self.assertFalse(simpleapi.mtd.doesExist("test"))
示例#12
0
    def test_that_workspace_added_correctly_for_single_nested_structure(self):
        workspace = create_simple_workspace(data_x=[1, 2, 3, 4], data_y=[10, 10, 10, 10])
        workspace_handle = MuonWorkspaceWrapper(workspace=workspace)

        workspace_handle.show("group1/ws1")

        self.assert_group_workspace_exists("group1")
        self.assert_workspace_in_group("ws1", "group1")
示例#13
0
    def test_that_if_workspace_exists_with_same_name_as_group_then_it_is_replaced(self):
        workspace = create_simple_workspace(data_x=[1, 2, 3, 4], data_y=[10, 10, 10, 10])
        simpleapi.mtd.add("group", workspace)

        workspace_handle = MuonWorkspaceWrapper(workspace=workspace)
        workspace_handle.show("group/ws1")

        self.assert_group_workspace_exists("group")
    def test_that_workspace_property_returns_workspace_when_in_ADS(self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)

        workspace_handle.show("arbitrary_name")
        ws_property = workspace_handle.workspace

        six.assertCountEqual(self, ws_property.readX(0), [1, 2, 3, 4])
        six.assertCountEqual(self, ws_property.readY(0), [10, 10, 10, 10])
    def test_that_running_show_twice_with_different_names_causes_the_workspace_to_be_moved(self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)

        workspace_handle.show("name1")
        workspace_handle.show("name2")

        self.assertFalse(simpleapi.mtd.doesExist("name1"))
        self.assertTrue(simpleapi.mtd.doesExist("name2"))
    def test_that_workspace_property_returns_workspace_when_in_ADS(self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)

        workspace_handle.show("arbitrary_name")
        ws_property = workspace_handle.workspace

        six.assertCountEqual(self, ws_property.readX(0), [1, 2, 3, 4])
        six.assertCountEqual(self, ws_property.readY(0), [10, 10, 10, 10])
    def test_that_if_workspace_exists_with_same_name_as_group_then_it_is_replaced(
            self):
        group = simpleapi.CreateWorkspace([1, 2, 3, 4], [10, 10, 10, 10])

        workspace_handle = MuonWorkspaceWrapper('group')
        workspace_handle.show("group/ws1")

        self.assert_group_workspace_exists("group")
 def add_optional_outputs_to_ADS(self, alg, output_options, base_name, directory):
     for key in output_options:
         if output_options[key]:
             output = alg.getProperty(key).valueAsStr
             self.load.ads_observer.observeRename(False)
             wrapped_workspace = MuonWorkspaceWrapper(output)
             wrapped_workspace.show(directory + base_name + optional_output_suffixes[key])
             self.load.ads_observer.observeRename(True)
    def test_that_if_workspace_exists_with_same_name_as_group_then_it_is_replaced(self):
        workspace = create_simple_workspace(data_x=[1, 2, 3, 4], data_y=[10, 10, 10, 10])
        simpleapi.mtd.add("group", workspace)

        workspace_handle = MuonWorkspaceWrapper(workspace=workspace)
        workspace_handle.show("group/ws1")

        self.assert_group_workspace_exists("group")
示例#20
0
    def add_fft_workspace_to_ADS(self, input_workspace, imaginary_input_workspace, fft_workspace):
        run = re.search('[0-9]+', input_workspace).group()
        fft_workspace_name = get_fft_workspace_name(input_workspace, imaginary_input_workspace)
        group = get_fft_workspace_group_name(fft_workspace_name, self.load.data_context.instrument)
        directory = get_base_data_directory(self.load, run) + group

        muon_workspace_wrapper = MuonWorkspaceWrapper(fft_workspace, directory + fft_workspace_name)
        muon_workspace_wrapper.show()
示例#21
0
def load_workspace_from_filename(filename,
                                 input_properties=DEFAULT_INPUTS,
                                 output_properties=DEFAULT_OUTPUTS):
    try:
        alg, psi_data = create_load_algorithm(filename, input_properties)
        alg.execute()
    except:
        alg, psi_data = create_load_algorithm(
            filename.split(os.sep)[-1], input_properties)
        alg.execute()

    workspace = AnalysisDataService.retrieve(
        alg.getProperty("OutputWorkspace").valueAsStr)
    if is_workspace_group(workspace):
        # handle multi-period data
        load_result = _get_algorithm_properties(alg, output_properties)
        load_result["OutputWorkspace"] = [
            MuonWorkspaceWrapper(ws) for ws in workspace.getNames()
        ]
        run = get_run_from_multi_period_data(workspace)
        if not psi_data:
            load_result["DataDeadTimeTable"] = AnalysisDataService.retrieve(
                load_result["DeadTimeTable"]).getNames()[0]
            for index, deadtime_table in enumerate(
                    AnalysisDataService.retrieve(
                        load_result["DeadTimeTable"]).getNames()):
                if index == 0:
                    load_result["DataDeadTimeTable"] = deadtime_table
                else:
                    DeleteWorkspace(Workspace=deadtime_table)

            load_result["FirstGoodData"] = round(
                load_result["FirstGoodData"] - load_result['TimeZero'], 2)
            UnGroupWorkspace(load_result["DeadTimeTable"])
            load_result["DeadTimeTable"] = None
            UnGroupWorkspace(workspace.name())
        else:
            load_result["DataDeadTimeTable"] = None
            load_result["FirstGoodData"] = round(load_result["FirstGoodData"],
                                                 2)
    else:
        # single period data
        load_result = _get_algorithm_properties(alg, output_properties)
        load_result["OutputWorkspace"] = [
            MuonWorkspaceWrapper(load_result["OutputWorkspace"])
        ]
        run = int(workspace.getRunNumber())
        if not psi_data:
            load_result["DataDeadTimeTable"] = load_result["DeadTimeTable"]
            load_result["DeadTimeTable"] = None
            load_result["FirstGoodData"] = round(
                load_result["FirstGoodData"] - load_result['TimeZero'], 2)
        else:
            load_result["DataDeadTimeTable"] = None
            load_result["FirstGoodData"] = round(load_result["FirstGoodData"],
                                                 2)

    return load_result, run, filename, psi_data
示例#22
0
    def test_that_setting_a_new_workspace_removes_the_previous_one_from_the_ADS(self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)
        workspace_handle.show("name1")

        workspace2 = create_simple_workspace(data_x=[5, 6, 7, 8], data_y=[20, 20, 20, 20])

        self.assertTrue(simpleapi.mtd.doesExist("name1"))
        workspace_handle.workspace = workspace2
        self.assertFalse(simpleapi.mtd.doesExist("name1"))
    def test_that_cannot_initialize_with_non_workspace_objects(self):
        with self.assertRaises(AttributeError):
            MuonWorkspaceWrapper(workspace="string")

        with self.assertRaises(AttributeError):
            MuonWorkspaceWrapper(workspace=1234)

        with self.assertRaises(AttributeError):
            MuonWorkspaceWrapper(workspace=5.5)
    def test_that_setting_a_new_workspace_removes_the_previous_one_from_the_ADS(self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)
        workspace_handle.show("name1")

        workspace2 = create_simple_workspace(data_x=[5, 6, 7, 8], data_y=[20, 20, 20, 20])

        self.assertTrue(simpleapi.mtd.doesExist("name1"))
        workspace_handle.workspace = workspace2
        self.assertFalse(simpleapi.mtd.doesExist("name1"))
    def test_that_setting_a_new_workspace_resets_the_name_to_empty_string(self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)
        workspace_handle.show("name1")

        workspace2 = create_simple_workspace(data_x=[5, 6, 7, 8], data_y=[20, 20, 20, 20])

        self.assertEqual(workspace_handle.name, "name1")
        workspace_handle.workspace = workspace2
        self.assertEqual(workspace_handle.name, "")
    def test_that_showing_the_workspace_puts_it_in_ADS(self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)

        workspace_handle.show("test")

        self.assertTrue(simpleapi.mtd.doesExist("test"))
        ads_workspace = simpleapi.mtd["test"]
        six.assertCountEqual(self, ads_workspace.readX(0), [1, 2, 3, 4])
        six.assertCountEqual(self, ads_workspace.readY(0), [10, 10, 10, 10])
    def test_that_running_show_twice_with_different_names_causes_the_workspace_to_be_moved(
            self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)

        workspace_handle.show("name1")
        workspace_handle.show("name2")

        self.assertFalse(simpleapi.mtd.doesExist("name1"))
        self.assertTrue(simpleapi.mtd.doesExist("name2"))
    def test_that_showing_the_workspace_puts_it_in_ADS(self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)

        workspace_handle.show("test")

        self.assertTrue(simpleapi.mtd.doesExist("test"))
        ads_workspace = simpleapi.mtd["test"]
        six.assertCountEqual(self, ads_workspace.readX(0), [1, 2, 3, 4])
        six.assertCountEqual(self, ads_workspace.readY(0), [10, 10, 10, 10])
    def add_phase_table_to_ADS(self, base_name, detector_table):
        run = re.search('[0-9]+', base_name).group()

        phase_table_group = get_phase_table_workspace_group_name(base_name,
                                                                 self.context.data_context.instrument)
        directory = get_base_data_directory(self.context, run) + phase_table_group
        muon_workspace_wrapper = MuonWorkspaceWrapper(detector_table, directory + base_name)
        muon_workspace_wrapper.show()

        self.context.phase_context.add_phase_table(muon_workspace_wrapper)
示例#30
0
    def add_phase_quad_to_ADS(self, input_workspace, phasequad_workspace_name):
        run = re.search('^{}([0-9, -]+)[;,_]?'.format(self.context.data_context.instrument), input_workspace).group(1)

        directory = get_base_data_directory(self.context, run)

        muon_workspace_wrapper = MuonWorkspaceWrapper(directory + phasequad_workspace_name)
        muon_workspace_wrapper.show()

        self.context.phase_context.add_phase_quad(muon_workspace_wrapper, run)
        self.phase_quad_calculation_complete_nofifier.notify_subscribers()
示例#31
0
 def update_asymmetry_workspace(self,
                                asymmetry_workspace,
                                run,
                                rebin=False):
     if not rebin:
         self._workspace.update(
             {str(run): MuonWorkspaceWrapper(asymmetry_workspace)})
     else:
         self.workspace_rebin.update(
             {str(run): MuonWorkspaceWrapper(asymmetry_workspace)})
示例#32
0
    def add_maxent_workspace_to_ADS(self, input_workspace, maxent_workspace, alg):
        run = re.search('[0-9]+', input_workspace).group()
        base_name = get_maxent_workspace_name(input_workspace)
        directory = get_maxent_workspace_group_name(base_name, self.load.data_context.instrument, self.load.workspace_suffix)

        muon_workspace_wrapper = MuonWorkspaceWrapper(maxent_workspace, directory + base_name)
        muon_workspace_wrapper.show()

        maxent_output_options = self.get_maxent_output_options()
        self.load._frequency_context.add_maxEnt(run, maxent_workspace)
        self.add_optional_outputs_to_ADS(alg, maxent_output_options, base_name, directory)
示例#33
0
    def add_phase_quad_to_ADS(self, input_workspace, input_phase_table, phase_quad):
        run = re.search('[0-9]+', input_workspace).group()
        phasequad_workspace_name = get_phase_quad_workspace_name(input_workspace, input_phase_table)

        directory = get_base_data_directory(self.context, run)

        muon_workspace_wrapper = MuonWorkspaceWrapper(phase_quad, directory + phasequad_workspace_name)
        muon_workspace_wrapper.show()

        self.context.phase_context.add_phase_quad(muon_workspace_wrapper)
        self.phase_quad_calculation_complete_nofifier.notify_subscribers()
    def test_that_setting_a_new_workspace_resets_the_name_to_empty_string(
            self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)
        workspace_handle.show("name1")

        workspace2 = create_simple_workspace(data_x=[5, 6, 7, 8],
                                             data_y=[20, 20, 20, 20])

        self.assertEqual(workspace_handle.name, "name1")
        workspace_handle.workspace = workspace2
        self.assertEqual(workspace_handle.name, "")
    def add_phase_quad_to_ADS(self, input_workspace, input_phase_table, phase_quad):
        run = re.search('[0-9]+', input_workspace).group()
        phasequad_workspace_name = get_phase_quad_workspace_name(input_workspace, input_phase_table)
        phase_table_group = get_phase_table_workspace_group_name(phasequad_workspace_name,
                                                                 self.context.data_context.instrument)
        directory = get_base_data_directory(self.context, run) + phase_table_group

        muon_workspace_wrapper = MuonWorkspaceWrapper(phase_quad, directory + phasequad_workspace_name)
        muon_workspace_wrapper.show()

        self.context.phase_context.add_phase_quad(muon_workspace_wrapper)
        self.phase_quad_calculation_complete_nofifier.notify_subscribers()
示例#36
0
 def update_workspaces(self,
                       counts_workspace,
                       rebin,
                       rebin_index=0,
                       rebin_option=None):
     if rebin:
         self._counts_workspace_rebin = MuonWorkspaceWrapper(
             counts_workspace)
         self.rebin_index = rebin_index
         self.rebin_option = rebin_option
     else:
         self._counts_workspace = MuonWorkspaceWrapper(counts_workspace)
    def add_maxent_workspace_to_ADS(self, input_workspace, maxent_workspace, alg):
        run = re.search('[0-9]+', input_workspace).group()
        base_name = get_maxent_workspace_name(input_workspace)
        group = get_maxent_workspace_group_name(base_name, self.load.data_context.instrument)
        directory = get_base_data_directory(self.load, run) + group

        muon_workspace_wrapper = MuonWorkspaceWrapper(maxent_workspace, directory + base_name)
        muon_workspace_wrapper.show()

        maxent_output_options = self.get_maxent_output_options()

        self.add_optional_outputs_to_ADS(alg, maxent_output_options, base_name, directory)
示例#38
0
    def add_fitting_info_to_ADS_if_required(self, base_name, fit_workspace_name):
        if not self.view.output_fit_information:
            return

        run = re.search('[0-9]+', base_name).group()
        phase_table_group = get_phase_table_workspace_group_name(base_name,
                                                                 self.context.data_context.instrument,
                                                                 self.context.workspace_suffix)
        directory = get_base_data_directory(self.context, run) + phase_table_group

        muon_workspace_wrapper = MuonWorkspaceWrapper(directory + fit_workspace_name)
        muon_workspace_wrapper.show()
示例#39
0
 def update_asymmetry_workspace(
         self,
         asymmetry_workspace,
         run,
         rebin=False):
     run_object = MuonRun(run)
     if not rebin:
         self._workspace.update(
             {run_object: MuonWorkspaceWrapper(asymmetry_workspace)})
     else:
         self.workspace_rebin.update(
             {run_object: MuonWorkspaceWrapper(asymmetry_workspace)})
示例#40
0
    def add_fft_workspace_to_ADS(self, input_workspace,
                                 imaginary_input_workspace, fft_workspace):
        run = re.search('[0-9]+', input_workspace).group()
        fft_workspace_name = get_fft_workspace_name(input_workspace,
                                                    imaginary_input_workspace)
        group = get_fft_workspace_group_name(fft_workspace_name,
                                             self.load.data_context.instrument)
        directory = get_base_data_directory(self.load, run) + group

        muon_workspace_wrapper = MuonWorkspaceWrapper(
            fft_workspace, directory + fft_workspace_name)
        muon_workspace_wrapper.show()
    def add_fitting_info_to_ADS_if_required(self, base_name, fitting_information):
        if not self.view.output_fit_information:
            return

        run = re.search('[0-9]+', base_name).group()
        phase_table_group = get_phase_table_workspace_group_name(base_name,
                                                                 self.context.data_context.instrument)
        fitting_workspace_name = get_fitting_workspace_name(base_name)
        directory = get_base_data_directory(self.context, run) + phase_table_group

        muon_workspace_wrapper = MuonWorkspaceWrapper(fitting_information, directory + fitting_workspace_name)
        muon_workspace_wrapper.show()
示例#42
0
    def add_phase_table_to_ADS(self, base_name, detector_table):
        run = re.search('[0-9]+', base_name).group()

        phase_table_group = get_phase_table_workspace_group_name(
            base_name, self.context.data_context.instrument,
            self.context.workspace_suffix)
        directory = get_base_data_directory(self.context,
                                            run) + phase_table_group
        muon_workspace_wrapper = MuonWorkspaceWrapper(detector_table,
                                                      directory + base_name)
        muon_workspace_wrapper.show()

        self.context.phase_context.add_phase_table(muon_workspace_wrapper)
示例#43
0
def load_workspace_from_filename(filename,
                                 input_properties=DEFAULT_INPUTS,
                                 output_properties=DEFAULT_OUTPUTS):
    try:
        alg, psi_data = create_load_algorithm(filename, input_properties)
        alg.execute()
    except:
        alg, psi_data = create_load_algorithm(
            filename.split(os.sep)[-1], input_properties)
        alg.execute()

    # The filename given to the loading algorithm can be different to the file that was actually loaded.
    # Pulling the filename back out of the algorithm after loading ensures that the path is accurate.
    filename = alg.getProperty("Filename").value
    workspace = AnalysisDataService.retrieve(
        alg.getProperty("OutputWorkspace").valueAsStr)
    if is_workspace_group(workspace):
        # handle multi-period data
        load_result = _get_algorithm_properties(alg, output_properties)
        load_result["OutputWorkspace"] = [
            MuonWorkspaceWrapper(ws) for ws in workspace.getNames()
        ]
        run = get_run_from_multi_period_data(workspace)

        deadtime_tables = AnalysisDataService.retrieve(
            load_result["DeadTimeTable"]).getNames()
        load_result["DataDeadTimeTable"] = deadtime_tables[0]
        for table in deadtime_tables[1:]:
            DeleteWorkspace(Workspace=table)

        load_result["FirstGoodData"] = round(
            load_result["FirstGoodData"] - load_result['TimeZero'], 3)
        print("hiii", )
        UnGroupWorkspace(load_result["DeadTimeTable"])
        load_result["DeadTimeTable"] = None
        UnGroupWorkspace(workspace.name())

    else:
        # single period data
        load_result = _get_algorithm_properties(alg, output_properties)
        load_result["OutputWorkspace"] = [
            MuonWorkspaceWrapper(load_result["OutputWorkspace"])
        ]
        run = int(workspace.getRunNumber())

        load_result["DataDeadTimeTable"] = load_result["DeadTimeTable"]
        load_result["DeadTimeTable"] = None
        load_result["FirstGoodData"] = round(
            load_result["FirstGoodData"] - load_result['TimeZero'], 3)

    return load_result, run, filename, psi_data
示例#44
0
    def add_maxent_workspace_to_ADS(self, input_workspace, maxent_workspace, alg):
        run = re.search('[0-9]+', input_workspace).group()
        base_name = get_maxent_workspace_name(input_workspace, self.view.get_method)
        directory = get_maxent_workspace_group_name(base_name, self.context.data_context.instrument, self.context.workspace_suffix)

        muon_workspace_wrapper = MuonWorkspaceWrapper(directory + base_name)
        muon_workspace_wrapper.show()

        maxent_output_options = self.get_maxent_output_options()
        self.context.frequency_context.add_maxEnt(run, maxent_workspace)
        self.add_optional_outputs_to_ADS(alg, maxent_output_options, base_name, directory)

        # Storing this on the class so it can be sent as part of the calculation
        # finished signal.
        self._maxent_output_workspace_name = base_name
示例#45
0
    def _calculate_phasequads(self, phasequad_obj, rebin):
        for run in self._data_context.current_runs:
            if self._data_context.num_periods(run) > 1:
                raise ValueError("Cannot support multiple periods")

            ws_list = self.calculate_phasequad(phasequad_obj, run, rebin)
            run_string = run_list_to_string(run)
            directory = get_base_data_directory(self, run_string)
            for ws in ws_list:
                muon_workspace_wrapper = MuonWorkspaceWrapper(directory + ws)
                muon_workspace_wrapper.show()

            phasequad_obj.update_asymmetry_workspaces(ws_list,
                                                      run,
                                                      rebin=rebin)
    def test_that_hiding_workspace_more_than_once_has_no_effect_but_raises_RuntimeWarning(self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)
        workspace_handle.show("name1")

        workspace_handle.hide()

        with self.assertRaises(RuntimeWarning):
            workspace_handle.hide()
    def test_that_workspaces_in_existing_folders_are_not_moved_by_directory_manipulation(self):
        workspace1 = create_simple_workspace(data_x=[1, 2, 3, 4], data_y=[10, 10, 10, 10])
        workspace2 = create_simple_workspace(data_x=[1, 2, 3, 4], data_y=[10, 10, 10, 10])
        workspace_handle1 = MuonWorkspaceWrapper(workspace=workspace1)
        workspace_handle2 = MuonWorkspaceWrapper(workspace=workspace2)

        workspace_handle1.show("group1/group2/ws1")
        workspace_handle2.show("group1/group2/group3/ws2")

        self.assert_group_workspace_exists("group1")
        self.assert_group_workspace_exists("group2")
        self.assert_group_workspace_exists("group3")
        self.assert_group1_is_inside_group2("group2", "group1")
        self.assert_group1_is_inside_group2("group3", "group2")
        self.assert_workspace_in_group("ws1", "group2")
        self.assert_workspace_in_group("ws2", "group3")
    def test_that_showing_the_workspace_with_empty_string_for_name_raises_ValueError(self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)

        with self.assertRaises(ValueError):
            workspace_handle.show("")
    def test_that_can_change_name_when_workspace_not_in_ADS(self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)

        workspace_handle.name = "new_name"

        self.assertEqual(workspace_handle.name, "new_name")
    def test_that_hiding_workspace_more_than_once_has_no_effect(self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)
        workspace_handle.show("name1")

        workspace_handle.hide()
    def test_that_if_workspace_deleted_from_ADS_then_hide_does_nothing(self):
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)
        workspace_handle.show("name1")

        simpleapi.mtd.clear()
    def test_that_cannot_modify_is_hidden_property(self):
        # the ADS handling interface is restricted to the show() / hide() methods
        workspace_handle = MuonWorkspaceWrapper(workspace=self.workspace)

        with self.assertRaises(AttributeError):
            workspace_handle.is_hidden = True