Issues with BIDSLayout in Nipype

I try to use nipype BIDSDataGrabber to iterate through subject’s files.
When I try to use it I get an error.
The code I try to run is:

from nipype.interfaces.io import BIDSDataGrabber
bg_all = pe.Node(BIDSDataGrabber(), name=‘bids-grabber’)
bg_all.inputs.base_dir = data_dir
bg_all.inputs.output_query = {‘bolds’: dict(type=‘bold’)}
bg_all.iterables = (‘subject’, layout.get_subjects()[:2])
bg_all.run()

The error I receive is:

190806-09:49:16,733 nipype.workflow INFO:
[Node] Setting-up “bids-grabber” in “/tmp/tmp0eqr4eua/bids-grabber”.
190806-09:49:16,740 nipype.workflow INFO:
[Node] Running “bids-grabber” (“nipype.interfaces.io.BIDSDataGrabber”)
190806-09:49:16,747 nipype.workflow WARNING:
[Node] Error on “bids-grabber” (/tmp/tmp0eqr4eua/bids-grabber)

Traceback (most recent call last):

File “”, line 1, in
bg_all.run()

File “/home/or/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py”, line 472, in run
result = self._run_interface(execute=True)

File “/home/or/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py”, line 563, in _run_interface
return self._run_command(execute)

File “/home/or/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py”, line 643, in _run_command
result = self._interface.run(cwd=outdir)

File “/home/or/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/core.py”, line 377, in run
outputs = self.aggregate_outputs(runtime)

File “/home/or/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/core.py”, line 455, in aggregate_outputs
predicted_outputs = self._list_outputs()

File “/home/or/anaconda3/lib/python3.6/site-packages/nipype/interfaces/io.py”, line 2831, in _list_outputs
from bids import BIDSLayout

ImportError: cannot import name ‘BIDSLayout’

If I use a different pybids import there is no issue at all.
Code:

from bids.grabbids import BIDSLayout
layout = BIDSLayout(data_dir)

Any idea what is happening?

Hi @orduek,

It looks like this might be an issue of different pybids versions. Could you confirm that you can execute from bids import BIDSLayout in a python console ? Could you also send your bids version (accessible with bids.__version__) ?

HTH,

Elizabeth

1 Like

The import works ok.
Version is 0.9.2

Thanks

Ahoi hoi @orduek & @emdupre,

I think @emdupre is right, it looks like you’re using different python environments, as pybids.grabbids is not a thing anymore since pybids version 0.7 (please check here for the corresponding API change). So, it appears that your nipype script runs in a different environment than whatever python console you tried. Could you maybe check that via e.g., running which python in your shell or have a look at the project interpreter of whatever IDE you’re using?

HTH, cheers, Peer

1 Like

Indeed you were right - I’ve updated the pybids version.
But now I face a new problem - BIDSLayout finds nothing in my folder, although it was built by fmriPrep.

Ahoi hoi @orduek,

ok, cool, we’re getting there.
So the workflow runs, but returns nothing or does it give you an error?
Could you try in your shell again and/or try the approach mentioned here?

HTH, cheers, Peer

OK.
I think it works.
For some reason, I can’t find the option to read only specific modalities (‘func’).
When I run layout.modalities() I get an empty list

2 Likes

@orduek I have the exact same issue when I run layout.modalities, would be greatful for any ideas what the problem might be.

1 Like