Skip to content

Commit 9a349c8

Browse files
authored
Merge pull request #731 from mgxd/fix/collect-data-clobber
FIX: Ensure we do not clobber entities from bids filters
2 parents eec150e + e25613c commit 9a349c8

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

niworkflows/utils/bids.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ def collect_data(
207207
>>> bids_root['t2w'] # doctest: +ELLIPSIS
208208
[]
209209
>>> bids_root, _ = collect_data(str(datadir / 'ds051'), '01',
210-
... bids_validate=False, bids_filters={'t1w':{'run': 1}})
210+
... bids_validate=False,
211+
... bids_filters={'t1w':{'run': 1, 'session': None}})
211212
>>> bids_root['t1w'] # doctest: +ELLIPSIS
212213
['.../ds051/sub-01/anat/sub-01_run-01_T1w.nii.gz']
213214
@@ -217,6 +218,13 @@ def collect_data(
217218
else:
218219
layout = BIDSLayout(str(bids_dir), validate=bids_validate)
219220

221+
layout_get_kwargs = {
222+
'return_type': 'file',
223+
'subject': participant_label,
224+
'extension': ['.nii', '.nii.gz'],
225+
'session': session_id,
226+
}
227+
220228
queries = {
221229
"fmap": {"datatype": "fmap"},
222230
"bold": {"datatype": "func", "suffix": "bold", "part": ["mag", None]},
@@ -229,6 +237,10 @@ def collect_data(
229237
bids_filters = bids_filters or {}
230238
for acq, entities in bids_filters.items():
231239
queries[acq].update(entities)
240+
for entity in list(layout_get_kwargs.keys()):
241+
if entity in entities:
242+
# avoid clobbering layout.get
243+
del layout_get_kwargs[entity]
232244

233245
if task:
234246
queries["bold"]["task"] = task
@@ -237,15 +249,7 @@ def collect_data(
237249
queries["bold"]["echo"] = echo
238250

239251
subj_data = {
240-
dtype: sorted(
241-
layout.get(
242-
return_type="file",
243-
subject=participant_label,
244-
session=session_id,
245-
extension=[".nii", ".nii.gz"],
246-
**query,
247-
)
248-
)
252+
dtype: sorted(layout.get(**layout_get_kwargs, **query))
249253
for dtype, query in queries.items()
250254
}
251255

0 commit comments

Comments
 (0)