| 3 | | Documentation not yet available |
|---|
| | 3 | ================= |
|---|
| | 4 | The ``io`` module |
|---|
| | 5 | ================= |
|---|
| | 6 | |
|---|
| | 7 | This module will be the gateway of all the input/output relations in NeuroTools, especially regarding |
|---|
| | 8 | the inferface with pyNN. This is in that module that you'll have the Standard Formats currently |
|---|
| | 9 | supported by NeuroTools (text and pickle, hdf5 planned in a near future), and if you want to |
|---|
| | 10 | implement your own ``load`` function, reading your own particular data structure for the ``signals`` module, |
|---|
| | 11 | you should read the documentation |
|---|
| | 12 | |
|---|
| | 13 | ------------- |
|---|
| | 14 | File Handlers |
|---|
| | 15 | ------------- |
|---|
| | 16 | |
|---|
| | 17 | A File handler is an abstract object that will have to implement some key methods in order to be able |
|---|
| | 18 | to read and write NeuroTools objects from a file (given in the constructor). |
|---|
| | 19 | The idea is that is you want to design your own File handler, you just have to implement |
|---|
| | 20 | the abstract methods of the objects, i.e ``write()`` (to write an object to a file), |
|---|
| | 21 | ``read_spikes(params)`` read data and return a SpikeList object and |
|---|
| | 22 | ``read_analogs(params, type)``, read data and returns an analog signal according to type. To have a better |
|---|
| | 23 | understanding, just have a look to the two file handlers implemented in NeuroTools, i.e ``StandardTextFile`` and |
|---|
| | 24 | ``StandPickleFile``. |
|---|
| | 25 | |
|---|
| | 26 | |
|---|
| | 27 | The ``StandardTextFile`` class |
|---|
| | 28 | ------------------------------ |
|---|
| | 29 | |
|---|
| | 30 | Creation |
|---|
| | 31 | ~~~~~~~~ |
|---|
| | 32 | |
|---|
| | 33 | The ``StandardTextFile`` inherits from ``FileHandler`` |
|---|
| | 34 | |
|---|
| | 35 | Here is an example of creating simple ``StandardTextFile`` objects:: |
|---|
| | 36 | |
|---|
| | 37 | >>> textfile = StandardTextFile("test.txt") |
|---|
| | 38 | |
|---|
| | 39 | |
|---|
| | 40 | Usage |
|---|
| | 41 | ~~~~~~~~ |
|---|
| | 42 | |
|---|
| | 43 | If you want to read a data file with spikes, and return a SpikeList object:: |
|---|
| | 44 | |
|---|
| | 45 | >>> spklist = textfile.read_spikes(id_list=range(11), t_start = 0, t_stop=1000) |
|---|
| | 46 | |
|---|
| | 47 | More generally, the ``read_spikes()`` method of an object inheriting from ``FileHandler`` accepts arguments |
|---|
| | 48 | like id_list, t_start, t_stop, which are the one used in the SpikeList constructor. Note that the ``StandardTextFile`` object have private functions for an internal use only that will check/read |
|---|
| | 49 | informations in the headers of the text file, ... See io.py for a deeper understanding of its behavior. |
|---|
| | 50 | |
|---|
| | 51 | Similar syntax is used for reading a analog signal object:: |
|---|
| | 52 | |
|---|
| | 53 | >>> aslist = textfile.read_analog('vm', range(11)) |
|---|
| | 54 | |
|---|
| | 55 | In the case of an ``AnalogSignal``, the type here, selected in [vm, conductance, current] will specified |
|---|
| | 56 | the type of the NeuroTools object returned by the function. Either a ``VmList``, ``ConductanceList`` or |
|---|
| | 57 | ``CurrentList`` |
|---|
| | 58 | |
|---|
| | 59 | It you want to save an object to a file, just do:: |
|---|
| | 60 | |
|---|
| | 61 | >>> textfile.write(object) |
|---|
| | 62 | |
|---|
| | 63 | objet can be a SpikeList or any kind of AnalogSignalList. |
|---|
| | 64 | |
|---|
| | 65 | |
|---|
| | 66 | The ``StandardPickleFile`` class |
|---|
| | 67 | -------------------------------- |
|---|
| | 68 | |
|---|
| | 69 | Creation |
|---|
| | 70 | ~~~~~~~~ |
|---|
| | 71 | |
|---|
| | 72 | The ``StandardPickleFile`` also inherits from ``FileHandler`` |
|---|
| | 73 | |
|---|
| | 74 | Here is an example of creating simple ``StandardPickleFile`` objects:: |
|---|
| | 75 | |
|---|
| | 76 | >>> pickfile = StandardPickleFile("test.pick") |
|---|
| | 77 | |
|---|
| | 78 | |
|---|
| | 79 | Usage |
|---|
| | 80 | ~~~~~~~~ |
|---|
| | 81 | |
|---|
| | 82 | If you want to read a data file with spikes, and return a SpikeList object:: |
|---|
| | 83 | |
|---|
| | 84 | >>> spklist = pickfile.read_spikes(id_list=range(11), t_start = 0, t_stop=1000) |
|---|
| | 85 | |
|---|
| | 86 | Since this object inherits from ``FileHandler``, the idea is that its behavior is *exactly* the |
|---|
| | 87 | same than the ``StandardTextFile``. Similar syntax is used for reading a analog signal object:: |
|---|
| | 88 | |
|---|
| | 89 | >>> aslist = pickfile.read_analog('vm', range(11)) |
|---|
| | 90 | |
|---|
| | 91 | In the case of an ``AnalogSignal``, the type here, selected in [vm, conductance, current] will specified |
|---|
| | 92 | the type of the NeuroTools object returned by the function. Either a ``VmList``, ``ConductanceList`` or |
|---|
| | 93 | ``CurrentList`` |
|---|
| | 94 | |
|---|
| | 95 | It you want to save an object to a file, just do:: |
|---|
| | 96 | |
|---|
| | 97 | >>> pickfile.write(object) |
|---|
| | 98 | |
|---|
| | 99 | objet can be a SpikeList or any kind of AnalogSignalList. |
|---|
| | 100 | |
|---|
| | 101 | |
|---|
| | 102 | The ``YOURStandardFormatFile`` class |
|---|
| | 103 | ------------------------------------ |
|---|
| | 104 | |
|---|
| | 105 | As said before, you just have to implement some key functions, as defined in the ``FileHandler``:: |
|---|
| | 106 | |
|---|
| | 107 | >>> class YOURStandardFormatFile(FileHandler): |
|---|
| | 108 | |
|---|
| | 109 | def write(self, object): |
|---|
| | 110 | ### Your method here ######### |
|---|
| | 111 | ### Should save an object to the file self.filename### |
|---|
| | 112 | |
|---|
| | 113 | def read_spikes(self, params): |
|---|
| | 114 | ### Your method here, reading data from self.filename ######### |
|---|
| | 115 | ### Should read data and return a SpikeList object constrained by params |
|---|
| | 116 | from NeuroTools import signals |
|---|
| | 117 | return signals.SpikeList(...) |
|---|
| | 118 | |
|---|
| | 119 | def read_analogs(self, type, params): |
|---|
| | 120 | if not type in ["vm", "current", "conductance"]: |
|---|
| | 121 | raise Exception("The type %s is not available for the Analogs Signals" %type) |
|---|
| | 122 | ### Your method here reading data from self.filename ######### |
|---|
| | 123 | from NeuroTools import signals |
|---|
| | 124 | if type == 'vm': |
|---|
| | 125 | return signals.VmList(...) |
|---|
| | 126 | elif type == 'conductance': |
|---|
| | 127 | return signals.ConductanceList(...) |
|---|
| | 128 | elif type == 'current': |
|---|
| | 129 | return signals.CurrentList(...) |
|---|
| | 130 | |
|---|
| | 131 | |
|---|
| | 132 | ------------- |
|---|
| | 133 | Data Handlers |
|---|
| | 134 | ------------- |
|---|
| | 135 | |
|---|
| | 136 | The data handler is just a file input/output manager. This is just an interface for ``load/save`` functions. |
|---|
| | 137 | This is this kind of object which is created by all the ``load`` methods of NeuroTools.signals |
|---|
| | 138 | |
|---|
| | 139 | The ``DataHandler`` class |
|---|
| | 140 | ------------------------- |
|---|
| | 141 | |
|---|
| | 142 | You should not have to deal directly with this class, because this is just an interface. See io.py for more details |
|---|
| | 143 | |
|---|
| | 144 | |
|---|