Skip to content

Commit ecc3d0d

Browse files
authored
Merge pull request #150 from oesteban/fix/issue-146
ENH: Write ``fmapid-`` entity in Derivatives
2 parents 17aa3a4 + 2ece413 commit ecc3d0d

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

sdcflows/workflows/base.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,19 @@ def init_fmap_preproc_wf(
7171

7272
workflow = Workflow(name=name)
7373

74-
out_fields = ("fmap", "fmap_ref", "fmap_coeff", "fmap_mask")
74+
out_fields = ("fmap", "fmap_ref", "fmap_coeff", "fmap_mask", "fmap_id")
7575
out_merge = {
7676
f: pe.Node(niu.Merge(len(estimators)), name=f"out_merge_{f}")
7777
for f in out_fields
7878
}
7979
outputnode = pe.Node(niu.IdentityInterface(fields=out_fields), name="outputnode")
8080

81-
workflow.connect([
82-
(mergenode, outputnode, [("out", field)])
83-
for field, mergenode in out_merge.items()
84-
])
81+
workflow.connect(
82+
[
83+
(mergenode, outputnode, [("out", field)])
84+
for field, mergenode in out_merge.items()
85+
]
86+
)
8587

8688
for n, estimator in enumerate(estimators):
8789
est_wf = estimator.get_workflow(omp_nthreads=omp_nthreads, debug=debug)
@@ -90,11 +92,12 @@ def init_fmap_preproc_wf(
9092
out_map = pe.Node(
9193
niu.IdentityInterface(fields=out_fields), name=f"out_{estimator.bids_id}"
9294
)
95+
out_map.inputs.fmap_id = estimator.bids_id
9396

9497
fmap_derivatives_wf = init_fmap_derivatives_wf(
9598
output_dir=str(output_dir),
9699
write_coeff=True,
97-
bids_fmap_id=estimator.bids_id.replace("_", ""),
100+
bids_fmap_id=estimator.bids_id,
98101
name=f"fmap_derivatives_wf_{estimator.bids_id}",
99102
)
100103
fmap_derivatives_wf.inputs.inputnode.source_files = source_files
@@ -105,6 +108,7 @@ def init_fmap_preproc_wf(
105108
fmap_reports_wf = init_fmap_reports_wf(
106109
output_dir=str(output_dir),
107110
fmap_type=str(estimator.method).rpartition(".")[-1].lower(),
111+
bids_fmap_id=estimator.bids_id,
108112
name=f"fmap_reports_wf_{estimator.bids_id}",
109113
)
110114
fmap_reports_wf.inputs.inputnode.source_files = source_files

sdcflows/workflows/outputs.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ class DerivativesDataSink(_DDS):
1616

1717

1818
def init_fmap_reports_wf(
19-
*, output_dir, fmap_type, custom_entities=None, name="fmap_reports_wf",
19+
*,
20+
output_dir,
21+
fmap_type,
22+
bids_fmap_id=None,
23+
custom_entities=None,
24+
name="fmap_reports_wf",
2025
):
2126
"""
2227
Set up a battery of datasinks to store reports in the right location.
@@ -25,10 +30,12 @@ def init_fmap_reports_wf(
2530
----------
2631
fmap_type : :obj:`str`
2732
The fieldmap estimator type.
28-
custom_entities : :obj:`dict`
29-
Define extra entities that will be written out in filenames.
3033
output_dir : :obj:`str`
3134
Directory in which to save derivatives
35+
bids_fmap_id : :obj:`str`
36+
Sets the ``B0FieldIdentifier`` metadata into the outputs.
37+
custom_entities : :obj:`dict`
38+
Define extra entities that will be written out in filenames.
3239
name : :obj:`str`
3340
Workflow name (default: ``"fmap_reports_wf"``)
3441
@@ -47,6 +54,8 @@ def init_fmap_reports_wf(
4754
from ..interfaces.reportlets import FieldmapReportlet
4855

4956
custom_entities = custom_entities or {}
57+
if bids_fmap_id:
58+
custom_entities["fmapid"] = bids_fmap_id.replace("_", "")
5059

5160
workflow = pe.Workflow(name=name)
5261
inputnode = pe.Node(
@@ -100,14 +109,16 @@ def init_fmap_derivatives_wf(
100109
101110
Parameters
102111
----------
112+
output_dir : :obj:`str`
113+
Directory in which to save derivatives
103114
bids_fmap_id : :obj:`str`
104115
Sets the ``B0FieldIdentifier`` metadata into the outputs.
105116
custom_entities : :obj:`dict`
106117
Define extra entities that will be written out in filenames.
107-
output_dir : :obj:`str`
108-
Directory in which to save derivatives
109118
name : :obj:`str`
110119
Workflow name (default: ``"fmap_derivatives_wf"``)
120+
write_coeff : :obj:`bool`
121+
Build the workflow path to map coefficients into target space.
111122
112123
Inputs
113124
------
@@ -122,6 +133,8 @@ def init_fmap_derivatives_wf(
122133
123134
"""
124135
custom_entities = custom_entities or {}
136+
if bids_fmap_id:
137+
custom_entities["fmapid"] = bids_fmap_id.replace("_", "")
125138

126139
workflow = pe.Workflow(name=name)
127140
inputnode = pe.Node(

0 commit comments

Comments
 (0)