Skip to content

Commit 6c43b2d

Browse files
ashdrewagramfortdrammockwmvanvlietjadrew43
authored
[DOC, WIP] Testpathchanging (#10846)
* path changes * deleting unwanted file * Update mixed_source_space_inverse.py white space fixing * Update mixed_source_space_inverse.py changing %'s to f'{subject} * Update mixed_source_space_inverse.py * Update mixed_source_space_inverse.py * Update examples/inverse/mixed_source_space_inverse.py Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org> * Update examples/inverse/mixed_source_space_inverse.py Co-authored-by: Daniel McCloy <dan@mccloy.info> * path handling (#10868) * path handling (#10870) * update path handling (#10875) * hourglass change (#10873) * fix RSA example (#10879) * Relax the type checking for the cnorm paramter of plot_topomap (#10880) * Relax the type chekcing for the cnorm paramter of plot_topomap * Remove unnecessary import * CenterNorm does not exist in old matplotlib versions * epochs folder path handling (#10876) * name and enhancement added to change log for epoch_plot_xaxis (#10861) * name and enhancement added to change log for epoch_plot_xaxis * Update doc/changes/latest.inc [ci skip] Co-authored-by: Daniel McCloy <dan@mccloy.info> * fix typo in doc/overview/implementation [skip azp][skip actions] (#10884) * MRG: Change orig_format for EGI, BrainVision ASCII and artemis123 recordings to "single" (#10851) * check orig_format against a list of valid values * set original type to "single" * add test * replace egi "float" type by "single" * fix orig_format for brainvision files in ASCII fmt * add changelog entry * fix artemis123 reader * use double quotes for all edited lines [ci skip] * fix info type checking (allow path-like) (#10887) * fix info type checking (allow path-like) * add test * update docstrings * faster test * touch example * fix for new sklearn (#10889) * fix objectsize for Path objects * ensure mri_path is not a Path obj Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org> Co-authored-by: Daniel McCloy <dan@mccloy.info> Co-authored-by: Marijn van Vliet <w.m.vanvliet@gmail.com> Co-authored-by: jadrew43 <39603454+jadrew43@users.noreply.github.com> Co-authored-by: Dominik Welke <dominik.welke@web.de> Co-authored-by: Mathieu Scheltienne <mathieu.scheltienne@gmail.com>
1 parent 5b582a1 commit 6c43b2d

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

examples/inverse/mixed_source_space_inverse.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
# %%
1717

18-
import os.path as op
1918
import matplotlib.pyplot as plt
2019

2120
from nilearn import plotting
@@ -26,21 +25,21 @@
2625
# Set dir
2726
data_path = mne.datasets.sample.data_path()
2827
subject = 'sample'
29-
data_dir = op.join(data_path, 'MEG', subject)
30-
subjects_dir = op.join(data_path, 'subjects')
31-
bem_dir = op.join(subjects_dir, subject, 'bem')
28+
data_dir = data_path / 'MEG' / subject
29+
subjects_dir = data_path / 'subjects'
30+
bem_dir = subjects_dir / subject / 'bem'
3231

3332
# Set file names
34-
fname_mixed_src = op.join(bem_dir, '%s-oct-6-mixed-src.fif' % subject)
35-
fname_aseg = op.join(subjects_dir, subject, 'mri', 'aseg.mgz')
33+
fname_mixed_src = bem_dir / f'{subject}-oct-6-mixed-src.fif'
34+
fname_aseg = subjects_dir / subject / 'mri' / 'aseg.mgz'
3635

37-
fname_model = op.join(bem_dir, '%s-5120-bem.fif' % subject)
38-
fname_bem = op.join(bem_dir, '%s-5120-bem-sol.fif' % subject)
36+
fname_model = bem_dir / f'{subject}-5120-bem.fif'
37+
fname_bem = bem_dir / f'{subject}-5120-bem-sol.fif'
3938

40-
fname_evoked = data_dir + '/sample_audvis-ave.fif'
41-
fname_trans = data_dir + '/sample_audvis_raw-trans.fif'
42-
fname_fwd = data_dir + '/sample_audvis-meg-oct-6-mixed-fwd.fif'
43-
fname_cov = data_dir + '/sample_audvis-shrunk-cov.fif'
39+
fname_evoked = data_dir / f'{subject}_audvis-ave.fif'
40+
fname_trans = data_dir / f'{subject}_audvis_raw-trans.fif'
41+
fname_fwd = data_dir / f'{subject}_audvis-meg-oct-6-mixed-fwd.fif'
42+
fname_cov = data_dir / f'{subject}_audvis-shrunk-cov.fif'
4443

4544
# %%
4645
# Set up our source space
@@ -92,9 +91,9 @@
9291
#
9392
# We can also export source positions to NIfTI file and visualize it again:
9493

95-
nii_fname = op.join(bem_dir, '%s-mixed-src.nii' % subject)
94+
nii_fname = bem_dir / f'{subject}-mixed-src.nii'
9695
src.export_volume(nii_fname, mri_resolution=True, overwrite=True)
97-
plotting.plot_img(nii_fname, cmap='nipy_spectral')
96+
plotting.plot_img(str(nii_fname), cmap='nipy_spectral')
9897

9998
# %%
10099
# Compute the fwd matrix

mne/forward/_make_forward.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from copy import deepcopy
1212
from contextlib import contextmanager
13+
from pathlib import Path
1314
import os
1415
import os.path as op
1516

@@ -443,8 +444,10 @@ def _prepare_for_forward(src, mri_head_t, info, bem, mindist, n_jobs,
443444
cmd = 'make_forward_solution(%s)' % (', '.join([str(a) for a in arg_list]))
444445
mri_id = dict(machid=np.zeros(2, np.int32), version=0, secs=0, usecs=0)
445446

447+
info_trans = str(trans) if isinstance(trans, Path) else trans
446448
info = Info(chs=info['chs'], comps=info['comps'],
447-
dev_head_t=info['dev_head_t'], mri_file=trans, mri_id=mri_id,
449+
dev_head_t=info['dev_head_t'], mri_file=info_trans,
450+
mri_id=mri_id,
448451
meas_file=info_extra, meas_id=None, working_dir=os.getcwd(),
449452
command_line=cmd, bads=info['bads'], mri_head_t=mri_head_t)
450453
info._update_redundant()

mne/utils/numerics.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
#
66
# License: BSD-3-Clause
77

8-
from contextlib import contextmanager
98
import hashlib
10-
from io import BytesIO, StringIO
11-
from math import sqrt
129
import numbers
1310
import operator
1411
import os
15-
import os.path as op
16-
from math import ceil
1712
import shutil
1813
import sys
14+
from contextlib import contextmanager
1915
from datetime import datetime, timedelta, timezone
16+
from io import BytesIO, StringIO
17+
from math import ceil, sqrt
18+
from pathlib import Path
2019

2120
import numpy as np
2221

@@ -427,7 +426,7 @@ def _replace_md5(fname):
427426
# adapted from sphinx-gallery
428427
assert fname.endswith('.new')
429428
fname_old = fname[:-4]
430-
if op.isfile(fname_old) and hashfunc(fname) == hashfunc(fname_old):
429+
if os.path.isfile(fname_old) and hashfunc(fname) == hashfunc(fname_old):
431430
os.remove(fname)
432431
else:
433432
shutil.move(fname, fname_old)
@@ -697,7 +696,7 @@ def object_size(x, memo=None):
697696
id_ = id(x)
698697
if id_ in memo:
699698
return 0 # do not add already existing ones
700-
if isinstance(x, (bytes, str, int, float, type(None))):
699+
if isinstance(x, (bytes, str, int, float, type(None), Path)):
701700
size = sys.getsizeof(x)
702701
elif isinstance(x, np.ndarray):
703702
# On newer versions of NumPy, just doing sys.getsizeof(x) works,

0 commit comments

Comments
 (0)