bids.BIDSLayout.build_path() removes dir- label from dwi images

I am using bids.BIDSLayout.build_path() to build valid BIDS-paths for images that I am saving. When I try to build a path using modified entities for a DWI image, bids.BIDSLayout.build_path() discards the provided dir- label.


import bids

layout = bids.BIDSLayout('./')

dwis = layout.get(suffix='dwi', extension=['nii', 'nii.gz'])

ent = dwis[0].entities
ent.update({'acquisition': 'new'})

# 'sub-01_ses-01_dir-AP_dwi.nii.gz'

# 'sub-01_ses-1_acq-new_dwi.nii.gz'

Do I need to use non-default path_patterns?

You have to modify the default_path_patterns, adding this entry (or replacing the dwi entry with it):


This looks like a bug, and perhaps we should update the default path patterns.

Can you submit an issue to the pybids repo? Issues · bids-standard/pybids · GitHub

1 Like

Thank you! Bug report has been submitted…