Esempio n. 1
0
    def FromDict(self, dict_source):
        """ Initialize kernel from dictionnary        

        Parameters
        ----------
        dict_source : dict. Must have the following keys: ['shape', 'type', 'padding']
        """
        assert ('shape' in dict_source and 'type' in dict_source and 'padding'
                in dict_source), 'Source dict missing required keys'

        _shape = sf.StrParse(dict_source['shape'], int)
        _type = str(dict_source['type'])
        _padding = sf.StrParse(dict_source['padding'], bool)
        if (_type == 'Gauss'):
            assert 'sigma' in dict_source, 'Gaussian kernel dict missing sigma key'
            _params = {'sigma': sf.StrParse(dict_source['sigma'], float)}
        else:
            _params = {}
        if 'n_dim' in dict_source:
            n_dim = int(dict_source['n_dim'])
        else:
            n_dim = len(_shape)
        _conv_kwargs = {}
        if 'convolve_kwargs' in dict_source:
            _conv_kwargs.update(sf.StrParse(dict_source['convolve_kwargs']))

        self.Initialize(_shape, _type, _params, n_dim, _padding, _conv_kwargs)
Esempio n. 2
0
 def Get(self, sect, key, default=None, cast_type=None, silent=True):
     """Gets configuration entry
     
     Parameters
     ----------
     sect : section name (string)
     key : key name (string)
     default : variable to be returned if section/key is not present
     cast_type : if not None, cast variable to type
                 default type is string
     silent : output default without printing any warning message
     
     Returns
     -------
     variable. Can be dictionary or list.
     """
     if (self.config.has_option(sect, key)):
         return sf.StrParse(self.config[sect][key], cast_type)
     else:
         if not silent:
             print('"' + key + '" not found in section "' + sect +
                   '": default value ' + str(default) + ' returned.')
         return default