pypet/trajectory.py
def _merge_derived_parameters(self,
                                    other_trajectory,
                                    used_runs,
                                    rename_dict,
                                    allowed_translations,
                                    ignore_data):
        """ Merges derived parameters that have the `run_ALL` in a name.

        Creates a new parameter with the name of the first new run and links to this
        parameter to avoid copying in all other runs.

        """
        other_derived_parameters = other_trajectory._derived_parameters.copy()
        # get first run_idx
        new_first_run_idx = min(used_runs.values())

        run_name_dummy = other_trajectory.f_wildcard('$', -1)
        for param_name in other_derived_parameters:
            if param_name in ignore_data:
                continue
            split_name = param_name.split('.')
            if not any(x in run_name_dummy for x in split_name):
                continue
            ignore_data.add(param_name)

            param = other_derived_parameters[param_name]
            new_param_name = self._rename_full_name(param_name, other_trajectory,
                                                    used_runs=used_runs)
            if new_param_name in self:
                my_param = self.f_get(new_param_name, fast_access=False)
                if (my_param._equal_values(my_param.f_get(), param.f_get()) and
                        not (my_param.f_has_range() or param.f_has_range())):
                    continue

            first_new_param_name = self._rename_full_name(param_name,
                                                          other_trajectory,
                                                          new_run_idx=new_first_run_idx)

            rename_dict[param_name] = first_new_param_name
            comment = param.v_comment
            param_type = param.f_get_class_name()
            param_type = self._create_class(param_type)
            first_param = self.f_add_leaf(param_type,
                                          first_new_param_name,
                                          comment=comment)
            for run_idx in used_runs.values():
                if run_idx == new_first_run_idx:
                    continue
                next_name = self._rename_full_name(param_name, other_trajectory,
                                                    new_run_idx=run_idx)
                split_name = next_name.split('.')
                link_name = split_name.pop()
                location_name = '.'.join(split_name)
                if not self.f_contains(location_name, shortcuts=False):
                    the_group = self.f_add_group(location_name)
                else:
                    the_group = self.f_get(location_name)

                the_group.f_add_link(link_name, first_param)

        for param_name in other_derived_parameters:
            if param_name in ignore_data:
                continue
            split_name = param_name.split('.')
            ignore_data.add(param_name)
            if any(x in other_trajectory._reversed_wildcards and x not in allowed_translations
                        for x in split_name):
                continue
            new_name = self._rename_full_name(param_name, other_trajectory,
                                                    used_runs=used_runs)
            if self.f_contains(new_name):
                my_param = self.f_get(new_name, fast_access=False)
                param = other_derived_parameters[param_name]
                if (my_param._equal_values(my_param.f_get(), param.f_get()) and
                        not (my_param.f_has_range() or param.f_has_range())):
                    continue
                else:
                    self._logger.error('Could not merge parameter `%s`. '
                                       'I will ignore it!' % new_name)
            rename_dict[param_name] = new_name
def _merge_derived_parameters(self,
                                    other_trajectory,
                                    used_runs,
                                    rename_dict,
                                    allowed_translations,
                                    ignore_data):
        """ Merges derived parameters that have the `run_ALL` in a name.

        Creates a new parameter with the name of the first new run and links to this
        parameter to avoid copying in all other runs.

        """
        other_derived_parameters = other_trajectory._derived_parameters.copy()
        # get first run_idx
        new_first_run_idx = min(used_runs.values())

        run_name_dummy = other_trajectory.f_wildcard('$', -1)
        for param_name in other_derived_parameters:
            if param_name in ignore_data:
                continue
            split_name = param_name.split('.')
            if not any(x in run_name_dummy for x in split_name):
                continue
            ignore_data.add(param_name)

            param = other_derived_parameters[param_name]
            new_param_name = self._rename_full_name(param_name, other_trajectory,
                                                    used_runs=used_runs)
            if new_param_name in self:
                my_param = self.f_get(new_param_name, fast_access=False)
                if (my_param._equal_values(my_param.f_get(), param.f_get()) and
                        not (my_param.f_has_range() or param.f_has_range())):
                    continue

            first_new_param_name = self._rename_full_name(param_name,
                                                          other_trajectory,
                                                          new_run_idx=new_first_run_idx)

            rename_dict[param_name] = first_new_param_name
            comment = param.v_comment
            param_type = param.f_get_class_name()
            param_type = self._create_class(param_type)
            first_param = self.f_add_leaf(param_type,
                                          first_new_param_name,
                                          comment=comment)
            for run_idx in used_runs.values():
                if run_idx == new_first_run_idx:
                    continue
                next_name = self._rename_full_name(param_name, other_trajectory,
                                                    new_run_idx=run_idx)
                split_name = next_name.split('.')
                link_name = split_name.pop()
                location_name = '.'.join(split_name)
                if not self.f_contains(location_name, shortcuts=False):
                    the_group = self.f_add_group(location_name)
                else:
                    the_group = self.f_get(location_name)

                the_group.f_add_link(link_name, first_param)

        for param_name in other_derived_parameters:
            if param_name in ignore_data:
                continue
            split_name = param_name.split('.')
            ignore_data.add(param_name)
            if any(x in other_trajectory._reversed_wildcards and x not in allowed_translations
                        for x in split_name):
                continue
            new_name = self._rename_full_name(param_name, other_trajectory,
                                                    used_runs=used_runs)
            if self.f_contains(new_name):
                my_param = self.f_get(new_name, fast_access=False)
                param = other_derived_parameters[param_name]
                if (my_param._equal_values(my_param.f_get(), param.f_get()) and
                        not (my_param.f_has_range() or param.f_has_range())):
                    continue
                else:
                    self._logger.error('Could not merge parameter `%s`. '
                                       'I will ignore it!' % new_name)
            rename_dict[param_name] = new_name
Merges derived parameters that have the `run_ALL` in a name.

        Creates a new parameter with the name of the first new run and links to this
        parameter to avoid copying in all other runs.