Changeset 186
- Timestamp:
- 07/25/08 14:55:23 (4 months ago)
- Files:
-
- trunk/src/plotting.py (modified) (1 diff)
- trunk/src/signals.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/plotting.py
r158 r186 87 87 bottommargin = 0.1 88 88 leftmargin=0.1 89 panelsep = 0.05 90 panelheight = (1 - topmargin - bottommargin - (nrows-1)*panelsep)/nrows 91 panelwidth = (1 - leftmargin - rightmargin - (ncolumns-1)*panelsep)/ncolumns 89 v_panelsep = 0.1*(1 - topmargin - bottommargin)/nrows #0.05 90 h_panelsep = 0.1*(1 - leftmargin - rightmargin)/ncolumns 91 panelheight = (1 - topmargin - bottommargin - (nrows-1)*v_panelsep)/nrows 92 panelwidth = (1 - leftmargin - rightmargin - (ncolumns-1)*h_panelsep)/ncolumns 92 93 assert panelheight > 0 93 94 94 bottomlist = [bottommargin + i* panelsep + i*panelheight for i in range(nrows)]95 leftlist = [leftmargin + j* panelsep + j*panelwidth for j in range(ncolumns)]95 bottomlist = [bottommargin + i*v_panelsep + i*panelheight for i in range(nrows)] 96 leftlist = [leftmargin + j*h_panelsep + j*panelwidth for j in range(ncolumns)] 96 97 bottomlist.reverse() 97 98 for j in range(ncolumns): trunk/src/signals.py
r185 r186 11 11 print "Warning: pylab not present" 12 12 from NeuroTools import analysis 13 13 import logging 14 14 15 15 class SpikeTrain(object): … … 259 259 return hist 260 260 261 def rescale(self): 262 """Rescale spike times to make t_start = 0.""" 261 def relative_times(self): 262 """ 263 Rescale spike times to make them relative to t_start. 264 t_start becomes 0.""" 263 265 if self.t_start != 0: 264 266 self.spike_times -= self.t_start … … 339 341 return F1/F0 340 342 343 def merge(self, spiketrain, relative_times=False): 344 """ 345 Add the spike times from `spiketrain` to this `SpikeTrain`s spike list. 346 """ 347 if relative_times: 348 self.relative_times() 349 spiketrain.relative_times() 350 self.spike_times = numpy.concatenate((self.spike_times, spiketrain.spike_times)) 351 self.spike_times.sort() 352 self.t_start = min(self.t_start, spiketrain.t_start) 353 self.t_stop = max(self.t_stop, spiketrain.t_stop) 354 341 355 342 356 class SpikeList(object): … … 430 444 self.__calc_startstop() 431 445 446 def __iter__(self): 447 return self.spiketrains.itervalues() 448 432 449 def __len__(self): 433 450 return len(self.spiketrains) … … 468 485 self.append(id, sl.spiketrains[id]) 469 486 487 def merge(self, spikelist, relative_times=False): 488 """ 489 For each `id` in `spikelist` that matches an `id` in this `SpikeList`, 490 merge the two `SpikeTrains` and save the result in this `SpikeList`. 491 492 `SpikeTrain`s with `id`s not in this `SpikeList` are appended to it. 493 """ 494 for id, spiketrain in spikelist.spiketrains.items(): 495 if id in self.id_list: 496 self.spiketrains[id].merge(spiketrain, relative_times) 497 else: 498 if relative_times: 499 spiketrain.relative_times() 500 self.append(spiketrain) 501 470 502 471 503 def idsubSpikeList(self, id_list): … … 618 650 """ 619 651 nbins = numpy.ceil((self.t_stop-self.t_start)/time_bin) 620 firing_rate= numpy.zeros((self.N(),nbins), float)621 print "nbins = %d" % nbins652 spike_hist = numpy.zeros((self.N(),nbins), float) 653 logging.debug("nbins = %d" % nbins) 622 654 for idx,id in enumerate(self.id_list): 623 print idx, id 624 firing_rate[idx,:] = self.spiketrains[id].time_histogram(time_bin,normalized) 625 if not display: 626 return firing_rate 627 else: 655 spike_hist[idx,:] = self.spiketrains[id].time_histogram(time_bin,normalized) 656 if display: 628 657 pylab.figure() 629 pylab.plot(self.time_axis(time_bin),sum( firing_rate)/self.N())658 pylab.plot(self.time_axis(time_bin),sum(spike_hist)/self.N()) 630 659 pylab.ylabel("Mean Number of Spikes per bin", size="x-large") 631 660 pylab.xlabel("Time (ms)", size="x-large") 661 return spike_hist 632 662 633 663 def firing_rate(self, time_bin, display=False): … … 894 924 return cor_coef_mean, cor_coef_std 895 925 926 def f1f0_ratios(self, time_bin, f_stim): 927 """ 928 Returns the F1/F0 amplitude ratios for the spike trains contained in the 929 spike list, where the input stimulus frequency is f_stim. 930 """ 931 f1f0_dict = {} 932 for id, spiketrain in self.spiketrains.items(): 933 f1f0_dict[id] = spiketrain.f1f0_ratio(time_bin, f_stim) 934 return f1f0_dict 935 896 936 # methods for different output formats 897 937 def as_ids_times(self, relative=False, quantized=False):

