Skip to content

Commit 9591e3d

Browse files
committed
ruff
1 parent bd95722 commit 9591e3d

File tree

8 files changed

+159
-38
lines changed

8 files changed

+159
-38
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ ignore = [
189189
"S113",
190190
"S202",
191191
"S602",
192+
"T100",
192193
]
193194

194195
[tool.ruff.lint.flake8-quotes]

src/simbids/cli/run.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@
2323
"""Simulated BIDS workflows."""
2424

2525
from simbids import config
26-
import sys
27-
import logging
2826

2927
EXITCODE: int = -1
3028

3129

3230
def main():
3331
"""Entry point."""
3432
import gc
35-
from multiprocessing import Manager, Process
3633

3734
from simbids.cli.parser import parse_args
3835
from simbids.cli.workflow import build_workflow

src/simbids/cli/workflow.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def build_workflow(config_file, retval):
4646
config.load(config_file)
4747
build_log = config.loggers.workflow
4848

49-
output_dir = config.execution.output_dir
5049
version = config.environment.version
5150

5251
retval['return_code'] = 1

src/simbids/config.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,7 @@ def init(cls):
481481
'sourcedata',
482482
'models',
483483
re.compile(r'^\.'),
484-
re.compile(
485-
r'sub-[a-zA-Z0-9]+(/ses-[a-zA-Z0-9]+)?/(beh|eeg|ieeg|meg|perf)'
486-
),
484+
re.compile(r'sub-[a-zA-Z0-9]+(/ses-[a-zA-Z0-9]+)?/(beh|eeg|ieeg|meg|perf)'),
487485
),
488486
)
489487
cls._layout = BIDSLayout(
@@ -731,6 +729,5 @@ def init_spaces(checkpoint=True):
731729
if 'MNI152NLin6Asym' not in spaces.get_spaces(nonstandard=False, dim=(3,)):
732730
spaces.add(Reference('MNI152NLin6Asym', {}))
733731

734-
735732
# Make the SpatialReferences object available
736733
workflow.spaces = spaces

src/simbids/utils/bids.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def collect_derivatives(
4848
patterns: list[str] | None = None,
4949
allow_multiple: bool = False,
5050
spaces: SpatialReferences | None = None,
51+
bids_app: str | None = None,
5152
) -> dict:
5253
"""Gather existing derivatives and compose a cache.
5354

src/simbids/utils/debug.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ def setup_exceptionhook(ipython=False):
5959
pdb.post_mortem; if not interactive, then invokes default handler.
6060
"""
6161

62-
def _pdb_excepthook(type, value, tb):
62+
def _pdb_excepthook(_type, value, tb):
6363
import traceback
6464

65-
traceback.print_exception(type, value, tb)
65+
traceback.print_exception(_type, value, tb)
6666
print()
6767
if is_interactive():
68+
# Import pdb only when needed
6869
import pdb
6970

7071
pdb.post_mortem(tb)

src/simbids/utils/utils.py

Lines changed: 151 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,135 @@
3333
# These lists define the order in which entities should appear in the YAML output
3434
# Using BIDS entity keys (e.g., 'ses' instead of 'session')
3535
DWI_ENTITIES = [
36-
'sub', 'ses', 'acq', 'dir', 'run', 'rec', 'mod', 'echo', 'flip',
37-
'inv', 'mt', 'part', 'ce', 'recording', 'proc', 'space', 'res', 'den',
38-
'desc', 'label', 'from', 'to', 'mode', 'cohort', 'res'
36+
'sub',
37+
'ses',
38+
'acq',
39+
'dir',
40+
'run',
41+
'rec',
42+
'mod',
43+
'echo',
44+
'flip',
45+
'inv',
46+
'mt',
47+
'part',
48+
'ce',
49+
'recording',
50+
'proc',
51+
'space',
52+
'res',
53+
'den',
54+
'desc',
55+
'label',
56+
'from',
57+
'to',
58+
'mode',
59+
'cohort',
60+
'res',
3961
]
4062

4163
FMAP_ENTITIES = [
42-
'sub', 'ses', 'acq', 'dir', 'run', 'rec', 'mod', 'echo', 'flip',
43-
'inv', 'mt', 'part', 'ce', 'recording', 'proc', 'space', 'res', 'den',
44-
'desc', 'label', 'from', 'to', 'mode', 'cohort', 'res'
64+
'sub',
65+
'ses',
66+
'acq',
67+
'dir',
68+
'run',
69+
'rec',
70+
'mod',
71+
'echo',
72+
'flip',
73+
'inv',
74+
'mt',
75+
'part',
76+
'ce',
77+
'recording',
78+
'proc',
79+
'space',
80+
'res',
81+
'den',
82+
'desc',
83+
'label',
84+
'from',
85+
'to',
86+
'mode',
87+
'cohort',
88+
'res',
4589
]
4690

4791
ANAT_ENTITIES = [
48-
'sub', 'ses', 'acq', 'ce', 'rec', 'run', 'mod', 'echo', 'flip',
49-
'inv', 'mt', 'part', 'proc', 'space', 'res', 'den', 'desc', 'label',
50-
'from', 'to', 'mode', 'cohort', 'res'
92+
'sub',
93+
'ses',
94+
'acq',
95+
'ce',
96+
'rec',
97+
'run',
98+
'mod',
99+
'echo',
100+
'flip',
101+
'inv',
102+
'mt',
103+
'part',
104+
'proc',
105+
'space',
106+
'res',
107+
'den',
108+
'desc',
109+
'label',
110+
'from',
111+
'to',
112+
'mode',
113+
'cohort',
114+
'res',
51115
]
52116

53117
FUNC_ENTITIES = [
54-
'sub', 'ses', 'task', 'acq', 'ce', 'rec', 'dir', 'run', 'echo',
55-
'recording', 'part', 'proc', 'space', 'res', 'den', 'desc', 'label',
56-
'from', 'to', 'mode', 'cohort', 'res'
118+
'sub',
119+
'ses',
120+
'task',
121+
'acq',
122+
'ce',
123+
'rec',
124+
'dir',
125+
'run',
126+
'echo',
127+
'recording',
128+
'part',
129+
'proc',
130+
'space',
131+
'res',
132+
'den',
133+
'desc',
134+
'label',
135+
'from',
136+
'to',
137+
'mode',
138+
'cohort',
139+
'res',
57140
]
58141

59142
PERF_ENTITIES = [
60-
'sub', 'ses', 'acq', 'rec', 'run', 'mod', 'echo', 'flip',
61-
'inv', 'mt', 'part', 'proc', 'space', 'res', 'den', 'desc', 'label',
62-
'from', 'to', 'mode', 'cohort', 'res'
143+
'sub',
144+
'ses',
145+
'acq',
146+
'rec',
147+
'run',
148+
'mod',
149+
'echo',
150+
'flip',
151+
'inv',
152+
'mt',
153+
'part',
154+
'proc',
155+
'space',
156+
'res',
157+
'den',
158+
'desc',
159+
'label',
160+
'from',
161+
'to',
162+
'mode',
163+
'cohort',
164+
'res',
63165
]
64166

65167
# Mapping from full entity names to BIDS entity keys
@@ -87,16 +189,18 @@
87189
'to': 'to',
88190
'mode': 'mode',
89191
'cohort': 'cohort',
90-
'res': 'res'
192+
'res': 'res',
91193
}
92194

93195
# Reverse mapping from BIDS entity keys to full names
94196
REVERSE_ENTITY_KEY_MAP = {v: k for k, v in ENTITY_KEY_MAP.items()}
95197

198+
96199
def _convert_to_bids_key(key):
97200
"""Convert full entity name to BIDS entity key."""
98201
return ENTITY_KEY_MAP.get(key, key)
99202

203+
100204
def _convert_from_bids_key(key):
101205
"""Convert BIDS entity key to full entity name."""
102206
return REVERSE_ENTITY_KEY_MAP.get(key, key)
@@ -250,7 +354,8 @@ def create_skeleton_from_bids(bids_dir, n_subjects, n_sessions):
250354
dwi_entry = {'suffix': 'dwi', 'metadata': dwi_sidecar}
251355
for key in DWI_ENTITIES:
252356
full_key = _convert_from_bids_key(key)
253-
if full_key in entities and full_key != 'session': # Skip session as it's handled separately
357+
# Skip session as it's handled separately
358+
if full_key in entities and full_key != 'session':
254359
dwi_entry[key] = _sanitize_value(entities[full_key])
255360
skeleton[subject]['dwi'].append(dwi_entry)
256361

@@ -264,7 +369,8 @@ def create_skeleton_from_bids(bids_dir, n_subjects, n_sessions):
264369
func_entry = {'suffix': 'bold', 'metadata': func_sidecar}
265370
for key in FUNC_ENTITIES:
266371
full_key = _convert_from_bids_key(key)
267-
if full_key in entities and full_key != 'session': # Skip session as it's handled separately
372+
# Skip session as it's handled separately
373+
if full_key in entities and full_key != 'session':
268374
func_entry[key] = _sanitize_value(entities[full_key])
269375
skeleton[subject]['func'].append(func_entry)
270376

@@ -276,20 +382,26 @@ def create_skeleton_from_bids(bids_dir, n_subjects, n_sessions):
276382
fmap_entry = {'suffix': 'epi', 'metadata': fmap_sidecar}
277383
for key in FMAP_ENTITIES:
278384
full_key = _convert_from_bids_key(key)
279-
if full_key in entities and full_key != 'session': # Skip session as it's handled separately
385+
if (
386+
full_key in entities and full_key != 'session'
387+
): # Skip session as it's handled separately
280388
fmap_entry[key] = _sanitize_value(entities[full_key])
281389
fmap_entries.append(fmap_entry)
282390
skeleton[subject]['fmap'] = fmap_entries
283391

284392
# Add anat entries
285393
anat_entries = []
286-
for anat_file in layout.get(subject=subject, suffix=['T1w', 'T2w', 'FLAIR', 'PDw'], extension='.json'):
394+
for anat_file in layout.get(
395+
subject=subject, suffix=['T1w', 'T2w', 'FLAIR', 'PDw'], extension='.json'
396+
):
287397
anat_sidecar = _sanitize_metadata(anat_file.get_metadata())
288398
entities = parse_file_entities(Path(anat_file).name)
289399
anat_entry = {'suffix': entities.get('suffix', ''), 'metadata': anat_sidecar}
290400
for key in ANAT_ENTITIES:
291401
full_key = _convert_from_bids_key(key)
292-
if full_key in entities and full_key != 'session': # Skip session as it's handled separately
402+
if (
403+
full_key in entities and full_key != 'session'
404+
): # Skip session as it's handled separately
293405
anat_entry[key] = _sanitize_value(entities[full_key])
294406
anat_entries.append(anat_entry)
295407
skeleton[subject]['anat'] = anat_entries
@@ -330,7 +442,8 @@ def create_skeleton_from_bids(bids_dir, n_subjects, n_sessions):
330442
dwi_entry = {'suffix': 'dwi', 'metadata': dwi_sidecar}
331443
for key in DWI_ENTITIES:
332444
full_key = _convert_from_bids_key(key)
333-
if full_key in entities and full_key != 'session': # Skip session as it's handled separately
445+
# Skip session as it's handled separately
446+
if full_key in entities and full_key != 'session':
334447
dwi_entry[key] = _sanitize_value(entities[full_key])
335448
session_data['dwi'].append(dwi_entry)
336449

@@ -346,32 +459,42 @@ def create_skeleton_from_bids(bids_dir, n_subjects, n_sessions):
346459
func_entry = {'suffix': 'bold', 'metadata': func_sidecar}
347460
for key in FUNC_ENTITIES:
348461
full_key = _convert_from_bids_key(key)
349-
if full_key in entities and full_key != 'session': # Skip session as it's handled separately
462+
# Skip session as it's handled separately
463+
if full_key in entities and full_key != 'session':
350464
func_entry[key] = _sanitize_value(entities[full_key])
351465
session_data['func'].append(func_entry)
352466

353467
# Add fmap entries
354468
fmap_entries = []
355-
for fmap_file in layout.get(subject=subject, session=session, suffix='epi', extension='.json'):
469+
for fmap_file in layout.get(
470+
subject=subject, session=session, suffix='epi', extension='.json'
471+
):
356472
fmap_sidecar = _sanitize_metadata(fmap_file.get_metadata())
357473
entities = parse_file_entities(Path(fmap_file).name)
358474
fmap_entry = {'suffix': 'epi', 'metadata': fmap_sidecar}
359475
for key in FMAP_ENTITIES:
360476
full_key = _convert_from_bids_key(key)
361-
if full_key in entities and full_key != 'session': # Skip session as it's handled separately
477+
# Skip session as it's handled separately
478+
if full_key in entities and full_key != 'session':
362479
fmap_entry[key] = _sanitize_value(entities[full_key])
363480
fmap_entries.append(fmap_entry)
364481
session_data['fmap'] = fmap_entries
365482

366483
# Add anat entries
367484
anat_entries = []
368-
for anat_file in layout.get(subject=subject, session=session, suffix=['T1w', 'T2w', 'FLAIR', 'PDw'], extension='.json'):
485+
for anat_file in layout.get(
486+
subject=subject,
487+
session=session,
488+
suffix=['T1w', 'T2w', 'FLAIR', 'PDw'],
489+
extension='.json',
490+
):
369491
anat_sidecar = _sanitize_metadata(anat_file.get_metadata())
370492
entities = parse_file_entities(Path(anat_file).name)
371493
anat_entry = {'suffix': entities.get('suffix', ''), 'metadata': anat_sidecar}
372494
for key in ANAT_ENTITIES:
373495
full_key = _convert_from_bids_key(key)
374-
if full_key in entities and full_key != 'session': # Skip session as it's handled separately
496+
# Skip session as it's handled separately
497+
if full_key in entities and full_key != 'session':
375498
anat_entry[key] = _sanitize_value(entities[full_key])
376499
anat_entries.append(anat_entry)
377500
session_data['anat'] = anat_entries
@@ -411,6 +534,7 @@ def _convert_to_serializable(obj):
411534
return {k: _convert_to_serializable(v) for k, v in obj.items()}
412535
return str(obj)
413536

537+
414538
# configs = {}
415539
# ds_paths = ("ds002278", "ds004146", "ds005237")
416540

src/simbids/workflows/xcp_d/xcp_d.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def init_single_subject_fmripost_wf(subject_id: str):
5050
from bids.utils import listify
5151

5252
from simbids.utils.bids import collect_derivatives
53+
5354
entities = config.execution.bids_filters or {}
5455
entities['subject'] = subject_id
5556

@@ -64,7 +65,7 @@ def init_single_subject_fmripost_wf(subject_id: str):
6465
fieldmap_id=None,
6566
allow_multiple=True,
6667
spaces=None,
67-
bids_app="xcp_d",
68+
bids_app='xcp_d',
6869
)
6970
subject_data['bold'] = listify(subject_data['bold_raw'])
7071
else:

0 commit comments

Comments
 (0)