Changes between Version 1 and Version 2 of io

Show
Ignore:
Author:
apdavison (IP: 157.136.60.154)
Timestamp:
11/04/08 09:27:16 (2 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • io

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