pybids icon indicating copy to clipboard operation
pybids copied to clipboard

'RunNode' object has no attribute 'get_collections'

Open adelavega opened this issue 5 years ago • 5 comments

In [1]: from bids.layout import BIDSLayout

In [2]: layout = BIDSLayout('/datasets/raw/SherlockMerlin/', derivatives=True)

In [3]: layout.get_collections(subject='19', task='MerlinMovie', level='run')

Throws the following error:

/usr/local/lib/python3.6/site-packages/bids/layout/layout.py in get_collections(self, level, types, variables, merge, sampling_rate, skip_empty, **kwargs)
    875         index = load_variables(self, types=types, levels=level,
    876                                skip_empty=skip_empty, **kwargs)
--> 877         return index.get_collections(level, variables, merge,
    878                                      sampling_rate=sampling_rate)
    879 

AttributeError: 'RunNode' object has no attribute 'get_collections'

I remember seeing this before but I see no mention of this in issues or PRs.

adelavega avatar Oct 14 '19 17:10 adelavega

Okay there are two problems here:

  1. There is a flaw in the logic for _load_time_variables. In this line: https://github.com/bids-standard/pybids/blob/0a14a17a824be629736082dec5193c04503ea180/bids/layout/layout.py#L800

When looping over images, if a "result" is found for those entities, it is returned. However, this results in a RunNode being returned instead of a RunIndex, and the subsequent calls are expecting a RunIndex, so I'm not sure why this is like this, and in what situations this would be triggered

  1. More relevant to my use case, the reason this is being triggered in the first place is because pybids is looping over the preproc and raw niftis that have the same entities. Thus, the first image gets processed as normal, and its events are extracted, but then on the second go-around there is already a "result" so that line gets triggered.

So more direct to my issue, I can fix this by limiting that image list to only "raw" or only "preproc" files (probably the former). But it seems like anything #1 gets triggered in another situation it'll cause problems, so that should probably get fixed too.

adelavega avatar Oct 14 '19 19:10 adelavega

Setting scope to raw will not work here, because I want the scope of variabels to include both raw and derivatives, but only loop over raw images when loading data.

adelavega avatar Oct 14 '19 19:10 adelavega

I believe I can fix my problem by querying like this:

layout.get_collections(subject='19', task='MerlinMovie', level='run', desc=None)

but I'll leave this issue open for when that refactor of the io happens.

adelavega avatar Oct 14 '19 19:10 adelavega

This is going to be a problem anytime you have multiple matching images.

For example, if you forgot to specify desc=preproc or space='MNI152NLin2009cAsym' in analysis.setup()

adelavega avatar Oct 30 '19 20:10 adelavega

This came up again for me... I think it's a pretty big bug so I'll try to get around to it.

One easy fix would be to throw an error when more than one file matches, and to show them

adelavega avatar Jan 08 '20 23:01 adelavega