Changeset 320

Show
Ignore:
Timestamp:
11/11/08 13:17:55 (2 months ago)
Author:
pierre
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/doc/io.txt

    r280 r320  
    4141If you want to read a data file with spikes, and return a SpikeList object:: 
    4242     
    43     >>> spklist = textfile.read_spikes(id_list=range(11), t_start = 0, t_stop=1000
     43    >>> spklist = textfile.read_spikes({'id_list' :range(11), 't_start' : 0, 't_stop' : 1000}
    4444 
    4545More generally, the ``read_spikes()`` method of an object inheriting from ``FileHandler`` accepts arguments 
     
    4949Similar syntax is used for reading a analog signal object:: 
    5050     
    51     >>> aslist = textfile.read_analog('vm', range(11)
     51    >>> aslist = textfile.read_analogs('vm', {'id_list':range(11)}
    5252 
    5353In the case of an ``AnalogSignal``, the type here, selected in [vm, conductance, current] will specified 
     
    8080If you want to read a data file with spikes, and return a SpikeList object:: 
    8181     
    82     >>> spklist = pickfile.read_spikes(id_list=range(11), t_start = 0, t_stop=1000
     82    >>> spklist = pickfile.read_spikes({'id_list' : range(11), 't_start' : 0, 't_stop' : 1000}
    8383 
    8484Since this object inherits from ``FileHandler``, the idea is that its behavior is *exactly* the 
    8585same than the ``StandardTextFile``. Similar syntax is used for reading a analog signal object:: 
    8686     
    87     >>> aslist = pickfile.read_analog('vm', range(11)
     87    >>> aslist = pickfile.read_analogs('vm', {'id_list' : range(11)}
    8888 
    8989In the case of an ``AnalogSignal``, the type here, selected in [vm, conductance, current] will specified 
     
    104104 
    105105    >>> class YOURStandardFormatFile(FileHandler): 
     106            def write(self, object): 
     107                ### Your method here ######### 
     108                ### Should save an object to the file self.filename### 
    106109     
    107         def write(self, object): 
    108             ### Your method here ######### 
    109             ### Should save an object to the file self.filename### 
     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(...) 
    110115     
    111         def read_spikes(self, params): 
    112             ### Your method here, reading data from self.filename ######### 
    113             ### Should read data and return a SpikeList object constrained by params 
    114             from NeuroTools import signals 
    115             return signals.SpikeList(...) 
    116      
    117         def read_analogs(self, type, params): 
    118             if not type in ["vm", "current", "conductance"]: 
    119                 raise Exception("The type %s is not available for the Analogs Signals" %type) 
    120             ### Your method here reading data from self.filename ######### 
    121             from NeuroTools import signals 
    122             if type == 'vm': 
    123                 return signals.VmList(...) 
    124             elif type == 'conductance': 
    125                 return signals.ConductanceList(...) 
    126             elif type == 'current': 
    127                 return signals.CurrentList(...) 
     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(...) 
    128127 
    129128 
  • trunk/src/io.py

    r313 r320  
    135135                logging.debug("dt is infered from the file header") 
    136136                params['dt'] = self.metadata['dt'] 
    137         if params['id_list'] is None
     137        if not ('id_list' in params) or (params['id_list'] is None)
    138138            if ('first_id' in self.metadata) and ('last_id' in self.metadata): 
    139139                logging.debug("id_list is infered from the file header") 
     
    145145        elif not isinstance(params['id_list'], list): 
    146146            raise Exception("id_list should be an int or a list !") 
    147         if params['dims'] is None
     147        if not ('dims' in params) or (params['dims'] is None)
    148148            if 'dimensions' in self.metadata: 
    149149                params['dims'] = self.metadata['dimensions'] 
     
    220220        self.metadata['first_id']   = numpy.min(object.id_list()) 
    221221        self.metadata['last_id']    = numpy.max(object.id_list()) 
    222         if hasattr(object, "dt"): 
     222        if hasattr(object, 'dt'): 
    223223            self.metadata['dt']     = object.dt 
    224224 
    225225    def __reformat(self, params, object): 
    226226        self.__fill_metadata(object) 
    227         if params['id_list'] != None: 
     227        if 'id_list' in params and params['id_list'] != None: 
    228228            if isinstance(params['id_list'], int): # allows to just specify the number of neurons 
    229229                params['id_list'] = range(params['id_list']) 
     
    233233        t_start = object.t_start 
    234234        t_stop  = object.t_stop 
    235         if params['t_start'] is not None and params['t_start'] != object.t_start: 
     235        if 't_start' in params and params['t_start'] is not None and params['t_start'] != object.t_start: 
    236236            t_start = params['t_start'] 
    237237            do_slice = True 
    238         if params['t_stop'] is not None and params['t_stop'] != object.t_stop: 
     238        if 't_stop' in params and params['t_stop'] is not None and params['t_stop'] != object.t_stop: 
    239239            t_stop = params['t_stop'] 
    240240            do_slice = True 
  • trunk/src/signals.py

    r317 r320  
    12011201        """ 
    12021202        Return the list of all the CV coefficients for each SpikeTrains object 
    1203         within the SpikeList. 
     1203        within the SpikeList. Return NaN when not enough spikes are present 
    12041204         
    12051205        Inputs: 
     
    12611261            subplot.plot(xaxis, values, **kwargs) 
    12621262            pylab.draw() 
    1263  
    1264  
    1265  
    1266  
    12671263 
    12681264    def cv_local(self, t_start=None, t_stop=None, length=12, step=6): 
  • trunk/test/test_signals.py

    r315 r320  
    137137    def testCvKL(self): 
    138138        poisson_param = 1./10 # 1 / firing_frequency 
    139         isi           = numpy.random.exponential(poisson_param, 10000
     139        isi           = numpy.random.exponential(poisson_param, 1000
    140140        poisson_times = numpy.cumsum(isi)*1000. # To convert the spikes_time in ms 
    141141        spk1 = signals.SpikeTrain(poisson_times) 
     
    145145        # does not depend on time 
    146146        poisson_param = 1./4 
    147         isi           = numpy.random.exponential(poisson_param, 10000
     147        isi           = numpy.random.exponential(poisson_param, 1000
    148148        poisson_times = numpy.cumsum(isi)*1000. # To convert the spikes_time in ms 
    149149        spk1 = signals.SpikeTrain(poisson_times) 
     
    154154    def testHistogram(self): 
    155155        poisson_param = 1./40 
    156         isi           = numpy.random.exponential(poisson_param, 10000
     156        isi           = numpy.random.exponential(poisson_param, 1000
    157157        poisson_times = numpy.cumsum(isi)*1000. # To convert the spikes_time in ms 
    158158        spk = signals.SpikeTrain(poisson_times)