34
34
35
35
LOGGER = logging .getLogger ('workflows' )
36
36
37
+
37
38
class BIDSDataGrabberInputSpec (DynamicTraitedSpec ):
38
39
base_dir = Directory (exists = True ,
39
40
desc = 'Path to BIDS Directory.' ,
@@ -91,7 +92,7 @@ class BIDSDataGrabber(BaseInterface):
91
92
output_spec = DynamicTraitedSpec
92
93
_always_run = True
93
94
94
- def __init__ (self , infields = None , outfields = None , ** kwargs ):
95
+ def __init__ (self , infields = None , ** kwargs ):
95
96
"""
96
97
Parameters
97
98
----------
@@ -104,17 +105,13 @@ def __init__(self, infields=None, outfields=None, **kwargs):
104
105
"""
105
106
super (BIDSDataGrabber , self ).__init__ (** kwargs )
106
107
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" }}
118
115
119
116
# If infields is None, use all BIDS entities
120
117
if infields is None :
@@ -123,13 +120,12 @@ def __init__(self, infields=None, outfields=None, **kwargs):
123
120
infields = [i ['name' ] for i in bids_config ['entities' ]]
124
121
125
122
self ._infields = infields
126
- self ._outfields = outfields
127
123
128
124
# used for mandatory inputs check
129
125
undefined_traits = {}
130
126
for key in infields :
131
127
self .inputs .add_trait (key , traits .Any )
132
- undefined_traits [key ] = Undefined
128
+ undefined_traits [key ] = kwargs [ key ] if key in kwargs else Undefined
133
129
134
130
self .inputs .trait_set (trait_change_notify = False , ** undefined_traits )
135
131
@@ -139,10 +135,6 @@ def _run_interface(self, runtime):
139
135
def _list_outputs (self ):
140
136
layout = gb .BIDSLayout (self .inputs .base_dir )
141
137
142
- for key in self ._outfields :
143
- if key not in self .inputs .output_query :
144
- raise ValueError ("Define query for all outputs" )
145
-
146
138
# If infield is not given nm input value, silently ignore
147
139
filters = {}
148
140
for key in self ._infields :
@@ -154,11 +146,9 @@ def _list_outputs(self):
154
146
for key , query in self .inputs .output_query .items ():
155
147
args = query .copy ()
156
148
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 )
159
150
if len (filelist ) == 0 :
160
- msg = 'Output key: %s returned no files' % (
161
- key )
151
+ msg = 'Output key: %s returned no files' % key
162
152
if self .inputs .raise_on_empty :
163
153
raise IOError (msg )
164
154
else :
0 commit comments