Exemple #1
0
def test_annot_with_different_orig_ids_settings():
    vertex_labels_orig, label_colors_orig, label_names_orig, meta_data_orig = an.annot(
        'subject1', TEST_DATA_DIR, 'aparc', hemi='both', orig_ids=True)
    vertex_labels, label_colors, label_names, meta_data = an.annot(
        'subject1', TEST_DATA_DIR, 'aparc', hemi='both', orig_ids=False)
    assert len(vertex_labels_orig) <= len(vertex_labels)
    assert label_colors_orig.shape == label_colors.shape
    assert len(label_names_orig) == len(label_names)
    assert_array_equal(label_names_orig, label_names)
    assert_array_equal(label_colors_orig, label_colors)
    assert vertex_labels[
        0] == 11  # the proper index into the label_colors and label_names datastructures for this vertex, pre-computed for us.
    assert vertex_labels_orig[0] == 9182740  # the original ID
Exemple #2
0
def test_annot_aparc_orig_ids():
    vertex_labels_mod, label_colors_mod, label_names_mod, meta_data_mod = an.annot(
        'subject1', TEST_DATA_DIR, 'aparc', hemi='both')
    vertex_labels_orig, label_colors_orig, label_names_orig, meta_data_orig = an.annot(
        'subject1', TEST_DATA_DIR, 'aparc', hemi='both', orig_ids=True)
    # these should not diff
    assert label_colors_mod.shape == (NUM_LABELS_APARC, 5)
    assert label_colors_mod.shape == label_colors_orig.shape
    assert label_names_mod == label_names_orig
    assert meta_data_mod == meta_data_orig
    assert vertex_labels_mod.shape == vertex_labels_orig.shape
    # now for the parts that should be different between the two
    assert_raises(AssertionError, assert_array_equal, vertex_labels_mod,
                  vertex_labels_orig)
Exemple #3
0
def test_annot_metadata_single_hemi_lh():
    vertex_labels, label_colors, label_names, meta_data = an.annot(
        'subject1', TEST_DATA_DIR, 'aparc', hemi='lh')
    assert len(meta_data) == 1
    assert len(label_names) == NUM_LABELS_APARC
    assert vertex_labels.shape == (SUBJECT1_SURF_LH_WHITE_NUM_VERTICES, )
    assert label_colors.shape == (NUM_LABELS_APARC, 5)
Exemple #4
0
def test_annot_metadata_both_hemispheres():
    vertex_labels, label_colors, label_names, meta_data = an.annot(
        'subject1', TEST_DATA_DIR, 'aparc', hemi='both', orig_ids=True)
    assert len(meta_data) == 2
    assert len(label_names) == NUM_LABELS_APARC
    assert vertex_labels.shape == (SUBJECT1_SURF_LH_WHITE_NUM_VERTICES +
                                   SUBJECT1_SURF_RH_WHITE_NUM_VERTICES, )
    assert label_colors.shape == (NUM_LABELS_APARC, 5)
Exemple #5
0
def test_annot_get_label_indices():
    vertex_labels, label_colors, label_names, meta_data = an.annot(
        'subject1', TEST_DATA_DIR, 'aparc', hemi='both', orig_ids=True)
    assert vertex_labels[0] == 9182740
    idx_map = an._get_indices_for_unique_vertex_labels(vertex_labels,
                                                       label_colors)
    assert len(idx_map) == len(label_colors) - 1
    assert len(idx_map) == len(label_names) - 1
    assert idx_map[9182740] == 11
Exemple #6
0
def test_annot_get_label_index():
    vertex_labels, label_colors, label_names, meta_data = an.annot(
        'subject1', TEST_DATA_DIR, 'aparc', hemi='both', orig_ids=True)
    assert vertex_labels[0] == 9182740
    idx = an._get_annot_label_index(vertex_labels[0], label_colors)
    assert idx == 11
    # this index can now be used to retrieve the color and the label name:
    color_rgbt = (label_colors[idx, 0], label_colors[idx, 1],
                  label_colors[idx, 2], label_colors[idx, 3])
    assert color_rgbt == (20, 30, 140, 0)
    label_name = label_names[idx]
    assert label_name == "lateraloccipital"
Exemple #7
0
def test_annot_aparc_data_makes_sense():
    vertex_labels, label_colors, label_names, meta_data = an.annot(
        'subject1', TEST_DATA_DIR, 'aparc', hemi='both', orig_ids=False)
    assert len(np.unique(vertex_labels)) == NUM_LABELS_APARC - 1
    index_for_first_vertex = vertex_labels[0]
    assert index_for_first_vertex > 0  # make sure it has a valid ID (-1 means has no label and color)
    assert index_for_first_vertex == 11
    color = (label_colors[index_for_first_vertex,
                          0], label_colors[index_for_first_vertex, 1],
             label_colors[index_for_first_vertex,
                          2], label_colors[index_for_first_vertex, 3])
    assert color == (20, 30, 140, 0)
Exemple #8
0
def test_annot_metadata_single_hemi_rh_and_keep_metadata():
    vertex_labels, label_colors, label_names, meta_data = an.annot(
        'subject1',
        TEST_DATA_DIR,
        'aparc',
        hemi='rh',
        meta_data={'todo': 'keep_this'})
    expected_annot_file = os.path.join(TEST_DATA_DIR, 'subject1', 'label',
                                       'rh.aparc.annot')
    assert len(meta_data) == 2
    assert meta_data['rh.annotation_file'] == expected_annot_file
    assert meta_data['todo'] == 'keep_this'
    assert len(label_names) == NUM_LABELS_APARC
    assert vertex_labels.shape == (SUBJECT1_SURF_RH_WHITE_NUM_VERTICES, )
    assert label_colors.shape == (NUM_LABELS_APARC, 5)
Exemple #9
0
def test_annot_raises_on_invalid_hemisphere():
    with pytest.raises(ValueError) as exc_info:
        vertex_labels, label_colors, label_names, meta_data = an.annot(
            'subject1', TEST_DATA_DIR, 'aparc', hemi='invalid_hemisphere')
    assert 'hemi must be one of' in str(exc_info.value)
    assert 'invalid_hemisphere' in str(exc_info.value)
Exemple #10
0
def test_annot_aparc():
    vertex_labels, label_colors, label_names, meta_data = an.annot(
        'subject1', TEST_DATA_DIR, 'aparc.DKTatlas', hemi='both')
    assert label_colors.shape == (NUM_LABELS_APARC_DKTATLAS, 5)