Changeset 418
- Timestamp:
- 08/17/09 21:30:58 (3 years ago)
- Files:
-
- 1 modified
-
branches/interval/src/signals/spikes.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/interval/src/signals/spikes.py
r410 r418 26 26 27 27 import os, re, numpy 28 import copy 28 29 import logging 29 30 from NeuroTools import check_dependency, check_numpy_version, analysis … … 111 112 112 113 113 114 114 def __str__(self): 115 115 return str(self.spike_times) 116 117 def __format__(self): 118 return 'hella' 116 119 117 120 def __len__(self): … … 393 396 spikes = interval.slice_times(self.spike_times) 394 397 else: 395 spikes = self 398 spikes = self.spike_times 396 399 397 400 subplot = get_display(display) … … 401 404 else: 402 405 if len(spikes) > 0: 403 subplot.plot(spikes,numpy.ones(len(spikes)),',', **kwargs)406 subplot.plot(spikes,numpy.ones(len(spikes)),',', **kwargs) 404 407 xlabel = "Time (ms)" 405 408 ylabel = "Neurons #" … … 466 469 """ 467 470 Bin the spikes with the specified bin width. The first and last bins 468 are calculated from `self.t_start` and `self.t_stop`.471 are calculated from the interval of the spike train. 469 472 470 473 Inputs: … … 576 579 577 580 578 def psth(self, events, time_bin=2, t_min=50, t_max=50, display = False, kwargs={}):581 def psth(self, events, time_bin=2, t_min=50, t_max=50, display = False, labels=True, kwargs={}): 579 582 """ 580 583 Return the psth of the spike times contained in the SpikeTrain according to selected events, … … 587 590 t_min - Time (>0) to average the signal before an event, in ms (default 0) 588 591 t_max - Time (>0) to average the signal after an event, in ms (default 100) 589 display - if True, a new figure is created. Could also be a subplot. 592 display - if True, the psth is displayed in a new figure. If a Matplotlib Axes name, 593 the psth is displayed inside this Axes. 594 labels - if True, psth plot has full labels. If not, the plot is shown 'raw' 590 595 kwargs - dictionary contening extra parameters that will be sent to the plot 591 596 function … … 603 608 events = events.spike_times 604 609 assert (t_min >= 0) and (t_max >= 0), "t_min and t_max should be greater than 0" 605 assert len(events) > 0, "events should not be empty and should contained at least one element" 606 610 assert len(events) > 0, "events should not be empty" 607 611 spk_hist = self.time_histogram(time_bin) 608 612 subplot = get_display(display) 609 613 count = 0 610 t_min_l = numpy.floor(t_min/ time_bin)611 t_max_l = numpy.floor(t_max/ time_bin)614 t_min_l = numpy.floor(t_min/float(time_bin)) 615 t_max_l = numpy.floor(t_max/float(time_bin)) 612 616 result = numpy.zeros((t_min_l+t_max_l), numpy.float32) 617 events_interval = copy.copy(self.interval) 618 events_interval.offset_start(t_min, colapse=True) 619 events_interval.offset_stop(-t_max, colapse=True) 620 events = events_interval.slice_times(events) 621 assert len(events) > 0, "the PSTH windows [event-t_min, event+t_max] should be included within the spike train interval" 613 622 for ev in events: 614 itv = Interval((ev-t_min,ev+t_max)) 615 ev = numpy.floor(ev/time_bin) 616 if itv.intersect(self.interval).total_duration() == (t_max+t_min): 617 count += 1 618 result += spk_hist[(ev-t_min_l):ev+t_max_l] 623 ev = numpy.floor((ev - self.interval.t_start())/float(time_bin)) 624 count += 1. 625 result += spk_hist[(ev-t_min_l):ev+t_max_l] 619 626 result /= count 620 627 … … 622 629 return result 623 630 else: 624 xlabel = "Time (ms)" 625 ylabel = "PSTH" 626 time = numpy.linspace(-t_min, t_max, (t_min+t_max)/time_bin) 627 set_labels(subplot, xlabel, ylabel) 631 if labels : 632 xlabel = "Time (ms)" 633 ylabel = "PSTH" 634 set_labels(subplot, xlabel, ylabel) 635 else : 636 subplot.xaxis.set_major_locator(pylab.NullLocator()) 637 subplot.yaxis.set_major_locator(pylab.NullLocator()) 638 time = numpy.linspace(-t_min, t_max, (t_min+t_max)/time_bin) 628 639 subplot.plot(time, result, c='k', **kwargs) 629 640 xmin, xmax, ymin, ymax = subplot.axis() 630 subplot.plot([0,0],[ymin, ymax], c='r')641 subplot.axvline(0, c='r') 631 642 set_axis_limits(subplot, -t_min, t_max, ymin, ymax) 632 643 pylab.draw() … … 795 806 [0,1,2,3,....,9999] 796 807 """ 808 print self.spiketrains.keys() 797 809 return numpy.array(self.spiketrains.keys(), int) 798 810
