From 92d418f0cb3ed8b70bcffd469f67f1c446e5d04b Mon Sep 17 00:00:00 2001 From: waldie11 <86674066+waldie11@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:38:51 +0100 Subject: [PATCH 01/15] enforce extension match on end of filename --- mne_bids/path.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne_bids/path.py b/mne_bids/path.py index 63d6d1259..98781f7a3 100644 --- a/mne_bids/path.py +++ b/mne_bids/path.py @@ -2286,7 +2286,7 @@ def _filter_fnames( r"_desc-(" + "|".join(description) + ")" if description else r"(|_desc-([^_]+))" ) suffix_str = r"_(" + "|".join(suffix) + ")" if suffix else r"_([^_]+)" - ext_str = r"(" + "|".join(extension) + ")" if extension else r".([^_]+)" + ext_str = r"(" + "|".join(extension) + ")$" if extension else r".([^_]+)" regexp = ( leading_path_str From 0fc5861d8cd92779d9cecb04da6755bffea806da Mon Sep 17 00:00:00 2001 From: waldie11 <86674066+waldie11@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:43:17 +0100 Subject: [PATCH 02/15] rework order in filtering for ignore_nosub including switch to glob.glob --- mne_bids/path.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/mne_bids/path.py b/mne_bids/path.py index 98781f7a3..9aec9d3e7 100644 --- a/mne_bids/path.py +++ b/mne_bids/path.py @@ -2455,13 +2455,25 @@ def _return_root_paths(root, datatype=None, ignore_json=True, ignore_nosub=False """ root = Path(root) # if root is str - if datatype is not None: - datatype = _ensure_tuple(datatype) - search_str = f'*/{"|".join(datatype)}/*' - else: + if datatype is None and not ignore_nosub: search_str = "*.*" + else: + + if datatype is not None: + datatype = _ensure_tuple(datatype) + search_str = f'**/{"|".join(datatype)}/*' - paths = root.rglob(search_str) + else: + search_str = "**/*.*" + if ignore_nosub: + search_str = "sub-*/" + search_str + + paths = list( + map( + lambda fn: Path(root, fn), + glob.glob(search_str, root_dir=root, recursive=True), + ) + ) # Only keep files (not directories), ... # and omit the JSON sidecars if `ignore_json` is True. if ignore_json: @@ -2469,12 +2481,6 @@ def _return_root_paths(root, datatype=None, ignore_json=True, ignore_nosub=False else: paths = [p for p in paths if p.is_file()] - # only keep files which are of the form root/sub-*, - # such that we only look in 'sub'-folders: - if ignore_nosub: - root_sub = str(root / "sub-") - paths = [p for p in paths if str(p).startswith(root_sub)] - return paths From 663389846eb372637c91adbbcbc5fac4e7d1c073 Mon Sep 17 00:00:00 2001 From: waldie11 <86674066+waldie11@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:44:06 +0100 Subject: [PATCH 03/15] provide last call from root.rglob --- mne_bids/path.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mne_bids/path.py b/mne_bids/path.py index 9aec9d3e7..85b41aa9a 100644 --- a/mne_bids/path.py +++ b/mne_bids/path.py @@ -2457,6 +2457,7 @@ def _return_root_paths(root, datatype=None, ignore_json=True, ignore_nosub=False if datatype is None and not ignore_nosub: search_str = "*.*" + paths = root.rglob(search_str) else: if datatype is not None: From 11131b395e93e6b88113c1cbbafbee1434aeb3f9 Mon Sep 17 00:00:00 2001 From: waldie11 <86674066+waldie11@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:45:52 +0100 Subject: [PATCH 04/15] in bids meg, it is allowed to have folders from ctf raw meg data which are not files. Are there more folders in different datatypes allowed? --- mne_bids/path.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/mne_bids/path.py b/mne_bids/path.py index 85b41aa9a..3eb0448a9 100644 --- a/mne_bids/path.py +++ b/mne_bids/path.py @@ -2430,7 +2430,7 @@ def find_matching_paths( def _return_root_paths(root, datatype=None, ignore_json=True, ignore_nosub=False): - """Return all file paths in root. + """Return all file paths + .ds paths in root. Can be filtered by datatype (which is present in the path but not in the BIDSPath basename). Can also be list of datatypes. @@ -2451,7 +2451,7 @@ def _return_root_paths(root, datatype=None, ignore_json=True, ignore_nosub=False Returns ------- paths : list of pathlib.Path - All paths in `root`, filtered according to the function parameters. + All files + .ds paths in `root`, filtered according to the function parameters. """ root = Path(root) # if root is str @@ -2478,9 +2478,21 @@ def _return_root_paths(root, datatype=None, ignore_json=True, ignore_nosub=False # Only keep files (not directories), ... # and omit the JSON sidecars if `ignore_json` is True. if ignore_json: - paths = [p for p in paths if p.is_file() and p.suffix != ".json"] + paths = [ + p + for p in paths + if (p.is_file() and p.suffix != ".json") + # do we really want to do this here? + or (p.is_dir() and p.suffix == ".ds") + ] else: - paths = [p for p in paths if p.is_file()] + paths = [ + p + for p in paths + if p.is_file() + # do we really want to do this here + or (p.is_dir() and p.suffix == ".ds") + ] return paths From 41de35ea9c924e7663efefc68b159a23a5aa8c69 Mon Sep 17 00:00:00 2001 From: waldie11 <86674066+waldie11@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:47:21 +0100 Subject: [PATCH 05/15] also filter for existence of file extension in name when datatype is provided --- mne_bids/path.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mne_bids/path.py b/mne_bids/path.py index 3eb0448a9..e51305359 100644 --- a/mne_bids/path.py +++ b/mne_bids/path.py @@ -2464,6 +2464,8 @@ def _return_root_paths(root, datatype=None, ignore_json=True, ignore_nosub=False datatype = _ensure_tuple(datatype) search_str = f'**/{"|".join(datatype)}/*' + # I think this one is more appropriate + search_str = search_str + ".*" else: search_str = "**/*.*" if ignore_nosub: From 163519717633132851cc7032a565bcb63aacc47c Mon Sep 17 00:00:00 2001 From: waldie11 <86674066+waldie11@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:48:33 +0100 Subject: [PATCH 06/15] comment on improved performance through sub-folder filtering --- mne_bids/path.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mne_bids/path.py b/mne_bids/path.py index e51305359..8f999263d 100644 --- a/mne_bids/path.py +++ b/mne_bids/path.py @@ -2468,6 +2468,10 @@ def _return_root_paths(root, datatype=None, ignore_json=True, ignore_nosub=False search_str = search_str + ".*" else: search_str = "**/*.*" + + # only browse files which are of the form root/sub-*, + # such that we truely only look in 'sub'-folders: + if ignore_nosub: search_str = "sub-*/" + search_str From 2ccdfc9c58792a8b89971ebe0e2e0d382db70281 Mon Sep 17 00:00:00 2001 From: waldie11 <86674066+waldie11@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:59:06 +0100 Subject: [PATCH 07/15] prefilter match in get_entity_vals scan --- mne_bids/path.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/mne_bids/path.py b/mne_bids/path.py index 8f999263d..05b636d64 100644 --- a/mne_bids/path.py +++ b/mne_bids/path.py @@ -14,6 +14,7 @@ from os import path as op from pathlib import Path from textwrap import indent +from itertools import chain as iter_chain import numpy as np from mne.utils import _check_fname, _validate_type, logger, verbose @@ -1897,6 +1898,7 @@ def get_entity_vals( ignore_modalities=None, ignore_datatypes=None, ignore_dirs=("derivatives", "sourcedata"), + include_match=None, with_key=False, verbose=None, ): @@ -1957,6 +1959,11 @@ def get_entity_vals( Directories nested directly within ``root`` to ignore. If ``None``, include all directories in the search. + .. versionadded:: 0.17-dev + include_match : str | array-like of str | None + Apply a starting match pragma following Unix style pattern syntax from + package glob to prefilter search criterion. + .. versionadded:: 0.9 with_key : bool If ``True``, returns the full entity with the key and the value. This @@ -2052,7 +2059,13 @@ def get_entity_vals( p = re.compile(rf"{entity_long_abbr_map[entity_key]}-(.*?)_") values = list() - filenames = root.glob(f"**/*{entity_long_abbr_map[entity_key]}-*_*") + search_str = f"**/*{entity_long_abbr_map[entity_key]}-*_*" + if include_match is not None: + include_match = _ensure_tuple(include_match) + filenames = [root.glob(im + search_str) for im in include_match] + filenames = iter_chain(*filenames) + else: + filenames = root.glob(search_str) for filename in filenames: # Skip ignored directories From a4efdeb1c4f4f13188a49c81bfac10023808e669 Mon Sep 17 00:00:00 2001 From: waldie11 <86674066+waldie11@users.noreply.github.com> Date: Thu, 2 Jan 2025 17:52:27 +0100 Subject: [PATCH 08/15] pre-commit changes --- mne_bids/path.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mne_bids/path.py b/mne_bids/path.py index 05b636d64..63b678c46 100644 --- a/mne_bids/path.py +++ b/mne_bids/path.py @@ -11,10 +11,10 @@ from copy import deepcopy from datetime import datetime from io import StringIO +from itertools import chain as iter_chain from os import path as op from pathlib import Path from textwrap import indent -from itertools import chain as iter_chain import numpy as np from mne.utils import _check_fname, _validate_type, logger, verbose @@ -2472,7 +2472,6 @@ def _return_root_paths(root, datatype=None, ignore_json=True, ignore_nosub=False search_str = "*.*" paths = root.rglob(search_str) else: - if datatype is not None: datatype = _ensure_tuple(datatype) search_str = f'**/{"|".join(datatype)}/*' From e9147c74438c0fb1cc2390fbad670a3d2028840c Mon Sep 17 00:00:00 2001 From: waldie11 <86674066+waldie11@users.noreply.github.com> Date: Mon, 23 Dec 2024 16:21:13 +0100 Subject: [PATCH 09/15] use iglob iterator --- mne_bids/path.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mne_bids/path.py b/mne_bids/path.py index 63b678c46..4d246b0f1 100644 --- a/mne_bids/path.py +++ b/mne_bids/path.py @@ -2487,12 +2487,8 @@ def _return_root_paths(root, datatype=None, ignore_json=True, ignore_nosub=False if ignore_nosub: search_str = "sub-*/" + search_str - paths = list( - map( - lambda fn: Path(root, fn), - glob.glob(search_str, root_dir=root, recursive=True), - ) - ) + paths = [ Path(root, fn) for fn in glob.iglob(search_str, root_dir=root, recursive=True) ] + # Only keep files (not directories), ... # and omit the JSON sidecars if `ignore_json` is True. if ignore_json: From 67578dd799d8b656a4d7a0a0595fd89291c79409 Mon Sep 17 00:00:00 2001 From: waldie11 <86674066+waldie11@users.noreply.github.com> Date: Mon, 3 Feb 2025 14:02:52 +0100 Subject: [PATCH 10/15] pre-commit syntax --- mne_bids/path.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne_bids/path.py b/mne_bids/path.py index 4d246b0f1..9ab0b80d4 100644 --- a/mne_bids/path.py +++ b/mne_bids/path.py @@ -2474,7 +2474,7 @@ def _return_root_paths(root, datatype=None, ignore_json=True, ignore_nosub=False else: if datatype is not None: datatype = _ensure_tuple(datatype) - search_str = f'**/{"|".join(datatype)}/*' + search_str = f"**/{'|'.join(datatype)}/*" # I think this one is more appropriate search_str = search_str + ".*" From def6ab2886b075053ad5cef700a31d3a37ea9b80 Mon Sep 17 00:00:00 2001 From: waldie11 <86674066+waldie11@users.noreply.github.com> Date: Mon, 3 Feb 2025 14:48:57 +0100 Subject: [PATCH 11/15] Add changelog --- doc/authors.rst | 3 ++- doc/whats_new.rst | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/authors.rst b/doc/authors.rst index cc061b1ea..22bcd1e43 100644 --- a/doc/authors.rst +++ b/doc/authors.rst @@ -5,10 +5,12 @@ .. _Amaia Benitez: https://github.com/AmaiaBA .. _Anand Saini: https://github.com/anandsaini024 .. _Ariel Rokem: https://github.com/arokem +.. _Arne Gottwald: https://github.com/waldie11 .. _Austin Hurst: https://github.com/a-hurst .. _Berk Gerçek: https://github.com/berkgercek .. _Bruno Hebling Vieira: https://github.com/bhvieira .. _Chris Holdgraf: https://bids.berkeley.edu/people/chris-holdgraf +.. _Christian O'Reilly: https://github.com/christian-oreilly .. _Clemens Brunner: https://github.com/cbrnr .. _Daniel McCloy: http://dan.mccloy.info .. _Denis Engemann: https://github.com/dengemann @@ -52,4 +54,3 @@ .. _Tom Donoghue: https://github.com/TomDonoghue .. _William Turner: https://bootstrapbill.github.io/ .. _Yorguin Mantilla: https://github.com/yjmantilla -.. _Christian O'Reilly: https://github.com/christian-oreilly diff --git a/doc/whats_new.rst b/doc/whats_new.rst index fcf110636..9b36f5861 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -19,6 +19,7 @@ The following authors contributed for the first time. Thank you so much! 🤩 * `Christian O'Reilly`_ * `Berk Gerçek`_ +* `Arne Gottwald`_ The following authors had contributed before. Thank you for sticking around! 🤘 @@ -35,6 +36,8 @@ Detailed list of changes - :func:`mne_bids.write_raw_bids()` can now handle mne `Raw` objects with `eyegaze` and `pupil` channels, by `Christian O'Reilly`_ (:gh:`1344`) - :func:`mne_bids.get_entity_vals()` has a new parameter ``ignore_suffixes`` to easily ignore sidecar files, by `Daniel McCloy`_ (:gh:`1362`) - Empty-room matching now preferentially finds recordings in the subject directory tagged as `task-noise` before looking in the `sub-emptyroom` directories. This adds support for a part of the BIDS specification for ER recordings, by `Berk Gerçek`_ (:gh:`1364`) +- Path matching is now implemenented in a more efficient manner within `_return_root_paths`, by `Arne Gottwald` (:gh:`1355`) +- :func:`mne_bids.get_entity_vals()` has a new parameter ``include_match`` to prefilter item matching and ignore non-matched items from begin of directory scan, by `Arne Gottwald` (:gh:`1355`) 🧐 API and behavior changes @@ -53,6 +56,7 @@ Detailed list of changes - :func:`mne_bids.read_raw_bids` can optionally return an ``event_id`` dictionary suitable for use with :func:`mne.events_from_annotations`, and if a ``values`` column is present in ``events.tsv`` it will be used as the source of the integer event ID codes, by `Daniel McCloy`_ (:gh:`1349`) - BIDS dictates that the recording entity should be displayed as "_recording-" in the filename. This PR makes :class:`mne_bids.BIDSPath` correctly display "_recording-" (instead of "_rec-") in BIDSPath.fpath. By `Scott Huberty`_ (:gh:`1348`) - :func:`mne_bids.make_dataset_description` now correctly encodes the dataset description as UTF-8 on disk, by `Scott Huberty`_ (:gh:`1357`) +- Corrects extension match within `_filter_fnames` at end of filename, by `Arne Gottwald` (:gh:`1355`) ⚕️ Code health ^^^^^^^^^^^^^^ From 9f2dff8e6bf2258ebf1ee79aa9a71df5db1bb0f5 Mon Sep 17 00:00:00 2001 From: waldie11 <86674066+waldie11@users.noreply.github.com> Date: Mon, 3 Feb 2025 21:24:44 +0100 Subject: [PATCH 12/15] benchmark _return_root_paths --- mne_bids/tests/test_path.py | 99 +++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/mne_bids/tests/test_path.py b/mne_bids/tests/test_path.py index c2913d56e..9a4fcb028 100644 --- a/mne_bids/tests/test_path.py +++ b/mne_bids/tests/test_path.py @@ -7,10 +7,12 @@ import os.path as op import shutil import shutil as sh +import timeit from datetime import datetime, timezone from pathlib import Path import mne +import numpy as np import pytest from mne.datasets import testing from mne.io import anonymize_info @@ -166,6 +168,103 @@ def test_get_entity_vals(entity, expected_vals, kwargs, return_bids_test_dir): shutil.rmtree(deriv_path) +def test_path_benchmark(tmp_path_factory): + """Benchmark exploring bids tree.""" + tmp_bids_root = tmp_path_factory.mktemp("abc") + + derivatives = ["derivatives/derivatives" + str(i) for i in range(17)] + + bids_subdirectories = ["", "sourcedata", *derivatives] + + def equal_length_subj_ids(v): + assert all(v > 0) + n_digits = len(str(np.max(v))) + 1 + return list(map(lambda i: "0" * (n_digits - len(str(i))) + str(i), v)) + + # Create a BIDS compliant directory tree with high number of branches + for i in equal_length_subj_ids(np.arange(1, 20, dtype=int)): + for j in range(1, 9): + for subdir in bids_subdirectories: + for datatype in ["eeg", "meg"]: + bids_subdir = BIDSPath( + subject=i, + session="0" + str(j), + datatype=datatype, + task="audvis", + root=str(tmp_bids_root / subdir), + ) + bids_subdir.mkdir(exist_ok=True) + Path(bids_subdir.root / "participants.tsv").touch() + Path(bids_subdir.root / "participants.csv").touch() + Path(bids_subdir.root / "README").touch() + + # os.makedirs(bids_subdir.directory, exist_ok=True) + Path( + bids_subdir.directory, bids_subdir.basename + "_events.tsv" + ).touch() + Path( + bids_subdir.directory, bids_subdir.basename + "_events.csv" + ).touch() + + if datatype == "meg": + ctf_path = Path( + bids_subdir.directory, bids_subdir.basename + "_meg.ds" + ) + ctf_path.mkdir(exist_ok=True) + Path(ctf_path, bids_subdir.basename + ".meg4").touch() + Path(ctf_path, bids_subdir.basename + ".hc").touch() + Path(ctf_path / "hz.ds").mkdir(exist_ok=True) + Path(ctf_path / "hz.ds" / "hz.meg4").touch() + Path(ctf_path / "hz.ds" / "hz.hc").touch() + + # apply nosub on find_matching_matchs with root level bids directory should + # yield a performance boost of order of length from bids_subdirectories. + timed_all, timed_ignored_nosub = ( + timeit.timeit( + "mne_bids.find_matching_paths(tmp_bids_root)", + setup="import mne_bids\ntmp_bids_root='" + str(tmp_bids_root) + "'", + number=1, + ), + timeit.timeit( + "mne_bids.find_matching_paths(tmp_bids_root, ignore_nosub=True)", + setup="import mne_bids\ntmp_bids_root='" + str(tmp_bids_root) + "'", + number=10, + ) + / 10, + ) + + assert ( + timed_all / (10 * np.maximum(1, np.floor(len(bids_subdirectories) / 10))) + # while this should be of same order, lets give it some space by a factor of 2 + > 0.5 * timed_ignored_nosub + ) + + # apply include_match on get_entity_vals with root level bids directory should + # yield a performance boost of order of length from bids_subdirectories. + timed_entity, timed_entity_match = ( + timeit.timeit( + "mne_bids.get_entity_vals(tmp_bids_root, 'session')", + setup="import mne_bids\ntmp_bids_root='" + str(tmp_bids_root) + "'", + number=1, + ), + timeit.timeit( + "mne_bids.get_entity_vals(tmp_bids_root, 'session', include_match='sub-*/')", # noqa: E501 + setup="import mne_bids\ntmp_bids_root='" + str(tmp_bids_root) + "'", + number=10, + ) + / 10, + ) + + assert ( + timed_entity / (10 * np.maximum(1, np.floor(len(bids_subdirectories) / 10))) + # while this should be of same order, lets give it some space by a factor of 2 + > 0.5 * timed_entity_match + ) + + # Clean up + shutil.rmtree(tmp_bids_root) + + def test_search_folder_for_text(capsys): """Test finding entries.""" with pytest.raises(ValueError, match="is not a directory"): From 662384fd5c9927286df6252144e6c585ab035e1c Mon Sep 17 00:00:00 2001 From: waldie11 <86674066+waldie11@users.noreply.github.com> Date: Mon, 3 Feb 2025 21:27:22 +0100 Subject: [PATCH 13/15] benchmark comparison with ignore_dirs --- mne_bids/tests/test_path.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mne_bids/tests/test_path.py b/mne_bids/tests/test_path.py index 9a4fcb028..e1b7be5e3 100644 --- a/mne_bids/tests/test_path.py +++ b/mne_bids/tests/test_path.py @@ -261,6 +261,21 @@ def equal_length_subj_ids(v): > 0.5 * timed_entity_match ) + # This should yield the same performance gain, it is not. + # # apply include_match on get_entity_vals with root level bids directory should + # # yield a performance boost of order of length from bids_subdirectories. + # timed_entity_ignore = timeit.timeit( + # "mne_bids.get_entity_vals(tmp_bids_root, 'session', ignore_dirs=['derivatives', 'sourcedata'])", # noqa: E501 + # setup="import mne_bids\ntmp_bids_root='" + str(tmp_bids_root) + "'", + # number=1, + # ) + + # assert ( + # timed_entity / (10 * np.maximum(1, np.floor(len(bids_subdirectories) / 10))) + # # while this should be of same order, lets give it some space by a factor of 2 + # > 0.5 * timed_entity_ignore + # ) + # Clean up shutil.rmtree(tmp_bids_root) From 824649e91f4baccac2b3b703b22ca0819ac091b3 Mon Sep 17 00:00:00 2001 From: waldie11 <86674066+waldie11@users.noreply.github.com> Date: Mon, 3 Feb 2025 22:16:01 +0100 Subject: [PATCH 14/15] Always use Path --- mne_bids/tests/test_path.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne_bids/tests/test_path.py b/mne_bids/tests/test_path.py index e1b7be5e3..eefce2e9e 100644 --- a/mne_bids/tests/test_path.py +++ b/mne_bids/tests/test_path.py @@ -172,7 +172,7 @@ def test_path_benchmark(tmp_path_factory): """Benchmark exploring bids tree.""" tmp_bids_root = tmp_path_factory.mktemp("abc") - derivatives = ["derivatives/derivatives" + str(i) for i in range(17)] + derivatives = [Path("derivatives", "derivatives" + str(i)) for i in range(17)] bids_subdirectories = ["", "sourcedata", *derivatives] From 970751ccdedee4b6237dec5ccc7f2f1361613f71 Mon Sep 17 00:00:00 2001 From: waldie11 <86674066+waldie11@users.noreply.github.com> Date: Mon, 3 Feb 2025 22:52:24 +0100 Subject: [PATCH 15/15] raw strings to allow windows path --- mne_bids/tests/test_path.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mne_bids/tests/test_path.py b/mne_bids/tests/test_path.py index eefce2e9e..422e465cb 100644 --- a/mne_bids/tests/test_path.py +++ b/mne_bids/tests/test_path.py @@ -222,12 +222,12 @@ def equal_length_subj_ids(v): timed_all, timed_ignored_nosub = ( timeit.timeit( "mne_bids.find_matching_paths(tmp_bids_root)", - setup="import mne_bids\ntmp_bids_root='" + str(tmp_bids_root) + "'", + setup="import mne_bids\ntmp_bids_root=r'" + str(tmp_bids_root) + "'", number=1, ), timeit.timeit( "mne_bids.find_matching_paths(tmp_bids_root, ignore_nosub=True)", - setup="import mne_bids\ntmp_bids_root='" + str(tmp_bids_root) + "'", + setup="import mne_bids\ntmp_bids_root=r'" + str(tmp_bids_root) + "'", number=10, ) / 10, @@ -244,12 +244,12 @@ def equal_length_subj_ids(v): timed_entity, timed_entity_match = ( timeit.timeit( "mne_bids.get_entity_vals(tmp_bids_root, 'session')", - setup="import mne_bids\ntmp_bids_root='" + str(tmp_bids_root) + "'", + setup="import mne_bids\ntmp_bids_root=r'" + str(tmp_bids_root) + "'", number=1, ), timeit.timeit( "mne_bids.get_entity_vals(tmp_bids_root, 'session', include_match='sub-*/')", # noqa: E501 - setup="import mne_bids\ntmp_bids_root='" + str(tmp_bids_root) + "'", + setup="import mne_bids\ntmp_bids_root=r'" + str(tmp_bids_root) + "'", number=10, ) / 10, @@ -266,7 +266,7 @@ def equal_length_subj_ids(v): # # yield a performance boost of order of length from bids_subdirectories. # timed_entity_ignore = timeit.timeit( # "mne_bids.get_entity_vals(tmp_bids_root, 'session', ignore_dirs=['derivatives', 'sourcedata'])", # noqa: E501 - # setup="import mne_bids\ntmp_bids_root='" + str(tmp_bids_root) + "'", + # setup="import mne_bids\ntmp_bids_root=r'" + str(tmp_bids_root) + "'", # number=1, # )