- Timestamp:
- 06/25/09 18:04:50 (3 years ago)
- Files:
-
- 1 modified
-
trunk/src/signals/spikes.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/signals/spikes.py
r404 r406 617 617 events - Can be a SpikeTrain object (and events will be the spikes) or just a list 618 618 of times 619 time_bin- The time bin (in ms) used to gather the spike for the psth 619 620 t_min - Time (>0) to average the signal before an event, in ms (default 0) 620 621 t_max - Time (>0) to average the signal after an event, in ms (default 100) … … 876 877 #def __setslice__(self, i, j): 877 878 879 880 878 881 def __setitem__(self, id, spktrain): 879 882 assert isinstance(spktrain, SpikeTrain), "A SpikeList object can only contain SpikeTrain objects" … … 1182 1185 1183 1186 1184 def select_ids(self, criteria =None):1187 def select_ids(self, criteria): 1185 1188 """ 1186 1189 Return the list of all the cells in the SpikeList that will match the criteria … … 1203 1206 selected_ids.append(id) 1204 1207 return selected_ids 1208 1209 def sort_by(self, criteria, descending=False): 1210 """ 1211 Return an array with all the ids of the cells in the SpikeList, 1212 sorted according to a particular criteria. 1213 1214 Inputs: 1215 criteria - the criteria used to sort the cells. It should be a string 1216 that can be evaluated on a SpikeTrain object, where the 1217 SpikeTrain should be named ``cell''. 1218 descending - if True, then the cells are sorted from max to min. 1219 1220 Examples: 1221 >> spk.sort_by('cell.mean_rate()') 1222 >> spk.sort_by('cell.cv_isi()', descending=True) 1223 >> spk.sort_by('cell.distance_victorpurpura(target, 0.05)') 1224 """ 1225 criterias = numpy.zeros(len(self), float) 1226 for count, id in enumerate(self.id_list()): 1227 cell = self.spiketrains[id] 1228 criterias[count] = eval(criteria) 1229 result = self.id_list()[numpy.argsort(criterias)] 1230 if descending: 1231 return result[numpy.arange(len(result)-1, -1, -1)] 1232 else: 1233 return result 1205 1234 1206 1235 … … 1559 1588 if newnum: 1560 1589 axis = axis[:len(axis)-1] 1561 subplot.plot(axis,numpy. sum(spike_hist, axis=0)/N,**kwargs)1590 subplot.plot(axis,numpy.mean(spike_hist, axis=0),**kwargs) 1562 1591 pylab.draw() 1563 1592 1564 1593 1565 def firing_rate(self, time_bin, display=False, kwargs={}):1594 def firing_rate(self, time_bin, display=False, average=False, kwargs={}): 1566 1595 """ 1567 1596 Generate an array with all the instantaneous firing rates along time (in Hz) 1568 of all the SpikeTrains objects within the SpikeList. 1597 of all the SpikeTrains objects within the SpikeList. If average is True, it gives the 1598 average firing rate over the whole SpikeList 1569 1599 1570 1600 Inputs: 1571 1601 time_bin - the time bin used to gather the data 1602 average - If True, return a single vector of the average firing rate over the whole SpikeList 1572 1603 display - if True, a new figure is created. Could also be a subplot. The averaged 1573 1604 spike_histogram over the whole population is then plotted … … 1578 1609 spike_histogram, time_axis 1579 1610 """ 1580 return self.spike_histogram(time_bin, normalized=True, display=display, kwargs=kwargs) 1581 1611 result = self.spike_histogram(time_bin, normalized=True, display=display, kwargs=kwargs) 1612 if average: 1613 return numpy.mean(result, axis=0) 1614 else: 1615 return result 1582 1616 1583 1617 def fano_factor(self, time_bin): … … 1596 1630 """ 1597 1631 firing_rate = self.spike_histogram(time_bin) 1598 firing_rate = numpy. sum(firing_rate,axis=0)1632 firing_rate = numpy.mean(firing_rate, axis=0) 1599 1633 fano = numpy.var(firing_rate)/numpy.mean(firing_rate) 1600 1634 return fano … … 1973 2007 """ 1974 2008 firing_rate = self.firing_rate(time_bin) 1975 return numpy.var(numpy. sum(firing_rate, axis=0)/len(self))2009 return numpy.var(numpy.mean(firing_rate, axis=0)) 1976 2010 1977 2011 def mean_rate_covariance(self, spikelist, time_bin): … … 1991 2025 if not spikelist.time_parameters() == self.time_parameters(): 1992 2026 raise Exception("Error, both SpikeLists should share common t_start, t_stop") 1993 frate_1 = self.firing_rate(time_bin) 1994 frate_1 = numpy.sum(frate_1, axis=0)/len(self) 1995 frate_2 = spikelist.firing_rate(time_bin) 1996 frate_2 = numpy.sum(frate_2, axis=0)/len(spikelist) 1997 N = len(frate_1) 2027 frate_1 = self.firing_rate(time_bin, average=True) 2028 frate_2 = spikelist.firing_rate(time_bin, average=True) 2029 N = len(frate_1) 1998 2030 cov = numpy.sum(frate_1*frate_2)/N-numpy.sum(frate_1)*numpy.sum(frate_2)/(N*N) 1999 2031 return cov … … 2062 2094 average - If True, return a single vector of the averaged waveform. If False, 2063 2095 return an array of all the waveforms. 2096 time_bin- The time bin (in ms) used to gather the spike for the psth 2064 2097 t_min - Time (>0) to average the signal before an event, in ms (default 0) 2065 2098 t_max - Time (>0) to average the signal after an event, in ms (default 100)
