Skip to content

Commit 17aa3a4

Browse files
authored
Merge pull request #149 from oesteban/fix/issue-147
ENH: Multiplex fieldmap estimation outputs into a single ``outputnode``
2 parents 4d02005 + afd4a00 commit 17aa3a4

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

sdcflows/workflows/base.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,25 @@ def init_fmap_preproc_wf(
7070
from .outputs import init_fmap_derivatives_wf, init_fmap_reports_wf
7171

7272
workflow = Workflow(name=name)
73-
for estimator in estimators:
73+
74+
out_fields = ("fmap", "fmap_ref", "fmap_coeff", "fmap_mask")
75+
out_merge = {
76+
f: pe.Node(niu.Merge(len(estimators)), name=f"out_merge_{f}")
77+
for f in out_fields
78+
}
79+
outputnode = pe.Node(niu.IdentityInterface(fields=out_fields), name="outputnode")
80+
81+
workflow.connect([
82+
(mergenode, outputnode, [("out", field)])
83+
for field, mergenode in out_merge.items()
84+
])
85+
86+
for n, estimator in enumerate(estimators):
7487
est_wf = estimator.get_workflow(omp_nthreads=omp_nthreads, debug=debug)
7588
source_files = [str(f.path) for f in estimator.sources]
7689

77-
outputnode = pe.Node(
78-
niu.IdentityInterface(
79-
fields=["fmap", "fmap_ref", "fmap_coeff", "fmap_mask"]
80-
),
81-
name=f"out_{estimator.bids_id}",
90+
out_map = pe.Node(
91+
niu.IdentityInterface(fields=out_fields), name=f"out_{estimator.bids_id}"
8292
)
8393

8494
fmap_derivatives_wf = init_fmap_derivatives_wf(
@@ -116,7 +126,7 @@ def init_fmap_preproc_wf(
116126
(est_wf, fmap_reports_wf, [
117127
("outputnode.fmap_mask", "inputnode.fmap_mask"),
118128
]),
119-
(est_wf, outputnode, [("outputnode.fmap_mask", "fmap_mask")]),
129+
(est_wf, out_map, [("outputnode.fmap_mask", "fmap_mask")]),
120130
])
121131
# fmt:on
122132

@@ -131,11 +141,15 @@ def init_fmap_preproc_wf(
131141
("outputnode.fmap", "inputnode.fieldmap"),
132142
("outputnode.fmap_ref", "inputnode.fmap_ref"),
133143
]),
134-
(est_wf, outputnode, [
144+
(est_wf, out_map, [
135145
("outputnode.fmap", "fmap"),
136146
("outputnode.fmap_ref", "fmap_ref"),
137147
("outputnode.fmap_coeff", "fmap_coeff"),
138148
]),
139149
])
140150
# fmt:on
151+
152+
for field, mergenode in out_merge.items():
153+
workflow.connect(out_map, field, mergenode, f"in{n}")
154+
141155
return workflow

0 commit comments

Comments
 (0)