Skip to content

Commit

Permalink
Update.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed Feb 20, 2025
1 parent 2d1869b commit aa43077
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/fmripost_aroma/tests/test_utils_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,21 +346,19 @@ def test_collect_derivatives_xsectional_02(tmpdir):
check_expected(subject_data, expected)

# Query for session 3 (no anat available) should raise an error
subject_data = xbids.collect_derivatives(
raw_dataset=None,
derivatives_dataset=layout,
entities={'subject': '102', 'session': '3'},
fieldmap_id=None,
spec=None,
with pytest.raises(
ValueError,
match='Multiple anatomical derivatives found for anat_mni152nlin6asym',
):
subject_data = xbids.collect_derivatives(
raw_dataset=None,
derivatives_dataset=layout,
entities={'subject': '102', 'session': '3'},
fieldmap_id=None,
spec=None,
patterns=None,
allow_multiple=False,
)
expected = {
'anat_mni152nlin6asym': (
'sub-102_ses-2_space-MNI152NLin6Asym_res-02_desc-preproc_T1w.nii.gz'
),
}
check_expected(subject_data, expected)


def test_collect_derivatives_xsectional_03(tmpdir):
Expand Down
5 changes: 5 additions & 0 deletions src/fmripost_aroma/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ def collect_derivatives(
if not item:
derivs_cache[k] = None
elif not allow_multiple and len(item) > 1 and k.startswith('anat'):
# Raise an error if multiple derivatives are found from different sessions
item_sessions = [layout.get_file(f).entities['session'] for f in item]
if len(set(item_sessions)) > 1:
raise ValueError(f'Multiple anatomical derivatives found for {k}: {item}')

# Anatomical derivatives are allowed to have multiple files (e.g., T1w and T2w)
# but we just grab the first one
derivs_cache[k] = item[0]
Expand Down

0 comments on commit aa43077

Please sign in to comment.