diff --git a/examples/convert_eeg_to_bids.py b/examples/convert_eeg_to_bids.py index dbf0acdd7..2df8915fd 100644 --- a/examples/convert_eeg_to_bids.py +++ b/examples/convert_eeg_to_bids.py @@ -114,7 +114,7 @@ # Get the electrode coordinates testing_data = mne.datasets.testing.data_path() -captrak_path = op.join(testing_data, "montage", "captrak_coords.bvct") +captrak_path = testing_data / "montage" / "captrak_coords.bvct" montage = mne.channels.read_dig_captrak(captrak_path) # Rename the montage channel names only for this example, because as said @@ -165,7 +165,7 @@ # .. warning:: Do not delete directories that may contain important data! # -if op.exists(bids_root): +if bids_root.exists(): shutil.rmtree(bids_root) # %% diff --git a/examples/convert_empty_room.py b/examples/convert_empty_room.py index 477689e04..748c9bac0 100644 --- a/examples/convert_empty_room.py +++ b/examples/convert_empty_room.py @@ -28,7 +28,6 @@ # # Let us first import mne_bids. -import os.path as op import shutil from datetime import datetime, timezone @@ -41,9 +40,9 @@ # And define the paths and event_id dictionary. data_path = sample.data_path() -raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_raw.fif") +raw_fname = data_path / "MEG" / "sample" / "sample_audvis_raw.fif" -bids_root = op.join(data_path, "..", "MNE-sample-data-bids") +bids_root = data_path / ".." / "MNE-sample-data-bids" # %% # To ensure the output path doesn't contain any leftover files from previous @@ -52,7 +51,7 @@ # .. warning:: Do not delete directories that may contain important data! # -if op.exists(bids_root): +if bids_root.exists(): shutil.rmtree(bids_root) # %% @@ -68,7 +67,7 @@ # %% # Specify some empty room data and run BIDS conversion on it. -er_raw_fname = op.join(data_path, "MEG", "sample", "ernoise_raw.fif") +er_raw_fname = data_path / "MEG" / "sample" / "ernoise_raw.fif" er_raw = mne.io.read_raw_fif(er_raw_fname) er_raw.info["line_freq"] = 60 # specify power line frequency as req. by BIDS diff --git a/examples/convert_group_studies.py b/examples/convert_group_studies.py index 24dc4cee8..d09bc9f61 100644 --- a/examples/convert_group_studies.py +++ b/examples/convert_group_studies.py @@ -69,7 +69,7 @@ # .. warning:: Do not delete directories that may contain important data! # -if op.exists(bids_root): +if bids_root.exists(): shutil.rmtree(bids_root) # %% diff --git a/examples/convert_ieeg_to_bids.py b/examples/convert_ieeg_to_bids.py index f6aed26f8..2656cfada 100644 --- a/examples/convert_ieeg_to_bids.py +++ b/examples/convert_ieeg_to_bids.py @@ -165,7 +165,7 @@ # .. warning:: Do not delete directories that may contain important data! # -if op.exists(bids_root): +if bids_root.exists(): shutil.rmtree(bids_root) # %% @@ -330,7 +330,7 @@ # ensure the output path doesn't contain any leftover files from previous # tests and example runs -if op.exists(bids_root): +if bids_root.exists(): shutil.rmtree(bids_root) # load our raw data again @@ -459,7 +459,7 @@ # ensure the output path doesn't contain any leftover files from previous # tests and example runs -if op.exists(bids_root): +if bids_root.exists(): shutil.rmtree(bids_root) # get a template mgz image to transform the montage to voxel coordinates diff --git a/examples/convert_nirs_to_bids.py b/examples/convert_nirs_to_bids.py index 5452b6ada..5c2b7474e 100644 --- a/examples/convert_nirs_to_bids.py +++ b/examples/convert_nirs_to_bids.py @@ -116,7 +116,7 @@ # .. warning:: Do not delete directories that may contain important data! # -if op.exists(bids_root): +if bids_root.exists(): shutil.rmtree(bids_root) # %% diff --git a/examples/mark_bad_channels.py b/examples/mark_bad_channels.py index 39ffee7fe..5ad2731b3 100644 --- a/examples/mark_bad_channels.py +++ b/examples/mark_bad_channels.py @@ -61,7 +61,7 @@ # .. warning:: Do not delete directories that may contain important data! # -if op.exists(bids_root): +if bids_root.exists(): shutil.rmtree(bids_root) # %% diff --git a/mne_bids/commands/tests/test_cli.py b/mne_bids/commands/tests/test_cli.py index 346a8b5f5..43dcb8163 100644 --- a/mne_bids/commands/tests/test_cli.py +++ b/mne_bids/commands/tests/test_cli.py @@ -23,7 +23,7 @@ ) data_path = testing.data_path(download=False) -base_path = op.join(op.dirname(mne.__file__), "io") +base_path = Path(mne.__file__).parent / "io" subject_id = "01" task = "testing" datatype = "meg" diff --git a/mne_bids/tests/test_copyfiles.py b/mne_bids/tests/test_copyfiles.py index 763d2f20e..a0ea25356 100644 --- a/mne_bids/tests/test_copyfiles.py +++ b/mne_bids/tests/test_copyfiles.py @@ -24,7 +24,7 @@ from mne_bids.path import _parse_ext testing_path = testing.data_path(download=False) -base_path = op.join(op.dirname(mne.__file__), "io") +base_path = Path(mne.__file__).parent / "io" @testing.requires_testing_data diff --git a/mne_bids/tests/test_dig.py b/mne_bids/tests/test_dig.py index adea8e29e..30c12e4a9 100644 --- a/mne_bids/tests/test_dig.py +++ b/mne_bids/tests/test_dig.py @@ -9,6 +9,7 @@ import os import os.path as op import warnings +from pathlib import Path import mne import numpy as np @@ -31,7 +32,7 @@ template_to_head, ) -base_path = op.join(op.dirname(mne.__file__), "io") +base_path = Path(mne.__file__).parent / "io" subject_id = "01" session_id = "01" run = "01" diff --git a/mne_bids/tests/test_pick.py b/mne_bids/tests/test_pick.py index 20dbf21f5..4dcc8e158 100644 --- a/mne_bids/tests/test_pick.py +++ b/mne_bids/tests/test_pick.py @@ -3,8 +3,6 @@ # Authors: The MNE-BIDS developers # SPDX-License-Identifier: BSD-3-Clause -import os.path as op - from mne.datasets import testing from mne.io import read_raw_fif @@ -16,7 +14,7 @@ @testing.requires_testing_data def test_coil_type(): """Test the correct coil type is retrieved.""" - raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif") + raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" raw = read_raw_fif(raw_fname) assert coil_type(raw.info, 0) == "meggradplanar" assert coil_type(raw.info, 2) == "megmag" diff --git a/mne_bids/tests/test_report.py b/mne_bids/tests/test_report.py index 94434bda8..558a9cc34 100644 --- a/mne_bids/tests/test_report.py +++ b/mne_bids/tests/test_report.py @@ -3,7 +3,6 @@ # Authors: The MNE-BIDS developers # SPDX-License-Identifier: BSD-3-Clause -import os.path as op import textwrap import mne @@ -26,7 +25,7 @@ # Get the MNE testing sample data data_path = testing.data_path(download=False) -raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif") +raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" warning_str = dict( channel_unit_changed="ignore:The unit for chann*.:RuntimeWarning:mne", diff --git a/mne_bids/tests/test_utils.py b/mne_bids/tests/test_utils.py index d23b53684..7351a6072 100644 --- a/mne_bids/tests/test_utils.py +++ b/mne_bids/tests/test_utils.py @@ -22,7 +22,7 @@ _infer_eeg_placement_scheme, ) -base_path = op.join(op.dirname(mne.__file__), "io") +base_path = Path(mne.__file__).parent / "io" subject_id = "01" session_id = "01" run = "01" diff --git a/mne_bids/tests/test_write.py b/mne_bids/tests/test_write.py index e1f369744..50378b9a6 100644 --- a/mne_bids/tests/test_write.py +++ b/mne_bids/tests/test_write.py @@ -62,7 +62,7 @@ ) from mne_bids.write import _get_fid_coords -base_path = op.join(op.dirname(mne.__file__), "io") +base_path = Path(mne.__file__).parent / "io" subject_id = "01" subject_id2 = "02" session_id = "01" @@ -475,8 +475,8 @@ def test_create_fif(_bids_validate, tmp_path): rng = np.random.RandomState(99) raw = mne.io.RawArray(rng.random((5, n_points)) * 1e-6, info) raw.info["line_freq"] = 60 - raw.save(op.join(out_dir, "test-raw.fif")) - raw = _read_raw_fif(op.join(out_dir, "test-raw.fif")) + raw.save(out_dir / "test-raw.fif") + raw = _read_raw_fif(out_dir / "test-raw.fif") write_raw_bids(raw, bids_path, verbose=False, overwrite=True) _bids_validate(bids_root) @@ -493,8 +493,8 @@ def test_line_freq(line_freq, _bids_validate, tmp_path): rng = np.random.RandomState(99) raw = mne.io.RawArray(rng.random((5, n_points)) * 1e-6, info) - raw.save(op.join(out_dir, "test-raw.fif")) - raw = _read_raw_fif(op.join(out_dir, "test-raw.fif")) + raw.save(out_dir / "test-raw.fif") + raw = _read_raw_fif(out_dir / "test-raw.fif") raw.info["line_freq"] = line_freq write_raw_bids(raw, bids_path, verbose=False, overwrite=True) _bids_validate(bids_root) @@ -846,15 +846,13 @@ def test_fif(_bids_validate, tmp_path): def test_chpi(_bids_validate, tmp_path, fmt): """Test writing of cHPI information.""" if fmt == "fif_no_chpi": - fif_raw_fname = op.join( - data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif" - ) + fif_raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" raw = _read_raw_fif(fif_raw_fname) elif fmt == "fif": - fif_raw_fname = op.join(data_path, "SSS", "test_move_anon_raw.fif") + fif_raw_fname = data_path / "SSS" / "test_move_anon_raw.fif" raw = _read_raw_fif(fif_raw_fname, allow_maxshield="yes") elif fmt == "ctf": - ctf_raw_fname = op.join(data_path, "CTF", "testdata_ctf.ds") + ctf_raw_fname = data_path / "CTF" / "testdata_ctf.ds" raw = _read_raw_ctf(ctf_raw_fname) elif fmt == "kit": kit_data_path = op.join(base_path, "kit", "tests", "data") @@ -1039,14 +1037,14 @@ def test_fif_exci(tmp_path): def test_kit(_bids_validate, tmp_path): """Test functionality of the write_raw_bids conversion for KIT data.""" bids_root = tmp_path / "bids" - kit_path = op.join(base_path, "kit", "tests", "data") - raw_fname = op.join(kit_path, "test.sqd") - events_fname = op.join(kit_path, "test-eve.txt") - hpi_fname = op.join(kit_path, "test_mrk.sqd") - hpi_pre_fname = op.join(kit_path, "test_mrk_pre.sqd") - hpi_post_fname = op.join(kit_path, "test_mrk_post.sqd") - electrode_fname = op.join(kit_path, "test.elp") - headshape_fname = op.join(kit_path, "test.hsp") + kit_path = base_path / "kit" / "tests" / "data" + raw_fname = kit_path / "test.sqd" + events_fname = kit_path / "test-eve.txt" + hpi_fname = kit_path / "test_mrk.sqd" + hpi_pre_fname = kit_path / "test_mrk_pre.sqd" + hpi_post_fname = kit_path / "test_mrk_post.sqd" + electrode_fname = kit_path / "test.elp" + headshape_fname = kit_path / "test.hsp" event_id = dict(cond=128) kit_bids_path = _bids_path.copy().update( @@ -1061,7 +1059,7 @@ def test_kit(_bids_validate, tmp_path): ) _bids_validate(bids_root) - assert op.exists(bids_root / "participants.tsv") + assert (bids_root / "participants.tsv").exists() read_raw_bids(bids_path=kit_bids_path) # ensure the marker file is produced in the right place @@ -1075,7 +1073,7 @@ def test_kit(_bids_validate, tmp_path): datatype="meg", root=bids_root, ) - assert op.exists(marker_fname) + assert marker_fname.exists() # test anonymize output_path = _test_anonymize( @@ -1091,7 +1089,7 @@ def test_kit(_bids_validate, tmp_path): assert "STI 014" not in data["name"] # ensure the marker file is produced in the right place - assert op.exists(marker_fname) + assert marker_fname.exists() # test attempts at writing invalid event data event_data = np.loadtxt(events_fname) @@ -1147,11 +1145,11 @@ def test_kit(_bids_validate, tmp_path): ) # check that everything works with MRK markers, and CON files - kit_path = op.join(data_path, "KIT") - raw_fname = op.join(kit_path, "data_berlin.con") - hpi_fname = op.join(kit_path, "MQKIT_125.mrk") - electrode_fname = op.join(kit_path, "MQKIT_125.elp") - headshape_fname = op.join(kit_path, "MQKIT_125.hsp") + kit_path = data_path / "KIT" + raw_fname = kit_path / "data_berlin.con" + hpi_fname = kit_path / "MQKIT_125.mrk" + electrode_fname = kit_path / "MQKIT_125.elp" + headshape_fname = kit_path / "MQKIT_125.hsp" bids_root = tmp_path / "bids_kit_mrk" kit_bids_path = _bids_path.copy().update( acquisition=None, root=bids_root, suffix="meg"