Skip to content

Commit ec519ff

Browse files
mgxdoesteban
andcommitted
fix: do not allow sessionwise with no session
Co-authored-by: Oscar Esteban <[email protected]>
1 parent fdd6312 commit ec519ff

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/smriprep/cli/run.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ def _warn_redirect(message, category, filename, lineno, file=None, line=None):
481481
bootstrap_file = data.load('reports-spec.yml')
482482
errno += generate_reports(
483483
subject_session_list,
484-
smriprep_dir, run_uuid,
484+
smriprep_dir,
485+
run_uuid,
485486
bootstrap_file=bootstrap_file,
486487
)
487488
write_derivative_description(bids_dir, smriprep_dir)
@@ -538,27 +539,26 @@ def build_workflow(opts, retval):
538539

539540
subject_session_list = []
540541
for subject in subject_list:
541-
sessions = layout.get_sessions(
542-
scope='raw',
543-
subject=subject,
544-
session=session_list or Query.OPTIONAL,
545-
suffix=['T1w', 'T2w'], # TODO: Track supported modalities globally
542+
sessions = (
543+
layout.get_sessions(
544+
scope='raw',
545+
subject=subject,
546+
session=session_list or Query.OPTIONAL,
547+
suffix=['T1w', 'T2w'], # TODO: Track supported modalities globally
548+
)
549+
or None
546550
)
547-
if not sessions:
548-
if opts.subject_anatomical_reference == 'sessionwise':
549-
logger.warning(
550-
'--subject-anatomical-reference "sessionwise" was requested, but no sessions '
551-
f'were found for subject {subject}.'
552-
)
553-
subject_session_list.append((subject, None))
554-
continue
555551

556552
if opts.subject_anatomical_reference == 'sessionwise':
553+
if not sessions:
554+
raise RuntimeError(
555+
'--subject-anatomical-reference "sessionwise" was requested, but no sessions '
556+
f'found for subject {subject}.'
557+
)
557558
for session in sessions:
558559
subject_session_list.append((subject, session))
559560
else:
560561
# This will use all sessions either found by layout or passed in via --session-id
561-
# MG: Should session names be concatenated into a label to preserve provenance?
562562
subject_session_list.append((subject, sessions))
563563

564564
bids_filters = json.loads(opts.bids_filter_file.read_text()) if opts.bids_filter_file else None

src/smriprep/utils/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def fs_isRunning(subjects_dir, subject_id, mtime_tol=86400, logger=None):
100100
def stringify_sessions(lst: list[str], max_length: int = 10, digest_size: int = 2) -> str:
101101
"""
102102
Convert a list of session into a string identifier.
103+
103104
If the list has only one element, it returns that element.
104105
If the list has more than one element, it concatenates them with '+'.
105106
If the concatenated string exceeds `max_length`, it returns a
@@ -117,7 +118,6 @@ def stringify_sessions(lst: list[str], max_length: int = 10, digest_size: int =
117118
'a+b+toolong'
118119
>>> stringify_sessions(['a', 'b', 'toolong'], digest_size=4)
119120
'multi+dd8bb349'
120-
>>>
121121
122122
"""
123123
if len(lst) == 1:

0 commit comments

Comments
 (0)