pypet/storageservice.py
def _prm_load_parameter_or_result(self, instance,
                                      load_data=pypetconstants.LOAD_DATA,
                                      load_only=None,
                                      load_except=None,
                                      load_flags=None,
                                      with_links=False,
                                      recursive=False,
                                      max_depth=None,
                                      _hdf5_group=None,):
        """Loads a parameter or result from disk.

        :param instance:

            Empty parameter or result instance

        :param load_data:

            How to load stuff

        :param load_only:

            List of data keys if only parts of a result should be loaded

        :param load_except:

            List of data key that should NOT be loaded.

        :param load_flags:

            Dictionary to determine how something is loaded

        :param with_links:

            Placeholder, because leaves have no links

        :param recursive:

            Dummy variable, no-op because leaves have no children

        :param max_depth:

            Dummy variable, no-op because leaves have no children

        :param _hdf5_group:

            The corresponding hdf5 group of the instance

        """
        if load_data == pypetconstants.LOAD_NOTHING:
            return

        if _hdf5_group is None:
            _hdf5_group = self._all_get_node_by_name(instance.v_full_name)

        if load_data == pypetconstants.OVERWRITE_DATA:
            if instance.v_is_parameter and instance.v_locked:
                self._logger.debug('Parameter `%s` is locked, I will skip loading.' %
                                     instance.v_full_name)
                return
            instance.f_empty()
            instance.v_annotations.f_empty()
            instance.v_comment = ''

        self._all_load_skeleton(instance, _hdf5_group)
        instance._stored = True

        # If load only is just a name and not a list of names, turn it into a 1 element list
        if isinstance(load_only, str):
            load_only = [load_only]
        if isinstance(load_except, str):
            load_except = [load_except]

        if load_data == pypetconstants.LOAD_SKELETON:
            # We only load skeleton if asked for it and thus only
            # signal completed node loading
            self._node_processing_timer.signal_update()
            return
        elif load_only is not None:
            if load_except is not None:
                raise ValueError('Please use either `load_only` or `load_except` and not '
                             'both at the same time.')
            elif instance.v_is_parameter and instance.v_locked:
                raise pex.ParameterLockedException('Parameter `%s` is locked, '
                                                   'I will skip loading.' %
                                                    instance.v_full_name)
            self._logger.debug('I am in load only mode, I will only load %s.' %
                               str(load_only))
            load_only = set(load_only)
        elif load_except is not None:
            if instance.v_is_parameter and instance.v_locked:
                raise pex.ParameterLockedException('Parameter `%s` is locked, '
                                                   'I will skip loading.' %
                                                    instance.v_full_name)
            self._logger.debug('I am in load except mode, I will load everything except %s.' %
                               str(load_except))
            # We do not want to modify the original list
            load_except = set(load_except)
        elif not instance.f_is_empty():
            # We only load data if the instance is empty or we specified load_only or
            # load_except and thus only
            # signal completed node loading
            self._node_processing_timer.signal_update()
            return

        full_name = instance.v_full_name
        self._logger.debug('Loading data of %s' % full_name)

        load_dict = {}  # Dict that will be used to keep all data for loading the parameter or
        # result

        if load_flags is None:
            load_flags = {}
        try:
            # Ask the instance for load flags
            instance_flags = instance._load_flags().copy() # copy to avoid modifying the
            # original data
        except AttributeError:
            # If it does not provide any, set it to the empty dictionary
            instance_flags = {}
        # User specified flags have priority over the flags from the instance
        instance_flags.update(load_flags)
        load_flags = instance_flags

        self._prm_load_into_dict(full_name=full_name,
                                 load_dict=load_dict,
                                 hdf5_group=_hdf5_group,
                                 instance=instance,
                                 load_only=load_only,
                                 load_except=load_except,
                                 load_flags=load_flags)

        if load_only is not None:
            # Check if all data in `load_only` was actually found in the hdf5 file
            if len(load_only) > 0:
                self._logger.warning('You marked %s for load only, '
                                     'but I cannot find these for `%s`' %
                                     (str(load_only), full_name))
        elif load_except is not None:
            if len(load_except) > 0:
                self._logger.warning(('You marked `%s` for not loading, but these were not part '
                                      'of `%s` anyway.' % (str(load_except), full_name)))

        # Finally tell the parameter or result to load the data, if there was any ;-)
        if load_dict:
            try:
                instance._load(load_dict)
                if instance.v_is_parameter:
                    # Lock parameter as soon as data is loaded
                    instance.f_lock()
            except:
                self._logger.error(
                    'Error while reconstructing data of leaf `%s`.' % full_name)
                raise

        # Signal completed node loading
        self._node_processing_timer.signal_update()
def _prm_load_parameter_or_result(self, instance,
                                      load_data=pypetconstants.LOAD_DATA,
                                      load_only=None,
                                      load_except=None,
                                      load_flags=None,
                                      with_links=False,
                                      recursive=False,
                                      max_depth=None,
                                      _hdf5_group=None,):
        """Loads a parameter or result from disk.

        :param instance:

            Empty parameter or result instance

        :param load_data:

            How to load stuff

        :param load_only:

            List of data keys if only parts of a result should be loaded

        :param load_except:

            List of data key that should NOT be loaded.

        :param load_flags:

            Dictionary to determine how something is loaded

        :param with_links:

            Placeholder, because leaves have no links

        :param recursive:

            Dummy variable, no-op because leaves have no children

        :param max_depth:

            Dummy variable, no-op because leaves have no children

        :param _hdf5_group:

            The corresponding hdf5 group of the instance

        """
        if load_data == pypetconstants.LOAD_NOTHING:
            return

        if _hdf5_group is None:
            _hdf5_group = self._all_get_node_by_name(instance.v_full_name)

        if load_data == pypetconstants.OVERWRITE_DATA:
            if instance.v_is_parameter and instance.v_locked:
                self._logger.debug('Parameter `%s` is locked, I will skip loading.' %
                                     instance.v_full_name)
                return
            instance.f_empty()
            instance.v_annotations.f_empty()
            instance.v_comment = ''

        self._all_load_skeleton(instance, _hdf5_group)
        instance._stored = True

        # If load only is just a name and not a list of names, turn it into a 1 element list
        if isinstance(load_only, str):
            load_only = [load_only]
        if isinstance(load_except, str):
            load_except = [load_except]

        if load_data == pypetconstants.LOAD_SKELETON:
            # We only load skeleton if asked for it and thus only
            # signal completed node loading
            self._node_processing_timer.signal_update()
            return
        elif load_only is not None:
            if load_except is not None:
                raise ValueError('Please use either `load_only` or `load_except` and not '
                             'both at the same time.')
            elif instance.v_is_parameter and instance.v_locked:
                raise pex.ParameterLockedException('Parameter `%s` is locked, '
                                                   'I will skip loading.' %
                                                    instance.v_full_name)
            self._logger.debug('I am in load only mode, I will only load %s.' %
                               str(load_only))
            load_only = set(load_only)
        elif load_except is not None:
            if instance.v_is_parameter and instance.v_locked:
                raise pex.ParameterLockedException('Parameter `%s` is locked, '
                                                   'I will skip loading.' %
                                                    instance.v_full_name)
            self._logger.debug('I am in load except mode, I will load everything except %s.' %
                               str(load_except))
            # We do not want to modify the original list
            load_except = set(load_except)
        elif not instance.f_is_empty():
            # We only load data if the instance is empty or we specified load_only or
            # load_except and thus only
            # signal completed node loading
            self._node_processing_timer.signal_update()
            return

        full_name = instance.v_full_name
        self._logger.debug('Loading data of %s' % full_name)

        load_dict = {}  # Dict that will be used to keep all data for loading the parameter or
        # result

        if load_flags is None:
            load_flags = {}
        try:
            # Ask the instance for load flags
            instance_flags = instance._load_flags().copy() # copy to avoid modifying the
            # original data
        except AttributeError:
            # If it does not provide any, set it to the empty dictionary
            instance_flags = {}
        # User specified flags have priority over the flags from the instance
        instance_flags.update(load_flags)
        load_flags = instance_flags

        self._prm_load_into_dict(full_name=full_name,
                                 load_dict=load_dict,
                                 hdf5_group=_hdf5_group,
                                 instance=instance,
                                 load_only=load_only,
                                 load_except=load_except,
                                 load_flags=load_flags)

        if load_only is not None:
            # Check if all data in `load_only` was actually found in the hdf5 file
            if len(load_only) > 0:
                self._logger.warning('You marked %s for load only, '
                                     'but I cannot find these for `%s`' %
                                     (str(load_only), full_name))
        elif load_except is not None:
            if len(load_except) > 0:
                self._logger.warning(('You marked `%s` for not loading, but these were not part '
                                      'of `%s` anyway.' % (str(load_except), full_name)))

        # Finally tell the parameter or result to load the data, if there was any ;-)
        if load_dict:
            try:
                instance._load(load_dict)
                if instance.v_is_parameter:
                    # Lock parameter as soon as data is loaded
                    instance.f_lock()
            except:
                self._logger.error(
                    'Error while reconstructing data of leaf `%s`.' % full_name)
                raise

        # Signal completed node loading
        self._node_processing_timer.signal_update()
def _prm_load_parameter_or_result ( self , instance , load_data = pypetconstants . LOAD_DATA , load_only = None , load_except = None , load_flags = None , with_links = False , recursive = False , max_depth = None , _hdf5_group = None , ) : if load_data == pypetconstants . LOAD_NOTHING : return if _hdf5_group is None : _hdf5_group = self . _all_get_node_by_name ( instance . v_full_name ) if load_data == pypetconstants . OVERWRITE_DATA : if instance . v_is_parameter and instance . v_locked : self . _logger . debug ( 'Parameter `%s` is locked, I will skip loading.' % instance . v_full_name ) return instance . f_empty ( ) instance . v_annotations . f_empty ( ) instance . v_comment = '' self . _all_load_skeleton ( instance , _hdf5_group ) instance . _stored = True # If load only is just a name and not a list of names, turn it into a 1 element list if isinstance ( load_only , str ) : load_only = [ load_only ] if isinstance ( load_except , str ) : load_except = [ load_except ] if load_data == pypetconstants . LOAD_SKELETON : # We only load skeleton if asked for it and thus only # signal completed node loading self . _node_processing_timer . signal_update ( ) return elif load_only is not None : if load_except is not None : raise ValueError ( 'Please use either `load_only` or `load_except` and not ' 'both at the same time.' ) elif instance . v_is_parameter and instance . v_locked : raise pex . ParameterLockedException ( 'Parameter `%s` is locked, ' 'I will skip loading.' % instance . v_full_name ) self . _logger . debug ( 'I am in load only mode, I will only load %s.' % str ( load_only ) ) load_only = set ( load_only ) elif load_except is not None : if instance . v_is_parameter and instance . v_locked : raise pex . ParameterLockedException ( 'Parameter `%s` is locked, ' 'I will skip loading.' % instance . v_full_name ) self . _logger . debug ( 'I am in load except mode, I will load everything except %s.' % str ( load_except ) ) # We do not want to modify the original list load_except = set ( load_except ) elif not instance . f_is_empty ( ) : # We only load data if the instance is empty or we specified load_only or # load_except and thus only # signal completed node loading self . _node_processing_timer . signal_update ( ) return full_name = instance . v_full_name self . _logger . debug ( 'Loading data of %s' % full_name ) load_dict = { } # Dict that will be used to keep all data for loading the parameter or # result if load_flags is None : load_flags = { } try : # Ask the instance for load flags instance_flags = instance . _load_flags ( ) . copy ( ) # copy to avoid modifying the # original data except AttributeError : # If it does not provide any, set it to the empty dictionary instance_flags = { } # User specified flags have priority over the flags from the instance instance_flags . update ( load_flags ) load_flags = instance_flags self . _prm_load_into_dict ( full_name = full_name , load_dict = load_dict , hdf5_group = _hdf5_group , instance = instance , load_only = load_only , load_except = load_except , load_flags = load_flags ) if load_only is not None : # Check if all data in `load_only` was actually found in the hdf5 file if len ( load_only ) > 0 : self . _logger . warning ( 'You marked %s for load only, ' 'but I cannot find these for `%s`' % ( str ( load_only ) , full_name ) ) elif load_except is not None : if len ( load_except ) > 0 : self . _logger . warning ( ( 'You marked `%s` for not loading, but these were not part ' 'of `%s` anyway.' % ( str ( load_except ) , full_name ) ) ) # Finally tell the parameter or result to load the data, if there was any ;-) if load_dict : try : instance . _load ( load_dict ) if instance . v_is_parameter : # Lock parameter as soon as data is loaded instance . f_lock ( ) except : self . _logger . error ( 'Error while reconstructing data of leaf `%s`.' % full_name ) raise # Signal completed node loading self . _node_processing_timer . signal_update ( )
Loads a parameter or result from disk.

        :param instance:

            Empty parameter or result instance

        :param load_data:

            How to load stuff

        :param load_only:

            List of data keys if only parts of a result should be loaded

        :param load_except:

            List of data key that should NOT be loaded.

        :param load_flags:

            Dictionary to determine how something is loaded

        :param with_links:

            Placeholder, because leaves have no links

        :param recursive:

            Dummy variable, no-op because leaves have no children

        :param max_depth:

            Dummy variable, no-op because leaves have no children

        :param _hdf5_group:

            The corresponding hdf5 group of the instance
Loads a parameter or result from disk .