Skip to content

Commit 615515c

Browse files
committed
ENH: More flexible BIDSDataGrabber creation
1 parent 1a4e640 commit 615515c

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

nipype/interfaces/bids_utils.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
LOGGER = logging.getLogger('workflows')
3636

37+
3738
class BIDSDataGrabberInputSpec(DynamicTraitedSpec):
3839
base_dir = Directory(exists=True,
3940
desc='Path to BIDS Directory.',
@@ -91,7 +92,7 @@ class BIDSDataGrabber(BaseInterface):
9192
output_spec = DynamicTraitedSpec
9293
_always_run = True
9394

94-
def __init__(self, infields=None, outfields=None, **kwargs):
95+
def __init__(self, infields=None, **kwargs):
9596
"""
9697
Parameters
9798
----------
@@ -104,17 +105,13 @@ def __init__(self, infields=None, outfields=None, **kwargs):
104105
"""
105106
super(BIDSDataGrabber, self).__init__(**kwargs)
106107
if not have_pybids:
107-
raise ImportError("The BIDSEventsGrabber interface requires pybids."
108-
" Please make sure it is installed.")
109-
110-
# If outfields is None use anat and func as default
111-
if outfields is None:
112-
outfields = ['func', 'anat']
113-
self.inputs.output_query = {
114-
"func": {"modality": "func"},
115-
"anat": {"modality": "anat"}}
116-
else:
117-
self.inputs.output_query = {}
108+
raise ImportError(
109+
"The BIDSEventsGrabber interface requires pybids."
110+
" Please make sure it is installed.")
111+
112+
if not isdefined(self.inputs.output_query):
113+
self.inputs.output_query = {"func": {"modality": "func"},
114+
"anat": {"modality": "anat"}}
118115

119116
# If infields is None, use all BIDS entities
120117
if infields is None:
@@ -123,13 +120,12 @@ def __init__(self, infields=None, outfields=None, **kwargs):
123120
infields = [i['name'] for i in bids_config['entities']]
124121

125122
self._infields = infields
126-
self._outfields = outfields
127123

128124
# used for mandatory inputs check
129125
undefined_traits = {}
130126
for key in infields:
131127
self.inputs.add_trait(key, traits.Any)
132-
undefined_traits[key] = Undefined
128+
undefined_traits[key] = kwargs[key] if key in kwargs else Undefined
133129

134130
self.inputs.trait_set(trait_change_notify=False, **undefined_traits)
135131

@@ -139,10 +135,6 @@ def _run_interface(self, runtime):
139135
def _list_outputs(self):
140136
layout = gb.BIDSLayout(self.inputs.base_dir)
141137

142-
for key in self._outfields:
143-
if key not in self.inputs.output_query:
144-
raise ValueError("Define query for all outputs")
145-
146138
# If infield is not given nm input value, silently ignore
147139
filters = {}
148140
for key in self._infields:
@@ -154,11 +146,9 @@ def _list_outputs(self):
154146
for key, query in self.inputs.output_query.items():
155147
args = query.copy()
156148
args.update(filters)
157-
filelist = layout.get(return_type=self.inputs.return_type,
158-
**args)
149+
filelist = layout.get(return_type=self.inputs.return_type, **args)
159150
if len(filelist) == 0:
160-
msg = 'Output key: %s returned no files' % (
161-
key)
151+
msg = 'Output key: %s returned no files' % key
162152
if self.inputs.raise_on_empty:
163153
raise IOError(msg)
164154
else:

0 commit comments

Comments
 (0)