Changeset 481 for trunk

Show
Ignore:
Timestamp:
02/24/11 00:42:39 (15 months ago)
Author:
mpereira
bzr:base-revision:
svn-v4:400bb3d0-8d2e-0410-a2c0-f692ac833539:trunk:480
bzr:committer:
Michael Pereira <pereira@dantur>
bzr:file-ids:

src/signals/spikes.py 375@400bb3d0-8d2e-0410-a2c0-f692ac833539:trunk%2Fsrc%2Fsignals%2Fspikes.py
bzr:mapping-version:
v4
bzr:repository-uuid:
400bb3d0-8d2e-0410-a2c0-f692ac833539
bzr:revision-id:
pereira@dantur-20110216181753-oju9on3c6n026j12
bzr:revno:
425
bzr:revprop:branch-nick:
NeuroTools_branch
bzr:root:
trunk
bzr:timestamp:
2011-02-16 19:17:53.529000044 +0100
bzr:user-agent:
bzr2.2.4+bzr-svn1.0.3
svn:original-date:
2011-02-16T18:17:53.529000Z
Message:

started edit of new pairwise_crosscorrelate

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/signals/spikes.py

    r480 r481  
    19021902            pylab.draw() 
    19031903 
    1904  
     1904    def pairwise_crosscorrelate(self, nb_pairs, pairs_generator=None, time_bin=1., average=True, lag=None, n_pred=1, predictor=None, display=False, kwargs={}): 
     1905        """ 
     1906        Function to generate an array of cross correlations computed 
     1907        between pairs of cells within the SpikeTrains. Based on pairwise_cc but 
     1908        using function analysis.crosscorrelate instead. 
     1909         
     1910        Inputs: 
     1911            nb_pairs        - int specifying the number of pairs 
     1912            pairs_generator - The generator that will be used to draw the pairs. If None, a default one is 
     1913                              created as RandomPairs(spk, spk, no_silent=False, no_auto=True) 
     1914            time_bin        - The time bin used to gather the spikes 
     1915            average         - If true, only the averaged CC among all the pairs is returned (less memory needed) 
     1916            display         - if True, a new figure is created. Could also be a subplot. The averaged 
     1917                              spike_histogram over the whole population is then plotted 
     1918            kwargs          - dictionary contening extra parameters that will be sent to the plot  
     1919                              function 
     1920         
     1921        Examples 
     1922            >> a.pairwise_cc(500, time_bin=1, averaged=True) 
     1923            >> a.pairwise_cc(500, time_bin=1, averaged=True, display=subplot(221), kwargs={'color':'r'}) 
     1924            >> a.pairwise_cc(100, CustomPairs(a,a,[(i,i+1) for i in xrange(100)]), time_bin=5) 
     1925         
     1926        See also 
     1927            pairwise_pearson_corrcoeff, pairwise_cc_zero, RandomPairs, AutoPairs, CustomPairs 
     1928        """ 
     1929        subplot = get_display(display) 
     1930         
     1931        ## We have to extract only the non silent cells, to avoid problems 
     1932        if pairs_generator is None: 
     1933            pairs_generator = RandomPairs(self, self, False, True) 
     1934 
     1935        # Then we select the pairs of cells 
     1936        pairs  = pairs_generator.get_pairs(nb_pairs) 
     1937        N      = len(pairs) 
     1938        if newnum: 
     1939            length = 2*(len(pairs_generator.spk1.time_axis(time_bin))-1) 
     1940        else: 
     1941            length = 2*len(pairs_generator.spk1.time_axis(time_bin)) 
     1942        if not average: 
     1943            results = numpy.zeros((N,length), float) 
     1944        else: 
     1945            results = numpy.zeros(length, float) 
     1946        for idx in xrange(N): 
     1947            # We need to avoid empty spike histogram, otherwise the ccf function 
     1948            # will give a nan vector 
     1949            hist_1 = pairs_generator.spk1[pairs[idx,0]].time_histogram(time_bin) 
     1950            hist_2 = pairs_generator.spk2[pairs[idx,1]].time_histogram(time_bin) 
     1951            if not average: 
     1952                results[idx,:] = analysis.ccf(hist_1,hist_2) 
     1953            else: 
     1954                results += analysis.ccf(hist_1,hist_2) 
     1955        if not subplot or not HAVE_PYLAB: 
     1956            if not average: 
     1957                return results 
     1958            else: 
     1959                return results/N 
     1960        else: 
     1961            if average: 
     1962                results = results/N 
     1963            else: 
     1964                results = numpy.sum(results, axis=0)/N 
     1965            xaxis   = time_bin*numpy.arange(-len(results)/2, len(results)/2) 
     1966            xlabel  = "Time (ms)" 
     1967            ylabel  = "Cross Correlation" 
     1968            subplot.plot(xaxis, results, **kwargs) 
     1969            set_labels(subplot, xlabel, ylabel) 
     1970            pylab.draw() 
     1971             
    19051972    def pairwise_cc_zero(self, nb_pairs, pairs_generator=None, time_bin=1., time_window=None, display=False, kwargs={}): 
    19061973        """