def test_probabilistic_labels(): """Test plotting of probabilistic labels.""" _set_backend() brain = Brain("fsaverage", "lh", "inflated", cortex="low_contrast") extra, subj_dir = _get_extra() brain.add_label("BA1" + extra, color="darkblue") brain.add_label("BA1" + extra, color="dodgerblue", scalar_thresh=.5) brain.add_label("BA45" + extra, color="firebrick", borders=True) brain.add_label("BA45" + extra, color="salmon", borders=True, scalar_thresh=.5) label_file = pjoin(subj_dir, "fsaverage", "label", "lh.BA6%s.label" % (extra, )) prob_field = np.zeros_like(brain.geo['lh'].x) ids, probs = nib.freesurfer.read_label(label_file, read_scalars=True) prob_field[ids] = probs brain.add_data(prob_field, thresh=1e-5) with warnings.catch_warnings(record=True): brain.data["colorbar"].number_of_colors = 10 brain.data["colorbar"].number_of_labels = 11 brain.close()
def test_label(): """Test plotting of label.""" _set_backend() subject_id = "fsaverage" hemi = "lh" surf = "inflated" brain = Brain(subject_id, hemi, surf) view = get_view(brain) extra, subj_dir = _get_extra() brain.add_label("BA1" + extra) check_view(brain, view) brain.add_label("BA1" + extra, color="blue", scalar_thresh=.5) label_file = pjoin(subj_dir, subject_id, "label", "%s.MT%s.label" % (hemi, extra)) brain.add_label(label_file) brain.add_label("BA44" + extra, borders=True) brain.add_label("BA6" + extra, alpha=.7) brain.show_view("medial") brain.add_label("V1" + extra, color="steelblue", alpha=.6) brain.add_label("V2" + extra, color="#FF6347", alpha=.6) brain.add_label("entorhinal" + extra, color=(.2, 1, .5), alpha=.6) brain.set_surf('white') brain.show_view(dict(elevation=40, distance=430), distance=430) with pytest.raises(ValueError, match='!='): brain.show_view(dict(elevation=40, distance=430), distance=431) # remove labels brain.remove_labels('V1' + extra) assert 'V2' + extra in brain.labels_dict assert 'V1' + extra not in brain.labels_dict brain.remove_labels() assert 'V2' + extra not in brain.labels_dict brain.close()
def test_surface(): """Test IO for Surface class""" extra, subj_dir = utils._get_extra() for subjects_dir in [None, subj_dir]: surface = utils.Surface('fsaverage', 'lh', 'inflated', subjects_dir=subjects_dir) surface.load_geometry() surface.load_label('BA1' + extra) surface.load_curvature() xfm = np.eye(4) xfm[:3, -1] += 2 # translation x = surface.x surface.apply_xfm(xfm) x_ = surface.x assert_array_almost_equal(x + 2, x_) # normals nn = _slow_compute_normals(surface.coords, surface.faces[:10000]) nn_fast = utils._compute_normals(surface.coords, surface.faces[:10000]) assert_array_almost_equal(nn, nn_fast) assert 50 < np.linalg.norm(surface.coords, axis=-1).mean() < 100 # mm surface = utils.Surface('fsaverage', 'lh', 'inflated', subjects_dir=subj_dir, units='m') surface.load_geometry() assert 0.05 < np.linalg.norm(surface.coords, axis=-1).mean() < 0.1 # m
def test_surface(): """Test IO for Surface class""" extra, subj_dir = utils._get_extra() for subjects_dir in [None, subj_dir]: surface = utils.Surface('fsaverage', 'lh', 'inflated', subjects_dir=subjects_dir) surface.load_geometry() surface.load_label('BA1' + extra) surface.load_curvature() xfm = np.eye(4) xfm[:3, -1] += 2 # translation x = surface.x surface.apply_xfm(xfm) x_ = surface.x assert_allclose(x + 2, x_) # normals nn = _slow_compute_normals(surface.coords, surface.faces[:10000]) nn_fast = utils._compute_normals(surface.coords, surface.faces[:10000]) assert_allclose(nn, nn_fast) assert 50 < np.linalg.norm(surface.coords, axis=-1).mean() < 100 # mm surface = utils.Surface('fsaverage', 'lh', 'inflated', subjects_dir=subj_dir, units='m') surface.load_geometry() assert 0.05 < np.linalg.norm(surface.coords, axis=-1).mean() < 0.1 # m
def test_probabilistic_labels(): """Test plotting of probabilistic labels.""" _set_backend() brain = Brain("fsaverage", "lh", "inflated", cortex="low_contrast") extra, subj_dir = _get_extra() brain.add_label("BA1" + extra, color="darkblue") brain.add_label("BA1" + extra, color="dodgerblue", scalar_thresh=.5) brain.add_label("BA45" + extra, color="firebrick", borders=True) brain.add_label("BA45" + extra, color="salmon", borders=True, scalar_thresh=.5) label_file = pjoin(subj_dir, "fsaverage", "label", "lh.BA6%s.label" % (extra,)) prob_field = np.zeros_like(brain.geo['lh'].x) ids, probs = nib.freesurfer.read_label(label_file, read_scalars=True) prob_field[ids] = probs brain.add_data(prob_field, thresh=1e-5) with warnings.catch_warnings(record=True): brain.data["colorbar"].number_of_colors = 10 brain.data["colorbar"].number_of_labels = 11 brain.close()