pypet/trajectory.py
def _merge_links(self, other_trajectory, used_runs, allowed_translations, ignore_data):
        """ Merges all links"""
        linked_items = other_trajectory._linked_by
        run_name_dummys = set([f(-1) for f in other_trajectory._wildcard_functions.values()])
        if len(linked_items) > 0:
            self._logger.info('Merging potential links!')
            for old_linked_name in other_trajectory._linked_by:
                if old_linked_name in ignore_data:
                    continue
                split_name = old_linked_name.split('.')
                if any(x in run_name_dummys for x in split_name):
                    self._logger.warning('Ignoring all links linking to `%s` because '
                                     'I don`t know how to resolve links under `%s` nodes.' %
                                     (old_linked_name, str(run_name_dummys)))
                    continue
                old_link_dict = other_trajectory._linked_by[old_linked_name]
                split_name = old_linked_name.split('.')
                if all(x in allowed_translations for x in split_name):
                    new_linked_full_name = self._rename_full_name(old_linked_name,
                                                                  other_trajectory,
                                                                  used_runs=used_runs)
                else:
                    new_linked_full_name = old_linked_name

                for linking_node, link_set in old_link_dict.values():

                    linking_full_name = linking_node.v_full_name
                    split_name = linking_full_name .split('.')
                    if any(x in run_name_dummys for x in split_name):
                        self._logger.warning('Ignoring links under `%s` because '
                                             'I don`t know how to resolve links '
                                             'under a `%s` node.' %
                                             (linking_full_name, str(run_name_dummys)))

                    split_name = linking_full_name .split('.')
                    if any(x in allowed_translations for x in split_name):
                        new_linking_full_name = self._rename_full_name(linking_full_name,
                                                                      other_trajectory,
                                                                      used_runs=used_runs)
                    else:
                        new_linking_full_name = linking_full_name

                    for link in link_set:
                        if (linking_full_name + '.' + link) in ignore_data:
                            continue
                        if link in run_name_dummys:
                            self._logger.warning('Ignoring link `%s` under `%s` because '
                                                 'I don`t know how to resolve '
                                                 'links named as `%s`.' %
                                                 (link,
                                                  linking_full_name,
                                                  str(run_name_dummys)))
                            continue

                        try:
                            new_linked_item = self.f_get(new_linked_full_name,
                                                         shortcuts=False)
                            if self.f_contains(new_linking_full_name):
                                new_linking_item = self.f_get(new_linking_full_name,
                                                              shortcuts=False)
                            else:
                                new_linking_item =  self.f_add_group(new_linking_full_name)
                            if link in allowed_translations:
                                run_indices, wildcards = other_trajectory._reversed_wildcards[link]
                                link = self.f_wildcard(wildcards[0], used_runs[run_indices[0]])
                            if not link in new_linking_item._links:
                                new_linking_item.f_add_link(link, new_linked_item)
                            else:
                                self._logger.debug('Link `%s` exists already under `%s`.' %
                                                    (link, new_linked_item.v_full_name))
                        except (AttributeError, ValueError) as exc:
                            self._logger.error('Could not copy link `%s` under `%s` linking '
                                               'to `%s` due to `%s`' %
                                               (link, linking_full_name, old_linked_name,
                                                repr(exc)))
def _merge_links(self, other_trajectory, used_runs, allowed_translations, ignore_data):
        """ Merges all links"""
        linked_items = other_trajectory._linked_by
        run_name_dummys = set([f(-1) for f in other_trajectory._wildcard_functions.values()])
        if len(linked_items) > 0:
            self._logger.info('Merging potential links!')
            for old_linked_name in other_trajectory._linked_by:
                if old_linked_name in ignore_data:
                    continue
                split_name = old_linked_name.split('.')
                if any(x in run_name_dummys for x in split_name):
                    self._logger.warning('Ignoring all links linking to `%s` because '
                                     'I don`t know how to resolve links under `%s` nodes.' %
                                     (old_linked_name, str(run_name_dummys)))
                    continue
                old_link_dict = other_trajectory._linked_by[old_linked_name]
                split_name = old_linked_name.split('.')
                if all(x in allowed_translations for x in split_name):
                    new_linked_full_name = self._rename_full_name(old_linked_name,
                                                                  other_trajectory,
                                                                  used_runs=used_runs)
                else:
                    new_linked_full_name = old_linked_name

                for linking_node, link_set in old_link_dict.values():

                    linking_full_name = linking_node.v_full_name
                    split_name = linking_full_name .split('.')
                    if any(x in run_name_dummys for x in split_name):
                        self._logger.warning('Ignoring links under `%s` because '
                                             'I don`t know how to resolve links '
                                             'under a `%s` node.' %
                                             (linking_full_name, str(run_name_dummys)))

                    split_name = linking_full_name .split('.')
                    if any(x in allowed_translations for x in split_name):
                        new_linking_full_name = self._rename_full_name(linking_full_name,
                                                                      other_trajectory,
                                                                      used_runs=used_runs)
                    else:
                        new_linking_full_name = linking_full_name

                    for link in link_set:
                        if (linking_full_name + '.' + link) in ignore_data:
                            continue
                        if link in run_name_dummys:
                            self._logger.warning('Ignoring link `%s` under `%s` because '
                                                 'I don`t know how to resolve '
                                                 'links named as `%s`.' %
                                                 (link,
                                                  linking_full_name,
                                                  str(run_name_dummys)))
                            continue

                        try:
                            new_linked_item = self.f_get(new_linked_full_name,
                                                         shortcuts=False)
                            if self.f_contains(new_linking_full_name):
                                new_linking_item = self.f_get(new_linking_full_name,
                                                              shortcuts=False)
                            else:
                                new_linking_item =  self.f_add_group(new_linking_full_name)
                            if link in allowed_translations:
                                run_indices, wildcards = other_trajectory._reversed_wildcards[link]
                                link = self.f_wildcard(wildcards[0], used_runs[run_indices[0]])
                            if not link in new_linking_item._links:
                                new_linking_item.f_add_link(link, new_linked_item)
                            else:
                                self._logger.debug('Link `%s` exists already under `%s`.' %
                                                    (link, new_linked_item.v_full_name))
                        except (AttributeError, ValueError) as exc:
                            self._logger.error('Could not copy link `%s` under `%s` linking '
                                               'to `%s` due to `%s`' %
                                               (link, linking_full_name, old_linked_name,
                                                repr(exc)))
def _merge_links ( self , other_trajectory , used_runs , allowed_translations , ignore_data ) : linked_items = other_trajectory . _linked_by run_name_dummys = set ( [ f ( - 1 ) for f in other_trajectory . _wildcard_functions . values ( ) ] ) if len ( linked_items ) > 0 : self . _logger . info ( 'Merging potential links!' ) for old_linked_name in other_trajectory . _linked_by : if old_linked_name in ignore_data : continue split_name = old_linked_name . split ( '.' ) if any ( x in run_name_dummys for x in split_name ) : self . _logger . warning ( 'Ignoring all links linking to `%s` because ' 'I don`t know how to resolve links under `%s` nodes.' % ( old_linked_name , str ( run_name_dummys ) ) ) continue old_link_dict = other_trajectory . _linked_by [ old_linked_name ] split_name = old_linked_name . split ( '.' ) if all ( x in allowed_translations for x in split_name ) : new_linked_full_name = self . _rename_full_name ( old_linked_name , other_trajectory , used_runs = used_runs ) else : new_linked_full_name = old_linked_name for linking_node , link_set in old_link_dict . values ( ) : linking_full_name = linking_node . v_full_name split_name = linking_full_name . split ( '.' ) if any ( x in run_name_dummys for x in split_name ) : self . _logger . warning ( 'Ignoring links under `%s` because ' 'I don`t know how to resolve links ' 'under a `%s` node.' % ( linking_full_name , str ( run_name_dummys ) ) ) split_name = linking_full_name . split ( '.' ) if any ( x in allowed_translations for x in split_name ) : new_linking_full_name = self . _rename_full_name ( linking_full_name , other_trajectory , used_runs = used_runs ) else : new_linking_full_name = linking_full_name for link in link_set : if ( linking_full_name + '.' + link ) in ignore_data : continue if link in run_name_dummys : self . _logger . warning ( 'Ignoring link `%s` under `%s` because ' 'I don`t know how to resolve ' 'links named as `%s`.' % ( link , linking_full_name , str ( run_name_dummys ) ) ) continue try : new_linked_item = self . f_get ( new_linked_full_name , shortcuts = False ) if self . f_contains ( new_linking_full_name ) : new_linking_item = self . f_get ( new_linking_full_name , shortcuts = False ) else : new_linking_item = self . f_add_group ( new_linking_full_name ) if link in allowed_translations : run_indices , wildcards = other_trajectory . _reversed_wildcards [ link ] link = self . f_wildcard ( wildcards [ 0 ] , used_runs [ run_indices [ 0 ] ] ) if not link in new_linking_item . _links : new_linking_item . f_add_link ( link , new_linked_item ) else : self . _logger . debug ( 'Link `%s` exists already under `%s`.' % ( link , new_linked_item . v_full_name ) ) except ( AttributeError , ValueError ) as exc : self . _logger . error ( 'Could not copy link `%s` under `%s` linking ' 'to `%s` due to `%s`' % ( link , linking_full_name , old_linked_name , repr ( exc ) ) )
Merges all links
Merges all links