Changeset 266

Show
Ignore:
Timestamp:
11/02/08 17:42:18 (5 years ago)
Author:
JensKremkow
Message:

minor changes in signals, spikes and add IF-Curve example for spike2

Location:
trunk
Files:
2 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/signals.py

    r265 r266  
    19901990        self.t_start = t_start 
    19911991        self.t_stop  = t_stop 
    1992  
     1992         
    19931993        # If t_start is not None, we resize the signal keeping only 
    19941994        # elements with t >= t_start 
    1995         if self.t_start is not None: 
    1996             self.signal = self.signal[(self.t_start/self.dt):] 
     1995        #if self.t_start is not None: 
     1996        #    self.signal = self.signal[(self.t_start/self.dt):] 
    19971997 
    19981998        # If t_stop is not None, we resize the signal keeping only 
    19991999        # elements with t <= t_stop 
    2000         if self.t_stop is not None: 
    2001             self.signal = self.signal[:(self.t_stop-self.t_start)/self.dt] 
     2000        #if self.t_stop is not None: 
     2001        #    self.signal = self.signal[:(self.t_stop-self.t_start)/self.dt] 
    20022002 
    20032003        if len(self.signal) > 0: # spike list may be empty 
     
    20322032        return len(self.signal) 
    20332033 
     2034    def max(self): 
     2035        return self.signal.max() 
     2036 
     2037    def min(self): 
     2038        return self.signal.min() 
     2039 
    20342040    def copy(self): 
    20352041        """ 
     
    20382044        return AnalogSignal(self.signal, self.dt, self.t_start, self.t_stop) 
    20392045 
    2040     def time_axis(self): 
     2046    def time_axis(self,normalized=False): 
    20412047        """ 
    20422048        Return the time axis of the AnalogSignal 
    20432049        """ 
    2044         return numpy.linspace(self.t_start, self.t_stop, len(self.signal)) 
     2050        if normalized: 
     2051            norm = self.t_start 
     2052        else: 
     2053            norm = 0. 
     2054        return numpy.linspace(self.t_start-norm, self.t_stop-norm, len(self.signal)) 
    20452055 
    20462056    def time_parameters(self): 
     
    20692079        Inputs: 
    20702080             threshold - Threshold 
    2071              format - when 'spiketrain' a SpikeTrain object is returned, else a numpy.array 
     2081             format - when 'raw' the raw events array is returned, otherwise a SpikeTrain object 
    20722082         
    20732083        """ 
     
    20762086         
    20772087        above = numpy.where(self.signal > threshold)[0] 
    2078         take = numpy.where(numpy.diff(above)>1)[0]+1 
    2079         take = numpy.append(0,take) 
    2080                  
    2081         time = self.time_axis() 
    2082         events = time[above][take] 
    2083  
    2084         if format is 'spiketrain': 
     2088        if len(above) <= 0: 
     2089            events = [] 
     2090        else: 
     2091            take = numpy.where(numpy.diff(above)>1)[0]+1 
     2092            take = numpy.append(0,take) 
     2093             
     2094            time = self.time_axis() 
     2095            events = time[above][take] 
     2096 
     2097        if format is 'raw': 
     2098            return events 
     2099        else: 
    20852100            return SpikeTrain(events,t_start=self.t_start,t_stop=self.t_stop) 
    2086         else: 
    2087             return events 
    2088      
     2101             
    20892102                     
    20902103    def event_triggered_average(self, events, average = True, t_min = 0, t_max = 100, display = False, kwargs={}): 
     
    21692182            set_axis_limits(subplot, -t_min, t_max, ymin, ymax) 
    21702183            pylab.draw() 
     2184 
     2185    def slice_by_events(self,events,t_min=100,t_max=100): 
     2186        """ 
     2187         
     2188        """ 
     2189        if isinstance(events, SpikeTrain): 
     2190            events = events.spike_times 
     2191        else: 
     2192            assert numpy.iterable(events), "events should be a SpikeTrain object or an iterable object" 
     2193        assert (t_min >= 0) and (t_max >= 0), "t_min and t_max should be greater than 0" 
     2194        assert len(events) > 0, "events should not be empty and should contained at least one element" 
     2195         
     2196        # in timesteps 
     2197        events = numpy.floor(numpy.array(events)/self.dt) 
     2198        t_min_l = numpy.floor(t_min/self.dt) 
     2199        t_max_l = numpy.floor(t_max/self.dt) 
     2200        t_start = numpy.floor(self.t_start/self.dt) 
     2201        t_stop = numpy.floor(self.t_stop/self.dt) 
     2202         
     2203        result = {} 
     2204        for index, spike in enumerate(events): 
     2205            if ((spike-t_min_l) > t_start) and ((spike+t_max_l) < t_stop): 
     2206                spike = spike - t_start 
     2207                signal = self.signal[(spike-t_min_l):(spike+t_max_l)] 
     2208                t_start_new = (spike-t_min_l)*self.dt 
     2209                t_stop_new = (spike+t_max_l)*self.dt 
     2210                result[index] = AnalogSignal(signal, self.dt, t_start=t_start_new, t_stop=t_stop_new) 
     2211 
     2212        return result 
     2213         
     2214             
    21712215 
    21722216 
  • trunk/src/spike2/sonpy/son.py

    r265 r266  
    208208                if interval == 0: interval = 1. 
    209209                # in milliseconds 
    210                 self.dt = interval*fhead.usPerTime*fhead.dTimeBase*1e3 
     210                # have to multiply by 2, I dont know why, I have to check that 
     211                self.dt = interval*fhead.usPerTime*fhead.dTimeBase*1e3*2 
    211212                 
    212213        def type(self):