Problem with calc_phdiff node when running fmriprep on multiple sessions

I’ve been running fMRIPrep on some data and it’s running ok for one session, but as soon as I try to run two sessions I get an error message. It seems to be related to the field maps:

  1. error message is: > nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node calc_phdiff
  2. if I add the -ignore field maps option then it runs without any issues

I can’t work out what would be causing the problem- any ideas of things to check? I’ve pasted the full output below:

221109-15:01:20,968 nipype.workflow INFO:
	 [Node] Finished "mcflirt", elapsed time 25.947368s.
221109-15:01:22,947 nipype.workflow WARNING:
	 Storing result file without outputs
221109-15:01:22,947 nipype.workflow WARNING:
	 [Node] Error on "fmriprep_22_0_wf.single_subject_003_wf.fmap_preproc_wf.wf_phasediff_fmap0.phdiff_wf.calc_phdiff" (/scratch/fmriprep_22_0_wf/single_subject_003_wf/fmap_preproc_wf/wf_phasediff_fmap0/phdiff_wf/calc_phdiff)
221109-15:01:22,948 nipype.workflow ERROR:
	 Node calc_phdiff failed to run on host 311f56f406bb.
221109-15:01:22,951 nipype.workflow ERROR:
	 Saving crash info to /out/sub-003/log/20221109-145824_4b18e9de-0fad-4223-aa4a-576e27092be5/crash-20221109-150122-root-calc_phdiff-c17cf4c1-0e17-4cfc-a0ef-8963da658ad3.txt
Traceback (most recent call last):
  File "/opt/conda/lib/python3.9/site-packages/nipype/pipeline/plugins/multiproc.py", line 344, in _send_procs_to_workers
    self.procs[jobid].run(updatehash=updatehash)
  File "/opt/conda/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
  File "/opt/conda/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface
    return self._run_command(execute)
  File "/opt/conda/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py", line 771, in _run_command
    raise NodeExecutionError(msg)
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node calc_phdiff.

Traceback:
	Traceback (most recent call last):
	  File "/opt/conda/lib/python3.9/site-packages/nipype/interfaces/base/core.py", line 398, in run
	    runtime = self._run_interface(runtime)
	  File "/opt/conda/lib/python3.9/site-packages/sdcflows/interfaces/fmap.py", line 93, in _run_interface
	    self._results["phase_diff"], self._results["metadata"] = _subtract_phases(
	  File "/opt/conda/lib/python3.9/site-packages/sdcflows/utils/phasemanip.py", line 56, in subtract_phases
	    if echo_times[0] > echo_times[1]:
	TypeError: '>' not supported between instances of 'NoneType' and 'NoneType'


221109-15:01:22,968 nipype.workflow CRITICAL:
	 fMRIPrep failed: Traceback (most recent call last):
  File "/opt/conda/lib/python3.9/site-packages/nipype/pipeline/plugins/multiproc.py", line 344, in _send_procs_to_workers
    self.procs[jobid].run(updatehash=updatehash)
  File "/opt/conda/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py", line 527, in run
    result = self._run_interface(execute=True)
  File "/opt/conda/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py", line 645, in _run_interface
    return self._run_command(execute)
  File "/opt/conda/lib/python3.9/site-packages/nipype/pipeline/engine/nodes.py", line 771, in _run_command
    raise NodeExecutionError(msg)
nipype.pipeline.engine.nodes.NodeExecutionError: Exception raised while executing Node calc_phdiff.

Traceback:
	Traceback (most recent call last):
	  File "/opt/conda/lib/python3.9/site-packages/nipype/interfaces/base/core.py", line 398, in run
	    runtime = self._run_interface(runtime)
	  File "/opt/conda/lib/python3.9/site-packages/sdcflows/interfaces/fmap.py", line 93, in _run_interface
	    self._results["phase_diff"], self._results["metadata"] = _subtract_phases(
	  File "/opt/conda/lib/python3.9/site-packages/sdcflows/utils/phasemanip.py", line 56, in subtract_phases
	    if echo_times[0] > echo_times[1]:
	TypeError: '>' not supported between instances of 'NoneType' and 'NoneType'


221109-15:01:24,172 cli ERROR:
	 Preprocessing did not finish successfully. Errors occurred while processing data from participants: 003 (1). Check the HTML reports for details.
221109-15:01:24,172 cli ERROR:
	 Preprocessing did not finish successfully. Errors occurred while processing data from participants: 003 (1). Check the HTML reports for details.
221109-15:01:28,725 nipype.workflow INFO:
	 [Node] Finished "mcflirt", elapsed time 25.779675s.
221109-15:01:31,991 nipype.workflow INFO:
	 [Node] Finished "mcflirt", elapsed time 26.98499s.
221109-15:01:35,855 nipype.workflow INFO:
	 [Node] Finished "mcflirt", elapsed time 28.918328s.
221109-15:01:48,693 nipype.workflow INFO:
	 [Node] Finished "init_aff", elapsed time 31.484635s.
fMRIPrep: Please report errors to https://github.com/nipreps/fmriprep/issues

Hi,

Which FMRIPREP version are you using? Is your dataset BIDS validated?
How did you specify the relationship between the fmap images and the func images?

Hi @jsein

Thanks for getting back to me!

I’m using fMRIPrep 22.0.2, and yes the dataset is BIDS validated.

The folder structure is as follows:

dataset_description.json
sub-001
      ses-1
            anat
                  sub-001_ses-1_T1w.nii.gz
            fmap
                  sub-001_ses-1_magnitude1.nii.gz
                  sub-001_ses-1_phasediff.json
                  sub-001_ses-1_phasediff.nii.gz
            func
                  sub-001_ses-1_task-1_bold.json
                  sub-001_ses-1_task-1_bold.nii.gz
                  sub-001_ses-1_task-1_events.tsv
                  sub-001_ses-1_task-2_bold.json
                  sub-001_ses-1_task-2_bold.nii.gz
                  sub-001_ses-1_task-2_events.tsv
                  sub-001_ses-1_task-3_bold.json
                  sub-001_ses-1_task-3_bold.nii.gz
                  sub-001_ses-1_task-3_events.tsv
      ses-2
            anat
                  sub-001_ses-2_T1w.nii.gz
            fmap
                  sub-001_ses-2_magnitude1.nii.gz
                  sub-001_ses-2_phasediff.json
                  sub-001_ses-2_phasediff.nii.gz
            func
                  sub-001_ses-2_task-1_bold.json
                  sub-001_ses-2_task-1_bold.nii.gz
                  sub-001_ses-2_task-1_events.tsv
                  sub-001_ses-2_task-2_bold.json
                  sub-001_ses-2_task-2_bold.nii.gz
                  sub-001_ses-2_task-2_events.tsv
                  sub-001_ses-2_task-3_bold.json
                  sub-001_ses-2_task-3_bold.nii.gz
                  sub-001_ses-2_task-3_events.tsv

and the fmap json files contain:

{
			"SeriesDescription": "gre_field_mapping",
			"ScanningSequence": "GR",
			"SequenceVariant": "SP",
			"SequenceName": "*fm2d2r",
			"EchoTime1": 0.01, 
			"EchoTime2": 0.01476, 
			"RepetitionTime": 1.17,
			"FlipAngle": 90,
			"B0FieldIdentifier": "phasediff_fmap0",
			"PhaseEncodingDirection": "i", 
			"ImageType": [
			"ORIGINAL",
			"PRIMARY",
			"P",
			"ND",
			"PHASE"
			],
			"IntendedFor": ["ses-1/func/sub-001_ses-1_task-1_bold.nii.gz",
			"ses-1/func/sub-001_ses-1_task-2_bold.nii.gz",
			"ses-1/func/sub-001_ses-1_task-3_bold.nii.gz"]}

Thank you for those details.

Could you also show the content of a json file in the func/ folder?

I suspect that you are using the B0FieldIdentifier/B0FieldSource convention, in addition to the ‘IntendedFor’ convention, which is the recommended way to go, but if you use the the name for B0FieldSource in ses-1 and ses-2, FMRIPREP will try to merge the fieldmaps which is not what you want and may produce the error you see.

But my suspicion may be wrong, let’s see what you have.

Thanks again for looking at this @jsein !

That’s an interesting point, I hadn’t thought about that!

json files in the func folder are:

{
	"TaskName": "Task 1",
	"Modality": "MR",
	"MagneticFieldStrength": 1.5,
	"Manufacturer": "Siemens",
	"ManufacturersModelName": "Avanto",
	"InstitutionName": "University_College",
	"DeviceSerialNumber": "26099",
	"SoftwareVersions": "syngo_MR_B17",
	"ProtocolName": "oj_mepi_v01_32_Channel",
	"SliceThickness": 2,
	"SpacingBetweenSlices": 3,
	"EchoTime": 0.05,
	"RepetitionTime": 3.5,
	"FlipAngle": 90,
	"TotalReadoutTime": 0.032,
	"PhaseEncodingDirection": "j-",
	"B0FieldSource": "phasediff_fmap0",
	"SliceTiming":[0,0.0875,0.1750,0.2625,0.3500,0.4375,0.5250,0.6125,0.7000,0.7875,0.8750,0.9625,1.0500,1.1375,1.2250,1.3125,1.4000,1.4875,1.5750,1.6625,1.7500,1.8375,1.9250,2.0125,2.1000,2.1875,2.2750,2.3625,2.4500,2.5375,2.6250,2.7125,2.8000,2.8875,2.9750,3.0625,3.1500,3.2375,3.3250,3.4125],
}

If I remove B0FieldSource from the json files I get the same error- is there a different way around this that you can think of?

To follow up on this idea: did you also remove the mention B0FieldIdentifier in the fmap json files? (or at least give them a different name between the different sessions)?

When you re-run FMRIPREP, did you first remove the temporary files from the previous execution?