root/trunk/doc/io.txt

Revision 320, 5.3 KB (checked in by pierre, 4 years ago)

Fix some wrongs examples in doc/io.txt, and in the meanwhile consolidate the internal methods of StandardTextFile?.

Line 
1=================
2The ``io`` module
3=================
4
5This module will be the gateway of all the input/output relations in NeuroTools, especially regarding
6the inferface with pyNN. This is in that module that you'll have the Standard Formats currently
7supported by NeuroTools (text and pickle, hdf5 planned in a near future), and if you want to
8implement your own ``load`` function, reading your own particular data structure for the ``signals`` module,
9you should read the documentation
10
11-------------
12File Handlers
13-------------
14
15A File handler is an abstract object that will have to implement some key methods in order to be able
16to read and write NeuroTools objects from a file (given in the constructor).
17The idea is that is you want to design your own File handler, you just have to implement
18the 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
21understanding, just have a look to the two file handlers implemented in NeuroTools, i.e ``StandardTextFile`` and
22``StandPickleFile``.
23
24
25The ``StandardTextFile`` class
26------------------------------
27
28Creation
29~~~~~~~~
30
31The ``StandardTextFile`` inherits from ``FileHandler``
32
33Here is an example of creating simple ``StandardTextFile`` objects::
34
35    >>> textfile = StandardTextFile("test.txt")
36
37
38Usage
39~~~~~~~~
40
41If 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
45More generally, the ``read_spikes()`` method of an object inheriting from ``FileHandler`` accepts arguments
46like 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
47informations in the headers of the text file, ... See io.py for a deeper understanding of its behavior.
48
49Similar syntax is used for reading a analog signal object::
50   
51    >>> aslist = textfile.read_analogs('vm', {'id_list':range(11)})
52
53In the case of an ``AnalogSignal``, the type here, selected in [vm, conductance, current] will specified
54the type of the NeuroTools object returned by the function. Either a ``VmList``, ``ConductanceList`` or
55``CurrentList``
56
57It you want to save an object to a file, just do::
58   
59    >>> textfile.write(object)
60
61objet can be a SpikeList or any kind of AnalogSignalList.
62
63
64The ``StandardPickleFile`` class
65--------------------------------
66
67Creation
68~~~~~~~~
69
70The ``StandardPickleFile`` also inherits from ``FileHandler``
71
72Here is an example of creating simple ``StandardPickleFile`` objects::
73
74    >>> pickfile = StandardPickleFile("test.pick")
75
76
77Usage
78~~~~~~~~
79
80If 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
84Since this object inherits from ``FileHandler``, the idea is that its behavior is *exactly* the
85same 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
89In the case of an ``AnalogSignal``, the type here, selected in [vm, conductance, current] will specified
90the type of the NeuroTools object returned by the function. Either a ``VmList``, ``ConductanceList`` or
91``CurrentList``
92
93It you want to save an object to a file, just do::
94   
95    >>> pickfile.write(object)
96
97objet can be a SpikeList or any kind of AnalogSignalList.
98
99
100The ``YOURStandardFormatFile`` class
101------------------------------------
102
103As 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-------------
130Data Handlers
131-------------
132
133The data handler is just a file input/output manager. This is just an interface for ``load/save`` functions.
134This is this kind of object which is created by all the ``load`` methods of NeuroTools.signals
135
136The ``DataHandler`` class
137-------------------------
138
139You should not have to deal directly with this class, because this is just an interface. See io.py for more details
Note: See TracBrowser for help on using the browser.