Changeset 201

Show
Ignore:
Timestamp:
09/19/08 11:03:02 (4 months ago)
Author:
pierre
Message:

Continue the reorganization. Will make regular commit to ensure everything is correct. Add a system to simplify the plots, and write explicit documentation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/cleanup/src/signals.py

    r200 r201  
    461461class SpikeList(object): 
    462462    """ 
    463     A SpikeList object is a list of SpikeTrain objects. 
    464  
    465     >>> sl = SpikeList(3, [(0, 0.1), (1, 0.1), (0, 0.2)]) 
    466     >>> type( sl[0] ) 
    467     <type SpikeTrain> 
    468     >>> sl[0].spike_times 
    469     array([ 0.1,  0.2]) 
    470     >>> sl.as_ids_times() 
    471     (array([0,0,1]), array([0.1,0.2,0.1])) 
    472     >>> sl.as_ids_times(relative=True) 
    473     (array([0,1,0]), array([0.1,0.0,0.1])) 
    474     >>> sl.as_ids_times(quantized=0.01) 
    475     (array([0,0,1]), array([10,20,10])) 
    476     >>> sl.as_list_id_time() 
    477     [(0,0.1), (0,0.2), (1,0.1)] 
    478     >>> sl.as_id_list_times() 
    479     [(0, array([0.1, 0.2])), (1, array([0.1]))] 
    480     >>> sl.as_time_list_ids() 
    481     [(0.1, [0,1]), (0.2, [0])] 
    482     >>> sl.as_2byN_array() 
    483     >>> array([[0,0,1],[0.1,0.2,0.1]]) 
     463    SpikeList(spikes, id_list, dt=None, t_start=None, t_stop=None, dims=None, label='') 
     464     
     465    Return a SpikeList object which will be a list of SpikeTrain objects. 
     466 
     467    Inputs: 
     468        spikes  - a list of (id,time) tuples (id being in id_list) 
     469        is_list - the list of the ids of all recorded cells (needed for silent cells) 
     470        dt      - if dt is specified, time values should be floats 
     471        t_start - begining of the SpikeList, in ms. If None, will be infered from the data 
     472        t_stop  - end of the SpikeList, in ms. If None, will be infered from the data 
     473        dims    - dimensions of the recorded population, if not 1D population 
     474        label   - optionnal name to identify the SpikeList 
     475     
     476    dt, t_start and t_stop are shared for all SpikeTrains object within the SpikeList 
     477     
     478    Examples: 
     479        >>> sl = SpikeList(3, [(0, 0.1), (1, 0.1), (0, 0.2)]) 
     480        >>> type( sl[0] ) 
     481        >>> <type SpikeTrain> 
     482     
     483    See also 
     484        loadSpikeList 
    484485 
    485486    """ 
     
    491492        Constructor of the SpikeList object 
    492493 
    493         spikes is a list of (id,t) tuples (id in id_list) 
    494         id_list is the list of ids of all recorded cells (needed for silent cells) 
    495         If `dt` is specified, the time values should be ints, 
    496         and will be multiplied by `dt`, otherwise time values should be floats. 
    497         t_start and t_stop are defined in ms. If they are not specified, they  
    498             are inferred from the data. 
    499  
    500         dt, t_start and t_stop are shared for all SpikeTrains in the SpikeList 
    501          
    502         See also 
    503             loadSpikeList 
    504  
     494        See also 
     495            SpikeList, loadSpikeList 
    505496        """ 
    506497        self.id_list = id_list 
     
    568559 
    569560    def __getdisplay__(self,display): 
     561        """ 
     562        Return a pylab object with a plot() function to draw the plots. 
     563         
     564        Inputs: 
     565            display - if True, a new figure is created. Otherwise, if display is a 
     566                      subplot object, this object is returned. 
     567        """ 
    570568        if display is False: 
    571569            return None 
     
    575573        else: 
    576574            return display 
    577  
     575     
    578576    def __labels__(self, subplot, xlabel, ylabel): 
     577        """ 
     578        Function to put some labels on a plot 
     579         
     580        Inputs: 
     581            subplot - the targeted plot 
     582            xlabel  - a string for the x label 
     583            ylabel  - a string for the y label 
     584        """ 
    579585        if hasattr(subplot, 'xlabel'): 
    580586            subplot.xlabel(xlabel) 
     
    588594        Add a SpikeTrain object to the SpikeList 
    589595         
     596        Inputs: 
     597            id       - the id of the new cell 
     598            spktrain - the SpikeTrain object representing the new cell 
     599         
     600        The SpikeTrain object is sliced according to the t_start and t_stop times 
     601        of the SpikeLlist object 
     602         
     603        Examples 
     604            >>> st=SpikeTrain(range(0,100,5),0.1,0,100) 
     605            >>> spklist.append(999, st) 
     606            >>> spklist[999] 
     607         
    590608        See also 
    591609            concatenate 
     
    595613            raise Exception("id %d already present in SpikeList. Use setitem instead()" %id) 
    596614        else: 
    597             self.spiketrains[id] = spktrain 
     615            self.spiketrains[id] = spktrain.time_slice(self.t_start, self.t_stop) 
    598616            self.id_list.append(id) 
    599         self.t_start = min(self.t_start, spktrain.t_start) or spktrain.t_start # in case self.t_start is None 
    600         self.t_stop  = max(self.t_stop, spktrain.t_stop) 
    601617 
    602618    def get_time_parameters(self): 
     
    608624    def time_axis(self, time_bin): 
    609625        """ 
    610         Return a time_axis between t_start and t_stop with bin of size time_bin 
     626        Return a time axis between t_start and t_stop according to a time_bin 
     627         
     628        Inputs: 
     629            time_bin - the bin width 
     630         
     631        See also 
     632            spike_histogram 
    611633        """ 
    612634        return numpy.arange(self.t_start, self.t_stop, time_bin) 
     
    614636    def concatenate(self, spklists): 
    615637        """ 
    616         Concatenation of a SpikeLists to the current SpikeList. 
    617         SpikeLists could be a single SpikeList or a list of SpikeLists 
     638        Concatenation of SpikeLists to the current SpikeList. 
     639         
     640        Inputs: 
     641            spklists - could be a single SpikeList or a list of SpikeLists 
     642         
     643        The concatenated SpikeLists must have similar t_start and t_stop, and 
     644        they can't shared similar cells. All theirs ids have to be different 
    618645         
    619646        See also 
     
    621648        """ 
    622649        if isinstance(spklists, SpikeList): 
    623             spklists = [SpikeLists] 
     650            spklists = [spklists] 
    624651        # We check that Spike Lists have similar time_axis 
    625652        for sl in spklists: