Skip to content

Commit 75849ad

Browse files
committed
os.path to pathlib
1 parent 247ad2a commit 75849ad

File tree

13 files changed

+43
-47
lines changed

13 files changed

+43
-47
lines changed

examples/convert_eeg_to_bids.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114

115115
# Get the electrode coordinates
116116
testing_data = mne.datasets.testing.data_path()
117-
captrak_path = op.join(testing_data, "montage", "captrak_coords.bvct")
117+
captrak_path = testing_data / "montage" / "captrak_coords.bvct"
118118
montage = mne.channels.read_dig_captrak(captrak_path)
119119

120120
# Rename the montage channel names only for this example, because as said
@@ -165,7 +165,7 @@
165165
# .. warning:: Do not delete directories that may contain important data!
166166
#
167167

168-
if op.exists(bids_root):
168+
if bids_root.exists():
169169
shutil.rmtree(bids_root)
170170

171171
# %%

examples/convert_empty_room.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
# And define the paths and event_id dictionary.
4242

4343
data_path = sample.data_path()
44-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_raw.fif")
44+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_raw.fif"
4545

46-
bids_root = op.join(data_path, "..", "MNE-sample-data-bids")
46+
bids_root = data_path / ".." / "MNE-sample-data-bids"
4747

4848
# %%
4949
# To ensure the output path doesn't contain any leftover files from previous
@@ -52,7 +52,7 @@
5252
# .. warning:: Do not delete directories that may contain important data!
5353
#
5454

55-
if op.exists(bids_root):
55+
if bids_root.exists():
5656
shutil.rmtree(bids_root)
5757

5858
# %%
@@ -68,7 +68,7 @@
6868

6969
# %%
7070
# Specify some empty room data and run BIDS conversion on it.
71-
er_raw_fname = op.join(data_path, "MEG", "sample", "ernoise_raw.fif")
71+
er_raw_fname = data_path / "MEG" / "sample" / "ernoise_raw.fif"
7272
er_raw = mne.io.read_raw_fif(er_raw_fname)
7373
er_raw.info["line_freq"] = 60 # specify power line frequency as req. by BIDS
7474

examples/convert_group_studies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
# .. warning:: Do not delete directories that may contain important data!
7070
#
7171

72-
if op.exists(bids_root):
72+
if bids_root.exists():
7373
shutil.rmtree(bids_root)
7474

7575
# %%

examples/convert_ieeg_to_bids.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
# .. warning:: Do not delete directories that may contain important data!
166166
#
167167

168-
if op.exists(bids_root):
168+
if bids_root.exists():
169169
shutil.rmtree(bids_root)
170170

171171
# %%
@@ -330,7 +330,7 @@
330330

331331
# ensure the output path doesn't contain any leftover files from previous
332332
# tests and example runs
333-
if op.exists(bids_root):
333+
if bids_root.exists():
334334
shutil.rmtree(bids_root)
335335

336336
# load our raw data again
@@ -459,7 +459,7 @@
459459

460460
# ensure the output path doesn't contain any leftover files from previous
461461
# tests and example runs
462-
if op.exists(bids_root):
462+
if bids_root.exists():
463463
shutil.rmtree(bids_root)
464464

465465
# get a template mgz image to transform the montage to voxel coordinates

examples/convert_nirs_to_bids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
# .. warning:: Do not delete directories that may contain important data!
117117
#
118118

119-
if op.exists(bids_root):
119+
if bids_root.exists():
120120
shutil.rmtree(bids_root)
121121

122122
# %%

examples/mark_bad_channels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
# .. warning:: Do not delete directories that may contain important data!
6262
#
6363

64-
if op.exists(bids_root):
64+
if bids_root.exists():
6565
shutil.rmtree(bids_root)
6666

6767
# %%

mne_bids/commands/tests/test_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
)
2424

2525
data_path = testing.data_path(download=False)
26-
base_path = op.join(op.dirname(mne.__file__), "io")
26+
base_path = Path(mne.__file__).parent / "io"
2727
subject_id = "01"
2828
task = "testing"
2929
datatype = "meg"

mne_bids/tests/test_copyfiles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from mne_bids.path import _parse_ext
2525

2626
testing_path = testing.data_path(download=False)
27-
base_path = op.join(op.dirname(mne.__file__), "io")
27+
base_path = Path(mne.__file__).parent / "io"
2828

2929

3030
@testing.requires_testing_data

mne_bids/tests/test_dig.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010
import os.path as op
1111
import warnings
12+
from pathlib import Path
1213

1314
import mne
1415
import numpy as np
@@ -31,7 +32,7 @@
3132
template_to_head,
3233
)
3334

34-
base_path = op.join(op.dirname(mne.__file__), "io")
35+
base_path = Path(mne.__file__).parent / "io"
3536
subject_id = "01"
3637
session_id = "01"
3738
run = "01"

mne_bids/tests/test_pick.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
# Authors: The MNE-BIDS developers
44
# SPDX-License-Identifier: BSD-3-Clause
55

6-
import os.path as op
7-
86
from mne.datasets import testing
97
from mne.io import read_raw_fif
108

@@ -16,7 +14,7 @@
1614
@testing.requires_testing_data
1715
def test_coil_type():
1816
"""Test the correct coil type is retrieved."""
19-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
17+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
2018
raw = read_raw_fif(raw_fname)
2119
assert coil_type(raw.info, 0) == "meggradplanar"
2220
assert coil_type(raw.info, 2) == "megmag"

0 commit comments

Comments
 (0)