Skip to content

Commit 7173e53

Browse files
committed
added single volume fmaps
1 parent e5cb96b commit 7173e53

File tree

3 files changed

+59
-125
lines changed

3 files changed

+59
-125
lines changed

poetry.lock

-108
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/keprep/workflows/dwi/stages/eddy.py

+34-16
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from keprep.workflows.dwi.utils import read_field_from_json
1111

1212

13-
def init_eddy_wf(name: str = "eddy_wf") -> pe.Workflow:
13+
def init_eddy_wf(name: str = "eddy_wf", fieldmap_is_4d: bool = True) -> pe.Workflow:
1414
"""
1515
Build the SDC and motion correction workflow.
1616
@@ -45,7 +45,8 @@ def init_eddy_wf(name: str = "eddy_wf") -> pe.Workflow:
4545
)
4646

4747
dwi_b0_extractor = init_extract_b0_wf(name="dwi_b0_extractor")
48-
fmap_b0_extractor = init_extract_b0_wf(name="fmap_b0_extractor")
48+
if fieldmap_is_4d:
49+
fmap_b0_extractor = init_extract_b0_wf(name="fmap_b0_extractor")
4950

5051
# node to listify opposite phase encoding directions
5152
listify_b0 = pe.Node(niu.Merge(2), name="listify_b0")
@@ -87,20 +88,6 @@ def init_eddy_wf(name: str = "eddy_wf") -> pe.Workflow:
8788
("outputnode.dwi_reference", "in1"),
8889
],
8990
),
90-
(
91-
inputnode,
92-
fmap_b0_extractor,
93-
[
94-
("fmap_file", "inputnode.dwi_file"),
95-
],
96-
),
97-
(
98-
fmap_b0_extractor,
99-
listify_b0,
100-
[
101-
("outputnode.dwi_reference", "in2"),
102-
],
103-
),
10491
(
10592
listify_b0,
10693
prep_pe_pair,
@@ -110,6 +97,37 @@ def init_eddy_wf(name: str = "eddy_wf") -> pe.Workflow:
11097
),
11198
]
11299
)
100+
if fieldmap_is_4d:
101+
workflow.connect(
102+
[
103+
(
104+
inputnode,
105+
fmap_b0_extractor,
106+
[
107+
("fmap_file", "inputnode.dwi_file"),
108+
],
109+
),
110+
(
111+
fmap_b0_extractor,
112+
listify_b0,
113+
[
114+
("outputnode.dwi_reference", "in2"),
115+
],
116+
),
117+
]
118+
)
119+
else:
120+
workflow.connect(
121+
[
122+
(
123+
inputnode,
124+
listify_b0,
125+
[
126+
("fmap_file", "in2"),
127+
],
128+
)
129+
]
130+
)
113131

114132
query_pe_dir = pe.Node(
115133
niu.Function(

src/keprep/workflows/dwi/workflow.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@
2121
from keprep.workflows.dwi.utils import calculate_denoise_window, read_field_from_json
2222

2323

24+
def fieldmap_is_4d(fieldmap_file: str | Path) -> bool:
25+
"""
26+
Check if the fieldmap is 4D.
27+
28+
Parameters
29+
----------
30+
fieldmap_file : Union[str,Path]
31+
path to fieldmap file
32+
33+
Returns
34+
-------
35+
bool
36+
True if the fieldmap is 4D
37+
"""
38+
from nibabel import load
39+
40+
fieldmap_img = load(str(fieldmap_file))
41+
return fieldmap_img.ndim == 4
42+
43+
2444
def init_dwi_preproc_wf(dwi_file: str | Path, subject_data: dict):
2545
"""
2646
Build the dwi preprocessing workflow.
@@ -76,6 +96,10 @@ def init_dwi_preproc_wf(dwi_file: str | Path, subject_data: dict):
7696
inputnode.inputs.fmap_bvec = Path(layout.get_bvec(fieldmap))
7797
inputnode.inputs.fmap_bval = Path(layout.get_bval(fieldmap))
7898
inputnode.inputs.fmap_json = Path(layout.get_nearest(fieldmap, extension="json"))
99+
100+
# check if fieldmap is 4D
101+
fmap_is_4d = fieldmap_is_4d(fieldmap)
102+
79103
outputnode = pe.Node( # noqa: F841
80104
niu.IdentityInterface(
81105
fields=["dwi_preproc", "dwi_reference", "dwi_mask"],
@@ -212,7 +236,7 @@ def init_dwi_preproc_wf(dwi_file: str | Path, subject_data: dict):
212236
]
213237
)
214238

215-
eddy_wf = init_eddy_wf()
239+
eddy_wf = init_eddy_wf(fieldmap_is_4d=fmap_is_4d)
216240
workflow.connect(
217241
[
218242
(inputnode, eddy_wf, [("dwi_json", "inputnode.dwi_json")]),

0 commit comments

Comments
 (0)