Skip to content

Commit 5812b5b

Browse files
committed
enh: drafting connection to init_fmap_preproc_wf from *SDCFlows* 2.0
1 parent 2c3a792 commit 5812b5b

File tree

3 files changed

+65
-184
lines changed

3 files changed

+65
-184
lines changed

dmriprep/workflows/base.py

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
from ..interfaces import DerivativesDataSink, BIDSDataGrabber
1818
from ..interfaces.reports import SubjectSummary, AboutSummary
1919
from ..utils.bids import collect_data
20-
from .dwi.base import init_early_b0ref_wf
21-
from .fmap.base import init_fmap_estimation_wf
2220

2321

2422
def init_dmriprep_wf():
@@ -287,6 +285,7 @@ def init_single_subject_wf(subject_id):
287285
if anat_only:
288286
return workflow
289287

288+
from .dwi.base import init_early_b0ref_wf
290289
# Append the dMRI section to the existing anatomical excerpt
291290
# That way we do not need to stream down the number of DWI datasets
292291
anat_preproc_wf.__postdesc__ = (
@@ -399,17 +398,71 @@ def _bold_reg_suffix(fallback):
399398
])
400399
# fmt:on
401400

402-
fmap_estimation_wf = init_fmap_estimation_wf(
403-
subject_data["dwi"], debug=config.execution.debug
401+
if "fieldmap" in config.workflow.ignore:
402+
return workflow
403+
404+
from niworkflows.interfaces.utility import KeySelect
405+
from sdcflows import fieldmaps as fm
406+
from sdcflows.utils.wrangler import find_estimators
407+
from sdcflows.workflows.base import init_fmap_preproc_wf
408+
409+
# SDCFlows connection
410+
# Step 1: Run basic heuristics to identify available data for fieldmap estimation
411+
estimators = find_estimators(layout)
412+
413+
if not estimators and config.workflow.use_syn: # Add fieldmap-less estimators
414+
# estimators = [fm.FieldmapEstimation()]
415+
raise NotImplementedError
416+
417+
# Step 2: Manually add further estimators (e.g., fieldmap-less)
418+
fmap_wf = init_fmap_preproc_wf(
419+
debug=config.execution.debug,
420+
estimators=estimators,
421+
omp_nthreads=config.nipype.omp_nthreads,
422+
output_dir=str(output_dir),
423+
subject=subject_id,
404424
)
405-
# fmt:off
406-
workflow.connect([
407-
(referencenode, fmap_estimation_wf, [
408-
("dwi_reference", "inputnode.dwi_reference"),
409-
("dwi_mask", "inputnode.dwi_mask"),
410-
]),
411-
])
412-
# fmt:on
425+
426+
# Overwrite ``out_path_base`` of sdcflows's DataSinks
427+
for node in fmap_wf.list_node_names():
428+
if node.split(".")[-1].startswith("ds_"):
429+
fmap_wf.get_node(node).interface.out_path_base = "dmriprep"
430+
workflow.add_nodes([fmap_wf])
431+
432+
# Step 3: Manually connect PEPOLAR
433+
for estimator in estimators:
434+
if estimator.method != fm.EstimatorType.PEPOLAR:
435+
continue
436+
437+
suffices = set(s.suffix for s in estimator.sources)
438+
439+
if sorted(suffices) == ["epi"]:
440+
getattr(fmap_wf.inputs, f"in_{estimator.bids_id}").in_data = [
441+
str(s.path) for s in estimator.sources
442+
]
443+
getattr(fmap_wf.inputs, f"in_{estimator.bids_id}").metadata = [
444+
s.metadata for s in estimator.sources
445+
]
446+
else:
447+
est_id = estimator.bids_id
448+
fmap_select = pe.MapNode(
449+
KeySelect(fields=["metadata", "dwi_reference", "dwi_mask", "gradients_rasb",]),
450+
name=f"fmap_select_{est_id}",
451+
run_without_submitting=True,
452+
iterfields=["key"]
453+
)
454+
fmap_select.inputs.key = [
455+
str(s.path) for s in estimator.sources if s.suffix in ("epi", "dwi", "sbref")
456+
]
457+
# fmt:off
458+
workflow.connect([
459+
(referencenode, fmap_select, [("dwi_file", "keys"),
460+
("metadata", "metadata"),
461+
("dwi_reference", "dwi_reference"),
462+
("gradients_rasb", "gradients_rasb")]),
463+
])
464+
# fmt:on
465+
413466
return workflow
414467

415468

dmriprep/workflows/fmap/__init__.py

Whitespace-only changes.

dmriprep/workflows/fmap/base.py

Lines changed: 0 additions & 172 deletions
This file was deleted.

0 commit comments

Comments
 (0)