@@ -242,6 +242,14 @@ def collect_data(
242
242
...
243
243
ValueError: Conflicting entities for "session" found: madeup // retest
244
244
245
+ >>> bids_root, _ = collect_data(
246
+ ... str(datadir / 'ds114'),
247
+ ... '01',
248
+ ... bids_validate=False,
249
+ ... session_id=None,
250
+ ... bids_filters={'t1w': {'session': 'retest'}})
251
+ >>> bids_root['t1w'] # doctest: +ELLIPSIS
252
+ ['.../ds114/sub-01/ses-retest/anat/sub-01_ses-retest_T1w.nii.gz']
245
253
"""
246
254
if isinstance (bids_dir , BIDSLayout ):
247
255
layout = bids_dir
@@ -251,11 +259,12 @@ def collect_data(
251
259
if not queries :
252
260
queries = copy .deepcopy (DEFAULT_BIDS_QUERIES )
253
261
262
+ session_id = session_id or Query .OPTIONAL
254
263
layout_get_kwargs = {
255
264
'return_type' : 'file' ,
256
265
'subject' : participant_label ,
257
266
'extension' : ['.nii' , '.nii.gz' ],
258
- 'session' : session_id or Query . OPTIONAL ,
267
+ 'session' : session_id ,
259
268
}
260
269
261
270
reserved_entities = [('subject' , participant_label ), ('session' , session_id )]
@@ -264,6 +273,8 @@ def collect_data(
264
273
for acq , entities in bids_filters .items ():
265
274
# BIDS filters will not be able to override subject / session entities
266
275
for entity , param in reserved_entities :
276
+ if param == Query .OPTIONAL :
277
+ continue
267
278
if entity in entities and listify (param ) != listify (entities [entity ]):
268
279
raise ValueError (
269
280
f'Conflicting entities for "{ entity } " found: { entities [entity ]} // { param } '
0 commit comments