MCPcopy
hub / github.com/mne-tools/mne-python / test_read_labels_from_annot

Function test_read_labels_from_annot

mne/tests/test_label.py:469–543  ·  view source on GitHub ↗

Test reading labels from FreeSurfer parcellation.

(tmp_path)

Source from the content-addressed store, hash-verified

467
468@testing.requires_testing_data
469def test_read_labels_from_annot(tmp_path):
470 """Test reading labels from FreeSurfer parcellation."""
471 pytest.importorskip("nibabel")
472 # test some invalid inputs
473 pytest.raises(
474 ValueError,
475 read_labels_from_annot,
476 "sample",
477 hemi="bla",
478 subjects_dir=subjects_dir,
479 )
480 pytest.raises(
481 ValueError,
482 read_labels_from_annot,
483 "sample",
484 annot_fname="bla.annot",
485 subjects_dir=subjects_dir,
486 )
487 with pytest.raises(OSError, match="does not exist"):
488 _read_annot_cands("foo")
489 with pytest.raises(OSError, match="no candidate"):
490 _read_annot(str(tmp_path))
491
492 # read labels using hemi specification
493 labels_lh = read_labels_from_annot("sample", hemi="lh", subjects_dir=subjects_dir)
494 for label in labels_lh:
495 assert label.name.endswith("-lh")
496 assert label.hemi == "lh"
497 assert label.color is not None
498
499 # read labels using annot_fname
500 annot_fname = subjects_dir / "sample" / "label" / "rh.aparc.annot"
501 labels_rh = read_labels_from_annot(
502 "sample", annot_fname=annot_fname, subjects_dir=subjects_dir
503 )
504 for label in labels_rh:
505 assert label.name.endswith("-rh")
506 assert label.hemi == "rh"
507 assert label.color is not None
508
509 # combine the lh, rh, labels and sort them
510 labels_lhrh = list()
511 labels_lhrh.extend(labels_lh)
512 labels_lhrh.extend(labels_rh)
513
514 names = [label.name for label in labels_lhrh]
515 labels_lhrh = [label for (name, label) in sorted(zip(names, labels_lhrh))]
516
517 # read all labels at once
518 labels_both = read_labels_from_annot("sample", subjects_dir=subjects_dir)
519
520 # we have the same result
521 _assert_labels_equal(labels_lhrh, labels_both)
522
523 # aparc has 68 cortical labels
524 assert len(labels_both) == 68
525
526 # test regexp

Callers

nothing calls this directly

Calls 5

_read_annot_candsFunction · 0.90
_read_annotFunction · 0.90
read_labels_from_annotFunction · 0.90
_assert_labels_equalFunction · 0.85
extendMethod · 0.45

Tested by

no test coverage detected