Skip to content

Commit 88a3cdb

Browse files
authored
Merge pull request #161 from oesteban/enh/mask-unwarped
ENH: Generate a simple mask after correction
2 parents 194d2ae + 6858ba0 commit 88a3cdb

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

sdcflows/fieldmaps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import re
66
import attr
77
from json import loads
8-
from bids.layout import BIDSFile, parse_file_entities
8+
from bids.layout import parse_file_entities
99
from bids.utils import listify
1010
from niworkflows.utils.bids import relative_to_root
1111
from .utils.bimap import EstimatorRegistry

sdcflows/workflows/apply/correction.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
77

88

9-
def init_unwarp_wf(omp_nthreads=1, debug=False, name="unwarp_wf"):
9+
def init_unwarp_wf(omp_nthreads=1, debug=False, name="unwarp_wf", mask=True):
1010
"""
1111
Set up a workflow that unwarps the input :abbr:`EPI (echo-planar imaging)` dataset.
1212
@@ -24,6 +24,10 @@ def init_unwarp_wf(omp_nthreads=1, debug=False, name="unwarp_wf"):
2424
Maximum number of threads an individual process may use.
2525
name : :obj:`str`
2626
Unique name of this workflow.
27+
debug : :obj:`bool`
28+
Whether to run in *sloppy* mode.
29+
mask : obj:`bool`
30+
Generate a quick mask.
2731
2832
Inputs
2933
------
@@ -41,7 +45,7 @@ def init_unwarp_wf(omp_nthreads=1, debug=False, name="unwarp_wf"):
4145
4246
"""
4347
from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms
44-
from ...interfaces.epi import GetReadoutTime
48+
from ...interfaces.epi import GetReadoutTime, EPIMask
4549
from ...interfaces.bspline import Coefficients2Warp
4650

4751
workflow = Workflow(name=name)
@@ -50,7 +54,8 @@ def init_unwarp_wf(omp_nthreads=1, debug=False, name="unwarp_wf"):
5054
name="inputnode",
5155
)
5256
outputnode = pe.Node(
53-
niu.IdentityInterface(fields=["corrected", "fieldmap"]), name="outputnode"
57+
niu.IdentityInterface(fields=["corrected", "fieldmap", "corrected_mask"]),
58+
name="outputnode",
5459
)
5560

5661
rotime = pe.Node(GetReadoutTime(), name="rotime")
@@ -75,4 +80,16 @@ def init_unwarp_wf(omp_nthreads=1, debug=False, name="unwarp_wf"):
7580
(unwarp, outputnode, [("output_image", "corrected")]),
7681
])
7782
# fmt:on
83+
84+
if not mask:
85+
return workflow
86+
87+
epi_mask = pe.Node(EPIMask(), name="epi_mask")
88+
89+
# fmt:off
90+
workflow.connect([
91+
(unwarp, epi_mask, [("output_image", "in_file")]),
92+
(epi_mask, outputnode, [("out_file", "corrected_mask")]),
93+
])
94+
# fmt:on
7895
return workflow

sdcflows/workflows/apply/tests/test_correct.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ def test_unwarp_wf(tmpdir, datadir, workdir, outdir):
9696
# fmt: off
9797
workflow.connect([
9898
(epi_ref_wf, report, [("outputnode.fmap_ref", "before")]),
99-
(unwarp_wf, report, [("outputnode.corrected", "after")]),
99+
(unwarp_wf, report, [("outputnode.corrected", "after"),
100+
("outputnode.corrected_mask", "wm_seg")]),
100101
(report, ds_report, [("out_report", "in_file")]),
101102
(epi_ref_wf, rep, [("outputnode.fmap_ref", "reference"),
102103
("outputnode.fmap_mask", "mask")]),

0 commit comments

Comments
 (0)