Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ ignore = [
"B019",
"SIM108",
"C901",
"UP038",
]

[tool.ruff.lint.flake8-quotes]
Expand Down
16 changes: 8 additions & 8 deletions sdcflows/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def init_fmap_preproc_wf(
fmap_derivatives_wf = init_fmap_derivatives_wf(
output_dir=str(output_dir),
write_coeff=True,
write_mask=True,
bids_fmap_id=estimator.bids_id,
name=f'fmap_derivatives_wf_{estimator.sanitized_id}',
)
Expand All @@ -157,33 +158,32 @@ def init_fmap_preproc_wf(
niu.IdentityInterface(fields=fields),
name=f'in_{estimator.sanitized_id}',
)
# fmt:off
workflow.connect([
(inputnode, est_wf, [(f, f"inputnode.{f}") for f in fields])
])
# fmt:on
]) # fmt:skip

# fmt:off
workflow.connect([
(est_wf, fmap_derivatives_wf, [
("outputnode.fmap", "inputnode.fieldmap"),
("outputnode.fmap_ref", "inputnode.fmap_ref"),
("outputnode.fmap_coeff", "inputnode.fmap_coeff"),
("outputnode.fmap_mask", "inputnode.fmap_mask"),
]),
(est_wf, fmap_reports_wf, [
("outputnode.fmap", "inputnode.fieldmap"),
("outputnode.fmap_ref", "inputnode.fmap_ref"),
("outputnode.fmap_mask", "inputnode.fmap_mask"),
]),
(est_wf, out_map, [
("outputnode.fmap", "fmap"),
("outputnode.method", "method")
]),
(fmap_derivatives_wf, out_map, [
("outputnode.fieldmap", "fmap"),
("outputnode.fmap_ref", "fmap_ref"),
("outputnode.fmap_coeff", "fmap_coeff"),
("outputnode.fmap_mask", "fmap_mask"),
("outputnode.method", "method")
]),
])
# fmt:on
]) # fmt:skip

for field, mergenode in out_merge.items():
workflow.connect(out_map, field, mergenode, f'in{n}')
Expand Down
70 changes: 49 additions & 21 deletions sdcflows/workflows/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,20 @@ def init_fmap_reports_wf(
suffix='fieldmap',
desc=fmap_type,
dismiss_entities=('fmap',),
allowed_entities=tuple(custom_entities.keys()),
allowed_entities=tuple(custom_entities),
),
name='ds_fmap_report',
)
for k, v in custom_entities.items():
setattr(ds_fmap_report.inputs, k, v)
ds_fmap_report.inputs.trait_set(**custom_entities)

# fmt:off
workflow.connect([
(inputnode, fmap_rpt, [(("fieldmap", _pop), "fieldmap"),
("fmap_ref", "reference"),
("fmap_mask", "mask")]),
(fmap_rpt, ds_fmap_report, [("out_report", "in_file")]),
(inputnode, ds_fmap_report, [("source_files", "source_file")]),

])
# fmt:on
]) # fmt:skip

return workflow

Expand All @@ -126,6 +123,7 @@ def init_fmap_derivatives_wf(
custom_entities=None,
name='fmap_derivatives_wf',
write_coeff=False,
write_mask=False,
):
"""
Set up datasinks to store derivatives in the right location.
Expand Down Expand Up @@ -162,10 +160,14 @@ def init_fmap_derivatives_wf(
workflow = pe.Workflow(name=name)
inputnode = pe.Node(
niu.IdentityInterface(
fields=['source_files', 'fieldmap', 'fmap_coeff', 'fmap_ref', 'fmap_meta']
fields=['source_files', 'fieldmap', 'fmap_coeff', 'fmap_ref', 'fmap_mask', 'fmap_meta']
),
name='inputnode',
)
outputnode = pe.Node(
niu.IdentityInterface(fields=['fieldmap', 'fmap_coeff', 'fmap_ref', 'fmap_mask']),
name='outputnode',
)

merge_fmap = pe.Node(MergeSeries(), name='merge_fmap')

Expand All @@ -176,7 +178,7 @@ def init_fmap_derivatives_wf(
suffix='fieldmap',
datatype='fmap',
dismiss_entities=('fmap',),
allowed_entities=tuple(custom_entities.keys()),
allowed_entities=tuple(custom_entities),
),
name='ds_reference',
)
Expand All @@ -188,19 +190,17 @@ def init_fmap_derivatives_wf(
suffix='fieldmap',
datatype='fmap',
compress=True,
allowed_entities=tuple(custom_entities.keys()),
allowed_entities=tuple(custom_entities),
),
name='ds_fieldmap',
)
ds_fieldmap.inputs.Units = 'Hz'
if bids_fmap_id:
ds_fieldmap.inputs.B0FieldIdentifier = bids_fmap_id

for k, v in custom_entities.items():
setattr(ds_reference.inputs, k, v)
setattr(ds_fieldmap.inputs, k, v)
ds_reference.inputs.trait_set(**custom_entities)
ds_fieldmap.inputs.trait_set(**custom_entities)

# fmt:off
workflow.connect([
(inputnode, merge_fmap, [("fieldmap", "in_files")]),
(inputnode, ds_reference, [("source_files", "source_file"),
Expand All @@ -213,8 +213,38 @@ def init_fmap_derivatives_wf(
(("out_file", _getname), "AnatomicalReference"),
]),
(inputnode, ds_fieldmap, [(("fmap_meta", _selectintent), "IntendedFor")]),
])
# fmt:on
(ds_fieldmap, outputnode, [("out_file", "fieldmap")]),
(ds_reference, outputnode, [("out_file", "fmap_ref")]),
]) # fmt:skip

if write_mask:
ds_mask = pe.Node(
DerivativesDataSink(
base_directory=output_dir,
compress=True,
desc='brain',
suffix='mask',
datatype='fmap',
dismiss_entities=('fmap',),
allowed_entities=tuple(custom_entities),
),
name='ds_mask',
)
ds_mask._interface._file_patterns += (
'sub-{subject}[/ses-{session}]/{datatype<fmap>|fmap}/'
'sub-{subject}[_ses-{session}][_hash-{hash}][_acq-{acquisition}]'
'[_dir-{direction}][_run-{run}][_part-{part}][_space-{space}]'
'[_cohort-{cohort}][_res-{resolution}][_fmapid-{fmapid}]'
'[_desc-{desc}]_{suffix<mask>}{extension<.nii|.nii.gz|.json>|.nii.gz}',
)
Comment on lines +233 to +239
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opened nipreps/niworkflows#977 to make this less hacky


ds_mask.inputs.trait_set(**custom_entities)

workflow.connect([
(inputnode, ds_mask, [("source_files", "source_file"),
("fmap_mask", "in_file")]),
(ds_mask, outputnode, [("out_file", "fmap_mask")]),
]) # fmt:skip

if not write_coeff:
return workflow
Expand All @@ -225,26 +255,24 @@ def init_fmap_derivatives_wf(
suffix='fieldmap',
datatype='fmap',
compress=True,
allowed_entities=tuple(custom_entities.keys()),
allowed_entities=tuple(custom_entities),
),
name='ds_coeff',
iterfield=('in_file', 'desc'),
)

gen_desc = pe.Node(niu.Function(function=_gendesc), name='gen_desc')

for k, v in custom_entities.items():
setattr(ds_coeff.inputs, k, v)
ds_coeff.inputs.trait_set(**custom_entities)

# fmt:off
workflow.connect([
(inputnode, ds_coeff, [("source_files", "source_file"),
("fmap_coeff", "in_file")]),
(inputnode, gen_desc, [("fmap_coeff", "infiles")]),
(gen_desc, ds_coeff, [("out", "desc")]),
(ds_coeff, ds_fieldmap, [(("out_file", _getname), "AssociatedCoefficients")]),
])
# fmt:on
(ds_coeff, outputnode, [("out_file", "fmap_coeff")]),
]) # fmt:skip

return workflow

Expand Down
Loading