Show
Ignore:
Timestamp:
08/23/10 14:25:44 (21 months ago)
Author:
mpereira
Message:

Added crosscorrelate() to analysis.py

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/test/test_analysis.py

    r451 r453  
    77from numpy import pi, sin 
    88 
    9 from NeuroTools import analysis 
    10  
     9from NeuroTools import analysis, signals 
    1110 
    1211# test simple_frequency_spectrum 
     
    2726        self.exp_reversed = scipy.io.loadmat( 
    2827            'analysis/make_kernel/exp_reversed.mat') 
     28         
     29        #Used for the testcases of the crosscorrelate function 
     30        spk = signals.load_spikelist('analysis/crosscorrelate/spike_data') 
     31        self.spk0 = spk[0].spike_times 
     32        self.spk1 = spk[1].spike_times 
    2933 
    3034    def testSimpleFrequencySpectrum(self): 
     
    153157        self.assertEqual(true_m_idx, m_idx, 3) 
    154158         
     159    def testCrosscorrelateNoLag(self): 
     160            int, int_, norm = analysis.crosscorrelate(self.spk0, self.spk1) 
     161            #The following are output was generated with the FIND MATLAB toolbox 
     162            matlab_int = numpy.loadtxt('analysis/crosscorrelate/out_matlab_int') 
     163            numpy.testing.assert_array_almost_equal(int, matlab_int, 
     164                                                    decimal=3) 
     165            #The int_ output has a random component and for this reason the test 
     166            # cases are not as trivial 
     167             
     168    def testCrosscorrelateLag100(self): 
     169        """Test case with lag within the length of the input array 
     170        """ 
     171        int, int_, norm, = analysis.crosscorrelate(self.spk0, self.spk1, 
     172                                                   lag=100.0) 
     173        matlab_int = numpy.loadtxt('analysis/crosscorrelate/out_matlab_int_lag_100') 
     174        numpy.testing.assert_array_almost_equal(int, matlab_int, decimal = 3) 
     175             
     176    def testCrosscorrelateLag500(self): 
     177        """Test case with lag is higher than the trial length 
     178        """ 
     179        int, int_, norm = analysis.crosscorrelate(self.spk0, self.spk1, 
     180                                                  lag=500.0) 
     181        matlab_int = numpy.loadtxt('analysis/crosscorrelate/out_matlab_int_lag_500') 
     182        numpy.testing.assert_array_almost_equal(int, matlab_int, decimal = 3) 
     183             
    155184if __name__ == "__main__": 
    156185    unittest.main()