Ejemplo n.º 1
0
    def runTest(self):

        f = plotting.get_display(True)
        x = range(10)
        pylab.plot(x)
        plotting.set_axis_limits(pylab, 0., 123., -123., 456.)

        # set up a SimpleMultiplot with arbitrary values
        self.nrows = 1
        self.ncolumns = 1
        title = 'testMultiplot'
        xlabel = 'testXlabel'
        ylabel = 'testYlabel'
        scaling = ('linear','log')
        self.smt = plotting.SimpleMultiplot(nrows=self.nrows, ncolumns=self.ncolumns, title=title, xlabel=xlabel, ylabel=ylabel, scaling=scaling)
        plotting.set_axis_limits(self.smt.panel(0), 0., 123., -123., 456.)
Ejemplo n.º 2
0
 def event_triggered_average(self, events, average = True, t_min = 0, t_max = 100, display = False, with_time = False, kwargs={}):
     """
     Return the spike triggered averaged of an analog signal according to selected events, 
     on a time window t_spikes - tmin, t_spikes + tmax
     Can return either the averaged waveform (average = True), or an array of all the
     waveforms triggered by all the spikes.
     
     Inputs:
         events  - Can be a SpikeTrain object (and events will be the spikes) or just a list 
                   of times
         average - If True, return a single vector of the averaged waveform. If False, 
                   return an array of all the waveforms.
         t_min   - Time (>0) to average the signal before an event, in ms (default 0)
         t_max   - Time (>0) to average the signal after an event, in ms  (default 100)
         display - if True, a new figure is created. Could also be a subplot.
         kwargs  - dictionary contening extra parameters that will be sent to the plot 
                   function
         
     Examples:
         >> vm.event_triggered_average(spktrain, average=False, t_min = 50, t_max = 150)
         >> vm.event_triggered_average(spktrain, average=True)
         >> vm.event_triggered_average(range(0,1000,10), average=False, display=True)
     """
     
     if isinstance(events, SpikeTrain):
         events = events.spike_times
         ylabel = "Spike Triggered Average"
     else:
         assert numpy.iterable(events), "events should be a SpikeTrain object or an iterable object"
         ylabel = "Event Triggered Average"
     assert (t_min >= 0) and (t_max >= 0), "t_min and t_max should be greater than 0"
     assert len(events) > 0, "events should not be empty and should contained at least one element"
     time_axis = numpy.linspace(-t_min, t_max, (t_min+t_max)/self.dt)
     N         = len(time_axis)
     Nspikes   = 0.
     subplot   = get_display(display)
     if average:
         result = numpy.zeros(N, float)
     else:
         result = []
     
     # recalculate everything into timesteps, is more stable against rounding errors
     # and subsequent cutouts with different sizes
     events = numpy.floor(numpy.array(events)/self.dt)
     t_min_l = numpy.floor(t_min/self.dt)
     t_max_l = numpy.floor(t_max/self.dt)
     t_start = numpy.floor(self.t_start/self.dt)
     t_stop = numpy.floor(self.t_stop/self.dt)
     
     for spike in events:
         if ((spike-t_min_l) >= t_start) and ((spike+t_max_l) < t_stop):
             spike = spike - t_start
             if average:
                 result += self.signal[(spike-t_min_l):(spike+t_max_l)]
             else:
                 result.append(self.signal[(spike-t_min_l):(spike+t_max_l)])
             Nspikes += 1
     if average:
         result = result/Nspikes
     else:
         result = numpy.array(result)
         
     if not subplot or not HAVE_PYLAB:
         if with_time:
             return result, time_axis
         else:
             return result
     else:
         xlabel = "Time (ms)"
         set_labels(subplot, xlabel, ylabel)
         if average:
             subplot.plot(time_axis, result, **kwargs)
         else:
             for idx in xrange(len(result)):
                 subplot.plot(time_axis, result[idx,:], c='0.5', **kwargs)
                 subplot.hold(1)
             result = numpy.sum(result, axis=0)/Nspikes
             subplot.plot(time_axis, result, c='k', **kwargs)
         xmin, xmax, ymin, ymax = subplot.axis()
                     
         subplot.plot([0,0],[ymin, ymax], c='r')
         set_axis_limits(subplot, -t_min, t_max, ymin, ymax)
         pylab.draw()