Skip to content

Commit

Permalink
Merge pull request #360 from effigies/fix/synthetic_intendedfor
Browse files Browse the repository at this point in the history
FIX: Ensure IntendedFor metadata is a subject-relative path
  • Loading branch information
effigies authored Jun 1, 2023
2 parents b40d23a + c4ebb64 commit 4aa93fc
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
54 changes: 54 additions & 0 deletions sdcflows/utils/tests/test_wrangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,43 @@
}
}
]
},
{
"session": "04",
"anat": [{"suffix": "T1w", "metadata": {"EchoTime": 1}}],
"fmap": [
{"suffix": "epi", "dir": "AP", "metadata": {
"EchoTime": 1.2,
"PhaseEncodingDirection": "j-",
"TotalReadoutTime": 0.8,
"IntendedFor": [
"ses-04/func/sub-01_ses-04_task-rest_run-1_bold.nii.gz",
"ses-04/func/sub-01_ses-04_task-rest_run-2_bold.nii.gz",
],
}},
],
"func": [
{
"task": "rest",
"run": 1,
"suffix": "bold",
"metadata": {
"RepetitionTime": 0.8,
"TotalReadoutTime": 0.5,
"PhaseEncodingDirection": "j"
}
},
{
"task": "rest",
"run": 2,
"suffix": "bold",
"metadata": {
"RepetitionTime": 0.8,
"TotalReadoutTime": 0.5,
"PhaseEncodingDirection": "j"
}
},
]
}
]
}
Expand Down Expand Up @@ -216,3 +253,20 @@ def test_wrangler_filter(tmpdir, name, skeleton, estimations):
est = find_estimators(layout=layout, subject='01', bids_filters=filters['fmap'])
assert len(est) == estimations
clear_registry()


def test_single_reverse_pedir(tmp_path):
bids_dir = tmp_path / "bids"
generate_bids_skeleton(bids_dir, pepolar)
layout = gen_layout(bids_dir)
est = find_estimators(layout=layout, subject='01', bids_filters={'session': '04'})
assert len(est) == 2
subject_root = bids_dir / 'sub-01'
for estimator in est:
assert len(estimator.sources) == 2
epi, bold = estimator.sources
# Just checking order
assert epi.entities['fmap'] == 'epi'
# IntendedFor is a list of strings
# REGRESSION: The result was a PyBIDS BIDSFile (fmriprep#3020)
assert epi.metadata['IntendedFor'] == [str(bold.path.relative_to(subject_root))]
5 changes: 4 additions & 1 deletion sdcflows/utils/wrangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,10 @@ def find_estimators(
# The new estimator is IntendedFor the individual targets,
# even if the EPI file is IntendedFor multiple
estimator_md = epi_base_md.copy()
estimator_md["IntendedFor"] = intent
estimator_md["IntendedFor"] = [
str(Path(pathlike).relative_to(subject_root))
for pathlike in intent
]
try:
e = fm.FieldmapEstimation(
[
Expand Down

0 comments on commit 4aa93fc

Please sign in to comment.