Ejemplo n.º 1
0
def test_check_parameters_transform(test_image_2):
    rng = np.random.RandomState(42)
    # single confound
    confounds = rng.standard_normal(size=(10, 3))
    # Tests to check whether imgs, confounds returned are
    # list or not. Pre-check in parameters to work for list
    # of multi images and multi confounds
    imgs, confounds, single_subject = _check_parameters_transform(
        test_image_2, confounds)
    assert isinstance(imgs, (list, tuple))
    assert isinstance(confounds, (list, tuple))
    assert single_subject, True
    # confounds as pandas DataFrame
    imgs, confounds, single_subject = _check_parameters_transform(
        test_image_2, pd.DataFrame(np.array(confounds)[0]))
    assert isinstance(confounds, (list, tuple))
    # multi images
    fmri_imgs = [test_image_2] * 3
    confounds_list = [confounds] * 3
    imgs, confounds, _ = _check_parameters_transform(fmri_imgs, confounds_list)
    assert imgs == fmri_imgs
    assert confounds_list == confounds
    # Test the error when length of images and confounds are not same
    msg = ("Number of confounds given does not match with the "
           "given number of images")

    not_match_confounds_list = [confounds] * 2
    with pytest.raises(ValueError, match=msg):
        _check_parameters_transform(fmri_imgs, not_match_confounds_list)
Ejemplo n.º 2
0
def test_check_parameters_transform():
    rng = np.random.RandomState(0)
    data = np.ones((10, 11, 12, 10))
    data[6, 7, 8] = 2
    data[9, 10, 11] = 3

    # single image
    fmri_img = nibabel.Nifti1Image(data, affine=np.eye(4))
    # single confound
    confounds = rng.randn(*(10, 3))
    # Tests to check whether imgs, confounds returned are
    # list or not. Pre-check in parameters to work for list
    # of multi images and multi confounds
    imgs, confounds, single_subject = _check_parameters_transform(
        fmri_img, confounds)
    assert_true(isinstance(imgs, (list, tuple)))
    assert_true(isinstance(confounds, (list, tuple)))
    assert_true(single_subject, True)

    # multi images
    fmri_imgs = [fmri_img, fmri_img, fmri_img]
    confounds_list = [confounds, confounds, confounds]
    imgs, confounds, _ = _check_parameters_transform(fmri_imgs, confounds_list)
    assert_equal(imgs, fmri_imgs)
    assert_equal(confounds_list, confounds)

    # Test the error when length of images and confounds are not same
    msg = ("Number of confounds given does not match with the "
           "given number of images")
    not_match_confounds_list = [confounds, confounds]
    assert_raises_regex(ValueError, msg, _check_parameters_transform,
                        fmri_imgs, not_match_confounds_list)
Ejemplo n.º 3
0
def test_check_parameters_transform():
    rng = np.random.RandomState(0)
    data = np.ones((10, 11, 12, 10))
    data[6, 7, 8] = 2
    data[9, 10, 11] = 3

    # single image
    fmri_img = nibabel.Nifti1Image(data, affine=np.eye(4))
    # single confound
    confounds = rng.randn(*(10, 3))
    # Tests to check whether imgs, confounds returned are
    # list or not. Pre-check in parameters to work for list
    # of multi images and multi confounds
    imgs, confounds, single_subject = _check_parameters_transform(fmri_img,
                                                                  confounds)
    assert_true(isinstance(imgs, (list, tuple)))
    assert_true(isinstance(confounds, (list, tuple)))
    assert_true(single_subject, True)

    # multi images
    fmri_imgs = [fmri_img, fmri_img, fmri_img]
    confounds_list = [confounds, confounds, confounds]
    imgs, confounds, _ = _check_parameters_transform(fmri_imgs, confounds_list)
    assert_equal(imgs, fmri_imgs)
    assert_equal(confounds_list, confounds)

    # Test the error when length of images and confounds are not same
    msg = ("Number of confounds given does not match with the "
           "given number of images")
    not_match_confounds_list = [confounds, confounds]
    assert_raises_regex(ValueError, msg, _check_parameters_transform,
                        fmri_imgs, not_match_confounds_list)
Ejemplo n.º 4
0
def test_check_parameters_transform():
    rng = np.random.RandomState(42)
    data = np.ones((10, 11, 12, 10))
    data[6, 7, 8] = 2
    data[9, 10, 11] = 3

    # single image
    fmri_img = nibabel.Nifti1Image(data, affine=np.eye(4))
    # single confound
    confounds = rng.standard_normal(size=(10, 3))
    # Tests to check whether imgs, confounds returned are
    # list or not. Pre-check in parameters to work for list
    # of multi images and multi confounds
    imgs, confounds, single_subject = _check_parameters_transform(
        fmri_img, confounds)
    assert isinstance(imgs, (list, tuple))
    assert isinstance(confounds, (list, tuple))
    assert single_subject, True

    # confounds as pandas DataFrame
    imgs, confounds, single_subject = _check_parameters_transform(
        fmri_img, pd.DataFrame(np.array(confounds)[0]))
    assert isinstance(confounds, (list, tuple))

    # multi images
    fmri_imgs = [fmri_img, fmri_img, fmri_img]
    confounds_list = [confounds, confounds, confounds]
    imgs, confounds, _ = _check_parameters_transform(fmri_imgs, confounds_list)
    assert imgs == fmri_imgs
    assert confounds_list == confounds

    # Test the error when length of images and confounds are not same
    msg = ("Number of confounds given does not match with the "
           "given number of images")
    not_match_confounds_list = [confounds, confounds]
    with pytest.raises(ValueError, match=msg):
        _check_parameters_transform(fmri_imgs, not_match_confounds_list)