• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python testing.generate_maps函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nilearn._utils.testing.generate_maps函数的典型用法代码示例。如果您正苦于以下问题:Python generate_maps函数的具体用法?Python generate_maps怎么用?Python generate_maps使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了generate_maps函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_region_extractor_fit_and_transform

def test_region_extractor_fit_and_transform():
    n_regions = 9
    n_subjects = 5
    maps, mask_img = generate_maps((40, 40, 40), n_regions=n_regions)

    # smoke test to RegionExtractor with thresholding_strategy='ratio_n_voxels'
    extract_ratio = RegionExtractor(maps, threshold=0.2,
                                    thresholding_strategy='ratio_n_voxels')
    extract_ratio.fit()
    assert_not_equal(extract_ratio.regions_img_, '')
    assert_true(extract_ratio.regions_img_.shape[-1] >= 9)

    # smoke test with threshold=string and strategy=percentile
    extractor = RegionExtractor(maps, threshold=30,
                                thresholding_strategy='percentile',
                                mask_img=mask_img)
    extractor.fit()
    assert_true(extractor.index_, np.ndarray)
    assert_not_equal(extractor.regions_img_, '')
    assert_true(extractor.regions_img_.shape[-1] >= 9)

    n_regions_extracted = extractor.regions_img_.shape[-1]
    shape = (91, 109, 91, 7)
    expected_signal_shape = (7, n_regions_extracted)
    for id_ in range(n_subjects):
        img, data = _make_random_data(shape)
        # smoke test NiftiMapsMasker transform inherited in Region Extractor
        signal = extractor.transform(img)
        assert_equal(expected_signal_shape, signal.shape)

    # smoke test with high resolution image
    maps, mask_img = generate_maps((20, 20, 20), n_regions=n_regions,
                                   affine=.2 * np.eye(4))

    extract_ratio = RegionExtractor(maps,
                                    thresholding_strategy='ratio_n_voxels',
                                    smoothing_fwhm=.6,
                                    min_region_size=.4)
    extract_ratio.fit()
    assert_not_equal(extract_ratio.regions_img_, '')
    assert_true(extract_ratio.regions_img_.shape[-1] >= 9)

    # smoke test with zeros on the diagonal of the affine
    affine = np.eye(4)
    affine[[0, 1]] = affine[[1, 0]]  # permutes first and second lines
    maps, mask_img = generate_maps((40, 40, 40), n_regions=n_regions,
                                   affine=affine)

    extract_ratio = RegionExtractor(maps, threshold=0.2,
                                    thresholding_strategy='ratio_n_voxels')
    extract_ratio.fit()
    assert_not_equal(extract_ratio.regions_img_, '')
    assert_true(extract_ratio.regions_img_.shape[-1] >= 9)
开发者ID:bthirion,项目名称:nilearn,代码行数:53,代码来源:test_region_extractor.py


示例2: test_nans_threshold_maps_ratio

def test_nans_threshold_maps_ratio():
    maps, _ = generate_maps((10, 10, 10), n_regions=2)
    data = maps.get_data()
    data[:, :, 0] = np.nan

    maps_img = nibabel.Nifti1Image(data, np.eye(4))
    thr_maps = _threshold_maps_ratio(maps_img, threshold=0.8)
开发者ID:bthirion,项目名称:nilearn,代码行数:7,代码来源:test_region_extractor.py


示例3: test_region_extractor_fit_and_transform

def test_region_extractor_fit_and_transform():
    n_regions = 9
    n_subjects = 5
    maps, mask_img = generate_maps((40, 40, 40), n_regions=n_regions)

    # smoke test to RegionExtractor with thresholding_strategy='ratio_n_voxels'
    extract_ratio = RegionExtractor(maps, threshold=0.2,
                                    thresholding_strategy='ratio_n_voxels')
    extract_ratio.fit()
    assert_not_equal(extract_ratio.regions_img_, '')
    assert_true(extract_ratio.regions_img_.shape[-1] >= 9)

    # smoke test with threshold=string and strategy=percentile
    extractor = RegionExtractor(maps, threshold=30,
                                thresholding_strategy='percentile',
                                mask_img=mask_img)
    extractor.fit()
    assert_true(extractor.index_, np.ndarray)
    assert_not_equal(extractor.regions_img_, '')
    assert_true(extractor.regions_img_.shape[-1] >= 9)

    n_regions_extracted = extractor.regions_img_.shape[-1]
    shape = (91, 109, 91, 7)
    expected_signal_shape = (7, n_regions_extracted)
    for id_ in range(n_subjects):
        img, data = _make_random_data(shape)
        # smoke test NiftiMapsMasker transform inherited in Region Extractor
        signal = extractor.transform(img)
        assert_equal(expected_signal_shape, signal.shape)
开发者ID:AlexandreAbraham,项目名称:nilearn,代码行数:29,代码来源:test_region_extractor.py


示例4: test_invalid_threshold_strategies

def test_invalid_threshold_strategies():
    maps, _ = generate_maps((6, 8, 10), n_regions=1)

    extract_strategy_check = RegionExtractor(maps, thresholding_strategy='n_')
    valid_strategies = ['ratio_n_voxels', 'img_value', 'percentile']
    assert_raises_regex(ValueError,
                        "'thresholding_strategy' should be either of "
                        "these".format(valid_strategies),
                        extract_strategy_check.fit)
开发者ID:bthirion,项目名称:nilearn,代码行数:9,代码来源:test_region_extractor.py


示例5: test_isnan_threshold_img_data

def test_isnan_threshold_img_data():
    shape = (10, 10, 10)
    maps, _ = testing.generate_maps(shape, n_regions=2)
    data = maps.get_data()
    data[:, :, 0] = np.nan

    maps_img = nibabel.Nifti1Image(data, np.eye(4))
    # test threshold_img to converge properly when input image has nans.
    threshold_img(maps_img, threshold=0.8)
开发者ID:Naereen,项目名称:nilearn,代码行数:9,代码来源:test_image.py


示例6: test_invalid_thresholds_in_threshold_maps_ratio

def test_invalid_thresholds_in_threshold_maps_ratio():
    maps, _ = generate_maps((10, 11, 12), n_regions=2)

    for invalid_threshold in ['80%', 'auto', -1.0]:
        assert_raises_regex(ValueError,
                            "threshold given as ratio to the number of voxels must "
                            "be Real number and should be positive and between 0 and "
                            "total number of maps i.e. n_maps={0}. "
                            "You provided {1}".format(maps.shape[-1], invalid_threshold),
                            _threshold_maps_ratio,
                            maps, threshold=invalid_threshold)
开发者ID:bthirion,项目名称:nilearn,代码行数:11,代码来源:test_region_extractor.py


示例7: test_threshold_as_none_and_string_cases

def test_threshold_as_none_and_string_cases():
    maps, _ = generate_maps((6, 8, 10), n_regions=1)

    extract_thr_none_check = RegionExtractor(maps, threshold=None)
    assert_raises_regex(ValueError,
                        "The given input to threshold is not valid.",
                        extract_thr_none_check.fit)
    extract_thr_string_check = RegionExtractor(maps, threshold='30%')
    assert_raises_regex(ValueError,
                        "The given input to threshold is not valid.",
                        extract_thr_string_check.fit)
开发者ID:bthirion,项目名称:nilearn,代码行数:11,代码来源:test_region_extractor.py


示例8: test_invalids_extract_types_in_connected_regions

def test_invalids_extract_types_in_connected_regions():
    maps, _ = generate_maps((10, 11, 12), n_regions=2)
    valid_names = ['connected_components', 'local_regions']

    # test whether same error raises as expected when invalid inputs
    # are given to extract_type in connected_regions function
    message = ("'extract_type' should be {0}")
    for invalid_extract_type in ['connect_region', 'local_regios']:
        assert_raises_regex(ValueError,
                            message.format(valid_names),
                            connected_regions,
                            maps, extract_type=invalid_extract_type)
开发者ID:bthirion,项目名称:nilearn,代码行数:12,代码来源:test_region_extractor.py


示例9: test_generate_maps

def test_generate_maps():
    # Basic testing of generate_maps()
    shape = (10, 11, 12)
    n_regions = 9
    maps_img, _ = generate_maps(shape, n_regions, border=1)
    maps = maps_img.get_data()
    assert_true(maps.shape == shape + (n_regions,))
    # no empty map
    assert_true(np.all(abs(maps).sum(axis=0).sum(axis=0).sum(axis=0) > 0))
    # check border
    assert_true(np.all(maps[0, ...] == 0))
    assert_true(np.all(maps[:, 0, ...] == 0))
    assert_true(np.all(maps[:, :, 0, :] == 0))
开发者ID:banilo,项目名称:nilearn,代码行数:13,代码来源:test_signal_extraction.py


示例10: test_threshold_img

def test_threshold_img():
    # to check whether passes with valid threshold inputs
    shape = (10, 20, 30)
    maps, _ = testing.generate_maps(shape, n_regions=4)
    affine = np.eye(4)
    mask_img = nibabel.Nifti1Image(np.ones((shape), dtype=np.int8), affine)

    for img in iter_img(maps):
        # when threshold is a float value
        thr_maps_img = threshold_img(img, threshold=0.8)
        # when we provide mask image
        thr_maps_percent = threshold_img(img, threshold=1, mask_img=mask_img)
        # when threshold is a percentile
        thr_maps_percent2 = threshold_img(img, threshold='2%')
开发者ID:Naereen,项目名称:nilearn,代码行数:14,代码来源:test_image.py


示例11: test_threshold_maps_ratio

def test_threshold_maps_ratio():
    # smoke test for function _threshold_maps_ratio with randomly
    # generated maps

    # make sure that n_regions (4th dimension) are kept same even
    # in thresholded image
    maps, _ = generate_maps((6, 8, 10), n_regions=3)
    thr_maps = _threshold_maps_ratio(maps, threshold=1.0)
    assert_true(thr_maps.shape[-1] == maps.shape[-1])

    # check that the size should be same for 3D image
    # before and after thresholding
    img = np.zeros((30, 30, 30)) + 0.1 * np.random.randn(30, 30, 30)
    img = nibabel.Nifti1Image(img, affine=np.eye(4))
    thr_maps_3d = _threshold_maps_ratio(img, threshold=0.5)
    assert_true(img.shape == thr_maps_3d.shape)
开发者ID:bthirion,项目名称:nilearn,代码行数:16,代码来源:test_region_extractor.py


示例12: test_validity_threshold_value_in_threshold_img

def test_validity_threshold_value_in_threshold_img():
    shape = (6, 8, 10)
    maps, _ = testing.generate_maps(shape, n_regions=2)

    # testing to raise same error when threshold=None case
    testing.assert_raises_regex(ValueError,
                                "The input parameter 'threshold' is empty. ",
                                threshold_img, maps, threshold=None)

    invalid_threshold_values = ['90t%', 's%', 't', '0.1']
    name = 'threshold'
    for thr in invalid_threshold_values:
        testing.assert_raises_regex(ValueError,
                                    '{0}.+should be a number followed by '
                                    'the percent sign'.format(name),
                                    threshold_img, maps, threshold=thr)
开发者ID:Naereen,项目名称:nilearn,代码行数:16,代码来源:test_image.py


示例13: test_connected_regions

def test_connected_regions():
    # 4D maps
    n_regions = 4
    maps, _ = generate_maps((30, 30, 30), n_regions=n_regions)
    # 3D maps
    map_img = np.zeros((30, 30, 30)) + 0.1 * np.random.randn(30, 30, 30)
    map_img = nibabel.Nifti1Image(map_img, affine=np.eye(4))

    # smoke test for function connected_regions and also to check
    # if the regions extracted should be equal or more than already present.
    # 4D image case
    for extract_type in ['connected_components', 'local_regions']:
        connected_extraction_img, index = connected_regions(maps, min_region_size=10,
                                                            extract_type=extract_type)
        assert_true(connected_extraction_img.shape[-1] >= n_regions)
        assert_true(index, np.ndarray)
        # For 3D images regions extracted should be more than equal to one
        connected_extraction_3d_img, _ = connected_regions(map_img, min_region_size=10,
                                                           extract_type=extract_type)
        assert_true(connected_extraction_3d_img.shape[-1] >= 1)
开发者ID:AlexandreAbraham,项目名称:nilearn,代码行数:20,代码来源:test_region_extractor.py


示例14: test_connected_regions

def test_connected_regions():
    # 4D maps
    n_regions = 4
    maps, mask_img = generate_maps((30, 30, 30), n_regions=n_regions)
    # 3D maps
    map_img = np.zeros((30, 30, 30)) + 0.1 * np.random.randn(30, 30, 30)
    map_img = nibabel.Nifti1Image(map_img, affine=np.eye(4))

    # smoke test for function connected_regions and also to check
    # if the regions extracted should be equal or more than already present.
    # 4D image case
    for extract_type in ['connected_components', 'local_regions']:
        connected_extraction_img, index = connected_regions(maps, min_region_size=10,
                                                            extract_type=extract_type)
        assert_true(connected_extraction_img.shape[-1] >= n_regions)
        assert_true(index, np.ndarray)
        # For 3D images regions extracted should be more than equal to one
        connected_extraction_3d_img, _ = connected_regions(map_img, min_region_size=10,
                                                           extract_type=extract_type)
        assert_true(connected_extraction_3d_img.shape[-1] >= 1)

    # Test input mask_img
    extraction_with_mask_img, index = connected_regions(maps,
                                                        mask_img=mask_img)
    assert_true(extraction_with_mask_img.shape[-1] >= 1)

    # mask_img with different shape
    mask = np.zeros(shape=(10, 11, 12), dtype=np.int)
    mask[1:-1, 1:-1, 1:-1] = 1
    affine = np.array([[2., 0., 0., 0.],
                       [0., 2., 0., 0.],
                       [0., 0., 2., 0.],
                       [0., 0., 0., 2.]])
    mask_img = nibabel.Nifti1Image(mask, affine=affine)
    extraction_not_same_fov_mask, _ = connected_regions(maps,
                                                        mask_img=mask_img)
    assert_equal(maps.shape[:3], extraction_not_same_fov_mask.shape[:3])
    assert_not_equal(mask_img.shape, extraction_not_same_fov_mask.shape[:3])
开发者ID:bthirion,项目名称:nilearn,代码行数:38,代码来源:test_region_extractor.py


示例15: test_nifti_maps_masker_with_nans

def test_nifti_maps_masker_with_nans():
    length = 3
    n_regions = 8
    fmri_img, mask_img = generate_random_img((13, 11, 12),
                                             affine=np.eye(4), length=length)
    maps_img, maps_mask_img = testing.generate_maps((13, 11, 12), n_regions,
                                                    affine=np.eye(4))

    # nans
    maps_data = maps_img.get_data()
    mask_data = mask_img.get_data()

    maps_data[:, 9, 9] = np.nan
    maps_data[:, 5, 5] = np.inf
    mask_data[:, :, 7] = np.nan
    mask_data[:, :, 5] = np.inf

    maps_img = nibabel.Nifti1Image(maps_data, np.eye(4))
    mask_img = nibabel.Nifti1Image(mask_data, np.eye(4))

    masker = NiftiMapsMasker(maps_img, mask_img=mask_img)
    sig = masker.fit_transform(fmri_img)
    assert_equal(sig.shape, (length, n_regions))
    assert_true(np.all(np.isfinite(sig)))
开发者ID:AlexandreAbraham,项目名称:nilearn,代码行数:24,代码来源:test_nifti_maps_masker.py


示例16: test_nifti_maps_masker

def test_nifti_maps_masker():
    # Check working of shape/affine checks
    shape1 = (13, 11, 12)
    affine1 = np.eye(4)

    shape2 = (12, 10, 14)
    affine2 = np.diag((1, 2, 3, 1))

    n_regions = 9
    length = 3

    fmri11_img, mask11_img = generate_random_img(shape1, affine=affine1,
                                                 length=length)
    fmri12_img, mask12_img = generate_random_img(shape1, affine=affine2,
                                                 length=length)
    fmri21_img, mask21_img = generate_random_img(shape2, affine=affine1,
                                                 length=length)

    labels11_img, labels_mask_img = \
        testing.generate_maps(shape1, n_regions, affine=affine1)

    # No exception raised here
    for create_files in (True, False):
        with testing.write_tmp_imgs(labels11_img, create_files=create_files) \
                as labels11:
            masker11 = NiftiMapsMasker(labels11, resampling_target=None)
            signals11 = masker11.fit().transform(fmri11_img)
            assert_equal(signals11.shape, (length, n_regions))
            # enables to delete "labels11" on windows
            del masker11

    masker11 = NiftiMapsMasker(labels11_img, mask_img=mask11_img,
                               resampling_target=None)

    testing.assert_raises_regex(
        ValueError, 'has not been fitted. ',
        masker11.transform, fmri11_img)
    signals11 = masker11.fit().transform(fmri11_img)
    assert_equal(signals11.shape, (length, n_regions))

    NiftiMapsMasker(labels11_img).fit_transform(fmri11_img)

    # Test all kinds of mismatches between shapes and between affines
    for create_files in (True, False):
        with testing.write_tmp_imgs(labels11_img, mask12_img,
                                    create_files=create_files) as images:
            labels11, mask12 = images
            masker11 = NiftiMapsMasker(labels11, resampling_target=None)
            masker11.fit()
            assert_raises(ValueError, masker11.transform, fmri12_img)
            assert_raises(ValueError, masker11.transform, fmri21_img)

            masker11 = NiftiMapsMasker(labels11, mask_img=mask12,
                                       resampling_target=None)
            assert_raises(ValueError, masker11.fit)
            del masker11

    masker11 = NiftiMapsMasker(labels11_img, mask_img=mask21_img,
                               resampling_target=None)
    assert_raises(ValueError, masker11.fit)

    # Transform, with smoothing (smoke test)
    masker11 = NiftiMapsMasker(labels11_img, smoothing_fwhm=3,
                               resampling_target=None)
    signals11 = masker11.fit().transform(fmri11_img)
    assert_equal(signals11.shape, (length, n_regions))

    masker11 = NiftiMapsMasker(labels11_img, smoothing_fwhm=3,
                               resampling_target=None)
    signals11 = masker11.fit_transform(fmri11_img)
    assert_equal(signals11.shape, (length, n_regions))

    testing.assert_raises_regex(
        ValueError, 'has not been fitted. ',
        NiftiMapsMasker(labels11_img).inverse_transform, signals11)

    # Call inverse transform (smoke test)
    fmri11_img_r = masker11.inverse_transform(signals11)
    assert_equal(fmri11_img_r.shape, fmri11_img.shape)
    np.testing.assert_almost_equal(get_affine(fmri11_img_r),
                                   get_affine(fmri11_img))

    # Test with data and atlas of different shape: the atlas should be
    # resampled to the data
    shape22 = (5, 5, 6)
    affine2 = 2 * np.eye(4)
    affine2[-1, -1] = 1

    fmri22_img, _ = generate_random_img(shape22, affine=affine2,
                                        length=length)
    masker = NiftiMapsMasker(labels11_img, mask_img=mask21_img)

    masker.fit_transform(fmri22_img)
    np.testing.assert_array_equal(
        get_affine(masker._resampled_maps_img_),
        affine2)
开发者ID:AlexandreAbraham,项目名称:nilearn,代码行数:96,代码来源:test_nifti_maps_masker.py


示例17: test_nifti_maps_masker_2

def test_nifti_maps_masker_2():
    # Test resampling in NiftiMapsMasker
    affine = np.eye(4)

    shape1 = (10, 11, 12)  # fmri
    shape2 = (13, 14, 15)  # mask
    shape3 = (16, 17, 18)  # maps

    n_regions = 9
    length = 3

    fmri11_img, _ = generate_random_img(shape1, affine=affine,
                                        length=length)
    _, mask22_img = generate_random_img(shape2, affine=affine,
                                        length=length)

    maps33_img, _ = \
        testing.generate_maps(shape3, n_regions, affine=affine)

    mask_img_4d = nibabel.Nifti1Image(np.ones((2, 2, 2, 2), dtype=np.int8),
                                      affine=np.diag((4, 4, 4, 1)))

    # verify that 4D mask arguments are refused
    masker = NiftiMapsMasker(maps33_img, mask_img=mask_img_4d)
    testing.assert_raises_regex(DimensionError,
                                "Input data has incompatible dimensionality: "
                                "Expected dimension is 3D and you provided "
                                "a 4D image.",
                                masker.fit)

    # Test error checking
    assert_raises(ValueError, NiftiMapsMasker, maps33_img,
                  resampling_target="mask")
    assert_raises(ValueError, NiftiMapsMasker, maps33_img,
                  resampling_target="invalid")

    # Target: mask
    masker = NiftiMapsMasker(maps33_img, mask_img=mask22_img,
                             resampling_target="mask")

    masker.fit()
    np.testing.assert_almost_equal(get_affine(masker.mask_img_),
                                   get_affine(mask22_img))
    assert_equal(masker.mask_img_.shape, mask22_img.shape)

    np.testing.assert_almost_equal(get_affine(masker.mask_img_),
                                   get_affine(masker.maps_img_))
    assert_equal(masker.mask_img_.shape, masker.maps_img_.shape[:3])

    transformed = masker.transform(fmri11_img)
    assert_equal(transformed.shape, (length, n_regions))

    fmri11_img_r = masker.inverse_transform(transformed)
    np.testing.assert_almost_equal(get_affine(fmri11_img_r),
                                   get_affine(masker.maps_img_))
    assert_equal(fmri11_img_r.shape, (masker.maps_img_.shape[:3] + (length,)))

    # Target: maps
    masker = NiftiMapsMasker(maps33_img, mask_img=mask22_img,
                             resampling_target="maps")

    masker.fit()
    np.testing.assert_almost_equal(get_affine(masker.maps_img_),
                                   get_affine(maps33_img))
    assert_equal(masker.maps_img_.shape, maps33_img.shape)

    np.testing.assert_almost_equal(get_affine(masker.mask_img_),
                                   get_affine(masker.maps_img_))
    assert_equal(masker.mask_img_.shape, masker.maps_img_.shape[:3])

    transformed = masker.transform(fmri11_img)
    assert_equal(transformed.shape, (length, n_regions))

    fmri11_img_r = masker.inverse_transform(transformed)
    np.testing.assert_almost_equal(get_affine(fmri11_img_r),
                                   get_affine(masker.maps_img_))
    assert_equal(fmri11_img_r.shape, (masker.maps_img_.shape[:3] + (length,)))

    # Test with clipped maps: mask does not contain all maps.
    # Shapes do matter in that case
    affine1 = np.eye(4)
    shape1 = (10, 11, 12)
    shape2 = (8, 9, 10)  # mask
    affine2 = np.diag((2, 2, 2, 1))  # just for mask
    shape3 = (16, 18, 20)  # maps

    n_regions = 9
    length = 21

    fmri11_img, _ = generate_random_img(shape1, affine=affine1, length=length)
    _, mask22_img = testing.generate_fake_fmri(shape2, length=1,
                                               affine=affine2)
    # Target: maps
    maps33_img, _ = \
        testing.generate_maps(shape3, n_regions, affine=affine1)

    masker = NiftiMapsMasker(maps33_img, mask_img=mask22_img,
                             resampling_target="maps")

    masker.fit()
#.........这里部分代码省略.........
开发者ID:AlexandreAbraham,项目名称:nilearn,代码行数:101,代码来源:test_nifti_maps_masker.py


示例18: test_signal_extraction_with_maps

def test_signal_extraction_with_maps():
    shape = (10, 11, 12)
    n_regions = 9
    n_instants = 13

    # Generate signals
    rand_gen = np.random.RandomState(0)

    maps_img, mask_img = generate_maps(shape, n_regions, border=1)
    maps_data = maps_img.get_data()
    data = np.zeros(shape + (n_instants,), dtype=np.float32)

    mask_4d_img = nibabel.Nifti1Image(np.ones((shape + (2, ))), np.eye(4))

    signals = np.zeros((n_instants, maps_data.shape[-1]))
    for n in range(maps_data.shape[-1]):
        signals[:, n] = rand_gen.randn(n_instants)
        data[maps_data[..., n] > 0, :] = signals[:, n]
    img = nibabel.Nifti1Image(data, np.eye(4))

    # verify that 4d masks are refused
    assert_raises_regex(TypeError, _TEST_DIM_ERROR_MSG,
                        signal_extraction.img_to_signals_maps, img, maps_img,
                        mask_img=mask_4d_img)

    # Get signals
    signals_r, labels = signal_extraction.img_to_signals_maps(
        img, maps_img, mask_img=mask_img)

    # The output must be identical to the input signals, because every region
    # is homogeneous: there is the same signal in all voxels of one given
    # region (and all maps are uniform).
    np.testing.assert_almost_equal(signals, signals_r)

    # Same thing without mask (in that case)
    signals_r, labels = signal_extraction.img_to_signals_maps(img, maps_img)
    np.testing.assert_almost_equal(signals, signals_r)

    # Recover image
    img_r = signal_extraction.signals_to_img_maps(signals, maps_img,
                                                  mask_img=mask_img)
    np.testing.assert_almost_equal(img_r.get_data(), img.get_data())
    img_r = signal_extraction.signals_to_img_maps(signals, maps_img)
    np.testing.assert_almost_equal(img_r.get_data(), img.get_data())

    # Test input validation
    data_img = nibabel.Nifti1Image(np.zeros((2, 3, 4, 5)), np.eye(4))

    good_maps_img = nibabel.Nifti1Image(np.zeros((2, 3, 4, 7)), np.eye(4))
    bad_maps1_img = nibabel.Nifti1Image(np.zeros((2, 3, 5, 7)), np.eye(4))
    bad_maps2_img = nibabel.Nifti1Image(np.zeros((2, 3, 4, 7)), 2 * np.eye(4))

    good_mask_img = nibabel.Nifti1Image(np.zeros((2, 3, 4)), np.eye(4))
    bad_mask1_img = nibabel.Nifti1Image(np.zeros((2, 3, 5)), np.eye(4))
    bad_mask2_img = nibabel.Nifti1Image(np.zeros((2, 3, 4)), 2 * np.eye(4))
    assert_raises(ValueError, signal_extraction.img_to_signals_maps, data_img,
                  bad_maps1_img)
    assert_raises(ValueError, signal_extraction.img_to_signals_maps, data_img,
                  bad_maps2_img)
    assert_raises(ValueError, signal_extraction.img_to_signals_maps, data_img,
                  bad_maps1_img, mask_img=good_mask_img)
    assert_raises(ValueError, signal_extraction.img_to_signals_maps, data_img,
                  bad_maps2_img, mask_img=good_mask_img)
    assert_raises(ValueError, signal_extraction.img_to_signals_maps, data_img,
                  good_maps_img, mask_img=bad_mask1_img)
    assert_raises(ValueError, signal_extraction.img_to_signals_maps, data_img,
                  good_maps_img, mask_img=bad_mask2_img)
开发者ID:banilo,项目名称:nilearn,代码行数:67,代码来源:test_signal_extraction.py



注:本文中的nilearn._utils.testing.generate_maps函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python testing.write_tmp_imgs函数代码示例发布时间:2022-05-27
下一篇:
Python testing.generate_fake_fmri函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap