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

Function test_scale_morph_labels

mne/tests/test_source_estimate.py:1829–2001  ·  view source on GitHub ↗

Test label extraction, morphing, and MRI scaling relationships.

(kind, scale, monkeypatch, tmp_path)

Source from the content-addressed store, hash-verified

1827)
1828@pytest.mark.parametrize("scale", ((1.0, 0.8, 1.2), 1.0, 0.9))
1829def test_scale_morph_labels(kind, scale, monkeypatch, tmp_path):
1830 """Test label extraction, morphing, and MRI scaling relationships."""
1831 pytest.importorskip("nibabel")
1832 if kind == "volume":
1833 pytest.importorskip("dipy")
1834 subject_from = "sample"
1835 subject_to = "small"
1836 testing_dir = subjects_dir / subject_from
1837 from_dir = tmp_path / subject_from
1838 for root in ("mri", "surf", "label", "bem"):
1839 os.makedirs(from_dir / root, exist_ok=True)
1840 for hemi in ("lh", "rh"):
1841 for root, fname in (
1842 ("surf", "sphere"),
1843 ("surf", "white"),
1844 ("surf", "sphere.reg"),
1845 ("label", "aparc.annot"),
1846 ):
1847 use_fname = Path(root) / f"{hemi}.{fname}"
1848 copyfile(testing_dir / use_fname, from_dir / use_fname)
1849
1850 for root, fname in (("mri", "aseg.mgz"), ("mri", "brain.mgz")):
1851 use_fname = Path(root) / fname
1852 copyfile(testing_dir / use_fname, from_dir / use_fname)
1853 del testing_dir
1854 if kind == "surface":
1855 src_from = read_source_spaces(fname_src_3)
1856 assert src_from[0]["dist"] is None
1857 assert src_from[0]["nearest"] is not None
1858 # avoid patch calc
1859 src_from[0]["nearest"] = src_from[1]["nearest"] = None
1860 assert len(src_from) == 2
1861 assert src_from[0]["nuse"] == src_from[1]["nuse"] == 258
1862 klass = SourceEstimate
1863 labels_from = read_labels_from_annot(subject_from, subjects_dir=tmp_path)
1864 n_labels = len(labels_from)
1865 write_source_spaces(
1866 tmp_path / subject_from / "bem" / f"{subject_from}-oct-4-src.fif",
1867 src_from,
1868 )
1869 else:
1870 assert kind == "volume"
1871 pytest.importorskip("dipy")
1872 src_from = read_source_spaces(fname_src_vol)
1873 src_from[0]["subject_his_id"] = subject_from
1874 labels_from = tmp_path / subject_from / "mri" / "aseg.mgz"
1875 n_labels = 46
1876 assert labels_from.is_file()
1877 klass = VolSourceEstimate
1878 assert len(src_from) == 1
1879 assert src_from[0]["nuse"] == 4157
1880 write_source_spaces(from_dir / "bem" / "sample-vol20-src.fif", src_from)
1881 scale_mri(
1882 subject_from,
1883 subject_to,
1884 scale,
1885 subjects_dir=tmp_path,
1886 annot=True,

Callers

nothing calls this directly

Calls 9

read_source_spacesFunction · 0.90
read_labels_from_annotFunction · 0.90
write_source_spacesFunction · 0.90
scale_mriFunction · 0.90
labels_to_stcFunction · 0.90
compute_source_morphFunction · 0.90
normMethod · 0.80
applyMethod · 0.45

Tested by

no test coverage detected