@@ -261,47 +261,41 @@ class BIDSDataGrabber(SimpleInterface):
261261 input_spec = _BIDSDataGrabberInputSpec
262262 output_spec = _BIDSDataGrabberOutputSpec
263263
264- def __init__ (self , * args , ** kwargs ):
265- anat_only = kwargs .pop ('anat_only' , None )
266- anat_derivatives = kwargs .pop ('anat_derivatives' , None )
267- require_t1w = kwargs .pop ('require_t1w' , True )
268- require_funcs = kwargs .pop ('require_funcs' , True )
269- require_pet = kwargs .pop ('require_pet' , False )
270- super ().__init__ (* args , ** kwargs )
271-
264+ _image_types = {'asl' , 'bold' , 'dwi' , 'flair' , 'fmap' , 'pet' , 'roi' , 'sbref' , 't1w' , 't2w' }
265+
266+ def __init__ (
267+ self ,
268+ anat_only = False ,
269+ anat_derivatives = None ,
270+ * args ,
271+ ** kwargs ,
272+ ):
273+ default_required = {'t1w' , 'bold' }
274+
275+ for imtype in self ._image_types :
276+ kwarg = f'require_{ imtype } '
277+ val = kwargs .pop (kwarg , True if imtype in default_required else False )
278+ setattr (self , f'_{ kwarg } ' , val )
279+
280+ self ._require_t1w = self ._require_t1w and anat_derivatives is None
272281 if anat_only :
273- self ._require_funcs = False
282+ self ._require_bold = False
274283 self ._require_pet = False
275- else :
276- self ._require_funcs = False if require_pet else require_funcs
277- self ._require_pet = require_pet
278284
279- self . _require_t1w = require_t1w and anat_derivatives is None
285+ super (). __init__ ( * args , ** kwargs )
280286
281287 def _run_interface (self , runtime ):
282288 bids_dict = self .inputs .subject_data
283289
284290 self ._results ['out_dict' ] = bids_dict
285291 self ._results .update (bids_dict )
286292
287- if self ._require_t1w and not bids_dict ['t1w' ]:
288- raise FileNotFoundError (
289- f'No T1w images found for subject sub-{ self .inputs .subject_id } '
290- )
291-
292- if self ._require_funcs and not bids_dict ['bold' ]:
293- raise FileNotFoundError (
294- f'No functional images found for subject sub-{ self .inputs .subject_id } '
295- )
296-
297- if self ._require_pet and not bids_dict .get ('pet' ):
298- raise FileNotFoundError (
299- f'No PET images found for subject sub-{ self .inputs .subject_id } '
300- )
301-
302- for imtype in ['t2w' , 'flair' , 'fmap' , 'sbref' , 'roi' , 'pet' , 'asl' ]:
293+ for imtype in self ._image_types :
303294 if not bids_dict [imtype ]:
304- LOGGER .info ('No "%s" images found for sub-%s' , imtype , self .inputs .subject_id )
295+ msg = f'No "{ imtype } " images found for sub-{ self .inputs .subject_id } '
296+ if getattr (self , f'_require_{ imtype } ' , False ): # only raise if image is required
297+ raise FileNotFoundError (msg )
298+ LOGGER .info (msg )
305299
306300 return runtime
307301
0 commit comments