Skip to content

Commit 8d0822e

Browse files
committed
feat(cli): Disable Jacobians by default except PEPOLAR, allow forcing
1 parent d5743d8 commit 8d0822e

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

fmriprep/cli/parser.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def _slice_time_ref(value, parser):
347347
action='store',
348348
nargs='+',
349349
default=[],
350-
choices=['bbr', 'no-bbr', 'syn-sdc'],
350+
choices=['bbr', 'no-bbr', 'syn-sdc', 'fmap-jacobian'],
351351
help='Force selected processing choices, overriding automatic selections '
352352
'(a space delimited list).\n'
353353
' * [no-]bbr: Use/disable boundary-based registration for BOLD-to-T1w coregistration\n'
@@ -801,12 +801,20 @@ def parse_args(args=None, namespace=None):
801801
config.from_dict(vars(opts), init=['nipype'])
802802

803803
# Consistency checks
804-
if 'bbr' in config.workflow.force and 'no-bbr' in config.workflow.force:
804+
force_set = set(config.workflow.force)
805+
ignore_set = set(config.workflow.ignore)
806+
if {'bbr', 'no-bbr'} <= force_set:
805807
msg = (
806808
'Cannot force and disable boundary-based registration at the same time. '
807809
'Remove `bbr` or `no-bbr` from the `--force` options.'
808810
)
809811
raise ValueError(msg)
812+
if 'fmap-jacobian' in force_set & ignore_set:
813+
msg = (
814+
'Cannot force and ignore fieldmap Jacobian correction. '
815+
'Remove `fmap-jacobian` from either the `--force` or the `--ignore` option.'
816+
)
817+
raise ValueError(msg)
810818

811819
if not config.execution.notrack:
812820
import importlib.util

fmriprep/workflows/base.py

+11
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ def init_single_subject_wf(subject_id: str):
566566
for field in ['fmap', 'fmap_ref', 'fmap_coeff', 'fmap_mask', 'fmap_id', 'sdc_method']
567567
}
568568

569+
estimator_types = {est.bids_id: est.method for est in all_estimators}
569570
fmap_estimators = []
570571
if all_estimators:
571572
# Find precomputed fieldmaps that apply to this workflow
@@ -738,6 +739,15 @@ def init_single_subject_wf(subject_id: str):
738739
for bold_series in bold_runs:
739740
bold_file = bold_series[0]
740741
fieldmap_id = estimator_map.get(bold_file)
742+
jacobian = False
743+
744+
if fieldmap_id:
745+
if 'fmap-jacobian' in config.workflow.force:
746+
jacobian = True
747+
elif 'fmap-jacobian' not in config.workflow.ignore:
748+
# Default behavior is to only use Jacobians for PEPOLAR fieldmaps
749+
est_type = estimator_types[fieldmap_id]
750+
jacobian = est_type == est_type.__class__.PEPOLAR
741751

742752
functional_cache = {}
743753
if config.execution.derivatives:
@@ -758,6 +768,7 @@ def init_single_subject_wf(subject_id: str):
758768
bold_series=bold_series,
759769
precomputed=functional_cache,
760770
fieldmap_id=fieldmap_id,
771+
jacobian=jacobian,
761772
)
762773
if bold_wf is None:
763774
continue

fmriprep/workflows/bold/base.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def init_bold_wf(
5757
bold_series: list[str],
5858
precomputed: dict = None,
5959
fieldmap_id: str | None = None,
60+
jacobian: bool = False,
6061
) -> pe.Workflow:
6162
"""
6263
This workflow controls the functional preprocessing stages of *fMRIPrep*.
@@ -253,6 +254,7 @@ def init_bold_wf(
253254
bold_series=bold_series,
254255
precomputed=precomputed,
255256
fieldmap_id=fieldmap_id,
257+
jacobian=jacobian,
256258
omp_nthreads=omp_nthreads,
257259
)
258260

@@ -292,6 +294,7 @@ def init_bold_wf(
292294
bold_native_wf = init_bold_native_wf(
293295
bold_series=bold_series,
294296
fieldmap_id=fieldmap_id,
297+
jacobian=jacobian,
295298
omp_nthreads=omp_nthreads,
296299
)
297300

@@ -383,7 +386,7 @@ def init_bold_wf(
383386
fieldmap_id=fieldmap_id if not multiecho else None,
384387
omp_nthreads=omp_nthreads,
385388
mem_gb=mem_gb,
386-
jacobian='fmap-jacobian' not in config.workflow.ignore,
389+
jacobian=jacobian,
387390
name='bold_anat_wf',
388391
)
389392
bold_anat_wf.inputs.inputnode.resolution = 'native'
@@ -443,7 +446,7 @@ def init_bold_wf(
443446
fieldmap_id=fieldmap_id if not multiecho else None,
444447
omp_nthreads=omp_nthreads,
445448
mem_gb=mem_gb,
446-
jacobian='fmap-jacobian' not in config.workflow.ignore,
449+
jacobian=jacobian,
447450
name='bold_std_wf',
448451
)
449452
ds_bold_std_wf = init_ds_volumes_wf(
@@ -550,7 +553,7 @@ def init_bold_wf(
550553
fieldmap_id=fieldmap_id if not multiecho else None,
551554
omp_nthreads=omp_nthreads,
552555
mem_gb=mem_gb,
553-
jacobian='fmap-jacobian' not in config.workflow.ignore,
556+
jacobian=jacobian,
554557
name='bold_MNI6_wf',
555558
)
556559

fmriprep/workflows/bold/fit.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def init_bold_fit_wf(
9797
bold_series: list[str],
9898
precomputed: dict = None,
9999
fieldmap_id: str | None = None,
100+
jacobian: bool = False,
100101
omp_nthreads: int = 1,
101102
name: str = 'bold_fit_wf',
102103
) -> pe.Workflow:
@@ -668,6 +669,7 @@ def init_bold_native_wf(
668669
*,
669670
bold_series: list[str],
670671
fieldmap_id: str | None = None,
672+
jacobian: bool = False,
671673
omp_nthreads: int = 1,
672674
name: str = 'bold_native_wf',
673675
) -> pe.Workflow:
@@ -875,7 +877,7 @@ def init_bold_native_wf(
875877

876878
# Resample to boldref
877879
boldref_bold = pe.Node(
878-
ResampleSeries(jacobian='fmap-jacobian' not in config.workflow.ignore),
880+
ResampleSeries(jacobian=jacobian),
879881
name='boldref_bold',
880882
n_procs=omp_nthreads,
881883
mem_gb=mem_gb['resampled'],

0 commit comments

Comments
 (0)