Changeset 475 for trunk

Show
Ignore:
Timestamp:
11/11/10 14:13:19 (19 months ago)
Author:
emuller
Message:

Get rid of annoying 'scipy missing' message when using NeuroTools.parameters

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/random.py

    r446 r475  
    1919import numpy, numpy.random 
    2020 
    21 have_scipy = check_dependency('scipy') 
    22  
    23      
     21   
    2422class ParameterDist(object): 
    2523 
     
    6765        either mean,var ('ms', the default) or a,b ('ab') 
    6866        """ 
     67 
     68        if check_dependency('scipy'): 
     69            self.next = self._next_scipy 
     70 
    6971        self.repr_mode = repr_mode 
    7072        if 'm' in params and mean==None: 
     
    9395        self.dist_name = 'GammaDist' 
    9496 
    95     if have_scipy: 
     97    def _next_scipy(self,n=1): 
    9698        import scipy.stats 
    97         def next(self,n=1): 
    98             return scipy.stats.gamma.rvs(self.params['a'],size=n)*self.params['b'] 
    99     else: 
    100         def next(self,n=1): 
    101             raise Exception('Error scipy was not found at import time.  GammaDist realization disabled.') 
    102          
     99        return scipy.stats.gamma.rvs(self.params['a'],size=n)*self.params['b'] 
     100    def _next_no_scipy(self,n=1): 
     101        raise Exception('Error scipy was not found at import time.  GammaDist realization disabled.') 
     102 
     103    next = _next_no_scipy 
     104     
    103105    def mean(self): 
    104106        return self.params['a']*self.params['b'] 
     
    119121    mean + std 
    120122     
    121     Generally the distribution is implemented 
    122     by scipy.stats.gamma.pdf(x/b,a)/b 
    123  
    124     For more info, in ipython type: 
    125     >>> ? scipy.stats.gamma  
    126  
    127123    """ 
    128124