Skip to content

Commit

Permalink
added single volume fmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
GalKepler committed Sep 15, 2024
1 parent e5cb96b commit 7173e53
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 125 deletions.
108 changes: 0 additions & 108 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 34 additions & 16 deletions src/keprep/workflows/dwi/stages/eddy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from keprep.workflows.dwi.utils import read_field_from_json


def init_eddy_wf(name: str = "eddy_wf") -> pe.Workflow:
def init_eddy_wf(name: str = "eddy_wf", fieldmap_is_4d: bool = True) -> pe.Workflow:
"""
Build the SDC and motion correction workflow.
Expand Down Expand Up @@ -45,7 +45,8 @@ def init_eddy_wf(name: str = "eddy_wf") -> pe.Workflow:
)

dwi_b0_extractor = init_extract_b0_wf(name="dwi_b0_extractor")
fmap_b0_extractor = init_extract_b0_wf(name="fmap_b0_extractor")
if fieldmap_is_4d:
fmap_b0_extractor = init_extract_b0_wf(name="fmap_b0_extractor")

# node to listify opposite phase encoding directions
listify_b0 = pe.Node(niu.Merge(2), name="listify_b0")
Expand Down Expand Up @@ -87,20 +88,6 @@ def init_eddy_wf(name: str = "eddy_wf") -> pe.Workflow:
("outputnode.dwi_reference", "in1"),
],
),
(
inputnode,
fmap_b0_extractor,
[
("fmap_file", "inputnode.dwi_file"),
],
),
(
fmap_b0_extractor,
listify_b0,
[
("outputnode.dwi_reference", "in2"),
],
),
(
listify_b0,
prep_pe_pair,
Expand All @@ -110,6 +97,37 @@ def init_eddy_wf(name: str = "eddy_wf") -> pe.Workflow:
),
]
)
if fieldmap_is_4d:
workflow.connect(
[
(
inputnode,
fmap_b0_extractor,
[
("fmap_file", "inputnode.dwi_file"),
],
),
(
fmap_b0_extractor,
listify_b0,
[
("outputnode.dwi_reference", "in2"),
],
),
]
)
else:
workflow.connect(
[
(
inputnode,
listify_b0,
[
("fmap_file", "in2"),
],
)
]
)

query_pe_dir = pe.Node(
niu.Function(
Expand Down
26 changes: 25 additions & 1 deletion src/keprep/workflows/dwi/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@
from keprep.workflows.dwi.utils import calculate_denoise_window, read_field_from_json


def fieldmap_is_4d(fieldmap_file: str | Path) -> bool:
"""
Check if the fieldmap is 4D.
Parameters
----------
fieldmap_file : Union[str,Path]
path to fieldmap file
Returns
-------
bool
True if the fieldmap is 4D
"""
from nibabel import load

fieldmap_img = load(str(fieldmap_file))
return fieldmap_img.ndim == 4


def init_dwi_preproc_wf(dwi_file: str | Path, subject_data: dict):
"""
Build the dwi preprocessing workflow.
Expand Down Expand Up @@ -76,6 +96,10 @@ def init_dwi_preproc_wf(dwi_file: str | Path, subject_data: dict):
inputnode.inputs.fmap_bvec = Path(layout.get_bvec(fieldmap))
inputnode.inputs.fmap_bval = Path(layout.get_bval(fieldmap))
inputnode.inputs.fmap_json = Path(layout.get_nearest(fieldmap, extension="json"))

# check if fieldmap is 4D
fmap_is_4d = fieldmap_is_4d(fieldmap)

outputnode = pe.Node( # noqa: F841
niu.IdentityInterface(
fields=["dwi_preproc", "dwi_reference", "dwi_mask"],
Expand Down Expand Up @@ -212,7 +236,7 @@ def init_dwi_preproc_wf(dwi_file: str | Path, subject_data: dict):
]
)

eddy_wf = init_eddy_wf()
eddy_wf = init_eddy_wf(fieldmap_is_4d=fmap_is_4d)
workflow.connect(
[
(inputnode, eddy_wf, [("dwi_json", "inputnode.dwi_json")]),
Expand Down

0 comments on commit 7173e53

Please sign in to comment.