Test reading and creating morph maps.
(tmp_path)
| 21 | @pytest.mark.slowtest |
| 22 | @testing.requires_testing_data |
| 23 | def 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 |
nothing calls this directly
no test coverage detected