Skip to content

Commit

Permalink
Exclude echo entity from optimally combined derivatives (#3166)
Browse files Browse the repository at this point in the history
Closes #3165.

- Ensure that the echo entity is removed from CIFTI optimally combined
derivatives.
- Ensure that the echo entity is _retained_ in derivatives when
`--echo-idx` is used to process multi-echo data like single-echo.
- I initially ran the ds210 test with `--echo-idx 1` to determine if
`echo` was being retained in the filenames. It wasn't, but the
`dismiss_echo` function fixed that.
- Add function, `fmriprep.utils.bids.dismiss_echo`, to include `echo` in
`dismiss_entities` parameters only when applicable, based on the config.
  • Loading branch information
effigies committed Dec 6, 2023
2 parents 3c836e8 + fa402de commit d24f585
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 25 deletions.
13 changes: 13 additions & 0 deletions fmriprep/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from bids.utils import listify
from packaging.version import Version

from .. import config
from ..data import load as load_data


Expand Down Expand Up @@ -324,3 +325,15 @@ def _unique(inlist):
return inlist

return {k: _unique(v) for k, v in entities.items()}


def dismiss_echo(entities=None):
"""Set entities to dismiss in a DerivativesDataSink."""
if entities is None:
entities = []

echo_idx = config.execution.echo_idx
if echo_idx is None or len(listify(echo_idx)) > 2:
entities.append("echo")

return entities
5 changes: 3 additions & 2 deletions fmriprep/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from .. import config
from ..interfaces import DerivativesDataSink
from ..interfaces.reports import AboutSummary, SubjectSummary
from ..utils.bids import dismiss_echo


def init_fmriprep_wf():
Expand Down Expand Up @@ -296,7 +297,7 @@ def init_single_subject_wf(subject_id: str):
base_directory=config.execution.fmriprep_dir,
desc='summary',
datatype="figures",
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
),
name='ds_report_summary',
run_without_submitting=True,
Expand All @@ -307,7 +308,7 @@ def init_single_subject_wf(subject_id: str):
base_directory=config.execution.fmriprep_dir,
desc='about',
datatype="figures",
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
),
name='ds_report_about',
run_without_submitting=True,
Expand Down
8 changes: 5 additions & 3 deletions fmriprep/workflows/bold/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

from ... import config
from ...interfaces import DerivativesDataSink
from ...utils.bids import dismiss_echo
from ...utils.misc import estimate_bold_mem_usage

# BOLD workflows
Expand Down Expand Up @@ -367,7 +368,7 @@ def init_bold_wf(
DerivativesDataSink(
desc="t2scomp",
datatype="figures",
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
),
name="ds_report_t2scomp",
run_without_submitting=True,
Expand All @@ -377,7 +378,7 @@ def init_bold_wf(
DerivativesDataSink(
desc="t2starhist",
datatype="figures",
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
),
name="ds_report_t2star_hist",
run_without_submitting=True,
Expand Down Expand Up @@ -532,6 +533,7 @@ def init_bold_wf(
ds_bold_cifti = pe.Node(
DerivativesDataSink(
base_directory=fmriprep_dir,
dismiss_entities=dismiss_echo(),
space='fsLR',
density=config.workflow.cifti_output,
suffix='bold',
Expand Down Expand Up @@ -603,7 +605,7 @@ def init_bold_wf(
base_directory=fmriprep_dir,
desc='confounds',
suffix='timeseries',
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
),
name="ds_confounds",
run_without_submitting=True,
Expand Down
13 changes: 9 additions & 4 deletions fmriprep/workflows/bold/confounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
GatherConfounds,
RenameACompCor,
)
from ...utils.bids import dismiss_echo


def init_bold_confs_wf(
Expand Down Expand Up @@ -442,7 +443,7 @@ def init_bold_confs_wf(
)

ds_report_bold_rois = pe.Node(
DerivativesDataSink(desc="rois", datatype="figures", dismiss_entities=("echo",)),
DerivativesDataSink(desc="rois", datatype="figures", dismiss_entities=dismiss_echo()),
name="ds_report_bold_rois",
run_without_submitting=True,
mem_gb=DEFAULT_MEMORY_MIN_GB,
Expand All @@ -461,7 +462,9 @@ def init_bold_confs_wf(
)

ds_report_compcor = pe.Node(
DerivativesDataSink(desc="compcorvar", datatype="figures", dismiss_entities=("echo",)),
DerivativesDataSink(
desc="compcorvar", datatype="figures", dismiss_entities=dismiss_echo()
),
name="ds_report_compcor",
run_without_submitting=True,
mem_gb=DEFAULT_MEMORY_MIN_GB,
Expand All @@ -473,7 +476,9 @@ def init_bold_confs_wf(
name="conf_corr_plot",
)
ds_report_conf_corr = pe.Node(
DerivativesDataSink(desc="confoundcorr", datatype="figures", dismiss_entities=("echo",)),
DerivativesDataSink(
desc="confoundcorr", datatype="figures", dismiss_entities=dismiss_echo()
),
name="ds_report_conf_corr",
run_without_submitting=True,
mem_gb=DEFAULT_MEMORY_MIN_GB,
Expand Down Expand Up @@ -683,7 +688,7 @@ def init_carpetplot_wf(
)
ds_report_bold_conf = pe.Node(
DerivativesDataSink(
desc="carpetplot", datatype="figures", extension="svg", dismiss_entities=("echo",)
desc="carpetplot", datatype="figures", extension="svg", dismiss_entities=dismiss_echo()
),
name="ds_report_bold_conf",
run_without_submitting=True,
Expand Down
33 changes: 17 additions & 16 deletions fmriprep/workflows/bold/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from fmriprep import config
from fmriprep.config import DEFAULT_MEMORY_MIN_GB
from fmriprep.interfaces import DerivativesDataSink
from fmriprep.utils.bids import dismiss_echo


def prepare_timing_parameters(metadata: dict):
Expand Down Expand Up @@ -217,7 +218,7 @@ def init_func_fit_reports_wf(
base_directory=output_dir,
desc="summary",
datatype="figures",
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
),
name="ds_report_summary",
run_without_submitting=True,
Expand All @@ -229,7 +230,7 @@ def init_func_fit_reports_wf(
base_directory=output_dir,
desc="validation",
datatype="figures",
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
),
name="ds_report_validation",
run_without_submitting=True,
Expand Down Expand Up @@ -333,7 +334,7 @@ def init_func_fit_reports_wf(
desc="fmapCoreg",
suffix="bold",
datatype="figures",
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
),
name="ds_sdcreg_report",
)
Expand All @@ -355,7 +356,7 @@ def init_func_fit_reports_wf(
desc="sdc",
suffix="bold",
datatype="figures",
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
),
name="ds_sdc_report",
)
Expand Down Expand Up @@ -404,7 +405,7 @@ def init_func_fit_reports_wf(
desc="coreg",
suffix="bold",
datatype="figures",
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
),
name="ds_epi_t1_report",
)
Expand Down Expand Up @@ -446,7 +447,7 @@ def init_ds_boldref_wf(
desc=desc,
suffix="boldref",
compress=True,
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
),
name="ds_boldref",
run_without_submitting=True,
Expand Down Expand Up @@ -490,7 +491,7 @@ def init_ds_registration_wf(
mode='image',
suffix='xfm',
extension='.txt',
dismiss_entities=('echo', 'part'),
dismiss_entities=dismiss_echo(["part"]),
**{'from': source, 'to': dest},
),
name='ds_xform',
Expand Down Expand Up @@ -535,7 +536,7 @@ def init_ds_hmc_wf(
suffix="xfm",
extension=".txt",
compress=True,
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
**{"from": "orig", "to": "boldref"},
),
name="ds_xforms",
Expand Down Expand Up @@ -593,7 +594,7 @@ def init_ds_bold_native_wf(
desc='brain',
suffix='mask',
compress=True,
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
),
name='ds_bold_mask',
run_without_submitting=True,
Expand All @@ -615,7 +616,7 @@ def init_ds_bold_native_wf(
compress=True,
SkullStripped=multiecho,
TaskName=metadata.get('TaskName'),
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
**timing_parameters,
),
name='ds_bold',
Expand All @@ -640,7 +641,7 @@ def init_ds_bold_native_wf(
space='boldref',
suffix='T2starmap',
compress=True,
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
**t2star_meta,
),
name='ds_t2star_bold',
Expand Down Expand Up @@ -726,7 +727,7 @@ def init_ds_volumes_wf(
compress=True,
SkullStripped=multiecho,
TaskName=metadata.get('TaskName'),
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
**timing_parameters,
),
name='ds_bold',
Expand Down Expand Up @@ -769,7 +770,7 @@ def init_ds_volumes_wf(
base_directory=output_dir,
suffix='boldref',
compress=True,
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
),
name='ds_ref',
run_without_submitting=True,
Expand All @@ -781,7 +782,7 @@ def init_ds_volumes_wf(
desc='brain',
suffix='mask',
compress=True,
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
),
name='ds_mask',
run_without_submitting=True,
Expand Down Expand Up @@ -809,7 +810,7 @@ def init_ds_volumes_wf(
base_directory=output_dir,
suffix='T2starmap',
compress=True,
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
**t2star_meta,
),
name='ds_t2star_std',
Expand Down Expand Up @@ -905,7 +906,7 @@ def init_bold_preproc_report_wf(
base_directory=reportlets_dir,
desc='preproc',
datatype="figures",
dismiss_entities=("echo",),
dismiss_entities=dismiss_echo(),
),
name='ds_report_bold',
mem_gb=DEFAULT_MEMORY_MIN_GB,
Expand Down
2 changes: 2 additions & 0 deletions fmriprep/workflows/bold/resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

from ...config import DEFAULT_MEMORY_MIN_GB
from ...interfaces.workbench import MetricDilate, MetricMask, MetricResample
from ...utils.bids import dismiss_echo
from .outputs import prepare_timing_parameters


Expand Down Expand Up @@ -181,6 +182,7 @@ def select_target(subject_id, space):
DerivativesDataSink(
base_directory=output_dir,
extension=".func.gii",
dismiss_entities=dismiss_echo(),
TaskName=metadata.get('TaskName'),
**timing_parameters,
),
Expand Down

0 comments on commit d24f585

Please sign in to comment.