Skip to content

Commit 1a6d3b9

Browse files
authored
FIX: Use sanitized fieldmap naming (#3471)
Addresses #3468 Changes were made in sdcflows, but forgotten here... Replaces #3470
2 parents 70fcdea + 1c9029a commit 1a6d3b9

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

fmriprep/workflows/base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ def init_single_subject_wf(subject_id: str):
692692
if len(set(suffices)) == 1 or (
693693
len(suffices) == 2 and all(suf in ('epi', 'bold', 'sbref') for suf in suffices)
694694
):
695-
wf_inputs = getattr(fmap_wf.inputs, f'in_{estimator.bids_id}')
695+
wf_inputs = getattr(fmap_wf.inputs, f'in_{estimator.sanitized_id}')
696696
wf_inputs.in_data = [str(s.path) for s in estimator.sources]
697697
wf_inputs.metadata = [s.metadata for s in estimator.sources]
698698
else:
@@ -710,7 +710,7 @@ def init_single_subject_wf(subject_id: str):
710710
debug=config.execution.sloppy,
711711
auto_bold_nss=True,
712712
t1w_inversion=False,
713-
name=f'syn_preprocessing_{estimator.bids_id}',
713+
name=f'syn_preprocessing_{estimator.sanitized_id}',
714714
)
715715
syn_preprocessing_wf.inputs.inputnode.in_epis = sources
716716
syn_preprocessing_wf.inputs.inputnode.in_meta = source_meta
@@ -724,11 +724,11 @@ def init_single_subject_wf(subject_id: str):
724724
('std2anat_xfm', 'inputnode.std2anat_xfm'),
725725
]),
726726
(syn_preprocessing_wf, fmap_wf, [
727-
('outputnode.epi_ref', f'in_{estimator.bids_id}.epi_ref'),
728-
('outputnode.epi_mask', f'in_{estimator.bids_id}.epi_mask'),
729-
('outputnode.anat_ref', f'in_{estimator.bids_id}.anat_ref'),
730-
('outputnode.anat_mask', f'in_{estimator.bids_id}.anat_mask'),
731-
('outputnode.sd_prior', f'in_{estimator.bids_id}.sd_prior'),
727+
('outputnode.epi_ref', f'in_{estimator.sanitized_id}.epi_ref'),
728+
('outputnode.epi_mask', f'in_{estimator.sanitized_id}.epi_mask'),
729+
('outputnode.anat_ref', f'in_{estimator.sanitized_id}.anat_ref'),
730+
('outputnode.anat_mask', f'in_{estimator.sanitized_id}.anat_mask'),
731+
('outputnode.sd_prior', f'in_{estimator.sanitized_id}.sd_prior'),
732732
]),
733733
]) # fmt:skip
734734

fmriprep/workflows/tests/test_base.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@
6060
{'suffix': 'magnitude1', 'metadata': {'EchoTime': 0.005}},
6161
{
6262
'suffix': 'epi',
63-
'direction': 'PA',
63+
'dir': 'PA',
6464
'metadata': {'PhaseEncodingDirection': 'j', 'TotalReadoutTime': 0.6},
6565
},
6666
{
6767
'suffix': 'epi',
68-
'direction': 'AP',
68+
'dir': 'AP',
6969
'metadata': {'PhaseEncodingDirection': 'j-', 'TotalReadoutTime': 0.6},
7070
},
7171
],
@@ -230,6 +230,25 @@ def test_init_fmriprep_wf(
230230
generate_expanded_graph(wf._create_flat_graph())
231231

232232

233+
def test_init_fmriprep_wf_sanitize_fmaps(tmp_path):
234+
bids_dir = tmp_path / 'bids'
235+
236+
spec = deepcopy(BASE_LAYOUT)
237+
spec['01']['func'][0]['metadata']['B0FieldSource'] = 'epi<<run1>>'
238+
spec['01']['fmap'][2]['metadata']['B0FieldIdentifier'] = 'epi<<run1>>'
239+
spec['01']['fmap'][3]['metadata']['B0FieldIdentifier'] = 'epi<<run1>>'
240+
del spec['01']['func'][4:]
241+
242+
generate_bids_skeleton(bids_dir, spec)
243+
img = nb.Nifti1Image(np.zeros((10, 10, 10, 10)), np.eye(4))
244+
for img_path in bids_dir.glob('sub-01/*/*.nii.gz'):
245+
img.to_filename(img_path)
246+
247+
with mock_config(bids_dir=bids_dir):
248+
wf = init_fmriprep_wf()
249+
generate_expanded_graph(wf._create_flat_graph())
250+
251+
233252
def test_get_estimator_none(tmp_path):
234253
bids_dir = tmp_path / 'bids'
235254

@@ -265,6 +284,25 @@ def test_get_estimator_b0field_and_intendedfor(tmp_path):
265284
)
266285

267286
assert get_estimator(layout, bold_files[0]) == ('epi',)
287+
# if B0FieldIdentifiers are found, IntendedFor will not be used
288+
assert get_estimator(layout, bold_files[1]) == ()
289+
290+
291+
def test_get_estimator_intendedfor(tmp_path):
292+
bids_dir = tmp_path / 'bids'
293+
294+
# Set B0FieldSource for run 1
295+
spec = deepcopy(BASE_LAYOUT)
296+
spec['01']['fmap'][0]['metadata']['IntendedFor'] = 'func/sub-01_task-rest_run-2_bold.nii.gz'
297+
298+
generate_bids_skeleton(bids_dir, spec)
299+
layout = bids.BIDSLayout(bids_dir)
300+
_ = find_estimators(layout=layout, subject='01')
301+
302+
bold_files = sorted(
303+
layout.get(suffix='bold', task='rest', extension='.nii.gz', return_type='file')
304+
)
305+
268306
assert get_estimator(layout, bold_files[1]) == ('auto_00000',)
269307

270308

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies = [
3434
"psutil >= 5.4",
3535
"pybids >= 0.16",
3636
"requests >= 2.27",
37-
"sdcflows >= 2.13.0",
37+
"sdcflows >= 2.13.1",
3838
"smriprep >= 0.18.0",
3939
"tedana >= 25.0.0",
4040
"templateflow >= 24.2.2",

0 commit comments

Comments
 (0)