@@ -251,6 +251,8 @@ class Dcm2niixInputSpec(CommandLineInputSpec):
251251 argstr = "%s" ,
252252 position = - 1 ,
253253 copyfile = False ,
254+ deprecated = '1.0.2' ,
255+ new_name = 'source_dir' ,
254256 mandatory = True ,
255257 xor = ['source_dir' ])
256258 source_dir = Directory (
@@ -260,16 +262,28 @@ class Dcm2niixInputSpec(CommandLineInputSpec):
260262 mandatory = True ,
261263 xor = ['source_names' ])
262264 out_filename = traits .Str (
263- '%t%p' , argstr = "-f %s" , usedefault = True , desc = "Output filename" )
265+ argstr = "-f %s" ,
266+ desc = "Output filename" )
264267 output_dir = Directory (
265- exists = True , argstr = '-o %s' , genfile = True , desc = "Output directory" )
268+ os .getcwd (),
269+ usedefault = True ,
270+ exists = True ,
271+ argstr = '-o %s' ,
272+ desc = "Output directory" )
266273 bids_format = traits .Bool (
267- True , argstr = '-b' , usedefault = True , desc = "Create a BIDS sidecar file" )
274+ True ,
275+ argstr = '-b' ,
276+ usedefault = True ,
277+ desc = "Create a BIDS sidecar file" )
278+ anon_bids = traits .Bool (
279+ argstr = '-ba' ,
280+ requires = ["bids_format" ],
281+ desc = "Anonymize BIDS" )
268282 compress = traits .Enum (
269- 'i ' , [ 'y ' , 'i ' , 'n' ] ,
283+ 'y ' , 'i ' , 'n ' , '3' ,
270284 argstr = '-z %s' ,
271285 usedefault = True ,
272- desc = "Gzip compress images - [y=pigz, i=internal, n=no]" )
286+ desc = "Gzip compress images - [y=pigz, i=internal, n=no, 3=no,3D ]" )
273287 merge_imgs = traits .Bool (
274288 False ,
275289 argstr = '-m' ,
@@ -279,16 +293,39 @@ class Dcm2niixInputSpec(CommandLineInputSpec):
279293 False ,
280294 argstr = '-s' ,
281295 usedefault = True ,
282- desc = "Convert only one image (filename as last input " )
296+ desc = "Single file mode " )
283297 verbose = traits .Bool (
284- False , argstr = '-v' , usedefault = True , desc = "Verbose output" )
298+ False ,
299+ argstr = '-v' ,
300+ usedefault = True ,
301+ desc = "Verbose output" )
285302 crop = traits .Bool (
286- False , argstr = '-x' , usedefault = True , desc = "Crop 3D T1 acquisitions" )
303+ False ,
304+ argstr = '-x' ,
305+ usedefault = True ,
306+ desc = "Crop 3D T1 acquisitions" )
287307 has_private = traits .Bool (
288308 False ,
289309 argstr = '-t' ,
290310 usedefault = True ,
291311 desc = "Flag if text notes includes private patient details" )
312+ compression = traits .Enum (
313+ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ,
314+ argstr = '-%s' ,
315+ desc = "Gz compression level (1=fastest, 9=smallest)" )
316+ comment = traits .Str (
317+ argstr = '-c %s' ,
318+ desc = "Comment stored as NIfTI aux_file" )
319+ ignore_deriv = traits .Bool (
320+ argstr = '-i' ,
321+ desc = "Ignore derived, localizer and 2D images" )
322+ series_numbers = InputMultiPath (
323+ traits .Str (),
324+ argstr = '-n %s' ,
325+ desc = "Selectively convert by series number - can be used up to 16 times" )
326+ philips_float = traits .Bool (
327+ argstr = '-p' ,
328+ desc = "Philips precise float (not display) scaling" )
292329
293330
294331class Dcm2niixOutputSpec (TraitedSpec ):
@@ -306,27 +343,25 @@ class Dcm2niix(CommandLine):
306343
307344 >>> from nipype.interfaces.dcm2nii import Dcm2niix
308345 >>> converter = Dcm2niix()
309- >>> converter.inputs.source_names = ['functional_1.dcm', 'functional_2.dcm']
346+ >>> converter.inputs.source_dir = '.'
310347 >>> converter.inputs.compress = 'i'
311348 >>> converter.inputs.single_file = True
312- >>> converter.inputs.output_dir = '.'
313349 >>> converter.cmdline # doctest: +SKIP
314- 'dcm2niix -b y -z i -x n -t n -m n -f %t%p -o . - s y -v n functional_1.dcm '
350+ 'dcm2niix -b y -z y -x n -t n -m n -s y -v n . '
315351
316352 >>> flags = '-'.join([val.strip() + ' ' for val in sorted(' '.join(converter.cmdline.split()[1:-1]).split('-'))])
317353 >>> flags
318- ' -b y -f %t%p - m n -o . - s y -t n -v n -x n -z i '
354+ ' -b y -m n -s y -t n -v n -x n -z y '
319355 """
320356
321357 input_spec = Dcm2niixInputSpec
322358 output_spec = Dcm2niixOutputSpec
323359 _cmd = 'dcm2niix'
324360
325361 def _format_arg (self , opt , spec , val ):
326- if opt in [
327- 'bids_format' , 'merge_imgs' , 'single_file' , 'verbose' , 'crop' ,
328- 'has_private'
329- ]:
362+ bools = ['bids_format' , 'merge_imgs' , 'single_file' , 'verbose' , 'crop' ,
363+ 'has_private' , 'anon_bids' , 'ignore_deriv' , 'philips_float' ]
364+ if opt in bools :
330365 spec = deepcopy (spec )
331366 if val :
332367 spec .argstr += ' y'
@@ -338,14 +373,16 @@ def _format_arg(self, opt, spec, val):
338373 return super (Dcm2niix , self )._format_arg (opt , spec , val )
339374
340375 def _run_interface (self , runtime ):
341- new_runtime = super (Dcm2niix , self )._run_interface (runtime )
376+ # may use return code 1 despite conversion
377+ runtime = super (Dcm2niix , self )._run_interface (
378+ runtime , correct_return_codes = (0 , 1 , ))
342379 if self .inputs .bids_format :
343380 (self .output_files , self .bvecs , self .bvals ,
344- self .bids ) = self ._parse_stdout (new_runtime .stdout )
381+ self .bids ) = self ._parse_stdout (runtime .stdout )
345382 else :
346383 (self .output_files , self .bvecs , self .bvals ) = self ._parse_stdout (
347- new_runtime .stdout )
348- return new_runtime
384+ runtime .stdout )
385+ return runtime
349386
350387 def _parse_stdout (self , stdout ):
351388 files = []
@@ -359,11 +396,7 @@ def _parse_stdout(self, stdout):
359396 out_file = None
360397 if line .startswith ("Convert " ): # output
361398 fname = str (re .search ('\S+/\S+' , line ).group (0 ))
362- if isdefined (self .inputs .output_dir ):
363- output_dir = self .inputs .output_dir
364- else :
365- output_dir = self ._gen_filename ('output_dir' )
366- out_file = os .path .abspath (os .path .join (output_dir , fname ))
399+ out_file = os .path .abspath (fname )
367400 # extract bvals
368401 if find_b :
369402 bvecs .append (out_file + ".bvec" )
@@ -372,16 +405,11 @@ def _parse_stdout(self, stdout):
372405 # next scan will have bvals/bvecs
373406 elif 'DTI gradients' in line or 'DTI gradient directions' in line or 'DTI vectors' in line :
374407 find_b = True
375- else :
376- pass
377408 if out_file :
378- if self .inputs .compress == 'n' :
379- files .append (out_file + ".nii" )
380- else :
381- files .append (out_file + ".nii.gz" )
409+ ext = '.nii' if self .inputs .compress == 'n' else '.nii.gz'
410+ files .append (out_file + ext )
382411 if self .inputs .bids_format :
383412 bids .append (out_file + ".json" )
384- continue
385413 skip = False
386414 # just return what was done
387415 if not bids :
@@ -397,8 +425,3 @@ def _list_outputs(self):
397425 if self .inputs .bids_format :
398426 outputs ['bids' ] = self .bids
399427 return outputs
400-
401- def _gen_filename (self , name ):
402- if name == 'output_dir' :
403- return os .getcwd ()
404- return None
0 commit comments