[fmriprep & dcm2bids] KeyError: "'phasediff_fmap0' is already in mapping"

Hi, experts,

Summary of what happened:

I’m curious about why the following warning is generated in fmriprep.

KeyError: “‘phasediff_fmap0’ is already in mapping”

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

fmriprep-docker d:\test6 d:\test6\derivatives

Version:

fMRIPrep-23.2.3

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

docker

Relevant log outputs (up to 20 lines):

RUNNING: docker run --rm -e DOCKER_VERSION_8395080871=26.1.1 -it -v d:\test6:/data:ro -v d:\test6\derivatives:/out nipreps/fmriprep:23.2.3 /data /out participant
You are using fMRIPrep-23.2.3, and a newer version of fMRIPrep is available: 24.0.1.
Please check out our documentation about how and when to upgrade:
https://fmriprep.readthedocs.io/en/latest/faq.html#upgrading
bids-validator@1.14.6
(node:9) Warning: Closing directory handle on garbage collection
(Use `node --trace-warnings ...` to show where the warning was created)
        1: [WARN] The Authors field of dataset_description.json should contain an array of fields - with one author per field. This was triggered based on the presence of only one author field. Please ignore if all contributors are already properly listed. (code: 102 - TOO_FEW_AUTHORS)

        Please visit https://neurostars.org/search?q=TOO_FEW_AUTHORS for existing conversations about this issue.

        2: [WARN] The Name field of dataset_description.json is present but empty of visible characters. (code: 115 - EMPTY_DATASET_NAME)

        Please visit https://neurostars.org/search?q=EMPTY_DATASET_NAME for existing conversations about this issue.

        Summary:                  Available Tasks:        Available Modalities:
        41 Files, 415.49MB        rest                    MRI
        3 - Subjects
        1 - Session


        If you have any questions, please post on https://neurostars.org/tags/bids.
240818-17:00:06,929 nipype.workflow IMPORTANT:
         Running fMRIPrep version 23.2.3

         License NOTICE ##################################################
         fMRIPrep 23.2.3
         Copyright 2023 The NiPreps Developers.

         This product includes software developed by
         the NiPreps Community (https://nipreps.org/).

         Portions of this software were developed at the Department of
         Psychology at Stanford University, Stanford, CA, US.

         This software is also distributed as a Docker container image.
         The bootstrapping file for the image ("Dockerfile") is licensed
         under the MIT License.

         This software may be distributed through an add-on package called
         "Docker Wrapper" that is under the BSD 3-clause License.
         #################################################################
240818-17:00:06,951 nipype.workflow IMPORTANT:
         Building fMRIPrep's workflow:
           * BIDS dataset path: /data.
           * Participant list: ['y072', 'y073', 'y074'].
           * Run identifier: 20240818-170000_8b308741-cfe1-47b9-8d1f-7649d064186a.
           * Output spaces: MNI152NLin2009cAsym:res-native.
           * Pre-run FreeSurfer's SUBJECTS_DIR: /out/sourcedata/freesurfer.
240818-17:00:07,306 nipype.workflow INFO:
         ANAT Stage 1: Adding template workflow
240818-17:00:07,507 nipype.workflow INFO:
         ANAT Stage 2: Preparing brain extraction workflow
240818-17:00:07,549 nipype.workflow INFO:
         ANAT Stage 3: Preparing segmentation workflow
240818-17:00:07,552 nipype.workflow INFO:
         ANAT Stage 4: Preparing normalization workflow for ['MNI152NLin2009cAsym']
240818-17:00:07,556 nipype.workflow INFO:
         ANAT Stage 5: Preparing surface reconstruction workflow
240818-17:00:07,567 nipype.workflow INFO:
         ANAT Stage 6: Preparing mask refinement workflow
240818-17:00:07,568 nipype.workflow INFO:
         ANAT No T2w images provided - skipping Stage 7
240818-17:00:07,568 nipype.workflow INFO:
         ANAT Stage 8: Creating GIFTI surfaces for ['white', 'pial', 'midthickness', 'sphere_reg', 'sphere']
240818-17:00:07,577 nipype.workflow INFO:
         ANAT Stage 8: Creating GIFTI metrics for ['thickness', 'sulc']
240818-17:00:07,581 nipype.workflow INFO:
         ANAT Stage 8a: Creating cortical ribbon mask
240818-17:00:07,583 nipype.workflow INFO:
         ANAT Stage 9: Creating fsLR registration sphere
240818-17:00:07,585 nipype.workflow INFO:
         ANAT Stage 10: Creating MSM-Sulc registration sphere
240818-17:00:07,657 nipype.workflow INFO:
         B0 field inhomogeneity map will be estimated with the following 1 estimator(s): [<EstimatorType.PHASEDIFF: 3>].
240818-17:00:07,680 nipype.workflow INFO:
         Setting-up fieldmap "phasediff_fmap0" (EstimatorType.PHASEDIFF) with <sub-y072_ses-1_magnitude1.nii, sub-y072_ses-1_magnitude2.nii, sub-y072_ses-1_phasediff.nii>
240818-17:00:07,693 nipype.workflow INFO:
         No single-band-reference found for sub-y072_ses-1_task-rest_run-01_bold.nii.
240818-17:00:07,707 nipype.workflow INFO:
         Stage 1: Adding HMC boldref workflow
240818-17:00:07,710 nipype.workflow INFO:
         Stage 2: Adding motion correction workflow
240818-17:00:07,715 nipype.workflow INFO:
         Stage 3: Adding coregistration boldref workflow
240818-17:00:07,743 nipype.workflow IMPORTANT:
         BOLD series will be slice-timing corrected to an offset of 0.961s.
240818-17:00:07,787 nipype.workflow INFO:
         No single-band-reference found for sub-y072_ses-1_task-rest_run-02_bold.nii.
240818-17:00:07,797 nipype.workflow INFO:
         Stage 1: Adding HMC boldref workflow
240818-17:00:07,800 nipype.workflow INFO:
         Stage 2: Adding motion correction workflow
240818-17:00:07,803 nipype.workflow INFO:
         Stage 3: Adding coregistration boldref workflow
240818-17:00:07,829 nipype.workflow IMPORTANT:
         BOLD series will be slice-timing corrected to an offset of 0.96s.
240818-17:00:07,928 nipype.workflow INFO:
         ANAT Stage 1: Adding template workflow
240818-17:00:08,26 nipype.workflow INFO:
         ANAT Stage 2: Preparing brain extraction workflow
240818-17:00:08,61 nipype.workflow INFO:
         ANAT Stage 3: Preparing segmentation workflow
240818-17:00:08,64 nipype.workflow INFO:
         ANAT Stage 4: Preparing normalization workflow for ['MNI152NLin2009cAsym']
240818-17:00:08,68 nipype.workflow INFO:
         ANAT Stage 5: Preparing surface reconstruction workflow
240818-17:00:08,77 nipype.workflow INFO:
         ANAT Stage 6: Preparing mask refinement workflow
240818-17:00:08,79 nipype.workflow INFO:
         ANAT No T2w images provided - skipping Stage 7
240818-17:00:08,79 nipype.workflow INFO:
         ANAT Stage 8: Creating GIFTI surfaces for ['white', 'pial', 'midthickness', 'sphere_reg', 'sphere']
240818-17:00:08,88 nipype.workflow INFO:
         ANAT Stage 8: Creating GIFTI metrics for ['thickness', 'sulc']
240818-17:00:08,92 nipype.workflow INFO:
         ANAT Stage 8a: Creating cortical ribbon mask
240818-17:00:08,94 nipype.workflow INFO:
         ANAT Stage 9: Creating fsLR registration sphere
240818-17:00:08,95 nipype.workflow INFO:
         ANAT Stage 10: Creating MSM-Sulc registration sphere
Process Process-2:
Traceback (most recent call last):
  File "/opt/conda/envs/fmriprep/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/opt/conda/envs/fmriprep/lib/python3.10/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/fmriprep/cli/workflow.py", line 115, in build_workflow
    retval["workflow"] = init_fmriprep_wf()
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/fmriprep/workflows/base.py", line 94, in init_fmriprep_wf
    single_subject_wf = init_single_subject_wf(subject_id)
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/fmriprep/workflows/base.py", line 504, in init_single_subject_wf
    fmap_estimators, estimator_map = map_fieldmap_estimation(
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/fmriprep/workflows/base.py", line 745, in map_fieldmap_estimation
    fmap_estimators = find_estimators(
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/sdcflows/utils/wrangler.py", line 340, in find_estimators
    e = fm.FieldmapEstimation(
  File "<attrs generated init sdcflows.fieldmaps.FieldmapEstimation>", line 7, in __init__
    self.__attrs_post_init__()
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/sdcflows/fieldmaps.py", line 431, in __attrs_post_init__
    _estimators[self.bids_id] = self.paths()
  File "/opt/conda/envs/fmriprep/lib/python3.10/site-packages/sdcflows/utils/bimap.py", line 144, in __setitem__
    raise KeyError(
KeyError: "'phasediff_fmap0' is already  in mapping"

Screenshots / relevant information:

I used the dcm2bids v. 3.1.1 for bids format.
Below is the config file that was used.

{
  "dcm2niixOptions": "-ba n",
  "descriptions": [
    {
      "datatype": "anat",
      "suffix": "T1w",
      "criteria": {
        "SeriesDescription": "t1*",
        "EchoTime": 0.00236,
        "RepetitionTime": 2.3
      },
      "sidecar_changes": {
        "ProtocolName": "T1"
      }
    },
    {
      "datatype": "anat",
      "suffix": "FLAIR",
      "criteria": {
        "SeriesDescription": "t2*",
        "EchoTime": 0.093,
        "RepetitionTime": 9
      },
      "sidecar_changes": {
        "ProtocolName": "FLAIR"
      }
    },
    {
      "id": "id_task-rest",
      "datatype": "func",
      "suffix": "bold",
      "custom_entities": "task-rest",
      "criteria": {
        "EchoTime": 0.03,
        "RepetitionTime": 2
      },
      "sidecar_changes": {
        "TaskName": "rest",
        "B0FieldSource": ["phasediff_fmap0"]
      }
    },
    {
      "datatype": "fmap",
      "suffix": "magnitude1",
      "criteria": {
        "ProtocolName": "field_map",
        "EchoTime": 0.00492
      },
      "sidecar_changes": {
        "IntendedFor": ["id_task-rest"],
        "B0FieldIdentifier": "phasediff_fmap0"
      }
    },
    {
      "datatype": "fmap",
      "suffix": "magnitude2",
      "criteria": {
        "ProtocolName": "field_map",
        "EchoTime": 0.00738,
        "ImageType": ["ORIGINAL", "PRIMARY", "M", "ND"]
      },
      "sidecar_changes": {
        "IntendedFor": "id_task-rest",
        "B0FieldIdentifier": "phasediff_fmap0"
      }
    },
    {
      "datatype": "fmap",
      "suffix": "phasediff",
      "criteria": {
        "ProtocolName": "field_map",
        "EchoTime": 0.00738,
        "ImageType": ["ORIGINAL", "PRIMARY", "P", "ND", "PHASE"]
      },
      "sidecar_changes": {
        "IntendedFor": ["id_task-rest"],
        "B0FieldIdentifier": "phasediff_fmap0"
      }
    }
  ]
}

Hi @jj0012345,

Only put the B0FieldIdentifier in the phasediff.

Best,
Steven

Hi, @Steven
Thank you for your answer.

Which one should I delete?
I’m not sure which one to change.

Below is what I tried with dcm2bids:

  1. Remove B0FieldIdentifier from sidecars of ‘magnitude1 and 2’ in the ‘fmap’ sidecar
  2. Remove B0FieldIdentifier from sidecars of ‘mangitude1 and 2’, ‘phasediff’ in ‘fmap’ sidecar
  3. Remove ‘intendedfor’ from the sidecar of the all of the ‘fmap’

Hi @jj0012345,

I was referring to option 1. Do you also have IntendedFor specified for these files? May you return the BIDS validation report for the dataset?

Best,
Steven

Hi @Steven
Here is the valdiator of the option 1.

bids-validator@1.14.8
(node:40444) Warning: Closing directory handle on garbage collection
(Use `node --trace-warnings ...` to show where the warning was created)
        1: [WARN] The Authors field of dataset_description.json should contain an array of fields - with one author per field. This was triggered based on the presence of only one author field. Please ignore if all contributors are already properly listed. (code: 102 - TOO_FEW_AUTHORS)

        Please visit https://neurostars.org/search?q=TOO_FEW_AUTHORS for existing conversations about this issue.

        2: [WARN] The Name field of dataset_description.json is present but empty of visible characters. (code: 115 - EMPTY_DATASET_NAME)

        Please visit https://neurostars.org/search?q=EMPTY_DATASET_NAME for existing conversations about this issue.

        Summary:                  Available Tasks:        Available Modalities:
        41 Files, 415.49MB        rest                    MRI
        3 - Subjects
        1 - Session


        If you have any questions, please post on https://neurostars.org/tags/bids.

Below is the intendedfor of the phasediff.

    "ConversionSoftware": "dcm2niix",
    "ConversionSoftwareVersion": "v1.0.20240202",
    "Dcm2bidsVersion": "3.2.0",
    "IntendedFor": [
        "bids::sub-y073\\ses-2\\func\\sub-y073_ses-2_task-rest_run-01_bold.nii",
        "bids::sub-y073\\ses-2\\func\\sub-y073_ses-2_task-rest_run-02_bold.nii"
    ],
    "B0FieldIdentifier": "phasediff_fmap0"
}

Summary of what happened:

Hi, experts

I got the fmriprep results ‘Susceptibility distortion correction: FMB (field map-based) - phase-difference map’ in case I analyzed just one fMRI file.
However, when analyzing three files in the same way, the following error appears:
KeyError: “‘phasediff_fmap0’ is already in mapping”

I don’t know if this config file is the correct way.
These fMRI fieldmap files were gained in Simens and had two magnitude files and one phasediff file.

Below is the explanation in part of the config file.
I put “B0FieldSource”: [“phasediff_fmap0”] in func(rest) section.
Also put “B0FieldIdentifier”: “phasediff_fmap0” in two magnitude sections and one phasediff section.

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

1. [dcm2bdis] config file

{
  "dcm2niixOptions": "-ba n",
  "descriptions": [
    {
      "datatype": "anat",
      "suffix": "T1w",
      "criteria": {
        "SeriesDescription": "t1*",
        "EchoTime": 0.00236,
        "RepetitionTime": 2.3
      },
      "sidecar_changes": {
        "ProtocolName": "T1"
      }
    },
    {
      "datatype": "anat",
      "suffix": "FLAIR",
      "criteria": {
        "SeriesDescription": "t2*",
        "EchoTime": 0.093,
        "RepetitionTime": 9
      },
      "sidecar_changes": {
        "ProtocolName": "FLAIR"
      }
    },
    {
      "id": "id_task-rest",
      "datatype": "func",
      "suffix": "bold",
      "custom_entities": "task-rest",
      "criteria": {
        "EchoTime": 0.03,
        "RepetitionTime": 2
      },
      "sidecar_changes": {
        "TaskName": "rest",
        "B0FieldSource": ["phasediff_fmap0"]
      }
    },
    {
      "datatype": "fmap",
      "suffix": "magnitude1",
      "criteria": {
        "ProtocolName": "field_map",
        "EchoTime": 0.00492
      },
      "sidecar_changes": {
        "IntendedFor": ["id_task-rest"],
        "B0FieldIdentifier": "phasediff_fmap0"
      }
    },
    {
      "datatype": "fmap",
      "suffix": "magnitude2",
      "criteria": {
        "ProtocolName": "field_map",
        "EchoTime": 0.00738,
        "ImageType": ["ORIGINAL", "PRIMARY", "M", "ND"]
      },
      "sidecar_changes": {
        "IntendedFor": "id_task-rest",
        "B0FieldIdentifier": "phasediff_fmap0"
      }
    },
    {
      "datatype": "fmap",
      "suffix": "phasediff",
      "criteria": {
        "ProtocolName": "field_map",
        "EchoTime": 0.00738,
        "ImageType": ["ORIGINAL", "PRIMARY", "P", "ND", "PHASE"]
      },
      "sidecar_changes": {
        "IntendedFor": ["id_task-rest"],
        "B0FieldIdentifier": "phasediff_fmap0"
      }
    }
  ]
}

2. [fmriprep-docker] command

fmriprep-docker D:/t13 D:/t13/derivatives participant --fs-license-file D:/freesurfer.txt

Version:

dcm2bids version: 3.2.0
Based on BIDS version: v1.9.0
fMRIPrep v24.0.1
bids-validator 1.14.8

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

dcm2bids(anaconda)
fmriprep-docker

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

PS C:\Users\user> bids-validator d:\t13
bids-validator@1.14.8
(node:36360) Warning: Closing directory handle on garbage collection
(Use `node --trace-warnings ...` to show where the warning was created)
This dataset appears to be BIDS compatible.
        Summary:                 Available Tasks:        Available Modalities:
        17 Files, 138.5MB        rest                    MRI
        1 - Subject
        1 - Session


        If you have any questions, please post on https://neurostars.org/tags/bids.

Relevant log outputs (up to 20 lines):

KeyError: "'phasediff_fmap0' is already  in mapping"
fMRIPrep: Please report errors to https://github.com/nipreps/fmriprep/issues

Screenshots / relevant information:

I have the following information:

  • When setting the “IntendedFor” using dcm2bids, it is inputted as a BIDS URL. This does not work with fMRIPrep.
  • For fieldmap correction (SDC), a pair of BOLD file and fieldmap file is used. In this case, instead of “IntendedFor” in the JSON file, “B0FieldIdentifier” and “B0FieldSource” are used. Currently, it is recommended to use both “IntendedFor” and “B0FieldIdentifier” according to BIDS documentation.

Hello @jj0012345 ,

Depending on the fmriprep version you may need to follow this convention.

I’m not a fmriprep expert but at least we can make sure that the conversion is BIDS valid.

You could use the container with the option to validate BIDS in this section.

Arnaud