Skip to content

Commit

Permalink
Merge pull request #349 from effigies/enh/bids-uris
Browse files Browse the repository at this point in the history
ENH: Resolve BIDS-URIs
  • Loading branch information
oesteban authored Jan 18, 2024
2 parents 45eb7d0 + cea2cee commit 8ca5637
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
23 changes: 17 additions & 6 deletions sdcflows/utils/tests/test_wrangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ def gen_layout(bids_dir, database_dir=None):
"EchoTime": 1.2,
"PhaseEncodingDirection": "j-",
"TotalReadoutTime": 0.8,
"IntendedFor": "ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
"IntendedFor": "bids::sub-01/ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
}},
{"suffix": "epi", "dir": "PA", "metadata": {
"EchoTime": 1.2,
"PhaseEncodingDirection": "j",
"TotalReadoutTime": 0.8,
"IntendedFor": "ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
"IntendedFor": "bids::sub-01/ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
}}
],
"func": [
Expand All @@ -103,13 +103,13 @@ def gen_layout(bids_dir, database_dir=None):
"EchoTime": 1.2,
"PhaseEncodingDirection": "j-",
"TotalReadoutTime": 0.8,
"IntendedFor": "ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
"IntendedFor": "bids::sub-01/ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
}},
{"suffix": "epi", "dir": "PA", "metadata": {
"EchoTime": 1.2,
"PhaseEncodingDirection": "j",
"TotalReadoutTime": 0.8,
"IntendedFor": "ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
"IntendedFor": "bids::sub-01/ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
}}
],
"func": [
Expand Down Expand Up @@ -203,7 +203,7 @@ def gen_layout(bids_dir, database_dir=None):
"metadata": {
"EchoTime1": 1.2,
"EchoTime2": 1.4,
"IntendedFor": "ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
"IntendedFor": "bids::sub-01/ses-02/func/sub-01_ses-02_task-rest_bold.nii.gz"
}
},
{"suffix": "magnitude1", "metadata": {"EchoTime": 1.2}},
Expand All @@ -230,7 +230,7 @@ def gen_layout(bids_dir, database_dir=None):
"metadata": {
"EchoTime1": 1.2,
"EchoTime2": 1.4,
"IntendedFor": "ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
"IntendedFor": "bids::sub-01/ses-03/func/sub-01_ses-03_task-rest_bold.nii.gz"
}
},
{"suffix": "magnitude1", "metadata": {"EchoTime": 1.2}},
Expand Down Expand Up @@ -282,6 +282,17 @@ def test_wrangler_filter(tmpdir, name, skeleton, estimations):
assert len(est) == estimations
clear_registry()

@pytest.mark.parametrize('name,skeleton,estimations', [
('pepolar', pepolar, 3),
('phasediff', phasediff, 3),
])
def test_wrangler_URIs(tmpdir, name, skeleton, estimations):
bids_dir = str(tmpdir / name)
generate_bids_skeleton(bids_dir, skeleton)
layout = gen_layout(bids_dir)
est = find_estimators(layout=layout, subject='01')
assert len(est) == estimations
clear_registry()

def test_single_reverse_pedir(tmp_path):
bids_dir = tmp_path / "bids"
Expand Down
16 changes: 15 additions & 1 deletion sdcflows/utils/wrangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# https://www.nipreps.org/community/licensing/
#
"""Find fieldmaps on the BIDS inputs for :abbr:`SDC (susceptibility distortion correction)`."""
from __future__ import annotations
import logging
from functools import reduce
from itertools import product
Expand All @@ -33,6 +34,19 @@
from .. import fieldmaps as fm


def _resolve_intent(
intent: str,
layout: BIDSLayout,
subject: str
) -> str | None:
root = Path(layout.root)
if intent.startswith("bids::"):
return str(root / intent[6:])
if not intent.startswith("bids:"):
return str(root / f"sub-{subject}" / intent)
return intent


def find_estimators(
*,
layout: BIDSLayout,
Expand Down Expand Up @@ -427,7 +441,7 @@ def find_estimators(
# Find existing IntendedFor targets and warn if missing
all_targets = []
for intent in listify(epi_base_md["IntendedFor"]):
target = layout.get_file(str(subject_root / intent))
target = layout.get_file(_resolve_intent(intent, layout, subject))
if target is None:
logger.debug("Single PE target %s not found", intent)
continue
Expand Down

0 comments on commit 8ca5637

Please sign in to comment.