Beispiel #1
0
    def show_group(self, run, group, rebin):
        run_as_string = run_list_to_string(run)
        group_name = group.name
        periods = run_list_to_string(group.periods)

        directory = get_base_data_directory(self, run_as_string)

        name = get_group_data_workspace_name(self,
                                             group_name,
                                             run_as_string,
                                             periods,
                                             rebin=rebin)
        asym_name = get_group_asymmetry_name(self,
                                             group_name,
                                             run_as_string,
                                             periods,
                                             rebin=rebin)
        asym_name_unnorm = get_group_asymmetry_unnorm_name(self,
                                                           group_name,
                                                           run_as_string,
                                                           periods,
                                                           rebin=rebin)

        if not rebin:
            self.group_pair_context[group_name].show_raw(
                run, directory + name, directory + asym_name, asym_name_unnorm)
        else:
            self.group_pair_context[group_name].show_rebin(
                run, directory + name, directory + asym_name, asym_name_unnorm)
Beispiel #2
0
def _create_XML_subElement_for_groups(root_node, groups):
    group_nodes = []
    for group in groups:
        child = ET.SubElement(root_node, 'group', name=group.name)
        id_string = run_string_utils.run_list_to_string(group.detectors)
        ids = ET.SubElement(child, 'ids', val=id_string)
        child.extend(ids)
        period_string = run_string_utils.run_list_to_string(group.periods)
        periods = ET.SubElement(child, 'periods', val=period_string)
        child.extend(periods)
        group_nodes += [child]
    return group_nodes
Beispiel #3
0
    def _calculate_counts_or_asymmetry(self, calculation_func, run, group, rebin=False):
        """Calculates the counts or asymmetry workspace depending on the 'calculation_func' that is provided."""
        run_as_string = run_list_to_string(run)
        periods_as_string = run_list_to_string(group.periods)

        # A user requirement is that processing can continue if a period is missing from some
        # of the runs. This filters out periods which are not in a given run.
        periods = [period for period in group.periods if period <= self.num_periods(run)]

        if not periods:
            return None

        return calculation_func(run, group, periods, run_as_string, periods_as_string, rebin)
Beispiel #4
0
 def add_group_to_view(self, group, state, color, tooltip):
     self._view.disable_updates()
     assert isinstance(group, MuonGroup)
     entry = [str(group.name), run_utils.run_list_to_string(group.periods), state, run_utils.run_list_to_string(group.detectors, False),
              str(group.n_detectors)]
     self._view.add_entry_to_table(entry, color, tooltip)
     self._view.enable_updates()
 def current_runs(self) -> list:
     """Returns the currently selected run number in a list. If co-add is selected, there are multiple runs."""
     for run_list in self._data_context.current_runs:
         if run_list_to_string(
                 run_list) == self._corrections_context.current_run_string:
             return run_list
     return None
Beispiel #6
0
    def calculate_phasequad(self, phasequad, run, rebin):
        parameters = {}
        parameters['PhaseTable'] = phasequad.phase_table
        run_string = run_list_to_string(run)

        ws_name = get_pair_phasequad_name(self,
                                          add_phasequad_extensions(
                                              phasequad.name),
                                          run_string,
                                          rebin=rebin)

        parameters['InputWorkspace'] = self._run_deadtime(run_string, ws_name)
        runs = self._data_context.current_runs

        if runs:
            parameters['InputWorkspace'] = run_crop_workspace(
                parameters['InputWorkspace'], self.first_good_data(runs[0]),
                self.last_good_data(runs[0]))

        phase_quad = run_PhaseQuad(parameters, ws_name)
        if rebin:
            dt = self._get_bin_width(phase_quad)
            phase_quad = self._run_rebin(phase_quad, True)
            phase_quad = self._average_by_bin_widths(phase_quad, dt)

        workspaces = split_phasequad(phase_quad)
        return workspaces
Beispiel #7
0
    def show_raw_data(self):
        self.ads_observer.observeRename(False)
        for run in self.data_context.current_runs:
            with WorkspaceGroupDefinition():
                run_string = run_list_to_string(run)
                loaded_workspace = self.data_context._loaded_data.get_data(run=run, instrument=self.data_context.instrument)['workspace'][
                                       'OutputWorkspace']
                loaded_workspace_deadtime_table = self.corrections_context.get_default_dead_time_table_name_for_run(
                    self.data_context.instrument, run)
                directory = get_base_data_directory(
                    self,
                    run_string)

                deadtime_name = get_deadtime_data_workspace_name(self.data_context.instrument,
                                                                 str(run[0]), workspace_suffix=self.workspace_suffix)
                MuonWorkspaceWrapper(loaded_workspace_deadtime_table).show(directory + deadtime_name)
                self.corrections_context.set_default_dead_time_table_name_for_run(self.data_context.instrument, run,
                                                                                  deadtime_name)

                if len(loaded_workspace) > 1:
                    # Multi-period data
                    for i, single_ws in enumerate(loaded_workspace):
                        name = directory + get_raw_data_workspace_name(self.data_context.instrument, run_string,
                                                                       multi_period=True,
                                                                       period=str(i + 1),
                                                                       workspace_suffix=self.workspace_suffix)
                        single_ws.show(name)
                else:
                    # Single period data
                    name = directory + get_raw_data_workspace_name(self.data_context.instrument, run_string,
                                                                   multi_period=False,
                                                                   workspace_suffix=self.workspace_suffix)
                    loaded_workspace[0].show(name)

        self.ads_observer.observeRename(True)
Beispiel #8
0
 def set_run_edit_from_list(self, run_list):
     new_list = []
     for run_item in run_list:
         if isinstance(run_item, int):
             new_list += [run_item]
         elif isinstance(run_item, list):
             for run in run_item:
                 new_list += [run]
     run_string = run_utils.run_list_to_string(new_list)
     self._view.set_run_edit_text(run_string)
Beispiel #9
0
 def calculate_diff(self, diff: MuonDiff, run: List[int], rebin: bool=False):
     try:
         positive_workspace_name = self._group_pair_context[diff.positive].get_asymmetry_workspace_for_run(run, rebin)
         negative_workspace_name = self._group_pair_context[diff.negative].get_asymmetry_workspace_for_run(run, rebin)
     except KeyError:
         # A key error here means the requested workspace does not exist so return None
         return None
     run_as_string = run_list_to_string(run)
     output_workspace_name = get_diff_asymmetry_name(self, diff.name, run_as_string, rebin=rebin)
     return run_minus(positive_workspace_name, negative_workspace_name, output_workspace_name)
Beispiel #10
0
 def getWorkspaceNames(self):
     # get runs
     run_list = [run_list_to_string(run) for run in self.context.data_context.current_runs]
     self.view.addRuns(run_list)
     # get periods
     self._load_periods()
     # get min number of points as a power of 2
     start = int(
         math.ceil(math.log(self.context.data_context.num_points) / math.log(2.0)))
     values = [str(2**k) for k in range(start, 21)]
     self.view.addNPoints(values)
Beispiel #11
0
    def create_multiple_field_directions_error_message(self, run_list):
        transverse = []
        longitudinal = []
        for run in run_list:
            field_direction = self._loaded_data.get_main_field_direction(
                run=run, instrument=self.instrument)
            if field_direction.lower() == 'transverse':
                transverse += run
            elif field_direction.lower() == 'longitudinal':
                longitudinal += run
            else:
                return 'Unrecognised field direction {} for run {}'.format(
                    field_direction, run)

        message = 'MainFieldDirection changes within current run set:\n'
        message += 'transverse field runs {}\n'.format(
            run_list_to_string(transverse))
        message += 'longitudinal field runs {}\n'.format(
            run_list_to_string(longitudinal))
        return message
Beispiel #12
0
    def calculate_pair(self, pair: MuonPair, run: List[int], rebin: bool=False):
        try:
            forward_group_workspace_name = self._group_pair_context[pair.forward_group].get_counts_workspace_for_run(run, rebin)
            backward_group_workspace_name = self._group_pair_context[pair.backward_group].get_counts_workspace_for_run(run, rebin)
        except KeyError:
            # A key error here means the requested workspace does not exist so return None
            return None

        run_as_string = run_list_to_string(run)
        output_workspace_name = get_pair_asymmetry_name(self, pair.name, run_as_string, rebin=rebin)
        return calculate_pair_data(pair, forward_group_workspace_name, backward_group_workspace_name, output_workspace_name)
Beispiel #13
0
 def getGroupedWorkspaceNames(self):
     run_numbers = self.data_context.current_runs
     runs = [
         wsName.get_raw_data_workspace_name(
             self.data_context.instrument,
             run_list_to_string(run_number),
             self.data_context.is_multi_period(),
             period=str(period + 1),
             workspace_suffix=self.workspace_suffix)
         for run_number in run_numbers for period in range(self.data_context.num_periods(run_number))]
     return runs
Beispiel #14
0
    def show_diff(self, run: list, diff: MuonDiff):
        diff_name = diff.name

        run_as_string = run_list_to_string(run)
        name = get_diff_asymmetry_name(self, diff_name, run_as_string, rebin=False)
        directory = get_base_data_directory(self, run_as_string)

        self.group_pair_context[diff_name].show_raw(run, directory + name)

        if self._do_rebin():
            name = get_diff_asymmetry_name(self, diff_name, run_as_string, rebin=True)
            self.group_pair_context[diff_name].show_rebin(run, directory + name)
Beispiel #15
0
    def show_pair(self, run: list, pair: MuonPair):
        pair_name = pair.name
        # Do not want to rename phasequad parts here
        if "_Re_" in pair_name or "_Im_" in pair_name:
            return

        run_as_string = run_list_to_string(run)
        name = get_pair_asymmetry_name(self, pair_name, run_as_string, rebin=False)
        directory = get_base_data_directory(self, run_as_string)

        self.group_pair_context[pair_name].show_raw(run, directory + name)

        if self._do_rebin():
            name = get_pair_asymmetry_name(self, pair_name, run_as_string, rebin=True)
            self.group_pair_context[pair_name].show_rebin(run, directory + name)
Beispiel #16
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)
Beispiel #17
0
 def test_run_list_to_string_removes_duplicated_runs(self):
     run_list = [1, 1, 2, 2, 3, 4, 5, 3]
     run_string = utils.run_list_to_string(run_list)
     self.assertEqual(run_string, "1-5")
 def run_number_strings(self) -> list:
     """Returns a list of run number strings from the context. Its a string because of co-add mode."""
     return [
         run_list_to_string(run_list)
         for run_list in self._data_context.current_runs
     ]
 def create_tiled_keys(self, tiled_by):
     if tiled_by == "Group/Pair":
         keys = self.context.group_pair_context.selected_groups_and_pairs
     else:
         keys = [run_list_to_string(item) for item in self.context.data_context.current_runs]
     return keys
Beispiel #20
0
 def test_run_list_to_string_for_consecutive_runs(self):
     run_list = [1, 2, 3, 4, 5]
     run_string = utils.run_list_to_string(run_list)
     self.assertEqual(run_string, "1-5")
Beispiel #21
0
 def test_run_list_to_string_doesnt_throw_if_more_than_100_runs(self):
     run_list = [i for i in range(150)]
     utils.run_list_to_string(run_list)
Beispiel #22
0
 def test_run_list_to_string_orders_run_numbers(self):
     run_list = [5, 3, 2, 4, 1]
     run_string = utils.run_list_to_string(run_list)
     self.assertEqual(run_string, "1-5")
Beispiel #23
0
 def gen_run_list(self):
     run_list = []
     for run in self.context.data_context.current_runs:
         run_list.append(run_list_to_string(run))
     return run_list
Beispiel #24
0
 def test_run_list_to_string_removes_negative_runs(self):
     run_list = [-1, 1, 2, -2, 3, 4, 5, -3]
     run_string = utils.run_list_to_string(run_list)
     self.assertEqual(run_string, "1-5")
def get_pre_process_workspace_name(run: Iterable[int], instrument: str) -> str:
    workspace_name = "".join(["__", instrument, run_list_to_string(run), "_pre_processed_data"])
    return workspace_name
Beispiel #26
0
 def test_run_list_to_string_handles_non_consecutive_runs(self):
     run_lists = [[1, 3, 4, 5], [0, 1, 2, 3, 8, 9, 199, 200]]
     run_strings = ["1,3-5", "0-3,8-9,199-200"]
     for i in range(len(run_lists)):
         self.assertEqual(utils.run_list_to_string(run_lists[i]),
                          run_strings[i])
Beispiel #27
0
 def test_run_list_to_string_orders_non_consecutive_runs(self):
     run_list = [50, 49, 48, 3, 2, 1]
     run_string = utils.run_list_to_string(run_list)
     self.assertEqual(run_string, "1-3,48-50")
Beispiel #28
0
 def __str__(self):
     return run_list_to_string(list(self._runs))