Skip to content

Commit eff250b

Browse files
committed
gradunwarp wip
1 parent d1bd6f9 commit eff250b

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

fmriprep/cli/parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ def _slice_time_ref(value, parser):
279279
help="Ignore selected aspects of the input dataset to disable corresponding "
280280
"parts of the workflow (a space delimited list)",
281281
)
282+
g_conf.add_argument(
283+
"--gradunwarp-file",
284+
metavar="PATH",
285+
type=Path,
286+
help="Path to vendor file for gradunwarp gradient distortion "
287+
"correction.",
288+
)
282289
g_conf.add_argument(
283290
"--output-spaces",
284291
nargs="*",

fmriprep/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,9 @@ class workflow(_Config):
536536
ignore = None
537537
"""Ignore particular steps for *fMRIPrep*."""
538538
longitudinal = False
539-
"""Run FreeSurfer ``recon-all`` with the ``-logitudinal`` flag."""
539+
"""Run FreeSurfer ``recon-all`` with the ``-longitudinal`` flag."""
540+
gradunwarp_file = None
541+
"""Run GradUnwarp using the provided gradient or coefficient file"""
540542
medial_surface_nan = None
541543
"""Fill medial surface with :abbr:`NaNs (not-a-number)` when sampling."""
542544
project_goodvoxels = False

fmriprep/workflows/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ def init_single_subject_wf(subject_id: str):
319319
spaces=spaces,
320320
t1w=subject_data['t1w'],
321321
t2w=subject_data['t2w'],
322+
gradunwarp_file=config.workflow.gradunwarp_file,
322323
cifti_output=config.workflow.cifti_output,
323324
)
324325
# fmt:off

fmriprep/workflows/bold/base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False):
111111
LTA-style affine matrix translating from T1w to FreeSurfer-conformed subject space
112112
fsnative2t1w_xfm
113113
LTA-style affine matrix translating from FreeSurfer-conformed subject space to T1w
114+
gradunwarp_file
115+
Vendor provided .coeff or .grad file for gradient distortion correction.
114116
115117
Outputs
116118
-------
@@ -187,6 +189,7 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False):
187189
188190
"""
189191
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
192+
from niworkflows.workflows.gradunwarp import init_gradunwarp_wf
190193
from niworkflows.func.util import init_bold_reference_wf
191194
from niworkflows.interfaces.nibabel import ApplyMask
192195
from niworkflows.interfaces.reportlets.registration import (
@@ -478,6 +481,14 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False):
478481
# Top-level BOLD splitter
479482
bold_split = pe.Node(FSLSplit(dimension="t"), name="bold_split", mem_gb=mem_gb["filesize"] * 3)
480483

484+
# Gradient unwarping
485+
if config.workflow.gradunwarp_file:
486+
gradunwarp_wf = init_gradunwarp_wf()
487+
gradunwarp_wf.inputs.inputnode.grad_file = gradunwarp_file
488+
workflow.connect(
489+
[(initial_boldref_wf, gradunwarp_wf, [('raw_ref_image', 'in_file')])]
490+
)
491+
481492
# HMC on the BOLD
482493
bold_hmc_wf = init_bold_hmc_wf(
483494
name="bold_hmc_wf", mem_gb=mem_gb["filesize"], omp_nthreads=omp_nthreads
@@ -505,6 +516,7 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False):
505516
use_compression=False,
506517
)
507518
bold_t1_trans_wf.inputs.inputnode.fieldwarp = "identity"
519+
bold_t1_trans_wf.inputs.inputnode.gradient_warp = "identity"
508520

509521
# get confounds
510522
bold_confounds_wf = init_bold_confs_wf(
@@ -779,6 +791,7 @@ def init_func_preproc_wf(bold_file, has_fieldmap=False):
779791
use_compression=not config.execution.low_mem,
780792
)
781793
bold_std_trans_wf.inputs.inputnode.fieldwarp = "identity"
794+
bold_std_trans_wf.inputs.inputnode.gradient_warp = "identity"
782795

783796
# fmt:off
784797
workflow.connect([
@@ -1010,6 +1023,7 @@ def _last(inlist):
10101023
name="bold_bold_trans_wf",
10111024
)
10121025
bold_bold_trans_wf.inputs.inputnode.fieldwarp = "identity"
1026+
bold_bold_trans_wf.inputs.inputnode.gradient_warp = "identity"
10131027

10141028
# fmt:off
10151029
workflow.connect([

fmriprep/workflows/bold/resampling.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ def init_bold_std_trans_wf(
912912
"bold_split",
913913
"t2star",
914914
"fieldwarp",
915+
"gradient_warp",
915916
"hmc_xforms",
916917
"itk_bold_to_t1",
917918
"name_source",
@@ -964,7 +965,7 @@ def init_bold_std_trans_wf(
964965
)
965966

966967
merge_xforms = pe.Node(
967-
niu.Merge(4),
968+
niu.Merge(5),
968969
name="merge_xforms",
969970
run_without_submitting=True,
970971
mem_gb=DEFAULT_MEMORY_MIN_GB,
@@ -994,7 +995,8 @@ def init_bold_std_trans_wf(
994995
("templates", "keys")]),
995996
(inputnode, mask_std_tfm, [("bold_mask", "input_image")]),
996997
(inputnode, gen_ref, [(("bold_split", _first), "moving_image")]),
997-
(inputnode, merge_xforms, [("hmc_xforms", "in4"),
998+
(inputnode, merge_xforms, [("gradient_warp", "in5"),
999+
("hmc_xforms", "in4"),
9981000
("fieldwarp", "in3"),
9991001
(("itk_bold_to_t1", _aslist), "in2")]),
10001002
(inputnode, merge, [("name_source", "header_source")]),
@@ -1170,7 +1172,9 @@ def init_bold_preproc_trans_wf(
11701172
)
11711173

11721174
inputnode = pe.Node(
1173-
niu.IdentityInterface(fields=["name_source", "bold_file", "hmc_xforms", "fieldwarp"]),
1175+
niu.IdentityInterface(
1176+
fields=["name_source", "bold_file", "hmc_xforms", "fieldwarp", "gradient_warp"]
1177+
),
11741178
name="inputnode",
11751179
)
11761180

@@ -1203,7 +1207,8 @@ def init_bold_preproc_trans_wf(
12031207
# fmt:off
12041208
workflow.connect([
12051209
(inputnode, merge_xforms, [("fieldwarp", "in1"),
1206-
("hmc_xforms", "in2")]),
1210+
("hmc_xforms", "in2"),
1211+
("gradient_warp", "in3")]),
12071212
(inputnode, bold_transform, [("bold_file", "input_image"),
12081213
(("bold_file", _first), "reference_image")]),
12091214
(inputnode, merge, [("name_source", "header_source")]),

0 commit comments

Comments
 (0)