pypet/storageservice.py
def _trj_merge_trajectories(self, other_trajectory_name, rename_dict, move_nodes=False,
                                delete_trajectory=False, other_filename=None):
        """Merges another trajectory into the current trajectory (as in self._trajectory_name).

        :param other_trajectory_name: Name of other trajectory
        :param rename_dict: Dictionary with old names (keys) and new names (values).
        :param move_nodes: Whether to move hdf5 nodes or copy them
        :param delete_trajectory: Whether to delete the other trajectory

        """
        if other_filename is None or other_filename == self.filename:
            other_filename = self.filename
            other_file = self._hdf5file
            other_is_different = False
        else:
            other_file = pt.open_file(filename=other_filename, mode='r+')
            other_is_different = True

        try:
            if not '/' + other_trajectory_name in other_file:
                raise ValueError('Cannot merge `%s` and `%s`, because the second trajectory cannot '
                                 'be found in file: %s.' % (self._trajectory_name,
                                                            other_trajectory_name,
                                                            other_filename))
            for old_name in rename_dict:
                new_name = rename_dict[old_name]

                # Iterate over all items that need to be merged
                split_name = old_name.split('.')
                old_location = '/' + other_trajectory_name + '/' + '/'.join(split_name)

                split_name = new_name.split('.')
                new_parent_location = '/' + self._trajectory_name + '/' + '/'.join(split_name[:-1])

                new_short_name = split_name[-1]

                # Get the data from the other trajectory
                old_node = other_file.get_node(old_location)

                # Now move or copy the data
                if move_nodes:
                    self._hdf5file.move_node( where=old_node, newparent=new_parent_location,
                                       newname=new_short_name, createparents=True)
                else:
                    if other_is_different:
                        new_parent_dot_location = '.'.join(split_name[:-1])
                        new_parent_or_loc, _ = self._all_create_or_get_groups(
                            new_parent_dot_location)
                        create_parents = False
                    else:
                        new_parent_or_loc = new_parent_location
                        create_parents = True
                    self._hdf5file.copy_node(where=old_node, newparent=new_parent_or_loc,
                                       newname=new_short_name, createparents=create_parents,
                                       recursive=True)


            if delete_trajectory:
                other_file.remove_node(where='/', name=other_trajectory_name, recursive=True)
        finally:
            if other_is_different:
                other_file.flush()
                other_file.close()
def _trj_merge_trajectories(self, other_trajectory_name, rename_dict, move_nodes=False,
                                delete_trajectory=False, other_filename=None):
        """Merges another trajectory into the current trajectory (as in self._trajectory_name).

        :param other_trajectory_name: Name of other trajectory
        :param rename_dict: Dictionary with old names (keys) and new names (values).
        :param move_nodes: Whether to move hdf5 nodes or copy them
        :param delete_trajectory: Whether to delete the other trajectory

        """
        if other_filename is None or other_filename == self.filename:
            other_filename = self.filename
            other_file = self._hdf5file
            other_is_different = False
        else:
            other_file = pt.open_file(filename=other_filename, mode='r+')
            other_is_different = True

        try:
            if not '/' + other_trajectory_name in other_file:
                raise ValueError('Cannot merge `%s` and `%s`, because the second trajectory cannot '
                                 'be found in file: %s.' % (self._trajectory_name,
                                                            other_trajectory_name,
                                                            other_filename))
            for old_name in rename_dict:
                new_name = rename_dict[old_name]

                # Iterate over all items that need to be merged
                split_name = old_name.split('.')
                old_location = '/' + other_trajectory_name + '/' + '/'.join(split_name)

                split_name = new_name.split('.')
                new_parent_location = '/' + self._trajectory_name + '/' + '/'.join(split_name[:-1])

                new_short_name = split_name[-1]

                # Get the data from the other trajectory
                old_node = other_file.get_node(old_location)

                # Now move or copy the data
                if move_nodes:
                    self._hdf5file.move_node( where=old_node, newparent=new_parent_location,
                                       newname=new_short_name, createparents=True)
                else:
                    if other_is_different:
                        new_parent_dot_location = '.'.join(split_name[:-1])
                        new_parent_or_loc, _ = self._all_create_or_get_groups(
                            new_parent_dot_location)
                        create_parents = False
                    else:
                        new_parent_or_loc = new_parent_location
                        create_parents = True
                    self._hdf5file.copy_node(where=old_node, newparent=new_parent_or_loc,
                                       newname=new_short_name, createparents=create_parents,
                                       recursive=True)


            if delete_trajectory:
                other_file.remove_node(where='/', name=other_trajectory_name, recursive=True)
        finally:
            if other_is_different:
                other_file.flush()
                other_file.close()
def _trj_merge_trajectories ( self , other_trajectory_name , rename_dict , move_nodes = False , delete_trajectory = False , other_filename = None ) : if other_filename is None or other_filename == self . filename : other_filename = self . filename other_file = self . _hdf5file other_is_different = False else : other_file = pt . open_file ( filename = other_filename , mode = 'r+' ) other_is_different = True try : if not '/' + other_trajectory_name in other_file : raise ValueError ( 'Cannot merge `%s` and `%s`, because the second trajectory cannot ' 'be found in file: %s.' % ( self . _trajectory_name , other_trajectory_name , other_filename ) ) for old_name in rename_dict : new_name = rename_dict [ old_name ] # Iterate over all items that need to be merged split_name = old_name . split ( '.' ) old_location = '/' + other_trajectory_name + '/' + '/' . join ( split_name ) split_name = new_name . split ( '.' ) new_parent_location = '/' + self . _trajectory_name + '/' + '/' . join ( split_name [ : - 1 ] ) new_short_name = split_name [ - 1 ] # Get the data from the other trajectory old_node = other_file . get_node ( old_location ) # Now move or copy the data if move_nodes : self . _hdf5file . move_node ( where = old_node , newparent = new_parent_location , newname = new_short_name , createparents = True ) else : if other_is_different : new_parent_dot_location = '.' . join ( split_name [ : - 1 ] ) new_parent_or_loc , _ = self . _all_create_or_get_groups ( new_parent_dot_location ) create_parents = False else : new_parent_or_loc = new_parent_location create_parents = True self . _hdf5file . copy_node ( where = old_node , newparent = new_parent_or_loc , newname = new_short_name , createparents = create_parents , recursive = True ) if delete_trajectory : other_file . remove_node ( where = '/' , name = other_trajectory_name , recursive = True ) finally : if other_is_different : other_file . flush ( ) other_file . close ( )
Merges another trajectory into the current trajectory (as in self._trajectory_name).

        :param other_trajectory_name: Name of other trajectory
        :param rename_dict: Dictionary with old names (keys) and new names (values).
        :param move_nodes: Whether to move hdf5 nodes or copy them
        :param delete_trajectory: Whether to delete the other trajectory
Merges another trajectory into the current trajectory ( as in self . _trajectory_name ) .