Changeset 443

Show
Ignore:
Timestamp:
01/18/10 16:45:34 (2 years ago)
Author:
apdavison
Message:

datastore key-generators now work properly if the component is the __main__ module.
Fixed a couple of rounding errors in signals.

Location:
trunk/src
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/datastore/keygenerators.py

    r385 r443  
    22Key generators for data store objects 
    33""" 
    4 import hashlib, pickle 
     4import hashlib, pickle, sys, os.path 
    55 
    66def full_type(component): 
    77    """Returns a string representing the full type of the component.""" 
    88    if component.__class__.__name__ == 'module': # component is a module 
    9         return component.__name__ 
     9        if component.__name__ == "__main__": 
     10            return os.path.basename(sys.argv[0][:-3]) 
     11        else: 
     12            return component.__name__ 
    1013    else: 
    1114        return component.__module__ + '.' + component.__class__.__name__ 
  • trunk/src/signals/analogs.py

    r390 r443  
    209209         
    210210        t = self.time_axis() 
    211         i_start = int((t_start-self.t_start)/self.dt) 
    212         i_stop = int((t_stop-self.t_start)/self.dt) 
     211        i_start = int(round((t_start-self.t_start)/self.dt)) 
     212        i_stop = int(round((t_stop-self.t_start)/self.dt)) 
    213213        signal = self.signal[i_start:i_stop] 
    214214        result = AnalogSignal(signal, self.dt, t_start, t_stop) 
     
    471471            errmsgs = [] 
    472472            for attr in "dt", "t_start", "t_stop": 
    473                 if getattr(val, attr) != getattr(self, attr): 
    474                     errmsgs.append("%s: %g != %g" % (attr, getattr(val, attr), getattr(self, attr))) 
     473                if getattr(self, attr) == 0: 
     474                    if getattr(val, attr) != 0: 
     475                        errmsgs.append("%s: %g != %g (diff=%g)" % (attr, getattr(val, attr), getattr(self, attr), getattr(val, attr)-getattr(self, attr))) 
     476                elif (getattr(val, attr) - getattr(self, attr))/getattr(self, attr) > 1e-12: 
     477                    errmsgs.append("%s: %g != %g (diff=%g)" % (attr, getattr(val, attr), getattr(self, attr), getattr(val, attr)-getattr(self, attr))) 
    475478            if len(val) != self.signal_length: 
    476479                errmsgs.append("signal length: %g != %g" % (len(val), self.signal_length)) 
     
    703706            mean 
    704707        """ 
    705         result = numpy.zeros((len(self), int((self.t_stop - self.t_start)/self.dt)),float) 
     708        result = numpy.zeros((len(self), int(round((self.t_stop - self.t_start)/self.dt))), float) 
    706709        for count, id in enumerate(self.id_list()): 
    707710            try: 
  • trunk/src/signals/spikes.py

    r436 r443  
    16861686        if len(self.dimensions) == 2: 
    16871687            x = (id-offset) % self.dimensions[1] 
    1688             y = self.dimensions[0] - 1 - int(numpy.floor((id-offset)/self.dimensions[1])) 
     1688            y = self.dimensions[0] - 1 - numpy.floor((id-offset)/self.dimensions[1]).astype(int) 
    16891689            return (x,y) 
    16901690