Changeset 182

Show
Ignore:
Timestamp:
07/24/08 10:39:35 (4 months ago)
Author:
apdavison
Message:

Moved a bunch of comment lines from in front of methods into the docstrings of the methods. This way they are accessible using help(foo) (or foo? in ipython), and can be extracted using pydoc, etc.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/spikes.py

    r181 r182  
    1010except Exception: 
    1111    print "Warning: pylab not present" 
     12 
    1213 
    1314class SpikeTrain(object): 
     
    194195            raise Exception("No spikes in the SpikeTrain !") 
    195196 
    196     # Return a time axis between t_start and t_stop according to a time_bin 
    197197    def time_axis(self, time_bin): 
     198        """ 
     199        Return a time axis between t_start and t_stop according to a time_bin 
     200        """ 
    198201        return numpy.arange(self.t_start, self.t_stop, time_bin) 
    199202 
    200     # Generate a raster plot with the SpikeTrain in a subwindow of interest, 
    201     # defined by t_start and t_stop. Those are not the global t_start and t_stop 
    202     # of the SpikeTrain objects. If not defined, we use the one of the SpikeTrain 
    203     # object 
    204203    def raster_plot(self, t_start=None, t_stop=None, color='b'): 
     204        """ 
     205        Generate a raster plot with the SpikeTrain in a subwindow of interest, 
     206        defined by t_start and t_stop. Those are not the global t_start and t_stop 
     207        of the SpikeTrain objects. If not defined, we use the one of the SpikeTrain 
     208        object 
     209        """ 
    205210        if t_start is None: 
    206211            t_start = self.t_start 
     
    397402        return len(self.spiketrains) 
    398403 
    399     # Add a SpikeTrain object to the SpikeList 
    400404    def append(self, id, spiketrain): 
     405        """ 
     406        Add a SpikeTrain object to the SpikeList 
     407        """ 
    401408        assert isinstance(spiketrain, SpikeTrain), "A SpikeList object can only contain SpikeTrain objects" 
    402409        if id in self.id_list: 
     
    408415        self.__calc_startstop() 
    409416 
    410     # Returns the time parameters of the SpikeList (t_start, t_stop, dt) 
    411417    def get_time_parameters(self): 
     418        """ 
     419        Returns the time parameters of the SpikeList (t_start, t_stop, dt) 
     420        """ 
    412421        return (self.t_start, self.t_stop, self.dt) 
    413422 
     
    416425        return numpy.arange(self.t_start, self.t_stop, time_bin) 
    417426 
    418     # Allow the concatenation of a list of SpikeLists to the current SpikeList 
    419427    def concatenate(self, SpikeList_list): 
     428        """ 
     429        Concatenation of a list of SpikeLists to the current SpikeList 
     430        """ 
    420431        # We check that Spike Lists have similar time_axis 
    421432        sl_= SpikeList_list[0] 
     
    427438                self.append(id, sl.spiketrains[id]) 
    428439 
    429     # Generate a new SpikeList truncated from a particular sublist of cells 
     440     
    430441    def idsubSpikeList(self, id_list): 
     442        """ 
     443        Generate a new SpikeList truncated from a particular sublist of cells 
     444        """ 
    431445        # We check what are the elements that are in self.id_list and not in 
    432446        # id_list. We remove such elements from the SpikeList 
     
    441455        return new_SpkList 
    442456 
    443     # Generate a new SpikeList truncated from particular time boundaries 
    444457    def timesubSpikeList(self, t_start, t_stop): 
    445458        """ 
     459        Generate a new SpikeList truncated from particular time boundaries 
    446460        returns a new SpikeList 
    447461 
     
    458472    ####################################################################### 
    459473 
    460     # Return the list of all the isi vectors for all the SpikeTrains objects 
    461     # within the SpikeList. If display is True, then it plots the distribution 
    462     # of the ISI 
     474     
    463475    def isi(self, nbins=100, display=False): 
     476        """ 
     477        Return the list of all the isi vectors for all the SpikeTrains objects 
     478        within the SpikeList. If display is True, then it plots the distribution 
     479        of the ISI 
     480        """ 
    464481        isis = [] 
    465482        for idx,id in enumerate(self.id_list): 
     
    489506        return numpy.histogram(isis, bins=bins) 
    490507 
    491     # Return the list of all the cv coefficients for all the SpikeTrains objects 
    492     # within the SpikeList. If display is True, then it plots the distribution 
    493     # of the CVs 
     508     
    494509    def cv_isi(self, nbins=100, display=False): 
     510        """ 
     511        Return the list of all the cv coefficients for all the SpikeTrains objects 
     512        within the SpikeList. If display is True, then it plots the distribution 
     513        of the CVs 
     514        """ 
    495515        cvs_isi = [] 
    496516        for idx,id in enumerate(self.id_list): 
     
    517537        return numpy.arange(self.t_start, self.t_stop, time_bin) 
    518538 
    519  
    520     # Return the mean firing rate averaged accross all SpikeTrains 
    521539    def mean_rate(self, t_start=None, t_stop=None): 
    522540        """ 
    523         Mean rate for the population 
     541        Return the mean firing rate averaged accross all SpikeTrains 
    524542 
    525543        see mean_rates 
     
    527545        return numpy.mean(self.mean_rates(t_start, t_stop)) 
    528546     
    529     # Returns the std of the mean firing rate averaged accross all SpikeTrains 
    530547    def mean_rate_std(self, t_start=None, t_stop=None): 
    531548        """ 
    532         Std of the Mean firing rate for the population 
     549        Std deviation of the Mean firing rate averaged accross all SpikeTrains 
    533550 
    534551        see mean_rate 
     
    539556        """ returns a vector of the size of id_list giving the mean rate for each neuron 
    540557 
    541  
    542558        see SpikeTrain.mean_rate 
    543559        """ 
     
    547563 
    548564        return rates 
    549  
    550     # Return a vector with all the mean firing rates for all SpikeTrains. 
    551     # If display is True, then it plots the distribution of the rates 
     565     
    552566    def rate_distribution(self, nbins=25, normalize=True, display=False): 
     567        """ 
     568        Return a vector with all the mean firing rates for all SpikeTrains. 
     569        If display is True, then it plots the distribution of the rates 
     570        """ 
    553571        #rates = numpy.zeros(self.N(), float) 
    554572        #for idx,id in enumerate(self.id_list): 
     
    563581            pylab.xlabel("Average Firing Rate (Hz)", size="x-large") 
    564582 
    565     # Generate an array with all the spike_histograms of all the SpikeTrains 
    566     # objects within the SpikeList. If display is True, then it plots the 
    567     # mean firing rate of the all population along time 
    568583    def spike_histogram(self, time_bin, normalized=False, display=False): 
     584        """ 
     585        Generate an array with all the spike_histograms of all the SpikeTrains 
     586        objects within the SpikeList. If display is True, then it plots the 
     587        mean firing rate of the all population along time 
     588        """ 
    569589        nbins = numpy.ceil((self.t_stop-self.t_start)/time_bin) 
    570590        firing_rate = numpy.zeros((self.N(),nbins), float) 
     
    580600            pylab.ylabel("Mean Number of Spikes per bin", size="x-large") 
    581601            pylab.xlabel("Time (ms)", size="x-large") 
    582  
    583602 
    584603    def firing_rate(self, time_bin, display=False): 
     
    611630        return fano_factors 
    612631 
    613     # Allow to translate a gid (ranging from 0 to N*M) into 
    614     # a position on a N*M grid. dims should be given as a tuple 
    615     # (N,M) 
     632     
    616633    def id2position(self, id, dims): 
     634        """ 
     635        Allow to translate a gid (ranging from 0 to N*M) into 
     636        a position on a N*M grid. dims should be given as a tuple 
     637        (N,M) 
     638        """ 
    617639        # Then we translate it in 2D 
    618640        if len(dims) == 1: 
     
    623645            return (x,y) 
    624646 
    625     # Generate a map of the activity during t_start and t_stop. 
    626     # If dims is a tuple, then cells are placed on a grid of size 
    627     # (N,M), else if dims is an array of size (2,nb_cells) with the 
    628     # x (first line) and y (second line) flotting positions of the cells, 
    629     # we generate a scatter plot. bounds is a parameters allowing to specify 
    630     # the range of the colorbar 
     647     
    631648    def activity_map(self, dims, bounds=None, display=False): 
     649        """ 
     650        Generate a map of the activity during t_start and t_stop. 
     651        If dims is a tuple, then cells are placed on a grid of size 
     652        (N,M), else if dims is an array of size (2,nb_cells) with the 
     653        x (first line) and y (second line) flotting positions of the cells, 
     654        we generate a scatter plot. bounds is a parameters allowing to specify 
     655        the range of the colorbar 
     656        """ 
    632657        if isinstance(dims, tuple) or isinstance(dims, list): 
    633658            activity_map = numpy.zeros(dims,float) 
     
    661686                    pylab.clim(bounds) 
    662687 
    663     # Function to generate an array of cross correlation between computed 
    664     # between pairs of cells within the SpikeTrains. pairs should be therefore 
    665     # a list of (cell_id_1, cell_id_2). If display is True, then if plots the 
    666     # averaged cross correlation over all those pairs 
    667688    def pairwise_correlations(self, pairs, time_bin=1., display=False): 
     689        """ 
     690        Function to generate an array of cross correlation between computed 
     691        between pairs of cells within the SpikeTrains. pairs should be therefore 
     692        a list of (cell_id_1, cell_id_2). If display is True, then if plots the 
     693        averaged cross correlation over all those pairs 
     694        """ 
    668695        if len(pairs[0]) != len(pairs[1]): 
    669696            raise Exception("Pairs should have the same number of elements") 
     
    691718            return results 
    692719 
    693  
    694     # Function to extract the variance of the firing rate along time, 
    695     # if events are binned with a time bin. 
    696720    def mean_rate_variance(self, time_bin): 
     721        """ 
     722        Function to extract the variance of the firing rate along time, 
     723        if events are binned with a time bin. 
     724        """ 
    697725        firing_rate = self.firing_rate(time_bin) 
    698726        return numpy.var(sum(firing_rate)/self.N()) 
    699727 
    700     # Function to extract the covariance of the firing rate along time, 
    701     # if events are binned with a time bin. We need a second SpikeList 
    702     # object with same time parameters to calculate the covariance 
    703728    def mean_rate_covariance(self, SpkList, time_bin): 
     729        """ 
     730        Function to extract the covariance of the firing rate along time, 
     731        if events are binned with a time bin. We need a second SpikeList 
     732        object with same time parameters to calculate the covariance 
     733        """ 
    704734        if not isinstance(SpkList, SpikeList): 
    705735            raise Exception("Error, argument should be a SpikeList object") 
     
    713743        cov = sum(frate_1*frate_2)/N-sum(frate_1)*sum(frate_2)/(N*N) 
    714744        return cov 
    715  
    716745     
    717746    def raster_plot(self, id_list=None, t_start=None, t_stop=None, colors='b', subplot=None, size=1): 
     
    790819        for fname in files: os.remove(fname) 
    791820 
    792  
    793  
    794821    def pw_corr_pearson(self,edge,bins,number_of_neuron_pairs):  
    795822        """ 
     
    801828        [neuron_ids_array, spike_times_array] = self.as_list_id_list_time() 
    802829         
    803  
    804  
    805830        # Pairwise correlation 
    806831        neuron_ids_unique = numpy.unique(neuron_ids_array) 
     
    888913        return self.firing_rate(self.dt) 
    889914 
    890  
    891915    def as_pyNN_SpikeArray(self): 
    892916        """ 
     
    896920 
    897921        """ 
    898  
    899922        spike_array = list([ [] for i in range(self.N())]) 
    900923        for spike in spikes: 
     
    922945    return output_DATA 
    923946 
    924 # Function to read data. Should be optimize to deal with errors in the file 
    925 # that may append sometimes, when nest1 does not save the entire last line. 
    926 # It assumes that the data have been produced by pyNN under the format 
    927 # time (ms) gids (for raster) 
    928 # value (unit) gids (for continuous recordings like Vm, current, conductances) 
    929947def readFile(filename, sepchar = "\t", skipchar = '#'): 
     948    """ 
     949    Function to read data. Should be optimize to deal with errors in the file 
     950    that may append sometimes, when nest1 does not save the entire last line. 
     951    It assumes that the data have been produced by pyNN under the format 
     952    time (ms) gids (for raster) 
     953    value (unit) gids (for continuous recordings like Vm, current, conductances) 
     954    """ 
    930955    myfile = open(filename, "r", 10000) 
    931956    contents = myfile.readlines()