12
12
... '../../testing/data'))
13
13
>>> os.chdir(datadir)
14
14
"""
15
- from __future__ import print_function , division , unicode_literals , absolute_import
15
+ from __future__ import print_function , division , unicode_literals , \
16
+ absolute_import
16
17
from builtins import str
17
18
18
19
import os
@@ -106,7 +107,7 @@ def _run_interface(self, runtime):
106
107
out_file = self .inputs .out_fieldmap
107
108
im = nb .load (out_file , mmap = NUMPY_MMAP )
108
109
dumb_img = nb .Nifti1Image (np .zeros (im .shape ), im .affine ,
109
- im .header )
110
+ im .header )
110
111
out_nii = nb .funcs .concat_images ((im , dumb_img ))
111
112
nb .save (out_nii , out_file )
112
113
@@ -450,26 +451,25 @@ class EddyInputSpec(FSLCommandInputSpec):
450
451
451
452
452
453
class EddyOutputSpec (TraitedSpec ):
453
- out_corrected = File (exists = True ,
454
- desc = ('4D image file containing all the corrected '
455
- 'volumes' ))
456
- out_parameter = File (exists = True ,
457
- desc = ('text file with parameters definining the '
458
- 'field and movement for each scan' ))
459
- out_rotated_bvecs = File (exists = True ,
460
- desc = ('File containing rotated b-values for all volumes' ))
461
- out_movement_rms = File (exists = True ,
462
- desc = ('Summary of the "total movement" in each volume' ))
463
- out_restricted_movement_rms = File (exists = True ,
464
- desc = ('Summary of the "total movement" in each volume '
465
- 'disregarding translation in the PE direction' ))
466
- out_shell_alignment_parameters = File (exists = True ,
467
- desc = ('File containing rigid body movement parameters '
468
- 'between the different shells as estimated by a '
469
- 'post-hoc mutual information based registration' ))
470
- out_outlier_report = File (exists = True ,
471
- desc = ('Text-file with a plain language report '
472
- 'on what outlier slices eddy has found' ))
454
+ out_corrected = File (
455
+ exists = True , desc = '4D image file containing all the corrected volumes' )
456
+ out_parameter = File (
457
+ exists = True , desc = ('text file with parameters definining the field and'
458
+ 'movement for each scan' ))
459
+ out_rotated_bvecs = File (
460
+ exists = True , desc = 'File containing rotated b-values for all volumes' )
461
+ out_movement_rms = File (
462
+ exists = True , desc = 'Summary of the "total movement" in each volume' )
463
+ out_restricted_movement_rms = File (
464
+ exists = True , desc = ('Summary of the "total movement" in each volume '
465
+ 'disregarding translation in the PE direction' ))
466
+ out_shell_alignment_parameters = File (
467
+ exists = True , desc = ('File containing rigid body movement parameters '
468
+ 'between the different shells as estimated by a '
469
+ 'post-hoc mutual information based registration' ))
470
+ out_outlier_report = File (
471
+ exists = True , desc = ('Text-file with a plain language report on what '
472
+ 'outlier slices eddy has found' ))
473
473
474
474
475
475
class Eddy (FSLCommand ):
@@ -491,10 +491,16 @@ class Eddy(FSLCommand):
491
491
>>> eddy.inputs.in_acqp = 'epi_acqp.txt'
492
492
>>> eddy.inputs.in_bvec = 'bvecs.scheme'
493
493
>>> eddy.inputs.in_bval = 'bvals.scheme'
494
+ >>> eddy.inputs.use_cuda = True
494
495
>>> eddy.cmdline # doctest: +ELLIPSIS +ALLOW_UNICODE
495
- 'eddy_openmp --acqp=epi_acqp.txt --bvals=bvals.scheme --bvecs=bvecs.scheme \
496
+ 'eddy_cuda --acqp=epi_acqp.txt --bvals=bvals.scheme --bvecs=bvecs.scheme \
496
497
--imain=epi.nii --index=epi_index.txt --mask=epi_mask.nii \
497
498
--out=.../eddy_corrected'
499
+ >>> eddy.inputs.use_cuda = False
500
+ >>> eddy.cmdline # doctest: +ELLIPSIS +ALLOW_UNICODE
501
+ 'eddy_openmp --acqp=epi_acqp.txt --bvals=bvals.scheme \
502
+ --bvecs=bvecs.scheme --imain=epi.nii --index=epi_index.txt \
503
+ --mask=epi_mask.nii --out=.../eddy_corrected'
498
504
>>> res = eddy.run() # doctest: +SKIP
499
505
500
506
"""
@@ -507,12 +513,13 @@ class Eddy(FSLCommand):
507
513
def __init__ (self , ** inputs ):
508
514
super (Eddy , self ).__init__ (** inputs )
509
515
self .inputs .on_trait_change (self ._num_threads_update , 'num_threads' )
510
- if isdefined (self .inputs .use_cuda ):
511
- self ._use_cuda ()
512
516
if not isdefined (self .inputs .num_threads ):
513
517
self .inputs .num_threads = self ._num_threads
514
518
else :
515
519
self ._num_threads_update ()
520
+ self .inputs .on_trait_change (self ._use_cuda , 'use_cuda' )
521
+ if isdefined (self .inputs .use_cuda ):
522
+ self ._use_cuda ()
516
523
517
524
def _num_threads_update (self ):
518
525
self ._num_threads = self .inputs .num_threads
@@ -524,10 +531,21 @@ def _num_threads_update(self):
524
531
self .inputs .num_threads )
525
532
526
533
def _use_cuda (self ):
527
- if self .inputs .use_cuda :
528
- _cmd = 'eddy_cuda'
529
- else :
530
- _cmd = 'eddy_openmp'
534
+ self ._cmd = 'eddy_cuda' if self .inputs .use_cuda else 'eddy_openmp'
535
+
536
+ def _run_interface (self , runtime ):
537
+ # If 'eddy_openmp' is missing, use 'eddy'
538
+ FSLDIR = os .getenv ('FSLDIR' , '' )
539
+ cmd = self ._cmd
540
+ if all ((FSLDIR != '' ,
541
+ cmd == 'eddy_openmp' ,
542
+ not os .path .exists (os .path .join (FSLDIR , cmd )))):
543
+ self ._cmd = 'eddy'
544
+ runtime = super (Eddy , self )._run_interface (runtime )
545
+
546
+ # Restore command to avoid side-effects
547
+ self ._cmd = cmd
548
+ return runtime
531
549
532
550
def _format_arg (self , name , spec , value ):
533
551
if name == 'in_topup_fieldcoef' :
@@ -551,7 +569,8 @@ def _list_outputs(self):
551
569
out_restricted_movement_rms = os .path .abspath (
552
570
'%s.eddy_restricted_movement_rms' % self .inputs .out_base )
553
571
out_shell_alignment_parameters = os .path .abspath (
554
- '%s.eddy_post_eddy_shell_alignment_parameters' % self .inputs .out_base )
572
+ '%s.eddy_post_eddy_shell_alignment_parameters'
573
+ % self .inputs .out_base )
555
574
out_outlier_report = os .path .abspath (
556
575
'%s.eddy_outlier_report' % self .inputs .out_base )
557
576
@@ -560,9 +579,11 @@ def _list_outputs(self):
560
579
if os .path .exists (out_movement_rms ):
561
580
outputs ['out_movement_rms' ] = out_movement_rms
562
581
if os .path .exists (out_restricted_movement_rms ):
563
- outputs ['out_restricted_movement_rms' ] = out_restricted_movement_rms
582
+ outputs ['out_restricted_movement_rms' ] = \
583
+ out_restricted_movement_rms
564
584
if os .path .exists (out_shell_alignment_parameters ):
565
- outputs ['out_shell_alignment_parameters' ] = out_shell_alignment_parameters
585
+ outputs ['out_shell_alignment_parameters' ] = \
586
+ out_shell_alignment_parameters
566
587
if os .path .exists (out_outlier_report ):
567
588
outputs ['out_outlier_report' ] = out_outlier_report
568
589
0 commit comments