Changeset 484 for trunk

Show
Ignore:
Timestamp:
03/24/11 12:45:12 (14 months ago)
Author:
pierre
Message:

Fix some bugs in id_offset for negative offsets, and for the time_histogram. Rounding errors with int time bins.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/signals/spikes.py

    r483 r484  
    563563        else: 
    564564            hist, edges = numpy.histogram(self.spike_times, bins) 
    565         if normalized and isinstance(time_bin, int): # what about normalization if time_bin is a sequence? 
    566             hist *= 1000.0/time_bin 
     565        hist = hist.astype(float) 
     566        if normalized: # what about normalization if time_bin is a sequence? 
     567            hist *= 1000.0/float(time_bin) 
    567568        return hist 
    568569 
     
    769770        """ 
    770771        hist       = self.time_histogram(time_bin, normalized=False) 
     772        from NeuroTools import analysis 
    771773        freq_spect = analysis.simple_frequency_spectrum(hist) 
    772774        freq_bin   = 1000.0/self.duration() # Hz 
     
    11921194        id_list     = numpy.sort(self.id_list) 
    11931195        N           = len(id_list) 
    1194          
    1195         for idx in xrange(1,len(id_list)+1): 
    1196             id  = id_list[N-idx] 
    1197             spk = self.spiketrains.pop(id) 
    1198             self.spiketrains[id + offset] = spk 
     1196        if (offset > 0):         
     1197            for idx in xrange(1, len(id_list)+1): 
     1198                id  = id_list[N-idx] 
     1199                spk = self.spiketrains.pop(id) 
     1200                self.spiketrains[id + offset] = spk 
     1201        if (offset < 0):         
     1202            for idx in xrange(0, len(id_list)): 
     1203                id  = id_list[idx] 
     1204                spk = self.spiketrains.pop(id) 
     1205                self.spiketrains[id + offset] = spk 
    11991206     
    12001207    def first_spike_time(self): 
     
    18821889            hist_2 = pairs_generator.spk2[pairs[idx,1]].time_histogram(time_bin) 
    18831890            if not average: 
     1891                from NeuroTools import analysis 
    18841892                results[idx,:] = analysis.ccf(hist_1,hist_2) 
    18851893            else: 
     1894                from NeuroTools import analysis 
    18861895                results += analysis.ccf(hist_1,hist_2) 
    18871896        if not subplot or not HAVE_PYLAB: 
     
    21862195        for ev in events: 
    21872196           ev = numpy.floor(ev/time_bin) 
    2188            if ((ev - t_min_l )> t_start) and (ev + t_max_l ) < t_stop: 
     2197           if ((ev - t_min_l )> t_start) and (ev + t_max_l ) < t_stop:                
    21892198               count  += 1 
    2190                result += spk_hist[:,(ev-t_min_l):ev+t_max_l] 
     2199               result += spk_hist[:,(ev-t_start-t_min_l):ev-t_start+t_max_l] 
    21912200        result /= count 
    21922201        if average: 
     
    22562265        else: 
    22572266            files        = [] 
    2258             activity_map = numpy.zeros(self.dimensions) 
    2259             im           = subplot.imshow(activity_map, **kwargs) 
    2260             im.set_clim(bounds[0],bounds[1]) 
    2261             pylab.colorbar(im) 
     2267            if float_positions is None: 
     2268                activity_map = numpy.zeros(self.dimensions) 
     2269                im           = subplot.imshow(activity_map, **kwargs) 
     2270                im.set_clim(bounds[0],bounds[1]) 
     2271                pylab.colorbar(im) 
     2272            else: 
     2273                rates        = [0]*len(self) 
     2274                im           = subplot.scatter(float_positions[0,:], float_positions[1,:], c=rates, **kwargs) 
     2275                im.set_clim(bounds[0],bounds[1]) 
     2276                pylab.colorbar(im) 
    22622277            count     = 0 
    22632278            idx       = 0 
     
    22862301                    im.set_array(activity_map) 
    22872302                    subplot.title("time = %d ms" %t_start) 
    2288                     manager.canvas.draw() 
    22892303                    im.set_clim(bounds[0],bounds[1]) 
     2304                    manager.canvas.draw()                     
    22902305                    fname = "_tmp_spikes_%05d.png" %count 
    22912306                    #logging.debug("Saving Frame %s", fname) 
     
    22942309                    files.append(fname) 
    22952310                    t_start += time_bin 
    2296                     count += 1           
     2311                    count += 1    
     2312            elif isinstance(float_positions, numpy.ndarray): 
     2313                if not len(self) == len(float_positions[0]): 
     2314                    raise Exception("Error, the number of flotting positions does not match the number of cells in the SpikeList") 
     2315                while (t_start < t_stop): 
     2316                    rates = [0]*len(self) 
     2317                    while ((time[idx] < t_start + time_bin) and (idx < max_idx)):                                                 
     2318                        rates[pos[idx]] += 1 
     2319                        idx += 1 
     2320                    im = subplot.scatter(float_positions[0,:], float_positions[1,:], c=rates, **kwargs) 
     2321                    subplot.title("time = %d ms" %t_start) 
     2322                    im.set_clim(bounds[0],bounds[1]) 
     2323                    manager.canvas.draw() 
     2324                    fname = "_tmp_spikes_%05d.png" %count 
     2325                    #logging.debug("Saving Frame %s", fname) 
     2326                    progress_bar(float(t_start)/t_stop) 
     2327                    pylab.savefig(fname) 
     2328                    files.append(fname) 
     2329                    t_start += time_bin 
     2330                    count += 1    
    22972331            command = "mencoder 'mf://_tmp_*.png' -mf type=png:fps=%d -ovc lavc -lavcopts vcodec=wmv2 -oac copy -o %s" %(fps,output) 
    22982332            logging.debug(command)