Test generation of random cortical parcellation.
()
| 1022 | |
| 1023 | @testing.requires_testing_data |
| 1024 | def test_random_parcellation(): |
| 1025 | """Test generation of random cortical parcellation.""" |
| 1026 | pytest.importorskip("nibabel") |
| 1027 | hemi = "both" |
| 1028 | n_parcel = 50 |
| 1029 | surface = "sphere.reg" |
| 1030 | subject = "sample_ds" |
| 1031 | rng = np.random.RandomState(0) |
| 1032 | |
| 1033 | # Parcellation |
| 1034 | labels = random_parcellation( |
| 1035 | subject, n_parcel, hemi, subjects_dir, surface=surface, random_state=rng |
| 1036 | ) |
| 1037 | |
| 1038 | # test number of labels |
| 1039 | assert_equal(len(labels), n_parcel) |
| 1040 | if hemi == "both": |
| 1041 | hemi = ["lh", "rh"] |
| 1042 | hemis = np.atleast_1d(hemi) |
| 1043 | for hemi in set(hemis): |
| 1044 | vertices_total = [] |
| 1045 | for label in labels: |
| 1046 | if label.hemi == hemi: |
| 1047 | # test that labels are not empty |
| 1048 | assert len(label.vertices) > 0 |
| 1049 | |
| 1050 | # vertices of hemi covered by labels |
| 1051 | vertices_total = np.append(vertices_total, label.vertices) |
| 1052 | |
| 1053 | # test that labels don't intersect |
| 1054 | assert_equal(len(np.unique(vertices_total)), len(vertices_total)) |
| 1055 | |
| 1056 | surf_fname = subjects_dir / subject / "surf" / (hemi + "." + surface) |
| 1057 | vert, _ = read_surface(surf_fname) |
| 1058 | |
| 1059 | # Test that labels cover whole surface |
| 1060 | assert_array_equal(np.sort(vertices_total), np.arange(len(vert))) |
| 1061 | |
| 1062 | |
| 1063 | @testing.requires_testing_data |
nothing calls this directly
no test coverage detected