Changeset 308
- Timestamp:
- 11/08/08 13:26:05 (2 months ago)
- Files:
-
- trunk/doc/signals.txt (modified) (16 diffs)
- trunk/src/signals.py (modified) (6 diffs)
- trunk/test/test_signals.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/doc/signals.txt
r289 r308 18 18 **Note:** the standard time unit used by NeuroTools is milliseconds. 19 19 20 When several spikes train are gathered, they are collected in a so-called SpikeList, which is actually a dictionnary20 When several spikes train are gathered, they are collected in a so-called ``SpikeList``, which is actually a dictionnary 21 21 of spike trains, the id of the cells being used as a key. See the SpikeList_ class for more details. 22 22 … … 41 41 90 42 42 43 You can access the raw vector of the spike times by the spike_timesattribute::43 You can access the raw vector of the spike times by the ``spike_times`` attribute:: 44 44 45 45 >>> spk1.spike_times … … 52 52 details. 53 53 54 An example of basic use of a SpikeTrainobject is as follows::54 An example of basic use of a ``SpikeTrain`` object is as follows:: 55 55 56 56 >>> spk1.raster_plot() # Generates a raster_plot between t_start and t_stop … … 66 66 ----------------------- 67 67 68 A SpikeList is actually a dictionary of SpikeTrains, and can be thought of conceptually as the output of a network simulation,69 when one records the spikes of a given population. The SpikeListis an object to organize such a recording70 as a tuple of key-value pairs ( spike_source_id, spike_train), that is, a SpikeListobject acts as a dictionary created as follows:71 {'id' : SpikeTrain, ...}72 73 Creation 74 ~~~~~~~~ 75 76 The constructor of a SpikeListis works as follows: it will accepts a list of tuples (id, spike_time),68 A ``SpikeList`` is actually a dictionary of ``SpikeTrains`, and can be thought of conceptually as the output of a network simulation, 69 when one records the spikes of a given population. The ``SpikeList` is an object to organize such a recording 70 as a tuple of key-value pairs ( spike_source_id, spike_train), that is, a ``SpikeList`` object acts as a dictionary created as follows: 71 {'id' : ``SpikeTrain``, ...} 72 73 Creation 74 ~~~~~~~~ 75 76 The constructor of a ``SpikeList`` is works as follows: it will accepts a list of tuples (id, spike_time), 77 77 parameters t_start and t_stop, and the list of all the recorded ids. The last three parameters 78 can't be infered from the data safely, so it's better if they are specified by the user. Here is an simple example of how to create a SpikeList::78 can't be infered from the data safely, so it's better if they are specified by the user. Here is an simple example of how to create a ``SpikeList``:: 79 79 80 80 >>> list = [(numpy.random.random_integers(0,10,1)[0],1000*numpy.random.rand()) for i in xrange(1000)] … … 83 83 Here, range(11) is used to specify that in the lists we will have cells with id between 0 and 10 (it is needed, 84 84 because we can have silent cells in the SpikeList), and that I will kept the spike only between t_start and t_stop. 85 All the SpikeTrains objects within the SpikeListwill share the same t_start and t_stop86 87 Rather than calling the SpikeList constructor, a more commmon way to create a SpikeListin NeuroTools is to use the ``load_spikelist()`` or the ``load()`` functions.85 All the ``SpikeTrains`` objects within the ``SpikeList`` will share the same t_start and t_stop 86 87 Rather than calling the ``SpikeList`` constructor, a more commmon way to create a ``SpikeList`` in NeuroTools is to use the ``load_spikelist()`` or the ``load()`` functions. 88 88 If you have generated your data with pyNN, you can used the loading functions made for this purpose. For example if 89 you have recorded the spikes of a population in a file "spikes.dat", then one can load it as a SpikeListas follows::89 you have recorded the spikes of a population in a file "spikes.dat", then one can load it as a ``SpikeList`` as follows:: 90 90 91 91 >>> spklist = load("spikes.dat",'spikes') 92 92 93 93 Using this syntax, the header information contained in the file is used to create the population, and t_start and t_stop are 94 infered automatically as the min and the max of all the SpikeTrains within the SpikeList.94 infered automatically as the min and the max of all the ``SpikeTrains`` within the ``SpikeList``. 95 95 If you want to keep the control on the parameters while creating the SpikeList, do the following:: 96 96 … … 98 98 99 99 100 Now that the SpikeListhas been created, you can start to explore it.100 Now that the ``SpikeList`` has been created, you can start to explore it. 101 101 102 102 Navigation 103 103 ~~~~~~~~~~ 104 104 105 You can access SpikeTrain object within the Spikelistby the simple syntax spklist[id]::105 You can access ``SpikeTrain`` objects within the ``Spikelist`` by the simple syntax spklist[id]:: 106 106 107 107 >>> spklist[0] … … 112 112 print spktrain.isi() 113 113 114 As you can see in the example, one can naviguate and iterate over a SpikeListobject and have access to115 all the SpikeTrains within the object. To have an explicite list of all the id contained in the SpikeList,114 As you can see in the example, one can naviguate and iterate over a ``SpikeList`` object and have access to 115 all the ``SpikeTrains`` within the object. To have an explicite list of all the id contained in the ``SpikeList``, 116 116 use the function ``id_list()``:: 117 117 … … 121 121 <type 'exceptions.Exception'>: id 15 is not present in the SpikeList. See id_list() 122 122 123 You can't access SpikeTrainsof non recorded cells :-)123 You can't access ``SpikeTrains`` of non recorded cells :-) 124 124 125 125 … … 128 128 129 129 You can do slices of your ``SpikeList`` object, either according to the time axis or to selected ids. 130 130 131 >>> subspklist = spklist.time_slice(500,1500) 131 132 >>> subspklist = spklist.id_slice(50) # Will select 50 randoms id within spklist.id_list() … … 149 150 >>> spklist.raster_plot(100, t_start=0, t_stop=500, display=subplot(221), kwargs={'color':'red'}) 150 151 151 To save the SpikeList, you can use either a Standard Text file output, or a Pickle (compressed) file. To do that, just152 To save the ``SpikeList``, you can use either a Standard Text file output, or a Pickle (compressed) file. To do that, just 152 153 provide to the ``save()`` method the corresponding file objects:: 153 154 … … 189 190 ~~~~~ 190 191 191 Several functions can be applied to an AnalogSignal. See the global API for an exhaustive list. You can for example192 Several functions can be applied to an ``AnalogSignal``. See the global API for an exhaustive list. You can for example 192 193 do an ``event_trigger_average()``, slice the signal according to some events, detect areas of the signals which are 193 194 over a certain threshold, and so on... … … 197 198 ------------------------------ 198 199 199 As for the SpikeList, the AnalogSignalList is a container of AnalogSignalobjects. It has the same structure than200 the SpikeList, meaning this is a dictionnary containing AnalogSignalswith the key being the id of the cells.201 202 Creation 203 ~~~~~~~~ 204 205 The constructor of a AnalogSignalListis made as follows: it will accept an array with all the signals, the time step,200 As for the ``SpikeList``, the ``AnalogSignalList`` is a container of ``AnalogSignal`` objects. It has the same structure than 201 the ``SpikeList``, meaning this is a dictionnary containing ``AnalogSignals`` with the key being the id of the cells. 202 203 Creation 204 ~~~~~~~~ 205 206 The constructor of a ``AnalogSignalList`` is made as follows: it will accept an array with all the signals, the time step, 206 207 and additional parameters like t_start, t_stop, and the list of all the recorded ids. The last three parameters 207 208 can't be infered from the data safely, so it's better if they are specified by the user. Nevertheless, the most 208 commmon way to create SpikeListin NeuroTools is to use the ``load_analogsignal()`` or the ``load()`` functions, as209 explained below. Currently, the constructor of the AnalogSignalListis mainly tunned to be used with those load functions,210 and this is therefore not so simple to create one from a list of AnalogSignal.209 commmon way to create ``SpikeList`` in NeuroTools is to use the ``load_analogsignal()`` or the ``load()`` functions, as 210 explained below. Currently, the constructor of the ``AnalogSignalList`` is mainly tunned to be used with those load functions, 211 and this is therefore not so simple to create one from a list of ``AnalogSignal``. 211 212 212 213 >>> sig1 = AnalogSignal(sin(arange(10000),dt=0.1,t_start=0, t_stop=1000) … … 217 218 ~~~~~~~~~~ 218 219 219 You can access AnalogSignalobject within the ``AnalogSignalList`` by the simple syntax spklist[id]:220 You can access ``AnalogSignal`` object within the ``AnalogSignalList`` by the simple syntax spklist[id]: 220 221 221 222 >>> aslist[0] … … 226 227 print as.signal 227 228 228 As you can see in the example, one can naviguate and iterate over a AnalogSignalListobject and have access to229 all the AnalogSignal within the object. To have an explicite list of all the id contained in the AnalogSignalList,229 As you can see in the example, one can naviguate and iterate over a ``AnalogSignalList`` object and have access to 230 all the ``AnalogSignal`` within the object. To have an explicite list of all the id contained in the ``AnalogSignalList``, 230 231 use the function ``id_list()`` 231 232 … … 235 236 <type 'exceptions.Exception'>: id 15 is not present in the AnalogSignalList. See id_list() 236 237 237 You can't access AnalogSignalof non recorded cells :-)238 You can't access ``AnalogSignal`` of non recorded cells :-) 238 239 239 240 Viewing and saving … … 252 253 >>> vm = load(StandardPickleFile("vm.dat"),'v) # Read the pickle file 253 254 254 Note that for the moment, there is a slight dis inction for the conductance files, since the ``load`` function is255 Note that for the moment, there is a slight distinction for the conductance files, since the ``load`` function is 255 256 tunned for pyNN. Since pyNN saves exc/inh conductances in the same file, the ``load`` function, called on a file 256 257 generated by pyNN, will return two ``AnalogSignalList`` trunk/src/signals.py
r304 r308 1 1 """ 2 signals.py 3 4 Routines used to defined formally spike lists and membrane traces 2 NeuroTools.signals 3 ================== 4 5 A collection of functions to create, manipulate and play with spikes and analog 6 signals. 7 8 Classes 9 ------- 10 11 SpikeTrain - An object representing a spike train, for one cells. Useful for plots, 12 calculus like ISI, CV, mean rate(), ... 13 SpikeList - An object representing the activity of a population of neurons. It's a 14 dictionnary of SpikeTrain objects, and again, the SpikeList object have 15 built-in methods to compute firing_rate, ISI, CV, cross-correlations, and 16 so on. 17 AnalogSignal - An object representing an analog signal, with its data. Can be used to do 18 threshold detection, event triggered averages, ... 19 AnalogSignalList - A list of AnalogSignal objects, again with functions such as mean, std, plot, 20 and so on 21 VmList - An AnalogSignalList object used for Vm traces 22 ConductanceList - An AnalogSignalList object used for conductances traces 23 CurrentList - An AnalogSignalList object used for current traces 24 25 Functions 26 --------- 27 28 load_spikelist - Function to load a SpikeList object from a file that have been generated by pyNN. 29 Can also have been generated by your particular simulator/format, but then you have 30 to write your own File object that will know how to read the data (see io.py) 31 load_vmlist - Function to load a VmList object (inherits from AnalogSignalList) from a file 32 generated by pyNN. Same comments that previously. Note also that as load_conductancelist 33 the function returns two CurrentList, one for the exc current and one for the inh current 34 load_currentlist - Function to load a CurrentList object (inherits from AnalogSignalList) from a file 35 generated by pyNN. Same comments that previously. Note also that as load_conductancelist 36 the function returns two CurrentList, one for the exc current and one for the inh current 37 load_conductancelist - Function to load a ConductanceList object (inherits from AnalogSignalList) from a file 38 generated by pyNN. Same comments that previously. load_conductancelist returns two 39 ConductanceList, one for the exc conductance and one for the inh conductance 40 load - A generic loader for all those previous load method. 5 41 """ 6 42 … … 23 59 else: 24 60 MATPLOTLIB_ERROR = "No pylab package have been detected" 61 25 62 26 63 class SpikeTrain(object): … … 763 800 for idx in xrange(len(pairs)): 764 801 if (pairs[idx][0] not in cells1) or (pairs[idx][1] not in cells2): 765 to_remove.append(idx) 766 for idx in to_remove: 767 pairs.pop(idx) 802 to_remove.append(pairs[idx]) 803 N = len(to_remove) 804 if N > 0: 805 print "%d pairs have been removed because cells were not in the SpikeList" %len(to_remove) 806 for item in to_remove: 807 pairs.remove(item) 768 808 pairs = numpy.array(pairs) 769 809 spk1 = spk1.id_slice(pairs[:,0]) … … 1637 1677 spklist = self 1638 1678 subplot = get_display(display) 1639 1679 1680 all_cells1 = numpy.sort(self.id_list()) 1681 all_cells2 = numpy.sort(self.id_list()) 1682 1640 1683 spk1, spk2, pairs = self.__select_with_pairs__(pairs, self, spklist) 1641 1684 N = len(pairs) … … 1649 1692 times1, ids1 = spk1.convert("times, ids") 1650 1693 times2, ids2 = spk2.convert("times, ids") 1651 cells_id = numpy.sort(pairs[:,0]) 1652 for count, cell in enumerate(cells_id): 1653 ids1[numpy.where(ids1 == cell)[0]] = count 1654 cells_id = numpy.sort(pairs[:,1]) 1655 for count, cell in enumerate(cells_id): 1656 ids2[numpy.where(ids2 == cell)[0]] = count 1694 1695 cells_id = spk1.id_list() 1696 for idx in xrange(len(cells_id)): 1697 ids1[numpy.where(ids1 == cells_id[idx])[0]] = idx 1698 cells_id = spk2.id_list() 1699 for idx in xrange(len(cells_id)): 1700 ids2[numpy.where(ids2 == cells_id[idx])[0]] = idx 1657 1701 times1 = numpy.array(((times1 - self.t_start)/time_bin),int) 1658 1702 times2 = numpy.array(((times2 - self.t_start)/time_bin),int) … … 2139 2183 return AnalogSignal(self.signal, self.dt, self.t_start, self.t_stop) 2140 2184 2141 def time_axis(self, normalized=False):2185 def time_axis(self, normalized=False): 2142 2186 """ 2143 2187 Return the time axis of the AnalogSignal trunk/test/test_signals.py
r298 r308 368 368 369 369 def testCrossCorrZero(self): 370 cc1 = self.spk.pairwise_cc_zero([(i,i) for i in xrange(10)], time_bin=1.) 371 cc2 = self.spk.pairwise_cc_zero(1000, time_bin=1.) 370 cc1 = self.spk.pairwise_cc_zero([(i,i) for i in xrange(5)], time_bin=0.1) 371 cc2 = self.spk.pairwise_cc_zero(5, time_bin=0.1) 372 print cc1, cc2 372 373 assert (0 <= cc1 <= 1) and (cc1 > cc2) 373 374

