Dcm2bids no pairing with field maps

Dear community,

currently, I’m trying to get the apptainer version for dcm2bids to work. For the anatomy it seems to be ok, but for the restings state scans I get alyways no pairing issues.
The field map are from Siemens using the sequence gre_field_mapping_2.5mm, because the SeriesDescription is the same for the two resting state runs (and also the gre_field images), I copied the dicom images in specific folders (rest_run1, rest_run2 and fmap_run1, fmap_run2)

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

INFO    | Running the following command: /venv/bin/dcm2bids -d /server/fo2-22/data/AcEx/BIDS/new_scaffold/sourcedata/sub-4499/ses-V3 -p 4499 -s V3 -c /server/fo2-22/data/AcEx/BIDS/dcm2bids_config_new1.json -o /server/fo2-22/data/AcEx/BIDS/new_scaffold/BIDS --clobber
INFO    | OS version: Linux-5.14.0-503.35.1.el9_5.x86_64-x86_64-with-glibc2.36
INFO    | Python version: 3.12.3 | packaged by conda-forge | (main, Apr 15 2024, 18:38:13) [GCC 12.3.0]
INFO    | dcm2bids version: 3.2.0
INFO    | dcm2niix version: v1.0.20240202
INFO    | Checking for software update
WARNING | Checking latest version of UNFmontreal/Dcm2Bids was not possible, your machine is probably not connected to the Internet.
WARNING | Checking latest version of rordenlab/dcm2niix was not possible, your machine is probably not connected to the Internet.
INFO    | participant: sub-4499
INFO    | session: ses-V3
INFO    | config: /server/fo2-22/data/AcEx/BIDS/dcm2bids_config_new1.json
INFO    | BIDS directory: /server/fo2-22/data/AcEx/BIDS/new_scaffold/BIDS
INFO    | Auto extract entities: False
INFO    | Reorder entities: True
INFO    | Validate BIDS: False

INFO    | Running: dcm2niix -b y -ba y -z y -f %3s_%f_%p_%t -o /server/fo2-22/data/AcEx/BIDS/new_scaffold/BIDS/tmp_dcm2bids/sub-4499_ses-V3 /server/fo2-22/data/AcEx/BIDS/new_scaffold/sourcedata/sub-4499/ses-V3
INFO    | Check log file for dcm2niix output

INFO    | SIDECAR PAIRING
INFO    | No Pairing  <-  029_ses-V3_gre_field_mapping_2.5mm_20250123111111_e1
INFO    | No Pairing  <-  029_ses-V3_gre_field_mapping_2.5mm_20250123111111_e2
INFO    | No Pairing  <-  030_ses-V3_gre_field_mapping_2.5mm_20250123111111_e2_ph
INFO    | No Pairing  <-  031_ses-V3_Rest_ep2d_bold_s4_2p5mm_20250123111111
INFO    | sub-4499_ses-V3_T1w  <-  005_ses-V3_T1w_MPR_20250109124814
INFO    | sub-4499_ses-V3_T2w  <-  006_ses-V3_T2w_SPC_20250109124814
INFO    | No Pairing  <-  029_ses-V3_gre_field_mapping_2.5mm_20250109131757_e1
INFO    | No Pairing  <-  029_ses-V3_gre_field_mapping_2.5mm_20250109131757_e2
INFO    | No Pairing  <-  030_ses-V3_gre_field_mapping_2.5mm_20250109131757_e2_ph
INFO    | No Pairing  <-  031_ses-V3_Rest_ep2d_bold_s4_2p5mm_20250109131757
INFO    | Moving acquisitions into BIDS folder "/server/fo2-22/data/AcEx/BIDS/new_scaffold/BIDS/sub-4499/ses-V3".

INFO    | Logs saved in /server/fo2-22/data/AcEx/BIDS/new_scaffold/BIDS/tmp_dcm2bids/log/sub-4499_ses-V3_20250616-132644.log
INFO    | --- dcm2bids end ---


PASTE CODE HERE

Version:

3.2.0

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

apptainer version 1.4.0-1.el9

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

PASTE VALIDATOR OUTPUT HERE

Relevant log outputs (up to 20 lines):

PASTE LOG OUTPUT HERE
```{
  "descriptions": [
  {
    "datatype": "anat",
    "suffix": "T1w",
    "criteria": {
      "SeriesDescription": "*T1w*"
    },
    "customLabels": "",
    "sidecarChanges": {
       "ProtocolName":"T1w_MPR"
       }
  },
   {
    "datatype": "anat",
    "suffix": "T2w",
    "criteria": {
      "SeriesDescription": "*T2w*"
    },
    "customLabels": "",
    "sidecarChanges": {
       "ProtocolName":"T2w_SPC"
       }
  },
  {
    "id": "task-rest_run-01",
    "datatype": "func",
    "suffix": "bold",
    "criteria": {
      "Folder": "rest_run1"
    },
    "custom_entitites": "task-rest_run-01",
    "sidecarChanges": {
      "TaskName": "rest"
    }
  },
  {
    "id":"task-rest_run-02",
    "datatype": "func",
    "suffix": "bold",
    "criteria": {
      "Folder": "rest_run2"
    },
    "custom_entities": "task-rest_run-02",
    "sidecarChanges": {
      "TaskName": "rest"
    }
  },
  {
    "datatype": "fmap",
    "suffix": "phasediff",
    "criteria": {
      "Folder": "fmap_run1"
    },
    "custom_entitites": "run-01",
    "B0FieldIdentifier": "phasediff",
    "sidecarChanges": {
      "IntendedFor": [
        "ses-<session>_task-rest_run-01_bold.nii.gz"
      ]
    }
  },
  {
    "datatype": "fmap",
    "suffix": "magnitude1",
    "criteria": {
      "Folder": "fmap_run1"
    },
    "customentitiels": "run-01",
    "sidecarChanges": {}
  },
  {
    "dataType": "fmap",
    "suffix": "phasediff",
    "criteria": {
      "Folder": "fmap_run2"
    },
    "customLabels": "run-02",
    "B0FieldIdentifier": "phasediff",
    "sidecarChanges": {
      "IntendedFor": [
        "ses-<session>_task-rest_run-02_bold.nii.gz"
      ]
    }
  },
  {
    "dataType": "fmap",
    "suffix": "magnitude1",
    "criteria": {
      "Folder": "fmap_run2"
    },
    "customLabels": "run-02",
    "sidecarChanges": {}
  }
]
}

### Screenshots / relevant information:
<!-- Below this line, provide any other information that might be meaningful. This could be screenshots, troubleshooting steps you have tried, or information about your operating system, etc. -->

_____

Hi @Ralf,

Folder is not valid JSON metadata. You can specify multiple criteria in your config to make entries specific for each fmap entity. I imagine echo number and image type could be helpful in distinguishing.

Best,
Steven

Hi Steven,

ChatGPT might be not the best idea for creating config files ;-). I created subfolders for the two resting state runs (and fieldmaps), because the images can be only distinguished with AcquisitionTime. Now I modified according to your suggestions

{
  "descriptions": [
    {
      "datatype": "anat",
      "suffix": "T1w",
      "criteria": {
        "SeriesDescription": "*T1w*"
      },
      "customLabels": "",
      "sidecarChanges": {
        "ProtocolName": "T1w_MPR"
      }
    },
    {
      "datatype": "anat",
      "suffix": "T2w",
      "criteria": {
        "SeriesDescription": "*T2w*"
      },
      "customLabels": "",
      "sidecarChanges": {
        "ProtocolName": "T2w_SPC"
      }
    },
    {
      "id": "task-rest_run-01",
      "datatype": "func",
      "suffix": "bold",
      "customLabels": "task-rest_run-01",
      "sidecarChanges": {
        "TaskName": "rest"
      }
    },
    {
      "id": "task-rest_run-02",
      "datatype": "func",
      "suffix": "bold",
      "customLabels": "task-rest_run-02",
      "sidecarChanges": {
        "TaskName": "rest"
      }
    },
    {
      "datatype": "fmap",
      "suffix": "phasediff",
      "customLabels": "run-01",
      "criteria": {
         "ImageType":["ORIGINAL*","PRIMARY","P","ND"],
	 "EchoTime": 0.00738
	 },
      "B0FieldIdentifier": "phasediff1",
      "sidecarChanges": {
        "IntendedFor": [
          "sub-<subject>_ses-<session>_task-rest_run-01_bold.nii.gz"
        ]
      }
    },
    {
      "datatype": "fmap",
      "suffix": "magnitude1",
      "criteria": {
         "ImageType":["ORIGINAL*","PRIMARY","M","ND"],
	 "EchoTime": 0.00492 
	 },
      "customLabels": "run-01",
      "sidecarChanges": {}
    },
    {
      "datatype": "fmap",
      "suffix": "phasediff",
      "customLabels": "run-02",
      "B0FieldIdentifier": "phasediff2",
       "criteria": {
         "ImageType":["ORIGINAL*","PRIMARY","P","ND"],
	 "EchoTime": 0.00738
	 },
      "sidecarChanges": {
        "IntendedFor": [
          "sub-<subject>_ses-<session>_task-rest_run-02_bold.nii.gz"
        ]
      }
    },
    {
      "datatype": "fmap",
      "suffix": "magnitude1",
      "criteria": {
         "ImageType":["ORIGINAL*","PRIMARY","M","ND"],
	 "EchoTime": 0.00492
	 },   
      "customLabels": "run-02",
      "sidecarChanges": {}
    }
  ]
}

and I received the following error messages

INFO    | SIDECAR PAIRING
WARNING | Several Pairing  <-  029_ses-V3_gre_field_mapping_2.5mm_20240201121657_e1
WARNING |     ->  _magnitude1
WARNING |     ->  _magnitude1
INFO    | No Pairing  <-  029_ses-V3_gre_field_mapping_2.5mm_20240201121657_e2
INFO    | No Pairing  <-  030_ses-V3_gre_field_mapping_2.5mm_20240201121657_e2_ph
INFO    | No Pairing  <-  031_ses-V3_Rest_ep2d_bold_s4_2p5mm_20240201121657
INFO    | sub-4899_ses-V3_T1w  <-  005_ses-V3_T1w_MPR_20240125123354
INFO    | sub-4899_ses-V3_T2w  <-  006_ses-V3_T2w_SPC_20240125123354
WARNING | Several Pairing  <-  029_ses-V3_gre_field_mapping_2.5mm_20240125130759_e1
WARNING |     ->  _magnitude1
WARNING |     ->  _magnitude1
INFO    | No Pairing  <-  029_ses-V3_gre_field_mapping_2.5mm_20240125130759_e2
INFO    | No Pairing  <-  030_ses-V3_gre_field_mapping_2.5mm_20240125130759_e2_ph
INFO    | No Pairing  <-  031_ses-V3_Rest_ep2d_bold_s4_2p5mm_20240125130759
INFO    | Moving acquisitions into BIDS folder "/server/fo2-22/data/AcEx/BIDS/new_scaffold/BIDS/sub-4899/ses-V3".

can I use some come custom criteria or label?

Ralf

Hi @Ralf,

Yes, but you would need to convert dcm2nii before running dcm2bids to add in the custom json metadata, and then use those fields in your config. Or you can run dcm2bids multiple times for different dicom folders.

Unrelated, but for BIDS, fieldmaps are expected to have unique identifiers within the entire dataset not just the subject. So after conversion, you might want to prepend your B0Field metadata with the subject_session information.

Best,
Steven

Hi Steven,

here is my current structure of the dicom files (only ses-V3 shown)

── ses-V3
│ ├── anat
│ │ ├── 05_T1w_MPR
│ │ └── 06_T2w_SPC
│ ├── fmap_run1
│ │ ├── 29_gre_field_mapping_2.5mm
│ │ └── 30_gre_field_mapping_2.5mm
│ ├── fmap_run2
│ │ ├── 29_gre_field_mapping_2.5mm
│ │ └── 30_gre_field_mapping_2.5mm
│ ├── rest_run1
│ │ └── 31_Rest_ep2d_bold_s4_2p5mm
│ └── rest_run2
│ └── 31_Rest_ep2d_bold_s4_2p5mm

Should I delete (or move) the subfolders fmap_run2 and rest_run2, when I want to run dcm2bids multiple times? What do you think?

Best,
Ralf

Hi @Ralf,

By default, dcm2niix (and therefore dcm2bids) uses a search length of 5 directories. Keep that in mind as you are organizing your folders. Or you can change the search length by specifying a new -d parameter in your dcm2niix call (if you are running that separately), or specify different dcm2niixOptions (Use advanced commands - dcm2bids documentation) in dcm2bids if you are not running dcm2niix separately.

Alternatively, although I do not normally recommend this, you can use less than / greater than logic Use advanced commands - dcm2bids documentation and use the SeriesNumber (e.g., if you know run 1 has to occur before the Xth scan and run 2 has to occur after the Yth scan). Obviously this won’t work if you have some weird sessions where scans had to be reordered / repeated.

Best,
Steven

Hi Steven,

I’m still struggling with the conversion of the phasediff images. I reduced the sesssion to only one run for testing. Except for the phasediff image the conversion worked.
SIDECAR PAIRING
INFO | sub-4526_ses-V6_magnitude1 ← 029_ses-V6_gre_field_mapping_2.5mm_20241021114101_e1
INFO | sub-4526_ses-V6_magnitude2 ← 029_ses-V6_gre_field_mapping_2.5mm_20241021114101_e2
INFO | No Pairing ← 030_ses-V6_gre_field_mapping_2.5mm_20241021114101_e2_ph
INFO | sub-4526_ses-V6_bold ← 031_ses-V6_Rest_ep2d_bold_s4_2p5mm_20241021114101
INFO | sub-4526_ses-V6_T1w ← 005_ses-V6_T1w_MPR_20241021121030
INFO | sub-4526_ses-V6_T2w ← 006_ses-V6_T2w_SPC_20241021121030

here is my config file

{
“descriptions”: [
{
“datatype”: “anat”,
“suffix”: “T1w”,
“criteria”: {
“SeriesDescription”: “T1w
},
“customLabels”: “”,
“sidecarChanges”: {
“ProtocolName”: “T1w_MPR”
}
},
{
“datatype”: “anat”,
“suffix”: “T2w”,
“criteria”: {
“SeriesDescription”: “T2w
},
“customLabels”: “”,
“sidecarChanges”: {
“ProtocolName”: “T2w_SPC”
}
},
{
“id”: “task-rest_run-01”,
“datatype”: “func”,
“suffix”: “bold”,
“custom_entitites”:“task-rest_run-01”,
“criteria”: {
“ProtocolName”: “Rest_ep2d_bold_s4_2p5mm”
},
“sidecarChanges”: {
“TaskName”: “task-rest”
}
},
{
“datatype”: “fmap”,
“suffix”: “phasediff”,
“criteria”: {
“ImageType”:[“PHASE”],
“ProtocolName”: “gre_field_mapping_2.5mm”
},
“B0FieldIdentifier”: “phasediff”,
“sidecarChanges”: {
“IntendedFor”: [
“sub-_ses-_task-rest_run-01_bold.nii.gz”
]
}
},
{
“datatype”: “fmap”,
“suffix”: “magnitude1”,
“criteria”: {
“ImageType”:[“ORIG*”, “PRIMARY”, “M”,“ND”],
“EchoTime”: 0.00492
},
“sidecarChanges”: {}
},
{
“datatype”: “fmap”,
“suffix”: “magnitude2”,
“criteria”: {
“ImageType”:[“ORIG*”, “PRIMARY”, “M”,“ND”],
“EchoTime”: 0.00738
},
“sidecarChanges”: {}
}
]
}

I tested also with echotime1 and 2 but the results is always no pairing for the phasediff file. Interestingly there is a field
“BidsGuess”: [“fmap”,“_acq-fm2_phasediff”],
in the *_e2_ph.json file.

Best,
Ralf

Now it worked with the following config file.
{
“descriptions”: [
{
“datatype”: “anat”,
“suffix”: “T1w”,
“criteria”: {
“SeriesDescription”: “T1w
},
“customLabels”: “”,
“sidecarChanges”: {
“ProtocolName”: “T1w_MPR”
}
},
{
“datatype”: “anat”,
“suffix”: “T2w”,
“criteria”: {
“SeriesDescription”: “T2w
},
“customLabels”: “”,
“sidecarChanges”: {
“ProtocolName”: “T2w_SPC”
}
},
{
“id”: “task-rest_run-01”,
“datatype”: “func”,
“suffix”: “bold”,
“custom_entitites”:“task-rest_run-01”,
“criteria”: {
“ProtocolName”: “Rest_ep2d_bold_s4_2p5mm”
},
“sidecarChanges”: {
“TaskName”: “task-rest”
}
},
{
“datatype”: “fmap”,
“suffix”: “phasediff”,
“criteria”: {
“EchoTime1”: 0.00492,
“EchoTime2”: 0.00738,
“ProtocolName”: “gre_field_mapping_2.5mm”
},
“B0FieldIdentifier”: “phasediff”,
“sidecarChanges”: {
“IntendedFor”: [
“sub-_ses-_task-rest_run-01_bold.nii.gz”
]
}
},
{
“datatype”: “fmap”,
“suffix”: “magnitude1”,
“criteria”: {
“ImageType”:[“ORIG*”, “PRIMARY”, “M”,“ND”],
“EchoTime”: 0.00492
},
“sidecarChanges”: {}
},
{
“datatype”: “fmap”,
“suffix”: “magnitude2”,
“criteria”: {
“ImageType”:[“ORIG*”, “PRIMARY”, “M”,“ND”],
“EchoTime”: 0.00738
},
“sidecarChanges”: {}
}
]
}
Hopefully I can adapt it to the two run case.

Best,
Ralf