Changeset 181

Show
Ignore:
Timestamp:
07/23/08 20:25:14 (4 months ago)
Author:
apdavison
Message:

SpikeTrain.subSpikeTrain(t_start, t_stop) now allows t_start and t_stop to be sequences of start and stop values. e.g., to pick out spikes between 0 and 100 ms and between 1000 and 1100 ms:

    new_spike_train = spike_train.subSpikeTrain([0, 1000], [100, 1100])
Files:

Legend:

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

    r180 r181  
    219219        self.spike_time = sort(self.spike_time) 
    220220 
    221     # Return a sub SpikeTrain object between two time bounds 
    222221    def subSpikeTrain(self, t_start, t_stop): 
    223         """ returns a spike train sliced between t_start and t_stop 
    224  
    225         """ 
    226         idx = numpy.where((self.spike_times >= t_start) & (self.spike_times <= t_stop))[0] 
     222        """ Returns a spike train sliced between t_start and t_stop 
     223        t_start and t_stop may either be single values or sequences of start 
     224        and stop times. 
     225        """ 
     226        if hasattr(t_start, '__len__'): 
     227            assert len(t_start) == len(t_stop) 
     228            mask = False 
     229            for t0,t1 in zip(t_start, t_stop): 
     230                mask = mask | (self.spike_times >= t0) & (self.spike_times <= t1) 
     231            t_start = t_start[0] 
     232            t_stop = t_stop[-1] 
     233        else: 
     234            mask = (self.spike_times >= t_start) & (self.spike_times <= t_stop) 
     235        idx = numpy.where(mask)[0] 
    227236        spikes = self.spike_times[idx] 
    228237        return SpikeTrain(spikes, self.dt, t_start, t_stop) 
     
    240249            hist *= 1000.0/time_bin 
    241250        return hist 
     251 
     252    def rescale(self): 
     253        """Rescale spike times to make t_start = 0.""" 
     254        if self.t_start != 0: 
     255            self.spike_times -= self.t_start 
     256            self.t_stop -= self.t_start 
     257            self.t_start = 0.0 
    242258 
    243259    def tuning_curve(self, var_array, normalized=False, method='sum'): 
     
    269285        time_histogram = self.time_histogram(binwidth, normalized=normalized) 
    270286        assert len(time_histogram) == len(var_array) 
    271         #def _orientation_tuning_curve(time_bins, orientations, responses, method='sum'): 
    272287        tuning_curve = {} 
    273288        counts = {}