Changeset 489

Show
Ignore:
Timestamp:
07/25/11 16:08:20 (10 months ago)
Author:
pierre
Message:

Add an average option for PSTH, if the user wants to have errorbar or not on the final results

Files:
1 modified

Legend:

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

    r487 r489  
    737737     
    738738     
    739     def psth(self, events, time_bin=2, t_min=50, t_max=50, display = False, kwargs={}): 
     739    def psth(self, events, time_bin=2, t_min=50, t_max=50, display = False, kwargs={}, average=True): 
    740740        """ 
    741741        Return the psth of the spike times contained in the SpikeTrain according to selected events,  
     
    774774        t_start  = numpy.floor(self.t_start/time_bin) 
    775775        t_stop   = numpy.floor(self.t_stop/time_bin) 
     776        result   = [] 
    776777        for ev in events: 
    777778           ev = numpy.floor(ev/time_bin) 
    778779           if ((ev - t_min_l )> t_start) and (ev + t_max_l ) < t_stop: 
    779780               count  += 1 
    780                result += spk_hist[(ev-t_min_l):ev+t_max_l] 
    781         result /= count 
     781               result += [spk_hist[(ev-t_min_l):ev+t_max_l]] 
     782        result = numpy.array(result)     
     783        if average:         
     784            result /= count 
    782785         
    783786        if not subplot or not HAVE_PYLAB: 
     
    23952398               result += spk_hist[:,(ev-t_start-t_min_l):ev-t_start+t_max_l] 
    23962399        result /= count 
    2397         if average: 
    2398            result = numpy.mean(result, 0) 
    23992400             
    24002401        if not subplot or not HAVE_PYLAB: 
     
    24072408            if average: 
    24082409                subplot.plot(time, result, **kwargs) 
     2410                subplot.errorbar(times, mean(result, 0), yerr=std(result, 0)) 
    24092411            else: 
    24102412                for idx in xrange(len(result)): 
     
    24172419            set_axis_limits(subplot, -t_min, t_max, ymin, ymax) 
    24182420            pylab.draw() 
     2421        if average: 
     2422            result = numpy.mean(result, 0) 
    24192423        return result 
    24202424 
     
    25012505                    fname = "_tmp_spikes_%05d.png" %count 
    25022506                    #logging.debug("Saving Frame %s", fname) 
    2503                     progress_bar(float(t_start)/t_stop) 
     2507                    #progress_bar(float(t_start)/t_stop) 
    25042508                    pylab.savefig(fname) 
    25052509                    files.append(fname)