Example #1
0
def show_xcorr(cells):
    n = len(cells)
    maxlag = 3
    binsz = 0.1
    bins = np.arange(-maxlag, maxlag, 0.01)
    ax=None
    for i in range(n):
        for j in range(i,n):
            if i<>j:
                ax = plt.subplot(n,n,i+j*n+1, sharey=ax)

                crosscorrelate(cells[i]['spt'], cells[j]['spt'], maxlag,
                                display=ax,
                                kwargs={"bins":bins})
                plt.axvline(0, color='k')

                if ax:
                    ax.set_ylabel("")
                    ax.set_yticks([])
                    ax.set_xticks([])
                    ax.set_xlabel("")
            else:
                ax_label = plt.subplot(n,n,i+j*n+1, frameon=False)
                ax_label.set_xticks([])
                ax_label.set_yticks([])
                ax_label.text(0,0, cells[j]['dataset'],
                              transform=ax_label.transAxes,
                              rotation=45, ha='left',
                              va='bottom')

        
    ax.set_xticks((-maxlag, maxlag))
    ymin, ymax = ax.get_ylim()
    ax.set_yticks((ymin, ymax))
Example #2
0
def show_xcorr(cells):
    n = len(cells)
    maxlag = 3
    binsz = 0.1
    bins = np.arange(-maxlag, maxlag, 0.01)
    ax=None
    for i in range(n):
        for j in range(i,n):
            if i<>j:
                ax = plt.subplot(n,n,i+j*n+1, sharey=ax)

                crosscorrelate(cells[i]['spt'], cells[j]['spt'], maxlag,
                                display=ax,
                                kwargs={"bins":bins})
                plt.axvline(0, color='k')

                if ax:
                    ax.set_ylabel("")
                    ax.set_yticks([])
                    ax.set_xticks([])
                    ax.set_xlabel("")
            else:
                ax_label = plt.subplot(n,n,i+j*n+1, frameon=False)
                ax_label.set_xticks([])
                ax_label.set_yticks([])
                ax_label.text(0,0, cells[j]['dataset'],
                              transform=ax_label.transAxes,
                              rotation=45, ha='left',
                              va='bottom')

        
    ax.set_xticks((-maxlag, maxlag))
    ymin, ymax = ax.get_ylim()
    ax.set_yticks((ymin, ymax))
 def testCrosscorrelateLag500(self):
     """Test case with lag is higher than the trial length
     """
     int, int_, norm = analysis.crosscorrelate(self.spk0, self.spk1,
                                               lag=500.0)
     matlab_int = numpy.loadtxt(self.p + '/analysis/crosscorrelate/out_matlab_int_lag_500')
     numpy.testing.assert_array_almost_equal(int, matlab_int, decimal = 3)
 def testCrosscorrelateLag100(self):
     """Test case with lag within the length of the input array
     """
     int, int_, norm, = analysis.crosscorrelate(self.spk0, self.spk1,
                                                lag=100.0)
     matlab_int = numpy.loadtxt(self.p + '/analysis/crosscorrelate/out_matlab_int_lag_100')
     numpy.testing.assert_array_almost_equal(int, matlab_int, decimal = 3)
Example #5
0
 def testCrosscorrelateLag500(self):
     """Test case with lag is higher than the trial length
     """
     int, int_, norm = analysis.crosscorrelate(self.spk0,
                                               self.spk1,
                                               lag=500.0)
     matlab_int = numpy.loadtxt(
         self.p + '/analysis/crosscorrelate/out_matlab_int_lag_500')
     numpy.testing.assert_array_almost_equal(int, matlab_int, decimal=3)
Example #6
0
 def testCrosscorrelateLag100(self):
     """Test case with lag within the length of the input array
     """
     int, int_, norm, = analysis.crosscorrelate(self.spk0,
                                                self.spk1,
                                                lag=100.0)
     matlab_int = numpy.loadtxt(
         self.p + '/analysis/crosscorrelate/out_matlab_int_lag_100')
     numpy.testing.assert_array_almost_equal(int, matlab_int, decimal=3)
 def testCrosscorrelateNoLag(self):
     int, int_, norm = analysis.crosscorrelate(self.spk0, self.spk1)
     #The following are output was generated with the FIND MATLAB toolbox
     matlab_int = numpy.loadtxt(self.p + '/analysis/crosscorrelate/out_matlab_int')
     numpy.testing.assert_array_almost_equal(int, matlab_int,
                                                 decimal=3)
Example #8
0
  locs = (numpy.where(spiketrain[:,0] == cell+1))[0].tolist() #where returns tuple
  indiv_trains.append(spiketrain[locs].tolist())
print indiv_trains

print "crosscorrelation"
#Pairwise kappa
ccmat = numpy.zeros((cells,cells))
for cell1 in range(cells):
 for cell2 in range(cells):
  #print numpy.array(indiv_trains[cell1])
  st1 = signals.SpikeTrain(numpy.array(indiv_trains[cell1]).flatten())
  st2 = signals.SpikeTrain(numpy.array(indiv_trains[cell2]).flatten())
  #print st1, st2
  #analysis.crosscorrelate(st1,st2,display=True,lag=1,kwargs={'bins':1000}) #plot requires display=True
  #pylab.show()
  out=analysis.crosscorrelate(st1,st2,lag=delta_t/2.,display=False) #return requires display=False
  #print out[0]
  ccmat[cell1,cell2] = (out[0].shape)[0]

#Check that it performed correctly
cell1=9
cell2=9
print len(indiv_trains[1]), len(indiv_trains[cell2]), ccmat[cell1,cell2], cell1, cell2

#Get kappa_ii
kappa_ii = ccmat.diagonal()
print kappa_ii

kappamat = numpy.zeros((cells,cells))
for cell1 in range(cells):
 for cell2 in range(cells):
Example #9
0
 def testCrosscorrelateNoLag(self):
     int, int_, norm = analysis.crosscorrelate(self.spk0, self.spk1)
     #The following are output was generated with the FIND MATLAB toolbox
     matlab_int = numpy.loadtxt(self.p +
                                '/analysis/crosscorrelate/out_matlab_int')
     numpy.testing.assert_array_almost_equal(int, matlab_int, decimal=3)