From 46f38292215908c2a05d3d0eb6e02d4cfcc6ee2d Mon Sep 17 00:00:00 2001 From: arokem Date: Tue, 22 Nov 2016 13:49:30 -0800 Subject: [PATCH] Replace nose.tools with numpy.testing and assert_true with assert_ --- popeye/tests/test_auditory.py | 65 +++++++-------- popeye/tests/test_auditory_bin.py | 39 +++++---- popeye/tests/test_auditory_bin_pct.py | 37 ++++----- popeye/tests/test_css.py | 41 +++++---- popeye/tests/test_css_nohrf.py | 43 +++++----- popeye/tests/test_dog.py | 46 +++++------ popeye/tests/test_og.py | 89 ++++++++++---------- popeye/tests/test_ogb.py | 58 +++++++------ popeye/tests/test_ogb_nohrf.py | 76 +++++++++-------- popeye/tests/test_spinach.py | 53 ++++++------ popeye/tests/test_stimulus.py | 71 ++++++++-------- popeye/tests/test_strf.py | 99 +++++++++++----------- popeye/tests/test_utilities.py | 115 +++++++++++++------------- popeye/tests/test_xvalidation.py | 67 ++++++++------- 14 files changed, 440 insertions(+), 459 deletions(-) diff --git a/popeye/tests/test_auditory.py b/popeye/tests/test_auditory.py index 1648ae8..cc507fb 100644 --- a/popeye/tests/test_auditory.py +++ b/popeye/tests/test_auditory.py @@ -4,7 +4,6 @@ from matplotlib.pyplot import specgram import numpy as np -import nose.tools as nt import numpy.testing as npt from scipy.signal import chirp @@ -13,7 +12,7 @@ from popeye.auditory_stimulus import AuditoryStimulus def test_auditory_fit(): - + # stimulus features lo_freq = 200 # Hz hi_freq = 12000 # Hz @@ -29,63 +28,63 @@ def test_auditory_fit(): verbose = 0 resample_factor = 10 dtype = ctypes.c_double - + # sample the time from 0-duration by the fs time = np.linspace(0,duration,duration*Fs) - + # create a chirp stimulus ch = chirp(time, lo_freq, duration, hi_freq, method='quadratic') signal = np.concatenate((ch,ch[::-1])) - + # instantiate an instance of the Stimulus class stimulus = AuditoryStimulus(signal, NFFT, Fs, noverlap, resample_factor, dtype, tr_length) - + # initialize the gaussian model model = aud.AuditoryModel(stimulus, utils.double_gamma_hrf) - + # generate a random pRF estimate center_freq = 8910.0 sigma = 567.0 beta = 0.88 baseline = -1.5 hrf_delay = -0.25 - + # create the "data" data = model.generate_prediction(center_freq, sigma, beta, baseline, hrf_delay) - + # set search grid c_grid = (lo_freq,hi_freq) s_grid = (lo_freq,hi_freq) b_grid = (0.1,1) bl_grid = (-3,3) h_grid = (-3.0,3.0) - + # set search bounds c_bound = (lo_freq,hi_freq) s_bound = (lo_freq,hi_freq) b_bound = (1e-8,None) bl_bound = (None,None) h_bound = (-4.0,4.0) - + # loop over each voxel and set up a GaussianFit object grids = (c_grid, s_grid, b_grid, bl_grid, h_grid,) bounds = (c_bound, s_bound, b_bound, bl_bound, h_bound,) - + # fit the response fit = aud.AuditoryFit(model, data, grids, bounds, Ns, voxel_index, auto_fit=True, verbose=1) - + # assert equivalence - nt.assert_equal(np.round(fit.center_freq), center_freq) - nt.assert_equal(np.round(fit.sigma), sigma) - nt.assert_almost_equal(fit.beta, beta, 2) - nt.assert_almost_equal(fit.baseline, baseline, 2) - nt.assert_almost_equal(fit.hrf_delay, hrf_delay, 2) - + npt.assert_equal(np.round(fit.center_freq), center_freq) + npt.assert_equal(np.round(fit.sigma), sigma) + npt.assert_almost_equal(fit.beta, beta, 2) + npt.assert_almost_equal(fit.baseline, baseline, 2) + npt.assert_almost_equal(fit.hrf_delay, hrf_delay, 2) + npt.assert_almost_equal((fit.center_freq0,fit.sigma0,fit.beta0,fit.baseline0,fit.hrf0), (9050.0, 200.0, 0.32500000000000001, -1.5, 1.5)) - + def test_auditory_data_upsample(): - + lo_freq = 200 # Hz hi_freq = 12000 # Hz Fs = hi_freq*2 # Hz @@ -100,50 +99,50 @@ def test_auditory_data_upsample(): verbose = 0 resample_factor = 10 dtype = ctypes.c_double - + # sample the time from 0-duration by the fs time = np.linspace(0,duration,duration*Fs) - + # create a chirp stimulus ch = chirp(time, lo_freq, duration, hi_freq, method='quadratic') signal = np.concatenate((ch,ch[::-1])) - + # instantiate an instance of the Stimulus class stimulus = AuditoryStimulus(signal, NFFT, Fs, noverlap, resample_factor, dtype, tr_length) - + # initialize the gaussian model model = aud.AuditoryModel(stimulus, utils.double_gamma_hrf) - + # generate a random pRF estimate center_freq = 5910.0 sigma = 567.0 beta = 0.88 baseline = -1.5 hrf_delay = -0.25 - + # create the "data" data = model.generate_prediction(center_freq, sigma, beta, baseline, hrf_delay) data = data[np.arange(0,len(data),2)] - + # set search grid c_grid = (lo_freq,hi_freq) s_grid = (lo_freq,hi_freq) b_grid = (0.1,1) bl_grid = (-3,3) h_grid = (-3.0,3.0) - + # set search bounds c_bound = (lo_freq,hi_freq) s_bound = (lo_freq,hi_freq) b_bound = (1e-8,None) bl_bound = (None,None) h_bound = (-4.0,4.0) - + # loop over each voxel and set up a GaussianFit object grids = (c_grid, s_grid, b_grid, bl_grid, h_grid,) bounds = (c_bound, s_bound, b_bound, bl_bound, h_bound,) - + # fit the response fit = aud.AuditoryFit(model, data, grids, bounds, Ns, voxel_index, auto_fit=False, verbose=1) - - nt.assert_equal(len(fit.data), len(data)) \ No newline at end of file + + npt.assert_equal(len(fit.data), len(data)) diff --git a/popeye/tests/test_auditory_bin.py b/popeye/tests/test_auditory_bin.py index 091a12c..bc0347b 100644 --- a/popeye/tests/test_auditory_bin.py +++ b/popeye/tests/test_auditory_bin.py @@ -4,7 +4,6 @@ from matplotlib.pyplot import specgram import numpy as np -import nose.tools as nt import numpy.testing as npt from scipy.signal import chirp @@ -13,7 +12,7 @@ from popeye.auditory_stimulus import AuditoryStimulus def test_auditory_fit(): - + # stimulus features lo_freq = 200 # Hz hi_freq = 12000 # Hz @@ -29,57 +28,57 @@ def test_auditory_fit(): verbose = 0 resample_factor = 10 dtype = ctypes.c_double - + # sample the time from 0-duration by the fs time = np.linspace(0,duration,duration*Fs) - + # create a chirp stimulus ch = chirp(time, lo_freq, duration, hi_freq, method='quadratic') signal = np.concatenate((ch,ch[::-1])) - + # instantiate an instance of the Stimulus class stimulus = AuditoryStimulus(signal, NFFT, Fs, noverlap, resample_factor, dtype, tr_length) - + # initialize the gaussian model model = aud.AuditoryModel(stimulus, utils.double_gamma_hrf) - + # generate a random pRF estimate center_freq = 8910.0 sigma = 567.0 beta = 0.88 baseline = -1.5 hrf_delay = -0.25 - + # create the "data" data = model.generate_prediction(center_freq, sigma, beta, baseline, hrf_delay) - + # set search grid c_grid = (lo_freq,hi_freq) s_grid = (lo_freq,hi_freq) b_grid = (0.1,1) bl_grid = (-3,3) h_grid = (-3.0,3.0) - + # set search bounds c_bound = (lo_freq,hi_freq) s_bound = (lo_freq,hi_freq) b_bound = (1e-8,None) bl_bound = (None,None) h_bound = (-4.0,4.0) - + # loop over each voxel and set up a GaussianFit object grids = (c_grid, s_grid, b_grid, bl_grid, h_grid,) bounds = (c_bound, s_bound, b_bound, bl_bound, h_bound,) - + # fit the response fit = aud.AuditoryFit(model, data, grids, bounds, Ns, voxel_index, auto_fit=True, verbose=1) - + # assert equivalence - nt.assert_equal(np.round(fit.center_freq), center_freq) - nt.assert_equal(np.round(fit.sigma), sigma) - nt.assert_almost_equal(fit.beta, beta, 2) - nt.assert_almost_equal(fit.baseline, baseline, 2) - nt.assert_almost_equal(fit.hrf_delay, hrf_delay, 2) - + npt.assert_equal(np.round(fit.center_freq), center_freq) + npt.assert_equal(np.round(fit.sigma), sigma) + npt.assert_almost_equal(fit.beta, beta, 2) + npt.assert_almost_equal(fit.baseline, baseline, 2) + npt.assert_almost_equal(fit.hrf_delay, hrf_delay, 2) + npt.assert_almost_equal((fit.center_freq0,fit.sigma0,fit.beta0,fit.baseline0,fit.hrf0), - (9050.0, 200.0, 0.77500000000000002, -1.5, 0.0)) \ No newline at end of file + (9050.0, 200.0, 0.77500000000000002, -1.5, 0.0)) diff --git a/popeye/tests/test_auditory_bin_pct.py b/popeye/tests/test_auditory_bin_pct.py index b8457ec..950c9f6 100644 --- a/popeye/tests/test_auditory_bin_pct.py +++ b/popeye/tests/test_auditory_bin_pct.py @@ -4,7 +4,6 @@ from matplotlib.pyplot import specgram import numpy as np -import nose.tools as nt import numpy.testing as npt from scipy.signal import chirp @@ -13,7 +12,7 @@ from popeye.auditory_stimulus import AuditoryStimulus def test_auditory_fit(): - + # stimulus features lo_freq = 200 # Hz hi_freq = 12000 # Hz @@ -29,53 +28,53 @@ def test_auditory_fit(): verbose = 0 resample_factor = 10 dtype = ctypes.c_double - + # sample the time from 0-duration by the fs time = np.linspace(0,duration,duration*Fs) - + # create a chirp stimulus ch = chirp(time, lo_freq, duration, hi_freq, method='quadratic') signal = np.concatenate((ch,ch[::-1])) - + # instantiate an instance of the Stimulus class stimulus = AuditoryStimulus(signal, NFFT, Fs, noverlap, resample_factor, dtype, tr_length) - + # initialize the gaussian model model = aud.AuditoryModel(stimulus, utils.double_gamma_hrf) - + # generate a random pRF estimate center_freq = 8910.0 sigma = 567.0 beta = 0.88 hrf_delay = -0.25 - + # create the "data" data = model.generate_prediction(center_freq, sigma, beta, hrf_delay) - + # set search grid c_grid = (lo_freq,hi_freq) s_grid = (lo_freq,hi_freq) b_grid = (0.1,1) h_grid = (-3.0,3.0) - + # set search bounds c_bound = (lo_freq,hi_freq) s_bound = (lo_freq,hi_freq) b_bound = (1e-8,None) h_bound = (-4.0,4.0) - + # loop over each voxel and set up a GaussianFit object grids = (c_grid, s_grid, b_grid, h_grid,) bounds = (c_bound, s_bound, b_bound, h_bound,) - + # fit the response fit = aud.AuditoryFit(model, data, grids, bounds, Ns, voxel_index, auto_fit=True, verbose=1) - + # assert equivalence - nt.assert_equal(np.round(fit.center_freq), center_freq) - nt.assert_equal(np.round(fit.sigma), sigma) - nt.assert_almost_equal(fit.beta, beta, 2) - nt.assert_almost_equal(fit.hrf_delay, hrf_delay, 2) - + npt.assert_equal(np.round(fit.center_freq), center_freq) + npt.assert_equal(np.round(fit.sigma), sigma) + npt.assert_almost_equal(fit.beta, beta, 2) + npt.assert_almost_equal(fit.hrf_delay, hrf_delay, 2) + npt.assert_almost_equal((fit.center_freq0,fit.sigma0,fit.beta0,fit.hrf0), - (9050.0, 200.0, 0.77500000000000002, 0.0)) \ No newline at end of file + (9050.0, 200.0, 0.77500000000000002, 0.0)) diff --git a/popeye/tests/test_css.py b/popeye/tests/test_css.py index 882e8da..96ecacd 100644 --- a/popeye/tests/test_css.py +++ b/popeye/tests/test_css.py @@ -4,14 +4,13 @@ import numpy as np import numpy.testing as npt -import nose.tools as nt import popeye.utilities as utils from popeye import css from popeye.visual_stimulus import VisualStimulus, simulate_bar_stimulus, resample_stimulus def test_css_fit(): - + viewing_distance = 38 screen_width = 25 thetas = np.arange(0,360,90) @@ -28,18 +27,18 @@ def test_css_fit(): voxel_index = (1,2,3) auto_fit = True verbose = 1 - + # create the sweeping bar stimulus in memory - bar = simulate_bar_stimulus(pixels_across, pixels_down, viewing_distance, + bar = simulate_bar_stimulus(pixels_across, pixels_down, viewing_distance, screen_width, thetas, num_bar_steps, num_blank_steps, ecc) - + # create an instance of the Stimulus class stimulus = VisualStimulus(bar, viewing_distance, screen_width, scale_factor, tr_length, dtype) - + # initialize the gaussian model model = css.CompressiveSpatialSummationModel(stimulus, utils.spm_hrf) model.hrf_delay = 0.2 - + # generate a random pRF estimate x = -2.24 y = 1.58 @@ -48,10 +47,10 @@ def test_css_fit(): beta = 1.0 baseline = 0.0 hrf_delay = 0.25 - + # create the "data" data = model.generate_prediction(x, y, sigma, n, beta, baseline, hrf_delay) - + # set search grid x_grid = (-3,2) y_grid = (-3,2) @@ -60,7 +59,7 @@ def test_css_fit(): b_grid = (0.01,1) bl_grid = (-2,2) h_grid = (-2.0,2.0) - + # set search bounds x_bound = (-10,10) y_bound = (-10,10) @@ -69,25 +68,25 @@ def test_css_fit(): b_bound = (1e-8,1e5) bl_bound = (None,None) h_bound = (-3.0,3.0) - + # loop over each voxel and set up a GaussianFit object grids = (x_grid, y_grid, s_grid, n_grid, b_grid, bl_grid, h_grid,) bounds = (x_bound, y_bound, s_bound, n_bound, b_bound, bl_bound, h_bound,) - + # fit the response fit = css.CompressiveSpatialSummationFit(model, data, grids, bounds, Ns, voxel_index, auto_fit, 1) - + # coarse fit npt.assert_almost_equal((fit.x0,fit.y0,fit.s0,fit.n0,fit.beta0,fit.baseline0,fit.hrf0),(-3,2,1.73916969,0.9,1,0,0)) - + # fine fit - nt.assert_almost_equal(fit.x, x, 1) - nt.assert_almost_equal(fit.y, y, 1) - nt.assert_almost_equal(fit.sigma, sigma, 1) - nt.assert_almost_equal(fit.n, n, 1) - nt.assert_almost_equal(fit.beta, beta, 1) - nt.assert_almost_equal(fit.baseline, baseline, 1) - + npt.assert_almost_equal(fit.x, x, 1) + npt.assert_almost_equal(fit.y, y, 1) + npt.assert_almost_equal(fit.sigma, sigma, 1) + npt.assert_almost_equal(fit.n, n, 1) + npt.assert_almost_equal(fit.beta, beta, 1) + npt.assert_almost_equal(fit.baseline, baseline, 1) + # overloaded npt.assert_almost_equal(fit.overloaded_estimate, [2.5272803327894771, 2.7411676344231712, diff --git a/popeye/tests/test_css_nohrf.py b/popeye/tests/test_css_nohrf.py index b81ec01..f0b4e5f 100644 --- a/popeye/tests/test_css_nohrf.py +++ b/popeye/tests/test_css_nohrf.py @@ -4,14 +4,13 @@ import numpy as np import numpy.testing as npt -import nose.tools as nt import popeye.utilities as utils import popeye.css_nohrf as css from popeye.visual_stimulus import VisualStimulus, simulate_bar_stimulus, resample_stimulus def test_css_fit(): - + viewing_distance = 38 screen_width = 25 thetas = np.arange(0,360,90) @@ -28,18 +27,18 @@ def test_css_fit(): voxel_index = (1,2,3) auto_fit = True verbose = 1 - + # create the sweeping bar stimulus in memory - bar = simulate_bar_stimulus(pixels_across, pixels_down, viewing_distance, + bar = simulate_bar_stimulus(pixels_across, pixels_down, viewing_distance, screen_width, thetas, num_bar_steps, num_blank_steps, ecc) - + # create an instance of the Stimulus class stimulus = VisualStimulus(bar, viewing_distance, screen_width, scale_factor, tr_length, dtype) - + # initialize the gaussian model model = css.CompressiveSpatialSummationModel(stimulus, utils.spm_hrf) model.hrf_delay = 0.2 - + # generate a random pRF estimate x = -2.24 y = 1.58 @@ -47,10 +46,10 @@ def test_css_fit(): n = 0.90 beta = 1.0 baseline = 0.0 - + # create the "data" data = model.generate_prediction(x, y, sigma, n, beta, baseline) - + # set search grid x_grid = (-3,2) y_grid = (-3,2) @@ -59,7 +58,7 @@ def test_css_fit(): b_grid = (0.01,1) bl_grid = (-2,2) h_grid = (-4.0,4.0) - + # set search bounds x_bound = (-10,10) y_bound = (-10,10) @@ -68,29 +67,29 @@ def test_css_fit(): b_bound = (1e-8,1e5) bl_bound = (None,None) h_bound = (-5.0,5.0) - + # loop over each voxel and set up a GaussianFit object grids = (x_grid, y_grid, s_grid, n_grid, b_grid, bl_grid,) bounds = (x_bound, y_bound, s_bound, n_bound, b_bound, bl_bound,) - + # fit the response fit = css.CompressiveSpatialSummationFit(model, data, grids, bounds, Ns, voxel_index, auto_fit, 1) - + # fine - nt.assert_almost_equal(fit.x, x, 1) - nt.assert_almost_equal(fit.y, y, 1) - nt.assert_almost_equal(fit.sigma, sigma, 1) - nt.assert_almost_equal(fit.n, n, 1) - nt.assert_almost_equal(fit.beta, beta, 1) - nt.assert_almost_equal(fit.baseline, baseline, 1) - + npt.assert_almost_equal(fit.x, x, 1) + npt.assert_almost_equal(fit.y, y, 1) + npt.assert_almost_equal(fit.sigma, sigma, 1) + npt.assert_almost_equal(fit.n, n, 1) + npt.assert_almost_equal(fit.beta, beta, 1) + npt.assert_almost_equal(fit.baseline, baseline, 1) + # coarse npt.assert_almost_equal((fit.x0,fit.y0,fit.s0,fit.n0,fit.beta0,fit.baseline0),(2.0, -0.5, 0.72833937882323319, 0.10000000000000001, 1.0, 0.0)) - + # overloaded npt.assert_almost_equal(fit.overloaded_estimate,[2.5272803327899305, 2.7411676344232436, 1.2965338406630695, 0.89999999997351177, 0.99999999998062961, - 3.5926082629195817e-13]) \ No newline at end of file + 3.5926082629195817e-13]) diff --git a/popeye/tests/test_dog.py b/popeye/tests/test_dog.py index d3cfce3..aeff95c 100644 --- a/popeye/tests/test_dog.py +++ b/popeye/tests/test_dog.py @@ -2,7 +2,6 @@ import numpy as np import numpy.testing as npt -import nose.tools as nt from scipy.integrate import simps import popeye.utilities as utils @@ -10,7 +9,7 @@ from popeye.visual_stimulus import VisualStimulus, simulate_bar_stimulus def test_dog(): - + # stimulus features viewing_distance = 38 screen_width = 25 @@ -27,18 +26,18 @@ def test_dog(): voxel_index = (1,2,3) auto_fit = True verbose = 1 - + # create the sweeping bar stimulus in memory - bar = simulate_bar_stimulus(pixels_across, pixels_down, viewing_distance, + bar = simulate_bar_stimulus(pixels_across, pixels_down, viewing_distance, screen_width, thetas, num_bar_steps, num_blank_steps, ecc) - + # create an instance of the Stimulus class stimulus = VisualStimulus(bar, viewing_distance, screen_width, scale_factor, tr_length, dtype) - + # initialize the gaussian model model = dog.DifferenceOfGaussiansModel(stimulus, utils.spm_hrf) model.hrf_delay = 0.2 - + # set the pRF params x = -1.4 y = 1.5 @@ -46,10 +45,10 @@ def test_dog(): sigma_ratio = 2.0 volume_ratio = 0.5 hrf_delay = -0.2 - + # create "data" data = model.generate_prediction(x, y, sigma, sigma_ratio, volume_ratio,) - + # set up the grids x_grid = slice(-10,10,3) y_grid = slice(-10,10,3) @@ -57,7 +56,7 @@ def test_dog(): sr_grid = slice(1.0,5.0,3) vr_grid = slice(0.01,0.99,3) grids = (x_grid, y_grid, s_grid, sr_grid, vr_grid,) - + # set up the bounds x_bound = (-ecc,ecc) y_bound = (-ecc,ecc) @@ -65,29 +64,28 @@ def test_dog(): sr_bound = (1.0,None) vr_bound = (1e-8,1.0) bounds = (x_bound, y_bound, s_bound, sr_bound, vr_bound,) - + # fit it fit = dog.DifferenceOfGaussiansFit(model, data, grids, bounds, voxel_index) - + # coarse fit - nt.assert_almost_equal((fit.x0,fit.y0,fit.s0,fit.sr0,fit.vr0),(-1.0, 2.0, 0.72833937882323319, 1.0, 0.01)) - + npt.assert_almost_equal((fit.x0,fit.y0,fit.s0,fit.sr0,fit.vr0),(-1.0, 2.0, 0.72833937882323319, 1.0, 0.01)) + # fine fit - nt.assert_almost_equal(fit.x, x) - nt.assert_almost_equal(fit.y, y) - nt.assert_almost_equal(fit.sigma, sigma) - nt.assert_almost_equal(fit.sigma_ratio, sigma_ratio) - nt.assert_almost_equal(fit.volume_ratio, volume_ratio) - + npt.assert_almost_equal(fit.x, x) + npt.assert_almost_equal(fit.y, y) + npt.assert_almost_equal(fit.sigma, sigma) + npt.assert_almost_equal(fit.sigma_ratio, sigma_ratio) + npt.assert_almost_equal(fit.volume_ratio, volume_ratio) + # test the RF rf = fit.model.receptive_field(*fit.estimate) est = fit.estimate.copy() est[2] *= 2 rf_new = fit.model.receptive_field(*est) - value_1 = np.sqrt(simps(simps(rf))) + value_1 = np.sqrt(simps(simps(rf))) value_2 = np.sqrt(simps(simps(rf_new))) - nt.assert_almost_equal(value_2/value_1,sigma_ratio,1) - + npt.assert_almost_equal(value_2/value_1,sigma_ratio,1) + # polar coordinates npt.assert_almost_equal([fit.theta,fit.rho],[np.arctan2(y,x),np.sqrt(x**2+y**2)]) - \ No newline at end of file diff --git a/popeye/tests/test_og.py b/popeye/tests/test_og.py index 9fda0fc..08856ba 100644 --- a/popeye/tests/test_og.py +++ b/popeye/tests/test_og.py @@ -4,7 +4,6 @@ import numpy as np import numpy.testing as npt -import nose.tools as nt from scipy.signal import fftconvolve import statsmodels.api as sm @@ -14,7 +13,7 @@ from popeye.spinach import generate_og_receptive_field def test_og_fit(): - + # stimulus features viewing_distance = 38 screen_width = 25 @@ -32,67 +31,67 @@ def test_og_fit(): voxel_index = (1,2,3) auto_fit = True verbose = 1 - + # create the sweeping bar stimulus in memory - bar = simulate_bar_stimulus(pixels_across, pixels_down, viewing_distance, + bar = simulate_bar_stimulus(pixels_across, pixels_down, viewing_distance, screen_width, thetas, num_bar_steps, num_blank_steps, ecc) - + # create an instance of the Stimulus class stimulus = VisualStimulus(bar, viewing_distance, screen_width, scale_factor, tr_length, dtype) - + # initialize the gaussian model model = og.GaussianModel(stimulus, utils.double_gamma_hrf) - + # generate a random pRF estimate x = -5.24 y = 2.58 sigma = 1.24 beta = 2.5 hrf_delay = -0.25 - + # create the "data" data = model.generate_prediction(x, y, sigma, beta, hrf_delay) - + # set search grid x_grid = (-10,10) y_grid = (-10,10) s_grid = (0.25,5.25) b_grid = (0.1,1.0) h_grid = (-4.0,4.0) - + # set search bounds x_bound = (-12.0,12.0) y_bound = (-12.0,12.0) s_bound = (0.001,12.0) b_bound = (1e-8,1e2) h_bound = (-5.0,5.0) - + # loop over each voxel and set up a GaussianFit object grids = (x_grid, y_grid, s_grid, b_grid, h_grid) bounds = (x_bound, y_bound, s_bound, b_bound, h_bound) - + # fit the response fit = og.GaussianFit(model, data, grids, bounds, Ns, voxel_index, auto_fit, verbose) - + # coarse fit - nt.assert_almost_equal((fit.x0,fit.y0,fit.s0,fit.beta0,fit.hrf0),(-10.0, 0.0, 2.75, 1.0, 0.0)) - + npt.assert_almost_equal((fit.x0,fit.y0,fit.s0,fit.beta0,fit.hrf0),(-10.0, 0.0, 2.75, 1.0, 0.0)) + # assert equivalence - nt.assert_almost_equal(fit.x, x, 2) - nt.assert_almost_equal(fit.y, y, 2) - nt.assert_almost_equal(fit.sigma, sigma, 2) - nt.assert_almost_equal(fit.beta, beta, 2) - nt.assert_almost_equal(fit.hrf_delay, hrf_delay, 2) - + npt.assert_almost_equal(fit.x, x, 2) + npt.assert_almost_equal(fit.y, y, 2) + npt.assert_almost_equal(fit.sigma, sigma, 2) + npt.assert_almost_equal(fit.beta, beta, 2) + npt.assert_almost_equal(fit.hrf_delay, hrf_delay, 2) + # test receptive field rf = generate_og_receptive_field(x, y, sigma, fit.model.stimulus.deg_x, fit.model.stimulus.deg_y) - nt.assert_almost_equal(rf.sum(), fit.receptive_field.sum()) - + npt.assert_almost_equal(rf.sum(), fit.receptive_field.sum()) + # test model == fit RF - nt.assert_almost_equal(fit.model.generate_receptive_field(x,y,sigma).sum(), fit.receptive_field.sum()) + npt.assert_almost_equal(fit.model.generate_receptive_field(x,y,sigma).sum(), fit.receptive_field.sum()) def test_og_nuisance_fit(): - + # stimulus features viewing_distance = 38 screen_width = 25 @@ -110,64 +109,64 @@ def test_og_nuisance_fit(): voxel_index = (1,2,3) auto_fit = True verbose = 1 - + # create the sweeping bar stimulus in memory - bar = simulate_bar_stimulus(pixels_across, pixels_down, viewing_distance, + bar = simulate_bar_stimulus(pixels_across, pixels_down, viewing_distance, screen_width, thetas, num_bar_steps, num_blank_steps, ecc) - + # create an instance of the Stimulus class stimulus = VisualStimulus(bar, viewing_distance, screen_width, scale_factor, tr_length, dtype) - + # initialize the gaussian model model = og.GaussianModel(stimulus, utils.spm_hrf) - + # generate a random pRF estimate x = -5.24 y = 2.58 sigma = 1.24 beta = 2.5 hrf_delay = -0.25 - + # create the "data" data = model.generate_prediction(x, y, sigma, beta, hrf_delay) - + # create nuisance signal step = np.zeros(len(data)) step[30:-30] = 1 - + # add to data data += step - + # create design matrix nuisance = sm.add_constant(step) - + # recreate model with nuisance model = og.GaussianModel(stimulus, utils.spm_hrf, nuisance) - + # set search grid x_grid = (-10,10) y_grid = (-10,10) s_grid = (0.25,5.25) b_grid = (0.1,1.0) h_grid = (-4.0,4.0) - + # set search bounds x_bound = (-12.0,12.0) y_bound = (-12.0,12.0) s_bound = (0.001,12.0) b_bound = (1e-8,1e2) h_bound = (-5.0,5.0) - + # loop over each voxel and set up a GaussianFit object grids = (x_grid, y_grid, s_grid, b_grid, h_grid) bounds = (x_bound, y_bound, s_bound, b_bound, h_bound) - + # fit the response fit = og.GaussianFit(model, data, grids, bounds, Ns, voxel_index, auto_fit, verbose) - + # assert equivalence - nt.assert_almost_equal(fit.x, x, 2) - nt.assert_almost_equal(fit.y, y, 2) - nt.assert_almost_equal(fit.sigma, sigma, 2) - nt.assert_almost_equal(fit.beta, beta, 2) - nt.assert_almost_equal(fit.hrf_delay, hrf_delay, 2) \ No newline at end of file + npt.assert_almost_equal(fit.x, x, 2) + npt.assert_almost_equal(fit.y, y, 2) + npt.assert_almost_equal(fit.sigma, sigma, 2) + npt.assert_almost_equal(fit.beta, beta, 2) + npt.assert_almost_equal(fit.hrf_delay, hrf_delay, 2) diff --git a/popeye/tests/test_ogb.py b/popeye/tests/test_ogb.py index 0959c46..451ed86 100644 --- a/popeye/tests/test_ogb.py +++ b/popeye/tests/test_ogb.py @@ -4,7 +4,6 @@ import numpy as np import numpy.testing as npt -import nose.tools as nt from scipy.signal import fftconvolve import popeye.utilities as utils @@ -12,7 +11,7 @@ from popeye.visual_stimulus import VisualStimulus, simulate_bar_stimulus from popeye.spinach import generate_og_receptive_field def test_ogb_fit(): - + # stimulus features viewing_distance = 38 screen_width = 25 @@ -30,18 +29,18 @@ def test_ogb_fit(): voxel_index = (1,2,3) auto_fit = True verbose = 1 - + # create the sweeping bar stimulus in memory - bar = simulate_bar_stimulus(pixels_across, pixels_down, viewing_distance, + bar = simulate_bar_stimulus(pixels_across, pixels_down, viewing_distance, screen_width, thetas, num_bar_steps, num_blank_steps, ecc) - + # create an instance of the Stimulus class stimulus = VisualStimulus(bar, viewing_distance, screen_width, scale_factor, tr_length, dtype) - + # initialize the gaussian model model = ogb.GaussianModel(stimulus, utils.double_gamma_hrf) model.tr_length = 1.0 - + # generate a random pRF estimate x = -2.2 y = 2.6 @@ -49,10 +48,10 @@ def test_ogb_fit(): beta = 85 baseline = 0.5 hrf_delay = -0.3 - + # create data data = model.generate_prediction(x, y, sigma, beta, baseline, hrf_delay) - + # set search grid x_grid = (-5,5) y_grid = (-5,5) @@ -60,7 +59,7 @@ def test_ogb_fit(): b_grid = (1,100) bl_grid = (-1,1) h_grid = (-4.0,4.0) - + # set search bounds x_bound = (-12.0,12.0) y_bound = (-12.0,12.0) @@ -68,33 +67,32 @@ def test_ogb_fit(): b_bound = (1e-8,None) bl_bound = (-1,1) h_bound = (-5.0,5.0) - + # loop over each voxel and set up a GaussianFit object grids = (x_grid, y_grid, s_grid, b_grid, bl_grid, h_grid) bounds = (x_bound, y_bound, s_bound, b_bound, bl_bound, h_bound) - + # fit the response fit = ogb.GaussianFit(model, data, grids, bounds, Ns, voxel_index, auto_fit, verbose) - + # test ballpark - nt.assert_almost_equal(fit.x0, 0, 1) - nt.assert_almost_equal(fit.y0, 0, 1) - nt.assert_almost_equal(fit.s0, 2.8, 1) - nt.assert_almost_equal(fit.beta0, 100, 1) - nt.assert_almost_equal(fit.baseline0, -1, 1) - nt.assert_almost_equal(fit.hrf0, 0, 1) - + npt.assert_almost_equal(fit.x0, 0, 1) + npt.assert_almost_equal(fit.y0, 0, 1) + npt.assert_almost_equal(fit.s0, 2.8, 1) + npt.assert_almost_equal(fit.beta0, 100, 1) + npt.assert_almost_equal(fit.baseline0, -1, 1) + npt.assert_almost_equal(fit.hrf0, 0, 1) + # test final estimate - nt.assert_almost_equal(fit.x, x, 1) - nt.assert_almost_equal(fit.y, y, 1) - nt.assert_almost_equal(fit.sigma, sigma, 1) - nt.assert_almost_equal(np.round(fit.beta), beta, 1) - nt.assert_almost_equal(fit.hrf_delay, hrf_delay, 1) - + npt.assert_almost_equal(fit.x, x, 1) + npt.assert_almost_equal(fit.y, y, 1) + npt.assert_almost_equal(fit.sigma, sigma, 1) + npt.assert_almost_equal(np.round(fit.beta), beta, 1) + npt.assert_almost_equal(fit.hrf_delay, hrf_delay, 1) + # test receptive field rf = generate_og_receptive_field(x, y, sigma, fit.model.stimulus.deg_x, fit.model.stimulus.deg_y) - nt.assert_almost_equal(rf.sum(), fit.receptive_field.sum()) - + npt.assert_almost_equal(rf.sum(), fit.receptive_field.sum()) + # test HRF - nt.assert_almost_equal(fit.hemodynamic_response.sum(), fit.model.hrf_model(fit.hrf_delay, fit.model.stimulus.tr_length).sum()) - \ No newline at end of file + npt.assert_almost_equal(fit.hemodynamic_response.sum(), fit.model.hrf_model(fit.hrf_delay, fit.model.stimulus.tr_length).sum()) diff --git a/popeye/tests/test_ogb_nohrf.py b/popeye/tests/test_ogb_nohrf.py index 12c7001..a06569a 100644 --- a/popeye/tests/test_ogb_nohrf.py +++ b/popeye/tests/test_ogb_nohrf.py @@ -4,7 +4,6 @@ import numpy as np import numpy.testing as npt -import nose.tools as nt from scipy.signal import fftconvolve import popeye.utilities as utils @@ -12,7 +11,7 @@ from popeye.visual_stimulus import VisualStimulus, simulate_bar_stimulus def test_ogb_manual_grids(): - + # stimulus features viewing_distance = 38 screen_width = 25 @@ -30,7 +29,7 @@ def test_ogb_manual_grids(): voxel_index = (1,2,3) auto_fit = True verbose = 1 - + # insert blanks thetas = list(thetas) thetas.insert(0,-1) @@ -40,56 +39,56 @@ def test_ogb_manual_grids(): thetas.insert(11,-1) thetas.append(-1) thetas = np.array(thetas) - + # create the sweeping bar stimulus in memory - bar = simulate_bar_stimulus(pixels_across, pixels_down, viewing_distance, + bar = simulate_bar_stimulus(pixels_across, pixels_down, viewing_distance, screen_width, thetas, num_bar_steps, num_blank_steps, ecc) - + # create an instance of the Stimulus class stimulus = VisualStimulus(bar, viewing_distance, screen_width, scale_factor, tr_length, dtype) - + # initialize the gaussian model model = ogb.GaussianModel(stimulus, utils.spm_hrf) model.tr_length = 1.0 model.hrf_delay = 0.0 - + # generate a random pRF estimate x = -2.2 y = 2.6 sigma = 0.8 beta = 85 baseline = 0.5 - + # create data data = model.generate_prediction(x, y, sigma, beta, baseline,) - + # set search grid x_grid = slice(-5,5,3) y_grid = slice(-5,5,3) s_grid = slice(1/stimulus.ppd,5.25,5) b_grid = slice(1,100,2) bl_grid = slice(-1,1,3) - + # set search bounds x_bound = (-12.0,12.0) y_bound = (-12.0,12.0) s_bound = (1/stimulus.ppd,12.0) b_bound = (1e-8,None) bl_bound = (-1,1) - + # loop over each voxel and set up a GaussianFit object - grids = (x_grid, y_grid, s_grid, b_grid, bl_grid,) + grids = (x_grid, y_grid, s_grid, b_grid, bl_grid,) bounds = (x_bound, y_bound, s_bound, b_bound, bl_bound,) - + # fit the response fit = ogb.GaussianFit(model, data, grids, bounds, Ns, voxel_index, auto_fit, verbose) - + # assert equivalence - nt.assert_almost_equal(fit.x, x, 1) - nt.assert_almost_equal(fit.y, y, 1) - nt.assert_almost_equal(fit.sigma, sigma, 1) - nt.assert_almost_equal(np.round(fit.beta), beta, 1) - + npt.assert_almost_equal(fit.x, x, 1) + npt.assert_almost_equal(fit.y, y, 1) + npt.assert_almost_equal(fit.sigma, sigma, 1) + npt.assert_almost_equal(np.round(fit.beta), beta, 1) + npt.assert_almost_equal(fit.overloaded_estimate,[2.2730532583028005, 3.4058772731826976, 0.79999999999807414, @@ -98,7 +97,7 @@ def test_ogb_manual_grids(): def test_ogb_fit(): - + # stimulus features viewing_distance = 38 screen_width = 25 @@ -116,7 +115,7 @@ def test_ogb_fit(): voxel_index = (1,2,3) auto_fit = True verbose = 1 - + # insert blanks thetas = list(thetas) thetas.insert(0,-1) @@ -126,56 +125,55 @@ def test_ogb_fit(): thetas.insert(11,-1) thetas.append(-1) thetas = np.array(thetas) - + # create the sweeping bar stimulus in memory - bar = simulate_bar_stimulus(pixels_across, pixels_down, viewing_distance, + bar = simulate_bar_stimulus(pixels_across, pixels_down, viewing_distance, screen_width, thetas, num_bar_steps, num_blank_steps, ecc) - + # create an instance of the Stimulus class stimulus = VisualStimulus(bar, viewing_distance, screen_width, scale_factor, tr_length, dtype) - + # initialize the gaussian model model = ogb.GaussianModel(stimulus, utils.spm_hrf) model.tr_length = 1.0 model.hrf_delay = 0.0 - + # generate a random pRF estimate x = -2.2 y = 2.6 sigma = 0.8 beta = 85 baseline = 0.5 - + # create data data = model.generate_prediction(x, y, sigma, beta, baseline,) - + # set search grid x_grid = (-5,5) y_grid = (-5,5) s_grid = (1/stimulus.ppd,5.25) b_grid = (1,100) bl_grid = (-1,1) - + # set search bounds x_bound = (-12.0,12.0) y_bound = (-12.0,12.0) s_bound = (1/stimulus.ppd,12.0) b_bound = (1e-8,None) bl_bound = (-1,1) - + # loop over each voxel and set up a GaussianFit object grids = (x_grid, y_grid, s_grid, b_grid, bl_grid,) bounds = (x_bound, y_bound, s_bound, b_bound, bl_bound,) - + # fit the response fit = ogb.GaussianFit(model, data, grids, bounds, Ns, voxel_index, auto_fit, verbose) - + # coarse npt.assert_almost_equal((fit.x0,fit.y0,fit.s0,fit.beta0,fit.baseline0),(0.0, 0.0, 2.9891696894116166, 50.5, 1.0)) - + # assert equivalence - nt.assert_almost_equal(fit.x, x, 1) - nt.assert_almost_equal(fit.y, y, 1) - nt.assert_almost_equal(fit.sigma, sigma, 1) - nt.assert_almost_equal(fit.beta, beta, 1) - \ No newline at end of file + npt.assert_almost_equal(fit.x, x, 1) + npt.assert_almost_equal(fit.y, y, 1) + npt.assert_almost_equal(fit.sigma, sigma, 1) + npt.assert_almost_equal(fit.beta, beta, 1) diff --git a/popeye/tests/test_spinach.py b/popeye/tests/test_spinach.py index ce5031a..444b548 100644 --- a/popeye/tests/test_spinach.py +++ b/popeye/tests/test_spinach.py @@ -1,6 +1,5 @@ import numpy as np import numpy.testing as npt -import nose.tools as nt import popeye.utilities as utils import popeye.spinach as spin @@ -16,24 +15,24 @@ def test_generate_og_receptive_field(): xcenter = 0 # x coordinate of the pRF center ycenter = 0 # y coordinate of the pRF center sigma = 1 # width of the pRF - - test_value = 6 # this is the sum of a gaussian given 1 ppd + + test_value = 6 # this is the sum of a gaussian given 1 ppd # and a 1 sigma prf centered on (0,0) - + # generate the visuotopic coordinates dx,dy = generate_coordinate_matrices(xpixels, ypixels, ppd, scale_factor) - + # generate a pRF at (0,0) and 1 sigma wide rf = generate_og_receptive_field(xcenter, ycenter, sigma, dx, dy) - + # divide by integral rf /= 2 * np.pi * sigma ** 2 - + # compare the volume of the pRF to a known value - nt.assert_almost_equal(np.sum(rf),1) + npt.assert_almost_equal(np.sum(rf),1) def test_generate_og_timeseries(): @@ -41,35 +40,35 @@ def test_generate_og_timeseries(): ypixels = 100 # simulated screen height ppd = 1 # simulated visual angle scaleFactor = 1.0 # simulated stimulus resampling rate - + xcenter = 0 # x coordinate of the pRF center ycenter = 0 # y coordinate of the pRF center sigma = 10 # width of the pRF - + # generate the visuotopic coordinates dx,dy = generate_coordinate_matrices(xpixels, ypixels, ppd, scaleFactor) - + timeseries_length = 15 # number of frames to simulate our stimulus array - + # initialize the stimulus array stim_arr = np.zeros((xpixels, ypixels, timeseries_length)).astype('uint8') - + # make a circular mask appear for the first 5 frames xi,yi = np.nonzero(np.sqrt((dx-xcenter)**2 + (dy-ycenter)**2)sigma) stim_arr[xi,yi,5:10] = 1 - + # make a circular mask appear for the next 5 frames xi,yi = np.nonzero(np.sqrt((dx-xcenter)**2 + (dy-ycenter)**2)