Beispiel #1
0
 def test_signal(self):
     '''Test that signal is generated correctly given various params.'''
     # test with a single numpy function 
     alpha = 1.
     phi = 2. #should make two cycles
     omega = .5*pi 
     signal_func = sin
     obs = signal(alpha, phi, omega, signal_func, 
         sampling_freq=25, lb=0, ub=2*pi)
     exp = array([  1.22464680e-16,  -5.00000000e-01,  -8.66025404e-01,
     -1.00000000e+00,  -8.66025404e-01,  -5.00000000e-01,
     -2.44929360e-16,   5.00000000e-01,   8.66025404e-01,
      1.00000000e+00,   8.66025404e-01,   5.00000000e-01,
      3.67394040e-16,  -5.00000000e-01,  -8.66025404e-01,
     -1.00000000e+00,  -8.66025404e-01,  -5.00000000e-01,
     -4.89858720e-16,   5.00000000e-01,   8.66025404e-01,
      1.00000000e+00,   8.66025404e-01,   5.00000000e-01,
      6.12323400e-16])
     assert_array_almost_equal(exp, obs)
     # test with a single scipy function
     alpha = 3.
     phi = 1.5
     omega = .25*pi 
     signal_func = sawtooth
     obs = signal(alpha, phi, omega, signal_func,
         sampling_freq=25, lb=0, ub=2*pi)
     exp = array([-1.875, -1.5  , -1.125, -0.75 , -0.375,  0.   ,  0.375,  0.75 ,
     1.125,  1.5  ,  1.875,  2.25 ,  2.625, -3.   , -2.625, -2.25 ,
    -1.875, -1.5  , -1.125, -0.75 , -0.375,  0.   ,  0.375,  0.75 ,
     1.125])
     assert_array_almost_equal(exp, obs)
Beispiel #2
0
 def test_signal(self):
     '''Test that signal is generated correctly given various params.'''
     # test with a single numpy function
     alpha = 1.
     phi = 2.  #should make two cycles
     omega = .5 * pi
     signal_func = sin
     obs = signal(alpha,
                  phi,
                  omega,
                  signal_func,
                  sampling_freq=25,
                  lb=0,
                  ub=2 * pi)
     exp = array([
         1.22464680e-16, -5.00000000e-01, -8.66025404e-01, -1.00000000e+00,
         -8.66025404e-01, -5.00000000e-01, -2.44929360e-16, 5.00000000e-01,
         8.66025404e-01, 1.00000000e+00, 8.66025404e-01, 5.00000000e-01,
         3.67394040e-16, -5.00000000e-01, -8.66025404e-01, -1.00000000e+00,
         -8.66025404e-01, -5.00000000e-01, -4.89858720e-16, 5.00000000e-01,
         8.66025404e-01, 1.00000000e+00, 8.66025404e-01, 5.00000000e-01,
         6.12323400e-16
     ])
     assert_array_almost_equal(exp, obs)
     # test with a single scipy function
     alpha = 3.
     phi = 1.5
     omega = .25 * pi
     signal_func = sawtooth
     obs = signal(alpha,
                  phi,
                  omega,
                  signal_func,
                  sampling_freq=25,
                  lb=0,
                  ub=2 * pi)
     exp = array([
         -1.875, -1.5, -1.125, -0.75, -0.375, 0., 0.375, 0.75, 1.125, 1.5,
         1.875, 2.25, 2.625, -3., -2.625, -2.25, -1.875, -1.5, -1.125,
         -0.75, -0.375, 0., 0.375, 0.75, 1.125
     ])
     assert_array_almost_equal(exp, obs)
Beispiel #3
0
 def test_generate_otu_from_pt_in_R5(self):
     '''Test that an OTU is correctly generated.'''
     seed(0)
     pt = (2, 10, 0, .5, [subsample_otu_evenly, .5])
     nfap = [uniform, -5, 10]
     y_shift = 100
     wave_f = sawtooth
     base_otu = 100 + signal(pt[1], pt[0], pt[2], wave_f)
     noisy_otu = add_noise(nfap, base_otu)
     sampling_f = subsample_otu_evenly
     exp_otu = sampling_f(noisy_otu, .5)
     seed(0)
     obs_otu = generate_otu_from_pt_in_R5(pt, wave_f, y_shift)
     assert_array_almost_equal(obs_otu, exp_otu)
Beispiel #4
0
 def test_generate_otu_from_pt_in_R5(self):
     '''Test that an OTU is correctly generated.'''
     seed(0)
     pt = (2, 10, 0, .5, [subsample_otu_evenly, .5])
     nfap = [uniform, -5, 10]
     y_shift = 100
     wave_f = sawtooth
     base_otu = 100 + signal(pt[1], pt[0], pt[2], wave_f)
     noisy_otu = add_noise(nfap, base_otu)
     sampling_f = subsample_otu_evenly
     exp_otu = sampling_f(noisy_otu, .5)
     seed(0)
     obs_otu = generate_otu_from_pt_in_R5(pt, wave_f, y_shift)
     assert_array_almost_equal(obs_otu, exp_otu)