-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MAINT: Refactor _get_raw_paths #749
Changes from all commits
2ed2892
07da439
c5c5b75
831ee94
5f59817
f080aa5
ad07f3f
70d46f7
955f24d
5509b76
8bdc8a4
10e5eee
a6f9066
6f0a458
c30f4c4
5407c62
a3cc2d6
6dccd5c
3092b78
93fb70b
ac8cffc
871e863
60ccddd
85ea8c8
f907ef5
185b0f8
fa4ea95
c0e6fd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -416,6 +416,14 @@ | |
``` | ||
""" | ||
|
||
read_raw_bids_verbose: Optional[Literal["error"]] = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you mention this new setting in the changelog, please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
""" | ||
Verbosity level to pass to `read_raw_bids(..., verbose=read_raw_bids_verbose)`. | ||
If you know your dataset will contain files that are not perfectly BIDS | ||
compliant (e.g., "Did not find any meg.json..."), you can set this to | ||
`'error'` to suppress warnings emitted by read_raw_bids. | ||
""" | ||
|
||
############################################################################### | ||
# BREAK DETECTION | ||
# --------------- | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,16 +118,6 @@ def get_sessions(config: SimpleNamespace) -> Union[List[None], List[str]]: | |
return sessions | ||
|
||
|
||
@functools.lru_cache(maxsize=None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic here was backward I think. The "public" |
||
def _get_runs_all_subjects_cached( | ||
**config_dict: Dict[str, Any], | ||
) -> Dict[str, Union[List[None], List[str]]]: | ||
config = SimpleNamespace(**config_dict) | ||
# Sometimes we check list equivalence for ch_types, so convert it back | ||
config.ch_types = list(config.ch_types) | ||
return get_runs_all_subjects(config) | ||
|
||
|
||
def get_runs_all_subjects( | ||
config: SimpleNamespace, | ||
) -> Dict[str, Union[List[None], List[str]]]: | ||
|
@@ -139,7 +129,26 @@ def get_runs_all_subjects( | |
for each subject asked in the configuration file | ||
(and not for each subject present in the bids_path). | ||
""" | ||
# We cannot use get_subjects() because if there is just one subject | ||
# Use caching under the hood for speed | ||
return copy.deepcopy( | ||
_get_runs_all_subjects_cached( | ||
bids_root=config.bids_root, | ||
data_type=config.data_type, | ||
ch_types=tuple(config.ch_types), | ||
subjects=tuple(config.subjects) if config.subjects != "all" else "all", | ||
exclude_subjects=tuple(config.exclude_subjects), | ||
exclude_runs=tuple(config.exclude_runs) if config.exclude_runs else None, | ||
) | ||
) | ||
|
||
|
||
@functools.lru_cache(maxsize=None) | ||
def _get_runs_all_subjects_cached( | ||
**config_dict: Dict[str, Any], | ||
) -> Dict[str, Union[List[None], List[str]]]: | ||
config = SimpleNamespace(**config_dict) | ||
# Sometimes we check list equivalence for ch_types, so convert it back | ||
config.ch_types = list(config.ch_types) | ||
subj_runs = dict() | ||
for subject in get_subjects(config): | ||
# Only traverse through the current subject's directory | ||
|
@@ -193,15 +202,7 @@ def get_runs( | |
return [None] | ||
|
||
runs = copy.deepcopy(config.runs) | ||
|
||
subj_runs = _get_runs_all_subjects_cached( | ||
bids_root=config.bids_root, | ||
data_type=config.data_type, | ||
ch_types=tuple(config.ch_types), | ||
subjects=tuple(config.subjects) if config.subjects != "all" else "all", | ||
exclude_subjects=tuple(config.exclude_subjects), | ||
exclude_runs=tuple(config.exclude_runs) if config.exclude_runs else None, | ||
) | ||
subj_runs = get_runs_all_subjects(config=config) | ||
valid_runs = subj_runs[subject] | ||
|
||
if len(get_subjects(config)) > 1: | ||
|
@@ -239,24 +240,28 @@ def get_runs_tasks( | |
config: SimpleNamespace, | ||
subject: str, | ||
session: Optional[str], | ||
include_noise: bool = True, | ||
) -> List[Tuple[str]]: | ||
"""Get (run, task) tuples for all runs plus (maybe) rest.""" | ||
from ._import_data import _get_bids_path_in | ||
from ._import_data import _get_noise_path, _get_rest_path | ||
|
||
runs = get_runs(config=config, subject=subject) | ||
tasks = [config.task] * len(runs) | ||
if config.process_rest and not config.task_is_rest: | ||
run, task = None, "rest" | ||
bids_path_in = _get_bids_path_in( | ||
cfg=config, | ||
subject=subject, | ||
session=session, | ||
run=run, | ||
task=task, | ||
) | ||
if bids_path_in.fpath.exists(): | ||
tasks = [get_task(config=config)] * len(runs) | ||
kwargs = dict( | ||
cfg=config, | ||
subject=subject, | ||
session=session, | ||
kind="orig", | ||
add_bads=False, | ||
) | ||
if _get_rest_path(**kwargs): | ||
runs.append(None) | ||
tasks.append("rest") | ||
if include_noise: | ||
mf_reference_run = get_mf_reference_run(config=config) | ||
if _get_noise_path(mf_reference_run=mf_reference_run, **kwargs): | ||
runs.append(None) | ||
tasks.append("rest") | ||
tasks.append("noise") | ||
return tuple(zip(runs, tasks)) | ||
|
||
|
||
|
@@ -600,3 +605,7 @@ def _bids_kwargs(*, config: SimpleNamespace) -> dict: | |
bids_root=config.bids_root, | ||
deriv_root=config.deriv_root, | ||
) | ||
|
||
|
||
def _do_mf_autobad(*, cfg: SimpleNamespace) -> bool: | ||
return cfg.find_noisy_channels_meg or cfg.find_flat_channels_meg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this one because I was getting a bunch of warnings when processing
ds000117
: