fMRIPrep 3D multi-echo data - how to include fieldmaps

Summary of what happened:

Hello everyone,

I am new to fMRIPrep and I want to use it to preprocess my fMRI data. My data is in BIDS format (validated using BIDS Validator). I am using a 3D multi-echo (3 echoes) sequence with 2 sessions and 4 runs each. Before every functional run (AP direction), I run a short fmap in PA direction. My multi-echo sequence produces 3 echo NIfTI files per sequence. So for each functional run with a task, I have:
func

sub-HM70_ses-01_task-pi_run-01_echo-01_bold.nii.gz
sub-HM70_ses-01_task-pi_run-01_echo-02_bold.nii.gz
sub-HM70_ses-01_task-pi_run-01_echo-03_bold.nii.gz

fmap

sub-HM70_ses-01_acq-echo01_dir-PA_run-01_epi.nii.gz
sub-HM70_ses-01_acq-echo02_dir-PA_run-01_epi.nii.gz 
sub-HM70_ses-01_acq-echo03_dir-PA_run-01_epi.nii.gz

The below command was running fine without erros but produced weird looking output under the functional tab for “Brain mask and (anatomical/temporal) CompCor ROIs” (see screenshot).

As far as I could interpret this, brain was detected at the neck area… Is this normal or can I ignore this?

I thought that I could improve the output by including my fieldmaps. So far I did not have the IntendedFor key in the json file of my fmaps, but then I wanted to add this. This led to some errors (topup crash, extracted from log file), thus I did not have an output at all:

According to another conversation (Multi echo data field maps for fmriprep - #2 by Steven), I referenced my 3 func echos to echo01 of my fmap (see option a below).

My question now concerns the referencing of fmap and func, because I think there are several options:
option a: in json fmap echo01 I reference all 3 echoes of func → 1 to 3 mapping:

  "IntendedFor": [
    "ses-01/func/sub-HM70_ses-01_task-pi_run-01_echo-01_bold.nii.gz",
    "ses-01/func/sub-HM70_ses-01_task-pi_run-01_echo-02_bold.nii.gz",
    "ses-01/func/sub-HM70_ses-01_task-pi_run-01_echo-03_bold.nii.gz"
  ]

→ I tried this and it always produced an topup crash

option b: in json fmap echo01 I reference echo01 of func (and in json fmap echo02 I reference func echo02, in json fmap echo03 I reference func echo03) → 1:1 mapping:

  "IntendedFor": [
    "ses-01/func/sub-HM70_ses-01_task-pi_run-01_echo-01_bold.nii.gz",
  ]

What option should I use and why?
Is there anything else I could improve or try?

I am grateful for any help! :slight_smile:

Command used (and if a helper script was used, a link to the helper script or the command generated):

I sucessfully ran a “basic” fmriprep command on our HPC cluster:

apptainer run \
    --env APPTAINERENV_TEMPLATEFLOW_HOME=/tmp/templateflow   \
    -B /lustre/myuser/rawdata/BIDS:/bids   \
    -B /lustre/myuser/preprocessing/fmriprep:/out   \
    /lustre/myuser/preprocessing/resources/fmriprep_latest.sif   \
    --participant-label HM70   \
    --output-spaces T1w OASIS30ANTs MNI152NLin2009cAsym   \
    --nthreads 16   \
    --omp-nthreads 8   \
    --mem-mb 60000 \
    --fs-license-file /tmp/license.txt \
    /bids /out participant 

Version:

25.2.3, and also tried 25.2.4

Environment (Docker, Singularity / Apptainer, custom installation):

Apptainer

Data formatted according to a validatable standard? Please provide the output of the validator:

For BIDS validation I used: https://bids-standard.github.io/bids-validator/
This showed no errors, but the following warnings:
warning: README_FILE_MISSING
warning: TOO_FEW_AUTHORS
warning: JSON_KEY_RECOMMENDED (HEDVersion)
warning: JSON_KEY_RECOMMENDED (GeneratedBy)
warning: JSON_KEY_RECOMMENDED (SourceDatasets)
warning: SIDECAR_KEY_RECOMMENDED (MatrixCoilMode)
warning: SIDECAR_KEY_RECOMMENDED (PulseSequenceType)
warning: SIDECAR_KEY_RECOMMENDED (SpoilingType)
warning: SIDECAR_KEY_RECOMMENDED (PartialFourierDirection)
warning: SIDECAR_KEY_RECOMMENDED (Instructions)
warning: SIDECAR_KEY_RECOMMENDED (CogAtlasID)
warning: SIDECAR_KEY_RECOMMENDED (CogPOID)
warning: EVENTS_TSV_MISSING

Relevant log outputs (up to 20 lines):

260204-18:26:36,398 nipype.workflow ERROR: could not run node: fmriprep_25_2_wf.sub_HM70_ses_01-02_wf.fmap_preproc_wf.wf_auto_00000.topup
260204-18:26:36,401 nipype.workflow ERROR: could not run node: fmriprep_25_2_wf.sub_HM70_ses_01-02_wf.fmap_preproc_wf.wf_auto_00003.topup
260204-18:26:36,404 nipype.workflow ERROR: could not run node: fmriprep_25_2_wf.sub_HM70_ses_01-02_wf.fmap_preproc_wf.wf_auto_00006.topup
260204-18:26:36,406 nipype.workflow ERROR: could not run node: fmriprep_25_2_wf.sub_HM70_ses_01-02_wf.fmap_preproc_wf.wf_auto_00009.topup
260204-18:26:36,408 nipype.workflow ERROR: could not run node: fmriprep_25_2_wf.sub_HM70_ses_01-02_wf.fmap_preproc_wf.wf_auto_00012.topup
260204-18:26:36,410 nipype.workflow ERROR: could not run node: fmriprep_25_2_wf.sub_HM70_ses_01-02_wf.fmap_preproc_wf.wf_auto_00015.topup
260204-18:26:36,412 nipype.workflow ERROR: could not run node: fmriprep_25_2_wf.sub_HM70_ses_01-02_wf.fmap_preproc_wf.wf_auto_00018.topup
260204-18:26:36,415 nipype.workflow ERROR: could not run node: fmriprep_25_2_wf.sub_HM70_ses_01-02_wf.fmap_preproc_wf.wf_auto_00021.topup
260204-18:26:36,456 nipype.workflow CRITICAL: fMRIPrep failed: 8 raised. Re-raising first.

Screenshots / relevant information:


Hi @neurocartoCO and welcome to neurostars!

In the future, please use the Software Support post template to both organize your post and format code text for readability. You can see I have made these changes for you this time.

Can you return the BIDS validator output, after adding IntendedFor fields?

Please return the full traceback of these errors, which will specify the exact nature of what went wrong.

Best,
Steven

Thank you for your reply @Steven .
I added the output of the BIDS validator (I use the validator in the browser, not in the terminal). It does not show an error either before or after adding the IntendedFor keys.

I did not find any traceback, but maybe this helps:
content of /lustre/myuser/preprocessing/fmriprep/work/fmriprep_25_2_wf/sub_HM70_ses_01-02_wf/

fmap_preproc_wf/wf_auto_00000/topup:
command.txt   
result_topup.pklz
_inputs.pklz  
_node.pklz    
_report
sub-HM70_ses-01_task-pi_run-01_echo-01_bold_average_merged_sliced_volregLAS_encfile.txt
sub-HM70_ses-01_task-pi_run-01_echo-01_bold_average_merged_sliced_volregLAS_topup.log

and

$ cat command.txt
topup --config=/app/.pixi/envs/fmriprep/lib/python3.12/site-packages/sdcflows/data/flirtsch/b02b0.cnf --datain=/work/fmriprep_25_2_wf/sub_HM70_ses_01-02_wf/fmap_preproc_wf/wf_auto_00000/topup/sub-HM70_ses-01_task-pi_run-01_echo-01_bold_average_merged_sliced_volregLAS_encfile.txt --imain=/work/fmriprep_25_2_wf/sub_HM70_ses_01-02_wf/fmap_preproc_wf/wf_auto_00000/to_las/sub-HM70_ses-01_task-pi_run-01_echo-01_bold_average_merged_sliced_volregLAS.nii.gz --out=sub-HM70_ses-01_task-pi_run-01_echo-01_bold_average_merged_sliced_volregLAS_base --iout=sub-HM70_ses-01_task-pi_run-01_echo-01_bold_average_merged_sliced_volregLAS_corrected.nii.gz --fout=sub-HM70_ses-01_task-pi_run-01_echo-01_bold_average_merged_sliced_volregLAS_field.nii.gz --jacout=jac --logout=sub-HM70_ses-01_task-pi_run-01_echo-01_bold_average_merged_sliced_volregLAS_topup.log --rbmout=xfm --dfout=warpfield[ostercjw@login001 topup]$

I apologize if I misunderstood your comment. I am just starting to work with fmriprep and don’t know much about it yet.

Hi @neurocartoCO,

If you ran on a SLURM job scheduler, it would be in the .out/.err files.

Best,
Steven

Yes, I do run a slurm script. This is what I found in my job_log.out:

Traceback (most recent call last):
  File "/app/.pixi/envs/fmriprep/lib/python3.12/site-packages/nipype/pipeline/plugins/multiproc.py", line 67, in run_node
    result["result"] = node.run(updatehash=updatehash)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.pixi/envs/fmriprep/lib/python3.12/site-packages/nipype/pipeline/engine/nodes.py", line 525, in run
    result = self._run_interface(execute=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.pixi/envs/fmriprep/lib/python3.12/site-packages/nipype/pipeline/engine/nodes.py", line 643, in _run_interface
    return self._run_command(execute)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.pixi/envs/fmriprep/lib/python3.12/site-packages/nipype/pipeline/engine/nodes.py", line 769, in _run_command
    raise NodeExecutionError(msg)
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node topup.

Stderr:
	Error occurred when preparing to run topup
	Exception thrown with message: Topup::TopupScan::TopupScan: third element of pevec must be zero
Traceback:
	Traceback (most recent call last):
	  File "/app/.pixi/envs/fmriprep/lib/python3.12/site-packages/nipype/interfaces/base/core.py", line 457, in aggregate_outputs
	    setattr(outputs, key, val)
	  File "/app/.pixi/envs/fmriprep/lib/python3.12/site-packages/nipype/interfaces/base/traits_extension.py", line 325, in validate
	    value = super().validate(objekt, name, value, return_pathlike=True)
	            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	  File "/app/.pixi/envs/fmriprep/lib/python3.12/site-packages/nipype/interfaces/base/traits_extension.py", line 135, in validate
	    self.error(objekt, name, str(value))
	  File "/app/.pixi/envs/fmriprep/lib/python3.12/site-packages/traits/base_trait_handler.py", line 74, in error
	    raise TraitError(
	traits.trait_errors.TraitError: The 'out_fieldcoef' trait of a TOPUPOutputSpec instance must be a pathlike object or string representing an existing file, but a value of '/lustre/myuser/scripts/work/fmriprep_25_2_wf/sub_HM70_ses_01-02_wf/fmap_preproc_wf/wf_auto_00000/topup/sub-HM70_ses-01_task-pi_run-01_echo-01_bold_average_merged_sliced_volregLAS_base_fieldcoef.nii.gz' <class 'str'> was specified.

During handling of the above exception, another exception occurred:

	Traceback (most recent call last):
	  File "/app/.pixi/envs/fmriprep/lib/python3.12/site-packages/nipype/interfaces/base/core.py", line 404, in run
	    outputs = self.aggregate_outputs(runtime)
	              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	  File "/app/.pixi/envs/fmriprep/lib/python3.12/site-packages/nipype/interfaces/base/core.py", line 464, in aggregate_outputs
	    raise FileNotFoundError(msg)
	FileNotFoundError: No such file or directory '/lustre/myuser/scripts/work/fmriprep_25_2_wf/sub_HM70_ses_01-02_wf/fmap_preproc_wf/wf_auto_00000/topup/sub-HM70_ses-01_task-pi_run-01_echo-01_bold_average_merged_sliced_volregLAS_base_fieldcoef.nii.gz' for output 'out_fieldcoef' of a TOPUP interface

This kind of Traceback repeats 8 times, which fits to “fMRIPrep failed: 8 raised”.

Hi @neurocartoCO,

This is the cause of the error. May you return the contents of the fmap JSON?