Heudiconv KeyError for dwi

I am trying to setup a heuristic to convert my dicoms to bids. Using heudiconv I am successful with structural and functional data, but when I try to add a DWI sequence I am getting the following “KeyError”.

Traceback (most recent call last):
  File "/opt/conda/envs/neuro/bin/heudiconv", line 11, in <module>
    load_entry_point('heudiconv==0.5.2.dev0', 'console_scripts', 'heudiconv')()
  File "/opt/conda/envs/neuro/lib/python2.7/site-packages/heudiconv/cli/run.py", line 125, in main
  File "/opt/conda/envs/neuro/lib/python2.7/site-packages/heudiconv/cli/run.py", line 338, in process_args
  File "/opt/conda/envs/neuro/lib/python2.7/site-packages/heudiconv/convert.py", line 170, in prep_conversion
    info = heuristic.infotodict(seqinfo_list)
  File "/data/BIDS/convertEP199.py", line 74, in infotodict
KeyError: ('sub-{subject}/{session}/dwi/sub-{subject}_{session}_dwi', ('nii.gz',), None)

This is my infotodic() code:

def infotodict(seqinfo):

t1w = create_key('sub-{subject}/{session}/anat/sub-{subject}_{session}_T1w')
t2w = create_key('sub-{subject}/{session}/anat/sub-{subject}_{session}_T2w')
flair = create_key('sub-{subject}/{session}/anat/sub-{subject}_{session}_FLAIR')
rest = create_key('sub-{subject}/{session}/func/sub-{subject}_{session}_task-rest_run-{item:03d}_bold')
dwi = create_key('sub-{subject}/{session}/dwi/sub-{subject}_{session}_dwi')

info = {
        t1w: [],
        t2w: [],
        flair: [],
        rest: [],

for s in seqinfo:
    if s.series_description == 'MPRAGE_T1 _SAGITTAL STEALTH':
    if s.series_description == 'TRA T2 ROSA':
    if s.series_description == 't2_spc_3D_FLAIR':
    if s.series_description == 'act_ep2d_bold_functional_con': 
        info[rest].append({'item' : s.series_id})
    if s.series_description == 'ep2d_diff_mddw_12dir_tract':

return info

I haven’t been able to find anything on the web. Any help is greatly appreciated!

Nevermind. It turns out the solution is posting your code to NeuroStars and then the error becomes immediately obvious.

I forgot to add the dwi key to the info dict. :man_facepalming:

info = {
t1w: [],
t2w: [],
flair: [],
rest: [],
dwi: []

1 Like