@@ -251,6 +251,8 @@ class Dcm2niixInputSpec(CommandLineInputSpec):
251
251
argstr = "%s" ,
252
252
position = - 1 ,
253
253
copyfile = False ,
254
+ deprecated = '1.0.2' ,
255
+ new_name = 'source_dir' ,
254
256
mandatory = True ,
255
257
xor = ['source_dir' ])
256
258
source_dir = Directory (
@@ -260,16 +262,28 @@ class Dcm2niixInputSpec(CommandLineInputSpec):
260
262
mandatory = True ,
261
263
xor = ['source_names' ])
262
264
out_filename = traits .Str (
263
- '%t%p' , argstr = "-f %s" , usedefault = True , desc = "Output filename" )
265
+ argstr = "-f %s" ,
266
+ desc = "Output filename" )
264
267
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" )
266
273
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" )
268
282
compress = traits .Enum (
269
- 'i ' , [ 'y ' , 'i ' , 'n' ] ,
283
+ 'y ' , 'i ' , 'n ' , '3' ,
270
284
argstr = '-z %s' ,
271
285
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 ]" )
273
287
merge_imgs = traits .Bool (
274
288
False ,
275
289
argstr = '-m' ,
@@ -279,16 +293,39 @@ class Dcm2niixInputSpec(CommandLineInputSpec):
279
293
False ,
280
294
argstr = '-s' ,
281
295
usedefault = True ,
282
- desc = "Convert only one image (filename as last input " )
296
+ desc = "Single file mode " )
283
297
verbose = traits .Bool (
284
- False , argstr = '-v' , usedefault = True , desc = "Verbose output" )
298
+ False ,
299
+ argstr = '-v' ,
300
+ usedefault = True ,
301
+ desc = "Verbose output" )
285
302
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" )
287
307
has_private = traits .Bool (
288
308
False ,
289
309
argstr = '-t' ,
290
310
usedefault = True ,
291
311
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" )
292
329
293
330
294
331
class Dcm2niixOutputSpec (TraitedSpec ):
@@ -306,27 +343,25 @@ class Dcm2niix(CommandLine):
306
343
307
344
>>> from nipype.interfaces.dcm2nii import Dcm2niix
308
345
>>> converter = Dcm2niix()
309
- >>> converter.inputs.source_names = ['functional_1.dcm', 'functional_2.dcm']
346
+ >>> converter.inputs.source_dir = '.'
310
347
>>> converter.inputs.compress = 'i'
311
348
>>> converter.inputs.single_file = True
312
- >>> converter.inputs.output_dir = '.'
313
349
>>> 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 . '
315
351
316
352
>>> flags = '-'.join([val.strip() + ' ' for val in sorted(' '.join(converter.cmdline.split()[1:-1]).split('-'))])
317
353
>>> 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 '
319
355
"""
320
356
321
357
input_spec = Dcm2niixInputSpec
322
358
output_spec = Dcm2niixOutputSpec
323
359
_cmd = 'dcm2niix'
324
360
325
361
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 :
330
365
spec = deepcopy (spec )
331
366
if val :
332
367
spec .argstr += ' y'
@@ -338,14 +373,16 @@ def _format_arg(self, opt, spec, val):
338
373
return super (Dcm2niix , self )._format_arg (opt , spec , val )
339
374
340
375
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 , ))
342
379
if self .inputs .bids_format :
343
380
(self .output_files , self .bvecs , self .bvals ,
344
- self .bids ) = self ._parse_stdout (new_runtime .stdout )
381
+ self .bids ) = self ._parse_stdout (runtime .stdout )
345
382
else :
346
383
(self .output_files , self .bvecs , self .bvals ) = self ._parse_stdout (
347
- new_runtime .stdout )
348
- return new_runtime
384
+ runtime .stdout )
385
+ return runtime
349
386
350
387
def _parse_stdout (self , stdout ):
351
388
files = []
@@ -359,11 +396,7 @@ def _parse_stdout(self, stdout):
359
396
out_file = None
360
397
if line .startswith ("Convert " ): # output
361
398
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 )
367
400
# extract bvals
368
401
if find_b :
369
402
bvecs .append (out_file + ".bvec" )
@@ -372,16 +405,11 @@ def _parse_stdout(self, stdout):
372
405
# next scan will have bvals/bvecs
373
406
elif 'DTI gradients' in line or 'DTI gradient directions' in line or 'DTI vectors' in line :
374
407
find_b = True
375
- else :
376
- pass
377
408
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 )
382
411
if self .inputs .bids_format :
383
412
bids .append (out_file + ".json" )
384
- continue
385
413
skip = False
386
414
# just return what was done
387
415
if not bids :
@@ -397,8 +425,3 @@ def _list_outputs(self):
397
425
if self .inputs .bids_format :
398
426
outputs ['bids' ] = self .bids
399
427
return outputs
400
-
401
- def _gen_filename (self , name ):
402
- if name == 'output_dir' :
403
- return os .getcwd ()
404
- return None
0 commit comments