Changeset 250
- Timestamp:
- 10/30/08 17:37:26 (2 months ago)
- Files:
-
- trunk/src/plotting.py (modified) (1 diff)
- trunk/src/signals.py (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/plotting.py
r219 r250 51 51 if draw: 52 52 ax.add_line(side) 53 54 55 56 ############################################################# 57 ## Utility function for the plots. Common to all the objects 58 ## They are called when we try to do plots 59 ############################################################# 60 61 def get_display(display): 62 """ 63 Return a pylab object with a plot() function to draw the plots. 64 65 Inputs: 66 display - if True, a new figure is created. Otherwise, if display is a 67 subplot object, this object is returned. 68 """ 69 if display is False: 70 return None 71 elif display is True: 72 pylab.figure() 73 return pylab 74 else: 75 return display 76 77 def set_labels(subplot, xlabel, ylabel): 78 """ 79 Function to put some labels on a plot 80 81 Inputs: 82 subplot - the targeted plot 83 xlabel - a string for the x label 84 ylabel - a string for the y label 85 """ 86 if hasattr(subplot, 'xlabel'): 87 subplot.xlabel(xlabel) 88 subplot.ylabel(ylabel) 89 else: 90 subplot.set_xlabel(xlabel) 91 subplot.set_ylabel(ylabel) 92 93 94 def set_axis_limits(subplot, xmin, xmax, ymin, ymax): 95 """ 96 Function to set the axis on a plot 97 98 Inputs: 99 subplot - the targeted plot 100 xmin, xmax - the limits of the x axis 101 ymin, ymax - the limits of the y axis 102 """ 103 if hasattr(subplot, 'xlim'): 104 subplot.xlim(xmin, xmax) 105 subplot.ylim(ymin, ymax) 106 else: 107 subplot.set_xlim(xmin, xmax) 108 subplot.set_ylim(ymin, ymax) 109 110 111 112 113 114 53 115 54 116 trunk/src/signals.py
r249 r250 8 8 from NeuroTools import analysis 9 9 from NeuroTools import io 10 from NeuroTools.plotting import get_display, set_axis_limits, set_labels 10 11 11 12 numpy_version = numpy.__version__.split(".")[0:2] … … 48 49 49 50 50 #############################################################51 ## Utility function for the plots. Common to all the objects52 ## They are called when we try to do plots53 #############################################################54 55 def __getdisplay__(display):56 """57 Return a pylab object with a plot() function to draw the plots.58 59 Inputs:60 display - if True, a new figure is created. Otherwise, if display is a61 subplot object, this object is returned.62 """63 if display is False:64 return None65 elif display is True:66 pylab.figure()67 return pylab68 else:69 return display70 71 def __labels__(subplot, xlabel, ylabel):72 """73 Function to put some labels on a plot74 75 Inputs:76 subplot - the targeted plot77 xlabel - a string for the x label78 ylabel - a string for the y label79 """80 if hasattr(subplot, 'xlabel'):81 subplot.xlabel(xlabel)82 subplot.ylabel(ylabel)83 else:84 subplot.set_xlabel(xlabel)85 subplot.set_ylabel(ylabel)86 87 88 def __axis__(subplot, xmin, xmax, ymin, ymax):89 """90 Function to set the axis on a plot91 92 Inputs:93 subplot - the targeted plot94 xmin, xmax - the limits of the x axis95 ymin, ymax - the limits of the y axis96 """97 if hasattr(subplot, 'xlim'):98 subplot.xlim(xmin, xmax)99 subplot.ylim(ymin, ymax)100 else:101 subplot.set_xlim(xmin, xmax)102 subplot.set_ylim(ymin, ymax)103 51 104 52 … … 419 367 if t_stop is None: t_stop = self.t_stop 420 368 spikes = numpy.extract((self.spike_times >= t_start) & (self.spike_times <= t_stop), self.spike_times) 421 subplot = __getdisplay__(display)369 subplot = get_display(display) 422 370 if not subplot or not ENABLE_PLOTS: 423 371 print MATPLOTLIB_ERROR … … 427 375 xlabel = "Time (ms)" 428 376 ylabel = "Neurons #" 429 __labels__(subplot, xlabel, ylabel)377 set_labels(subplot, xlabel, ylabel) 430 378 subplot.scatter(spikes,numpy.ones(len(spikes)),**kwargs) 431 379 pylab.draw() … … 803 751 804 752 def __getitem__(self, id): 805 return self.spiketrains[id] 753 if id in self.id_list(): 754 return self.spiketrains[id] 755 else: 756 raise Exception("id %d is not present in the SpikeList. See id_list()" %id) 806 757 807 758 def __getslice__(self, i, j): … … 1155 1106 else: 1156 1107 values, xaxis = numpy.histogram(isis, bins=bins, normed=True) 1157 subplot = __getdisplay__(display)1108 subplot = get_display(display) 1158 1109 if not subplot or not ENABLE_PLOTS: 1159 1110 return values, xaxis … … 1161 1112 xlabel = "Inter Spike Interval (ms)" 1162 1113 ylabel = "% of Neurons" 1163 __labels__(subplot, xlabel, ylabel)1114 set_labels(subplot, xlabel, ylabel) 1164 1115 subplot.plot(xaxis, values, **kwargs) 1165 1116 pylab.draw() … … 1209 1160 else: 1210 1161 values, xaxis = numpy.histogram(cvs, bins=bins, normed=True) 1211 subplot = __getdisplay__(display)1162 subplot = get_display(display) 1212 1163 if not subplot or not ENABLE_PLOTS: 1213 1164 return values, xaxis … … 1215 1166 xlabel = " CV ISI" 1216 1167 ylabel = "% of Neurons" 1217 __labels__(subplot, xlabel, ylabel)1168 set_labels(subplot, xlabel, ylabel) 1218 1169 subplot.plot(xaxis, values, **kwargs) 1219 1170 pylab.draw() … … 1295 1246 """ 1296 1247 rates = self.mean_rates() 1297 subplot = __getdisplay__(display)1248 subplot = get_display(display) 1298 1249 if not subplot or not ENABLE_PLOTS: 1299 1250 return rates … … 1306 1257 xlabel = "Average Firing Rate (Hz)" 1307 1258 ylabel = "% of Neurons" 1308 __labels__(subplot, xlabel, ylabel)1259 set_labels(subplot, xlabel, ylabel) 1309 1260 subplot.plot(xaxis, values, **kwargs) 1310 1261 pylab.draw() … … 1335 1286 M -= 1 1336 1287 spike_hist = numpy.zeros((N, M), float) 1337 subplot = __getdisplay__(display)1288 subplot = get_display(display) 1338 1289 for idx,id in enumerate(self.id_list()): 1339 1290 spike_hist[idx,:] = self.spiketrains[id].time_histogram(time_bin, normalized) … … 1346 1297 ylabel = "Spikes per bin" 1347 1298 xlabel = "Time (ms)" 1348 __labels__(subplot, xlabel, ylabel)1299 set_labels(subplot, xlabel, ylabel) 1349 1300 axis = self.time_axis(time_bin) 1350 1301 if newnum: … … 1461 1412 activity_movie 1462 1413 """ 1463 subplot = __getdisplay__(display)1414 subplot = get_display(display) 1464 1415 1465 1416 if t_start == None: … … 1525 1476 pairwise_pearson_corrcoeff, pairwise_cc_zero 1526 1477 """ 1527 subplot = __getdisplay__(display)1478 subplot = get_display(display) 1528 1479 1529 1480 if spklist == None: … … 1572 1523 ylabel = "Cross Correlation" 1573 1524 subplot.plot(xaxis, results, **kwargs) 1574 __labels__(subplot, xlabel, ylabel)1525 set_labels(subplot, xlabel, ylabel) 1575 1526 pylab.draw() 1576 1527 … … 1614 1565 if spklist == None: 1615 1566 spklist = self 1616 subplot = __getdisplay__(display)1567 subplot = get_display(display) 1617 1568 1618 1569 spk1, spk2, pairs = self.__select_with_pairs__(pairs, self, spklist) … … 1658 1609 ylabel = "Normalized CC" 1659 1610 subplot.plot(xaxis+self.t_start, cc_time, **kwargs) 1660 __labels__(subplot, xlabel, ylabel)1611 set_labels(subplot, xlabel, ylabel) 1661 1612 pylab.draw() 1662 1613 else: … … 1786 1737 SpikeTrain.raster_plot 1787 1738 """ 1788 subplot = __getdisplay__(display)1739 subplot = get_display(display) 1789 1740 if id_list == None: 1790 1741 id_list = self.id_list() … … 1807 1758 xlabel = "Time (ms)" 1808 1759 ylabel = "Neuron #" 1809 __labels__(subplot, xlabel, ylabel)1760 set_labels(subplot, xlabel, ylabel) 1810 1761 min_id = numpy.min(spk.id_list()) 1811 1762 max_id = numpy.max(spk.id_list()) 1812 1763 length = t_stop - t_start 1813 __axis__(subplot, t_start-0.05*length, t_stop+0.05*length, min_id-2, max_id+2)1764 set_axis_limits(subplot, t_start-0.05*length, t_stop+0.05*length, min_id-2, max_id+2) 1814 1765 pylab.draw() 1815 1766 … … 1849 1800 activity_map 1850 1801 """ 1851 subplot = __getdisplay__(display)1802 subplot = get_display(display) 1852 1803 if t_start is None: t_start = self.t_start 1853 1804 if t_stop is None: t_stop = self.t_stop … … 2212 2163 raise Exception("No Analog Signals !") 2213 2164 2214 def __getitem__(self, i): 2215 return self.analog_signals[i] 2165 def __getitem__(self, id): 2166 if id in self.id_list(): 2167 return self.analog_signals[id] 2168 else: 2169 raise Exception("id %d is not present in the AnalogSignal. See id_list()" %id) 2216 2170 2217 2171 def __setitem__(self, i, val): … … 2423 2377 >> aslist.plot(5, v_thresh = -50, display=z, kwargs={'color':'r'}) 2424 2378 """ 2425 subplot = __getdisplay__(display)2379 subplot = get_display(display) 2426 2380 id_list = self._AnalogSignalList__sub_id_list(id_list) 2427 2381 time_axis = self.time_axis() … … 2431 2385 xlabel = "Time (ms)" 2432 2386 ylabel = "Membrane Potential (mV)" 2433 __labels__(subplot, xlabel, ylabel)2387 set_labels(subplot, xlabel, ylabel) 2434 2388 for id in id_list: 2435 2389 to_be_plot = self.analog_signals[id].signal … … 2458 2412 >> aslist.plot(5, display=z, kwargs={'color':'r'}) 2459 2413 """ 2460 subplot = __getdisplay__(display)2414 subplot = get_display(display) 2461 2415 id_list = self._AnalogSignalList__sub_id_list(id_list) 2462 2416 time_axis = self.time_axis() … … 2466 2420 xlabel = "Time (ms)" 2467 2421 ylabel = "Current (nA)" 2468 __labels__(subplot, xlabel, ylabel)2422 set_labels(subplot, xlabel, ylabel) 2469 2423 for id in id_list: 2470 2424 subplot.plot(time_axis, self.analog_signals[id].signal, **kwargs) … … 2473 2427 2474 2428 class ConductanceList(AnalogSignalList): 2475 2476 2429 2477 2430 def plot(self, id_list=None, v_thresh=None, display=True, kwargs={}): … … 2490 2443 >> aslist.plot(5, display=z, kwargs={'color':'r'}) 2491 2444 """ 2492 subplot = __getdisplay__(display)2445 subplot = get_display(display) 2493 2446 id_list = self._AnalogSignalList__sub_id_list(id_list) 2494 2447 time_axis = self.time_axis() … … 2498 2451 xlabel = "Time (ms)" 2499 2452 ylabel = "Conductance (nS)" 2500 __labels__(subplot, xlabel, ylabel)2453 set_labels(subplot, xlabel, ylabel) 2501 2454 for id in id_list: 2502 2455 subplot.plot(time_axis, self.analog_signals[id].signal, **kwargs)

