Changeset 342

Show
Ignore:
Timestamp:
11/15/08 16:28:02 (2 months ago)
Author:
JensKremkow
Message:

add SpikeTrain jitter function

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/signals.py

    r337 r342  
    239239 
    240240        return spike_times 
     241 
     242    def jitter(self,jitter): 
     243        """ 
     244        Returns a new SpikeTrain with spiketimes jittered by a normal distribution. 
     245 
     246        Inputs: 
     247              jitter - sigma of the normal distribution 
     248 
     249        Examples: 
     250              >> st_jittered = st.jitter(2.0) 
     251        """ 
     252         
     253        return SpikeTrain(self.spike_times+numpy.random.normal(loc=0.0,scale=jitter,size=self.spike_times.shape[0]),t_start=self.t_start,t_stop=self.t_stop) 
    241254 
    242255 
     
    22912304        assert t_stop<=self.t_stop 
    22922305        assert t_stop>t_start 
    2293  
     2306         
    22942307        t = self.time_axis() 
    22952308        i_start = numpy.searchsorted(t,t_start,'right')-1 
     
    23012314        return result 
    23022315 
    2303     def threshold_detection(self, threshold=None, format=None): 
     2316    def threshold_detection(self, threshold=None, format=None,sign='above'): 
    23042317        """ 
    23052318        Returns the times when the analog signal crosses a threshold. 
     
    23112324             format    - when 'raw' the raw events array is returned,  
    23122325                         otherwise this is a SpikeTrain object by default 
     2326             sign      - 'above' detects when the signal gets above the threshodl, 'below when it gets below the threshold' 
    23132327                 
    23142328        Examples: 
     
    23182332         
    23192333        assert threshold is not None, "threshold must be provided" 
    2320          
    2321         above = numpy.where(self.signal > threshold)[0] 
    2322         if len(above) <= 0: 
     2334 
     2335        if sign is 'above': 
     2336            cutout = numpy.where(self.signal > threshold)[0] 
     2337        elif sign in 'below': 
     2338            cutout = numpy.where(self.signal < threshold)[0] 
     2339             
     2340        if len(cutout) <= 0: 
    23232341            events = [] 
    23242342        else: 
    2325             take = numpy.where(numpy.diff(above)>1)[0]+1 
     2343            take = numpy.where(numpy.diff(cutout)>1)[0]+1 
    23262344            take = numpy.append(0,take) 
    23272345             
    23282346            time = self.time_axis() 
    2329             events = time[above][take] 
     2347            events = time[cutout][take] 
    23302348 
    23312349        if format is 'raw': 
     
    23352353             
    23362354                     
    2337     def event_triggered_average(self, events, average = True, t_min = 0, t_max = 100, display = False, kwargs={}): 
     2355    def event_triggered_average(self, events, average = True, t_min = 0, t_max = 100, display = False, with_time = False, kwargs={}): 
    23382356        """ 
    23392357        Return the spike triggered averaged of an analog signal according to selected events,  
     
    23982416             
    23992417        if not subplot or not ENABLE_PLOTS: 
    2400             return result 
     2418            if with_time: 
     2419                return result, time_axis 
     2420            else: 
     2421                return result 
    24012422        else: 
    24022423            xlabel = "Time (ms)"