Fmriprep: Fieldmaps KeyError: 'phase'

I get the following error, when I include fieldmaps. I have two phase images and two magnitude images in the fmap folder.

The directory structures passes the BIDS validator, albeit with some warnings, none of which related to fieldmaps.

/usr/local/miniconda/lib/python3.6/site-packages/bids/layout/ ResourceWarning: unclosed file <_io.TextIOWrapper name=’/data/sub-006/ses-glu/fmap/sub-006_ses-glu_run-1_phase1.json’ mode=‘r’ encoding=‘utf-8’>
Process Process-2:
Traceback (most recent call last):
File “/usr/local/miniconda/lib/python3.6/multiprocessing/”, line 258, in _bootstrap
File “/usr/local/miniconda/lib/python3.6/multiprocessing/”, line 93, in run
self._target(*self._args, **self._kwargs)
File “/usr/local/miniconda/lib/python3.6/site-packages/fmriprep/cli/”, line 738, in build_workflow
File “/usr/local/miniconda/lib/python3.6/site-packages/fmriprep/workflows/”, line 216, in init_fmriprep_wf
File “/usr/local/miniconda/lib/python3.6/site-packages/fmriprep/workflows/”, line 505, in init_single_subject_wf
File “/usr/local/miniconda/lib/python3.6/site-packages/fmriprep/workflows/bold/”, line 292, in init_func_preproc_wf
fmap[‘metadata’] = layout.get_metadata(fmap[fmap[‘type’]])
KeyError: ‘phase’

The content of the phase1.json is as follows:
{ “EchoTime”:.00562,
[“ses-%s/func/sub-%s_ses-%s_task-%s_run-1_bold.nii” % (session, subj, session, ‘abc’),
“ses-%s/func/sub-%s_ses-%s_task-%s_run-1_bold.nii” % (session, subj, session, ‘rest’)]}


1 Like

See and

1 Like

I’m running into the same issue myself. Is there a way to create a phase difference image from the two phase images so that fmriprep can apply the fieldmap corrections?

@CFS There is a work-in-progress on this:

You can try using Matt’s branch of fMRIPrep for the moment, and see if it works for you. See the patching working repositories section of the documentation.

1 Like