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

Function test_make_morph_maps

mne/tests/test_morph_map.py:23–61  ·  view source on GitHub ↗

Test reading and creating morph maps.

(tmp_path)

Source from the content-addressed store, hash-verified

21@pytest.mark.slowtest
22@testing.requires_testing_data
23def test_make_morph_maps(tmp_path):
24 """Test reading and creating morph maps."""
25 pytest.importorskip("nibabel")
26 # make a new fake subjects_dir
27 for subject in ("sample", "sample_ds", "fsaverage_ds"):
28 os.mkdir(tmp_path / subject)
29 os.mkdir(tmp_path / subject / "surf")
30 regs = ("reg", "left_right") if subject == "fsaverage_ds" else ("reg",)
31 for hemi in ["lh", "rh"]:
32 for reg in regs:
33 copyfile(
34 subjects_dir / subject / "surf" / f"{hemi}.sphere.{reg}",
35 tmp_path / subject / "surf" / f"{hemi}.sphere.{reg}",
36 )
37
38 for subject_from, subject_to, xhemi in (
39 ("fsaverage_ds", "sample_ds", False),
40 ("fsaverage_ds", "fsaverage_ds", True),
41 ):
42 # trigger the creation of morph-maps dir and create the map
43 with catch_logging() as log:
44 mmap = read_morph_map(
45 subject_from, subject_to, tmp_path, xhemi=xhemi, verbose=True
46 )
47 log = log.getvalue()
48 assert "does not exist" in log
49 assert "Creating" in log
50 mmap2 = read_morph_map(subject_from, subject_to, subjects_dir, xhemi=xhemi)
51 assert len(mmap) == len(mmap2)
52 for m1, m2 in zip(mmap, mmap2):
53 # deal with sparse matrix stuff
54 diff = (m1 - m2).data
55 assert_allclose(diff, np.zeros_like(diff), atol=1e-3, rtol=0)
56
57 # This will also trigger creation, but it's trivial
58 with _record_warnings():
59 mmap = read_morph_map("sample", "sample", subjects_dir=tmp_path)
60 for mm in mmap:
61 assert (mm - _eye_array(mm.shape[0])).sum() == 0

Callers

nothing calls this directly

Calls 6

catch_loggingClass · 0.90
read_morph_mapFunction · 0.90
_record_warningsFunction · 0.90
_eye_arrayFunction · 0.90
getvalueMethod · 0.80
sumMethod · 0.45

Tested by

no test coverage detected