コード例 #1
0
def test_clean_img():

    rng = np.random.RandomState(0)

    data = rng.randn(10, 10, 10, 100) + .5
    data_flat = data.T.reshape(100, -1)
    data_img = nibabel.Nifti1Image(data, np.eye(4))

    data_img_ = image.clean_img(data_img,
                                detrend=True,
                                standardize=False,
                                low_pass=0.1)
    data_flat_ = signal.clean(data_flat,
                              detrend=True,
                              standardize=False,
                              low_pass=0.1)

    np.testing.assert_almost_equal(data_img_.get_data().T.reshape(100, -1),
                                   data_flat_)
    # if NANs
    data[:, 9, 9] = np.nan
    # if infinity
    data[:, 5, 5] = np.inf
    nan_img = nibabel.Nifti1Image(data, np.eye(4))
    clean_im = image.clean_img(nan_img, ensure_finite=True)
    assert_true(np.any(np.isfinite(clean_im.get_data())), True)

    # test_clean_img_passing_nifti2image
    data_img_nifti2 = nibabel.Nifti2Image(data, np.eye(4))

    data_img_nifti2_ = image.clean_img(data_img_nifti2,
                                       detrend=True,
                                       standardize=False,
                                       low_pass=0.1)
コード例 #2
0
ファイル: test_image.py プロジェクト: miykael/nilearn
def test_clean_img():

    rng = np.random.RandomState(0)

    data = rng.randn(10, 10, 10, 100) + .5
    data_flat = data.T.reshape(100, -1)
    data_img = nibabel.Nifti1Image(data, np.eye(4))

    assert_raises(
        ValueError, image.clean_img, data_img, t_r=None, low_pass=0.1)

    data_img_ = image.clean_img(
        data_img, detrend=True, standardize=False, low_pass=0.1, t_r=1.0)
    data_flat_ = signal.clean(
        data_flat, detrend=True, standardize=False, low_pass=0.1, t_r=1.0)

    np.testing.assert_almost_equal(data_img_.get_data().T.reshape(100, -1),
                                   data_flat_)
    # if NANs
    data[:, 9, 9] = np.nan
    # if infinity
    data[:, 5, 5] = np.inf
    nan_img = nibabel.Nifti1Image(data, np.eye(4))
    clean_im = image.clean_img(nan_img, ensure_finite=True)
    assert_true(np.any(np.isfinite(clean_im.get_data())), True)

    # test_clean_img_passing_nifti2image
    data_img_nifti2 = nibabel.Nifti2Image(data, np.eye(4))

    data_img_nifti2_ = image.clean_img(
        data_img_nifti2, detrend=True, standardize=False, low_pass=0.1, t_r=1.0)
コード例 #3
0
def test_clean_img():

    rng = np.random.RandomState(0)

    data = rng.randn(10, 10, 10, 100) + .5
    data_flat = data.T.reshape(100, -1)
    data_img = nibabel.Nifti1Image(data, np.eye(4))

    assert_raises(ValueError,
                  image.clean_img,
                  data_img,
                  t_r=None,
                  low_pass=0.1)

    data_img_ = image.clean_img(data_img,
                                detrend=True,
                                standardize=False,
                                low_pass=0.1,
                                t_r=1.0)
    data_flat_ = signal.clean(data_flat,
                              detrend=True,
                              standardize=False,
                              low_pass=0.1,
                              t_r=1.0)

    np.testing.assert_almost_equal(data_img_.get_data().T.reshape(100, -1),
                                   data_flat_)
    # if NANs
    data[:, 9, 9] = np.nan
    # if infinity
    data[:, 5, 5] = np.inf
    nan_img = nibabel.Nifti1Image(data, np.eye(4))
    clean_im = image.clean_img(nan_img, ensure_finite=True)
    assert_true(np.any(np.isfinite(clean_im.get_data())), True)

    # test_clean_img_passing_nifti2image
    data_img_nifti2 = nibabel.Nifti2Image(data, np.eye(4))

    data_img_nifti2_ = image.clean_img(data_img_nifti2,
                                       detrend=True,
                                       standardize=False,
                                       low_pass=0.1,
                                       t_r=1.0)

    # if mask_img
    img, mask_img = data_gen.generate_fake_fmri(shape=(10, 10, 10), length=10)
    data_img_mask_ = image.clean_img(img, mask_img=mask_img)

    # Checks that output with full mask and without is equal
    data_img_ = image.clean_img(img)
    np.testing.assert_almost_equal(data_img_.get_data(),
                                   data_img_mask_.get_data())
コード例 #4
0
ファイル: test_image.py プロジェクト: jeromedockes/nilearn
def test_clean_img():

    rng = np.random.RandomState(0)

    data = rng.randn(10, 10, 10, 100) + .5
    data_flat = data.T.reshape(100, -1)
    data_img = nibabel.Nifti1Image(data, np.eye(4))

    assert_raises(
        ValueError, image.clean_img, data_img, t_r=None, low_pass=0.1)

    data_img_ = image.clean_img(
        data_img, detrend=True, standardize=False, low_pass=0.1, t_r=1.0)
    data_flat_ = signal.clean(
        data_flat, detrend=True, standardize=False, low_pass=0.1, t_r=1.0)

    np.testing.assert_almost_equal(data_img_.get_data().T.reshape(100, -1),
                                   data_flat_)
    # if NANs
    data[:, 9, 9] = np.nan
    # if infinity
    data[:, 5, 5] = np.inf
    nan_img = nibabel.Nifti1Image(data, np.eye(4))
    clean_im = image.clean_img(nan_img, ensure_finite=True)
    assert_true(np.any(np.isfinite(clean_im.get_data())), True)

    # test_clean_img_passing_nifti2image
    data_img_nifti2 = nibabel.Nifti2Image(data, np.eye(4))

    data_img_nifti2_ = image.clean_img(
        data_img_nifti2, detrend=True, standardize=False, low_pass=0.1, t_r=1.0)

    # if mask_img
    img, mask_img = data_gen.generate_fake_fmri(shape=(10, 10, 10), length=10)
    data_img_mask_ = image.clean_img(img, mask_img=mask_img)

    # Checks that output with full mask and without is equal
    data_img_ = image.clean_img(img)
    np.testing.assert_almost_equal(data_img_.get_data(),
                                   data_img_mask_.get_data())
コード例 #5
0
ファイル: test_image.py プロジェクト: Joaoloula/nilearn
def test_clean_img():

    rng = np.random.RandomState(0)

    data = rng.randn(10, 10, 10, 100) + .5
    data_flat = data.T.reshape(100, -1)
    data_img = nibabel.Nifti1Image(data, np.eye(4))

    data_img_ = image.clean_img(
        data_img, detrend=True, standardize=False, low_pass=0.1)
    data_flat_ = signal.clean(
        data_flat, detrend=True, standardize=False, low_pass=0.1)

    np.testing.assert_almost_equal(data_img_.get_data().T.reshape(100, -1),
                                   data_flat_)
コード例 #6
0
ファイル: test_image.py プロジェクト: luohongyu/nilearn
def test_clean_img():

    rng = np.random.RandomState(0)

    data = rng.randn(10, 10, 10, 100) + .5
    data_flat = data.T.reshape(100, -1)
    data_img = nibabel.Nifti1Image(data, np.eye(4))

    data_img_ = image.clean_img(data_img,
                                detrend=True,
                                standardize=False,
                                low_pass=0.1)
    data_flat_ = signal.clean(data_flat,
                              detrend=True,
                              standardize=False,
                              low_pass=0.1)

    np.testing.assert_almost_equal(data_img_.get_data().T.reshape(100, -1),
                                   data_flat_)