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