From 512bf41dda37da5ce627ad725a43839ba14e9ad0 Mon Sep 17 00:00:00 2001 From: vferat Date: Thu, 12 Dec 2024 19:14:30 +0100 Subject: [PATCH 01/18] Fixes make_scalp_surfaces --- mne/bem.py | 11 ++++++----- mne/tests/test_bem.py | 24 +++++++++++++++++++++--- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/mne/bem.py b/mne/bem.py index d361272fd49..fea1efd6dfa 100644 --- a/mne/bem.py +++ b/mne/bem.py @@ -2394,19 +2394,20 @@ def make_scalp_surfaces( mri = mri if (subj_path / "mri" / mri).exists() else "T1" logger.info("1. Creating a dense scalp tessellation with mkheadsurf...") + threshold = _ensure_int(threshold, "threshold") - def check_seghead(surf_path=subj_path / "surf"): + def check_seghead(surf_path=subj_path / "surf", overwrite=overwrite): surf = None for k in ["lh.seghead", "lh.smseghead"]: this_surf = surf_path / k if this_surf.exists(): surf = this_surf + _check_file(surf, overwrite) break return surf - my_seghead = check_seghead() - threshold = _ensure_int(threshold, "threshold") - if my_seghead is None: + my_seghead = check_seghead(overwrite=overwrite) + if (my_seghead is None) or overwrite: this_env = deepcopy(os.environ) this_env["SUBJECTS_DIR"] = str(subjects_dir) this_env["SUBJECT"] = subject @@ -2432,7 +2433,7 @@ def check_seghead(surf_path=subj_path / "surf"): env=this_env, ) - surf = check_seghead() + surf = check_seghead(overwrite=False) if surf is None: raise RuntimeError("mkheadsurf did not produce the standard output file.") diff --git a/mne/tests/test_bem.py b/mne/tests/test_bem.py index 9aa8a85fd4d..8945c996788 100644 --- a/mne/tests/test_bem.py +++ b/mne/tests/test_bem.py @@ -43,7 +43,7 @@ from mne.io import read_info from mne.surface import _get_ico_surface, read_surface from mne.transforms import translation -from mne.utils import _record_warnings, catch_logging, check_version +from mne.utils import _record_warnings, catch_logging, check_version, requires_freesurfer fname_raw = Path(__file__).parents[1] / "io" / "tests" / "data" / "test_raw.fif" subjects_dir = testing.data_path(download=False) / "subjects" @@ -519,11 +519,26 @@ def test_io_head_bem(tmp_path): assert np.allclose(head["tris"], head_defect["tris"]) -@pytest.mark.slowtest # ~4 s locally +@pytest.mark.slowtest +@requires_freesurfer("mkheadsurf") +@testing.requires_testing_data def test_make_scalp_surfaces_topology(tmp_path, monkeypatch): - """Test topology checks for make_scalp_surfaces.""" + """Test make_scalp_surfaces and topology checks.""" pytest.importorskip("pyvista") pytest.importorskip("nibabel") + + # tests on 'sample' + subject = 'sample' + with pytest.raises(OSError, match="use --overwrite to overwrite it"): + make_scalp_surfaces( + subject, subjects_dir, force=False, verbose=True, overwrite=False + ) + + make_scalp_surfaces( + subject, subjects_dir, force=False, verbose=True, overwrite=True + ) + + # tests on custom surface subjects_dir = tmp_path subject = "test" surf_dir = subjects_dir / subject / "surf" @@ -551,6 +566,7 @@ def _decimate_surface(points, triangles, n_triangles): make_scalp_surfaces( subject, subjects_dir, force=False, verbose=True, overwrite=True ) + bem_dir = subjects_dir / subject / "bem" sparse_path = bem_dir / f"{subject}-head-sparse.fif" assert not sparse_path.is_file() @@ -570,6 +586,8 @@ def _decimate_surface(points, triangles, n_triangles): (surf,) = read_bem_surfaces(sparse_path, on_defects="ignore") assert len(surf["tris"]) == 319 + + @pytest.mark.parametrize("bem_type", ["bem", "sphere"]) @pytest.mark.parametrize("n_pos", [1, 10]) From 83a950e0bf3e96eb681932315a82da5a6d8af745 Mon Sep 17 00:00:00 2001 From: vferat Date: Thu, 12 Dec 2024 19:34:31 +0100 Subject: [PATCH 02/18] Update bem.py --- mne/bem.py | 84 ++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 44 deletions(-) diff --git a/mne/bem.py b/mne/bem.py index fea1efd6dfa..8a6c5861e5e 100644 --- a/mne/bem.py +++ b/mne/bem.py @@ -2396,54 +2396,50 @@ def make_scalp_surfaces( logger.info("1. Creating a dense scalp tessellation with mkheadsurf...") threshold = _ensure_int(threshold, "threshold") - def check_seghead(surf_path=subj_path / "surf", overwrite=overwrite): - surf = None - for k in ["lh.seghead", "lh.smseghead"]: - this_surf = surf_path / k - if this_surf.exists(): - surf = this_surf - _check_file(surf, overwrite) - break - return surf - - my_seghead = check_seghead(overwrite=overwrite) - if (my_seghead is None) or overwrite: - this_env = deepcopy(os.environ) - this_env["SUBJECTS_DIR"] = str(subjects_dir) - this_env["SUBJECT"] = subject - this_env["subjdir"] = str(subj_path) - if "FREESURFER_HOME" not in this_env: - raise RuntimeError( - "The FreeSurfer environment needs to be set up to use " - "make_scalp_surfaces to create the outer skin surface " - "lh.seghead" - ) - run_subprocess( - [ - "mkheadsurf", - "-subjid", - subject, - "-srcvol", - mri, - "-thresh1", - str(threshold), - "-thresh2", - str(threshold), - ], - env=this_env, - ) - - surf = check_seghead(overwrite=False) - if surf is None: - raise RuntimeError("mkheadsurf did not produce the standard output file.") + # Check for existing files + _check_file(subj_path / "mri" / "seghead.mgz", overwrite) + _check_file(subj_path / "surf" / "lh.seghead", overwrite) + _check_file(subj_path / "surf" / "lh.smseghead", overwrite) bem_dir = subjects_dir / subject / "bem" - if not bem_dir.is_dir(): - os.mkdir(bem_dir) fname_template = bem_dir / (f"{subject}-head-{{}}.fif") dense_fname = str(fname_template).format("dense") - logger.info(f"2. Creating {dense_fname} ...") _check_file(dense_fname, overwrite) + + if not no_decimate: + for level in _tri_levels.items(): + dec_fname = str(fname_template).format(level) + _check_file(dec_fname, overwrite) + + this_env = deepcopy(os.environ) + this_env["SUBJECTS_DIR"] = str(subjects_dir) + this_env["SUBJECT"] = subject + this_env["subjdir"] = str(subj_path) + if "FREESURFER_HOME" not in this_env: + raise RuntimeError( + "The FreeSurfer environment needs to be set up to use " + "make_scalp_surfaces to create the outer skin surface " + "lh.seghead" + ) + run_subprocess( + [ + "mkheadsurf", + "-subjid", + subject, + "-srcvol", + mri, + "-thresh1", + str(threshold), + "-thresh2", + str(threshold), + ], + env=this_env, + ) + + if not bem_dir.is_dir(): + os.mkdir(bem_dir) + logger.info(f"2. Creating {dense_fname} ...") + # Helpful message if we get a topology error msg = ( "\n\nConsider using pymeshfix directly to fix the mesh, or --force " @@ -2453,6 +2449,7 @@ def check_seghead(surf_path=subj_path / "surf", overwrite=overwrite): [surf], [FIFF.FIFFV_BEM_SURF_ID_HEAD], [1], incomplete=incomplete, extra=msg )[0] write_bem_surfaces(dense_fname, surf, overwrite=overwrite) + if os.getenv("_MNE_TESTING_SCALP", "false") == "true": tris = [len(surf["tris"])] # don't actually decimate for ii, (level, n_tri) in enumerate(_tri_levels.items(), 3): @@ -2468,7 +2465,6 @@ def check_seghead(surf_path=subj_path / "surf", overwrite=overwrite): ) dec_fname = str(fname_template).format(level) logger.info(f"{ii}.2 Creating {dec_fname}") - _check_file(dec_fname, overwrite) dec_surf = _surfaces_to_bem( [dict(rr=points, tris=tris)], [FIFF.FIFFV_BEM_SURF_ID_HEAD], From b040e59b1984db7517474dd5a09213a5ceb526c4 Mon Sep 17 00:00:00 2001 From: vferat Date: Thu, 12 Dec 2024 20:09:53 +0100 Subject: [PATCH 03/18] Update bem.py --- mne/bem.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/mne/bem.py b/mne/bem.py index 8a6c5861e5e..d037e93d3da 100644 --- a/mne/bem.py +++ b/mne/bem.py @@ -2393,7 +2393,6 @@ def make_scalp_surfaces( if mri == "T1.mgz": mri = mri if (subj_path / "mri" / mri).exists() else "T1" - logger.info("1. Creating a dense scalp tessellation with mkheadsurf...") threshold = _ensure_int(threshold, "threshold") # Check for existing files @@ -2406,10 +2405,23 @@ def make_scalp_surfaces( dense_fname = str(fname_template).format("dense") _check_file(dense_fname, overwrite) - if not no_decimate: - for level in _tri_levels.items(): - dec_fname = str(fname_template).format(level) - _check_file(dec_fname, overwrite) + for level in _tri_levels.items(): + dec_fname = str(fname_template).format(level) + if overwrite: + os.remove(dec_fname) + else: + if no_decimate: + if os.path.exists(dec_fname): + raise OSError(f"Trying to generate new scalp surfaces" + f"but {dec_fname} already exists." + f"To avoid mixing different scalp surface solutions," + f"delete this file or use overwrite to automaticaly delete it.") + else: + _check_file(dec_fname, overwrite) + + + + logger.info("1. Creating a dense scalp tessellation with mkheadsurf...") this_env = deepcopy(os.environ) this_env["SUBJECTS_DIR"] = str(subjects_dir) From b7aafab0794b129906218a361e578b00697d8bb6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 19:10:02 +0000 Subject: [PATCH 04/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mne/tests/test_bem.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mne/tests/test_bem.py b/mne/tests/test_bem.py index 8945c996788..4e8dea66af7 100644 --- a/mne/tests/test_bem.py +++ b/mne/tests/test_bem.py @@ -43,7 +43,12 @@ from mne.io import read_info from mne.surface import _get_ico_surface, read_surface from mne.transforms import translation -from mne.utils import _record_warnings, catch_logging, check_version, requires_freesurfer +from mne.utils import ( + _record_warnings, + catch_logging, + check_version, + requires_freesurfer, +) fname_raw = Path(__file__).parents[1] / "io" / "tests" / "data" / "test_raw.fif" subjects_dir = testing.data_path(download=False) / "subjects" @@ -528,12 +533,12 @@ def test_make_scalp_surfaces_topology(tmp_path, monkeypatch): pytest.importorskip("nibabel") # tests on 'sample' - subject = 'sample' + subject = "sample" with pytest.raises(OSError, match="use --overwrite to overwrite it"): make_scalp_surfaces( subject, subjects_dir, force=False, verbose=True, overwrite=False ) - + make_scalp_surfaces( subject, subjects_dir, force=False, verbose=True, overwrite=True ) @@ -586,8 +591,6 @@ def _decimate_surface(points, triangles, n_triangles): (surf,) = read_bem_surfaces(sparse_path, on_defects="ignore") assert len(surf["tris"]) == 319 - - @pytest.mark.parametrize("bem_type", ["bem", "sphere"]) @pytest.mark.parametrize("n_pos", [1, 10]) From de52cf3c909d49a8e0b47c6bf014042187befbf1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 19:10:29 +0000 Subject: [PATCH 05/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mne/bem.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mne/bem.py b/mne/bem.py index d037e93d3da..56fdb969660 100644 --- a/mne/bem.py +++ b/mne/bem.py @@ -2412,14 +2412,14 @@ def make_scalp_surfaces( else: if no_decimate: if os.path.exists(dec_fname): - raise OSError(f"Trying to generate new scalp surfaces" - f"but {dec_fname} already exists." - f"To avoid mixing different scalp surface solutions," - f"delete this file or use overwrite to automaticaly delete it.") + raise OSError( + f"Trying to generate new scalp surfaces" + f"but {dec_fname} already exists." + f"To avoid mixing different scalp surface solutions," + f"delete this file or use overwrite to automaticaly delete it." + ) else: _check_file(dec_fname, overwrite) - - logger.info("1. Creating a dense scalp tessellation with mkheadsurf...") From 393002bbb67f7a3b1230e13abc702bb07d3c7907 Mon Sep 17 00:00:00 2001 From: vferat Date: Thu, 12 Dec 2024 21:04:34 +0100 Subject: [PATCH 06/18] Update test_bem.py --- mne/tests/test_bem.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mne/tests/test_bem.py b/mne/tests/test_bem.py index 8945c996788..1ba6bfc33e1 100644 --- a/mne/tests/test_bem.py +++ b/mne/tests/test_bem.py @@ -529,6 +529,7 @@ def test_make_scalp_surfaces_topology(tmp_path, monkeypatch): # tests on 'sample' subject = 'sample' + subjects_dir = testing.data_path(download=False) with pytest.raises(OSError, match="use --overwrite to overwrite it"): make_scalp_surfaces( subject, subjects_dir, force=False, verbose=True, overwrite=False From d23f200737189a7c523be3988a812d24b6f8622d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 20:07:39 +0000 Subject: [PATCH 07/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mne/tests/test_bem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/tests/test_bem.py b/mne/tests/test_bem.py index e7e40c4aada..55a8ab07cb3 100644 --- a/mne/tests/test_bem.py +++ b/mne/tests/test_bem.py @@ -533,7 +533,7 @@ def test_make_scalp_surfaces_topology(tmp_path, monkeypatch): pytest.importorskip("nibabel") # tests on 'sample' - subject = 'sample' + subject = "sample" subjects_dir = testing.data_path(download=False) with pytest.raises(OSError, match="use --overwrite to overwrite it"): make_scalp_surfaces( From 7c63404f411a0bf243bca2f57cbc625092238b65 Mon Sep 17 00:00:00 2001 From: vferat Date: Thu, 12 Dec 2024 21:29:56 +0100 Subject: [PATCH 08/18] Update bem.py --- mne/bem.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/mne/bem.py b/mne/bem.py index 56fdb969660..2263e1e73f2 100644 --- a/mne/bem.py +++ b/mne/bem.py @@ -2397,8 +2397,12 @@ def make_scalp_surfaces( # Check for existing files _check_file(subj_path / "mri" / "seghead.mgz", overwrite) - _check_file(subj_path / "surf" / "lh.seghead", overwrite) - _check_file(subj_path / "surf" / "lh.smseghead", overwrite) + + seghead_path = subj_path / "surf" / "lh.seghead" + _check_file(seghead_path, overwrite) + + smseghead_path = subj_path / "surf" / "lh.smseghead" + _check_file(smseghead_path, overwrite) bem_dir = subjects_dir / subject / "bem" fname_template = bem_dir / (f"{subject}-head-{{}}.fif") @@ -2447,10 +2451,17 @@ def make_scalp_surfaces( ], env=this_env, ) + if os.path.exists(seghead_path): + surf = seghead_path + elif os.path.exists(smseghead_path): + surf = smseghead_path + else: + raise ValueError("mkheadsurf did not produce the standard output file.") + + logger.info(f"2. Creating {dense_fname} ...") if not bem_dir.is_dir(): os.mkdir(bem_dir) - logger.info(f"2. Creating {dense_fname} ...") # Helpful message if we get a topology error msg = ( From 5af22d57c9ad6fef35c742495caa6ad2c51e9df6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 20:30:18 +0000 Subject: [PATCH 09/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mne/bem.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mne/bem.py b/mne/bem.py index 2263e1e73f2..4f528c6bbc0 100644 --- a/mne/bem.py +++ b/mne/bem.py @@ -2401,7 +2401,7 @@ def make_scalp_surfaces( seghead_path = subj_path / "surf" / "lh.seghead" _check_file(seghead_path, overwrite) - smseghead_path = subj_path / "surf" / "lh.smseghead" + smseghead_path = subj_path / "surf" / "lh.smseghead" _check_file(smseghead_path, overwrite) bem_dir = subjects_dir / subject / "bem" @@ -2458,7 +2458,6 @@ def make_scalp_surfaces( else: raise ValueError("mkheadsurf did not produce the standard output file.") - logger.info(f"2. Creating {dense_fname} ...") if not bem_dir.is_dir(): os.mkdir(bem_dir) From c771baa3b2ff682ed4d977f92462250476e9b194 Mon Sep 17 00:00:00 2001 From: vferat Date: Thu, 12 Dec 2024 21:56:00 +0100 Subject: [PATCH 10/18] Update bem.py --- mne/bem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/bem.py b/mne/bem.py index 2263e1e73f2..e5844488a18 100644 --- a/mne/bem.py +++ b/mne/bem.py @@ -2420,7 +2420,7 @@ def make_scalp_surfaces( f"Trying to generate new scalp surfaces" f"but {dec_fname} already exists." f"To avoid mixing different scalp surface solutions," - f"delete this file or use overwrite to automaticaly delete it." + f"delete this file or use overwrite to automatically delete it." ) else: _check_file(dec_fname, overwrite) From 102342538901e90f25399118e4301c45056b8ef4 Mon Sep 17 00:00:00 2001 From: vferat Date: Sun, 15 Dec 2024 11:31:29 +0100 Subject: [PATCH 11/18] Update test_commands.py --- mne/commands/tests/test_commands.py | 82 ++++++++++++++++++----------- 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/mne/commands/tests/test_commands.py b/mne/commands/tests/test_commands.py index ae885d3c21d..82d0f7f3a11 100644 --- a/mne/commands/tests/test_commands.py +++ b/mne/commands/tests/test_commands.py @@ -167,55 +167,75 @@ def test_kit2fiff(): check_usage(mne_kit2fiff, force_help=True) -@pytest.mark.slowtest @pytest.mark.ultraslowtest @testing.requires_testing_data +@requires_freesurfer("mkheadsurf") def test_make_scalp_surfaces(tmp_path, monkeypatch): """Test mne make_scalp_surfaces.""" pytest.importorskip("nibabel") pytest.importorskip("pyvista") check_usage(mne_make_scalp_surfaces) - has = "SUBJECTS_DIR" in os.environ - # Copy necessary files to avoid FreeSurfer call + tempdir = str(tmp_path) - surf_path = op.join(subjects_dir, "sample", "surf") - surf_path_new = op.join(tempdir, "sample", "surf") - os.mkdir(op.join(tempdir, "sample")) - os.mkdir(surf_path_new) - subj_dir = op.join(tempdir, "sample", "bem") - os.mkdir(subj_dir) + t1_path = op.join(subjects_dir, "sample", "mri", "T1.mgz") + t1_path_new = op.join(tempdir, "sample", "mri", "T1.mgz") - cmd = ("-s", "sample", "--subjects-dir", tempdir) - monkeypatch.setattr( - mne.bem, - "decimate_surface", - lambda points, triangles, n_triangles: (points, triangles), - ) - dense_fname = op.join(subj_dir, "sample-head-dense.fif") - medium_fname = op.join(subj_dir, "sample-head-medium.fif") + headseg_path = op.join(tempdir, "sample", "mri", "seghead.mgz") + surf_path = op.join(tempdir, "sample", "surf", "lh.seghead") + dense_fname = op.join(tempdir, "sample", "bem", "sample-head-dense.fif") + medium_fname = op.join(tempdir, "sample", "bem", "sample-head-medium.fif") + sparse_fname = op.join(tempdir, "sample", "bem", "sample-head-sparse.fif") + + os.makedirs(op.join(tempdir, "sample", "mri"), exist_ok=True) + os.makedirs(op.join(tempdir, "sample", "surf"), exist_ok=True) + + shutil.copy(op.join(t1_path, t1_path_new)) + cmd = ("-s", "sample", "--subjects-dir", tempdir, "--no-decimate") with ArgvSetter(cmd, disable_stdout=False, disable_stderr=False): monkeypatch.delenv("FREESURFER_HOME", raising=False) with pytest.raises(RuntimeError, match="The FreeSurfer environ"): mne_make_scalp_surfaces.run() - shutil.copy(op.join(surf_path, "lh.seghead"), surf_path_new) - monkeypatch.setenv("FREESURFER_HOME", tempdir) + + shutil.copy(op.join(t1_path, t1_path_new)) mne_make_scalp_surfaces.run() + + assert op.isfile(headseg_path) + assert op.isfile(surf_path) assert op.isfile(dense_fname) - assert op.isfile(medium_fname) - with pytest.raises(OSError, match="overwrite"): + assert not op.isfile(medium_fname) + assert not op.isfile(sparse_fname) + + cmd = ("-s", "sample", "--subjects-dir", tempdir) + with ArgvSetter(cmd, disable_stdout=False, disable_stderr=False): + with pytest.raises(RuntimeError, match="use --overwrite to overwrite it"): mne_make_scalp_surfaces.run() - # actually check the outputs - head_py = read_bem_surfaces(dense_fname) - assert_equal(len(head_py), 1) - head_py = head_py[0] - head_c = read_bem_surfaces( - op.join(subjects_dir, "sample", "bem", "sample-head-dense.fif") - )[0] - assert_allclose(head_py["rr"], head_c["rr"]) - if not has: - assert "SUBJECTS_DIR" not in os.environ + cmd = ("-s", "sample", "--subjects-dir", tempdir, "--overwrite") + with ArgvSetter(cmd, disable_stdout=False, disable_stderr=False): + mne_make_scalp_surfaces.run() + assert op.isfile(headseg_path) + assert op.isfile(surf_path) + assert op.isfile(dense_fname) + assert op.isfile(medium_fname) + assert op.isfile(sparse_fname) + cmd = ("-s", "sample", "--subjects-dir", tempdir, "--no-decimate", "--overwrite") + with ArgvSetter(cmd, disable_stdout=False, disable_stderr=False): + mne_make_scalp_surfaces.run() + assert op.isfile(headseg_path) + assert op.isfile(surf_path) + assert op.isfile(dense_fname) + assert not op.isfile(medium_fname) + assert not op.isfile(sparse_fname) + + os.remove(headseg_path) + os.remove(surf_path) + os.remove(dense_fname) + cmd = ("-s", "sample", "--subjects-dir", tempdir, "--no-decimate") + with ArgvSetter(cmd, disable_stdout=False, disable_stderr=False): + with pytest.raises(RuntimeError, match="Trying to generate new scalp surfaces"): + mne_make_scalp_surfaces.run() + @pytest.mark.slowtest @testing.requires_testing_data def test_report(tmp_path): From e52fb5b4377cc1fda9c615095ee0b8d1bb241827 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 15 Dec 2024 10:31:54 +0000 Subject: [PATCH 12/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mne/commands/tests/test_commands.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mne/commands/tests/test_commands.py b/mne/commands/tests/test_commands.py index 82d0f7f3a11..d4bd1c2023d 100644 --- a/mne/commands/tests/test_commands.py +++ b/mne/commands/tests/test_commands.py @@ -12,7 +12,6 @@ import pytest from numpy.testing import assert_allclose, assert_equal -import mne from mne import ( concatenate_raws, read_bem_solution, @@ -186,8 +185,8 @@ def test_make_scalp_surfaces(tmp_path, monkeypatch): medium_fname = op.join(tempdir, "sample", "bem", "sample-head-medium.fif") sparse_fname = op.join(tempdir, "sample", "bem", "sample-head-sparse.fif") - os.makedirs(op.join(tempdir, "sample", "mri"), exist_ok=True) - os.makedirs(op.join(tempdir, "sample", "surf"), exist_ok=True) + os.makedirs(op.join(tempdir, "sample", "mri"), exist_ok=True) + os.makedirs(op.join(tempdir, "sample", "surf"), exist_ok=True) shutil.copy(op.join(t1_path, t1_path_new)) cmd = ("-s", "sample", "--subjects-dir", tempdir, "--no-decimate") @@ -227,7 +226,7 @@ def test_make_scalp_surfaces(tmp_path, monkeypatch): assert op.isfile(dense_fname) assert not op.isfile(medium_fname) assert not op.isfile(sparse_fname) - + os.remove(headseg_path) os.remove(surf_path) os.remove(dense_fname) @@ -235,7 +234,8 @@ def test_make_scalp_surfaces(tmp_path, monkeypatch): with ArgvSetter(cmd, disable_stdout=False, disable_stderr=False): with pytest.raises(RuntimeError, match="Trying to generate new scalp surfaces"): mne_make_scalp_surfaces.run() - + + @pytest.mark.slowtest @testing.requires_testing_data def test_report(tmp_path): From ec914588102eb21b33a931b23adbfd93731d8d9a Mon Sep 17 00:00:00 2001 From: vferat Date: Sun, 15 Dec 2024 20:31:56 +0100 Subject: [PATCH 13/18] Update test_commands.py --- mne/commands/tests/test_commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/commands/tests/test_commands.py b/mne/commands/tests/test_commands.py index 82d0f7f3a11..8f83f98179b 100644 --- a/mne/commands/tests/test_commands.py +++ b/mne/commands/tests/test_commands.py @@ -189,7 +189,7 @@ def test_make_scalp_surfaces(tmp_path, monkeypatch): os.makedirs(op.join(tempdir, "sample", "mri"), exist_ok=True) os.makedirs(op.join(tempdir, "sample", "surf"), exist_ok=True) - shutil.copy(op.join(t1_path, t1_path_new)) + shutil.copy(t1_path, t1_path_new) cmd = ("-s", "sample", "--subjects-dir", tempdir, "--no-decimate") with ArgvSetter(cmd, disable_stdout=False, disable_stderr=False): monkeypatch.delenv("FREESURFER_HOME", raising=False) From bb94453766a461531a64dd016c4c0b454cc7fd5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20F=C3=A9rat?= Date: Mon, 16 Dec 2024 11:10:44 +0100 Subject: [PATCH 14/18] Update test_commands.py --- mne/commands/tests/test_commands.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mne/commands/tests/test_commands.py b/mne/commands/tests/test_commands.py index 53d5647bcb6..244dc60e422 100644 --- a/mne/commands/tests/test_commands.py +++ b/mne/commands/tests/test_commands.py @@ -194,10 +194,8 @@ def test_make_scalp_surfaces(tmp_path, monkeypatch): monkeypatch.delenv("FREESURFER_HOME", raising=False) with pytest.raises(RuntimeError, match="The FreeSurfer environ"): mne_make_scalp_surfaces.run() - - shutil.copy(op.join(t1_path, t1_path_new)) + mne_make_scalp_surfaces.run() - assert op.isfile(headseg_path) assert op.isfile(surf_path) assert op.isfile(dense_fname) From f85c601eada46894c1b4bfbf5352f7048b867327 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 10:11:07 +0000 Subject: [PATCH 15/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mne/commands/tests/test_commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/commands/tests/test_commands.py b/mne/commands/tests/test_commands.py index 244dc60e422..c27f8ee6346 100644 --- a/mne/commands/tests/test_commands.py +++ b/mne/commands/tests/test_commands.py @@ -194,7 +194,7 @@ def test_make_scalp_surfaces(tmp_path, monkeypatch): monkeypatch.delenv("FREESURFER_HOME", raising=False) with pytest.raises(RuntimeError, match="The FreeSurfer environ"): mne_make_scalp_surfaces.run() - + mne_make_scalp_surfaces.run() assert op.isfile(headseg_path) assert op.isfile(surf_path) From f25a8c38fb4de180fb2d1086be57ed6288967ab1 Mon Sep 17 00:00:00 2001 From: vferat Date: Mon, 16 Dec 2024 18:22:13 +0100 Subject: [PATCH 16/18] Update test_commands.py --- mne/commands/tests/test_commands.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mne/commands/tests/test_commands.py b/mne/commands/tests/test_commands.py index c27f8ee6346..7731dc0d2bc 100644 --- a/mne/commands/tests/test_commands.py +++ b/mne/commands/tests/test_commands.py @@ -194,8 +194,11 @@ def test_make_scalp_surfaces(tmp_path, monkeypatch): monkeypatch.delenv("FREESURFER_HOME", raising=False) with pytest.raises(RuntimeError, match="The FreeSurfer environ"): mne_make_scalp_surfaces.run() - + + monkeypatch.setenv("FREESURFER_HOME", tempdir) + shutil.copy(op.join(t1_path, t1_path_new)) mne_make_scalp_surfaces.run() + assert op.isfile(headseg_path) assert op.isfile(surf_path) assert op.isfile(dense_fname) From ce3aa97e5095b42106dd89f9e319dc654316033e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 17:22:36 +0000 Subject: [PATCH 17/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mne/commands/tests/test_commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/commands/tests/test_commands.py b/mne/commands/tests/test_commands.py index 7731dc0d2bc..26120d422b6 100644 --- a/mne/commands/tests/test_commands.py +++ b/mne/commands/tests/test_commands.py @@ -194,7 +194,7 @@ def test_make_scalp_surfaces(tmp_path, monkeypatch): monkeypatch.delenv("FREESURFER_HOME", raising=False) with pytest.raises(RuntimeError, match="The FreeSurfer environ"): mne_make_scalp_surfaces.run() - + monkeypatch.setenv("FREESURFER_HOME", tempdir) shutil.copy(op.join(t1_path, t1_path_new)) mne_make_scalp_surfaces.run() From e3584183d70ea6c6aae37ae9cc464c8c1031d4e9 Mon Sep 17 00:00:00 2001 From: vferat Date: Mon, 16 Dec 2024 22:37:59 +0100 Subject: [PATCH 18/18] Update test_commands.py --- mne/commands/tests/test_commands.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mne/commands/tests/test_commands.py b/mne/commands/tests/test_commands.py index 7731dc0d2bc..091b800d0eb 100644 --- a/mne/commands/tests/test_commands.py +++ b/mne/commands/tests/test_commands.py @@ -196,7 +196,6 @@ def test_make_scalp_surfaces(tmp_path, monkeypatch): mne_make_scalp_surfaces.run() monkeypatch.setenv("FREESURFER_HOME", tempdir) - shutil.copy(op.join(t1_path, t1_path_new)) mne_make_scalp_surfaces.run() assert op.isfile(headseg_path)