21
21
import nibabel as nb
22
22
import warnings
23
23
24
- from ... import logging
25
24
from ...utils .filemanip import split_filename
26
25
from ...utils import NUMPY_MMAP
27
26
@@ -492,13 +491,20 @@ class Eddy(FSLCommand):
492
491
>>> eddy.inputs.in_acqp = 'epi_acqp.txt'
493
492
>>> eddy.inputs.in_bvec = 'bvecs.scheme'
494
493
>>> eddy.inputs.in_bval = 'bvals.scheme'
494
+ >>> eddy.inputs.use_cuda = True
495
495
>>> eddy.cmdline # doctest: +ELLIPSIS +ALLOW_UNICODE
496
- 'eddy --acqp=epi_acqp.txt --bvals=bvals.scheme --bvecs=bvecs.scheme \
496
+ 'eddy_cuda --acqp=epi_acqp.txt --bvals=bvals.scheme --bvecs=bvecs.scheme \
497
497
--imain=epi.nii --index=epi_index.txt --mask=epi_mask.nii \
498
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'
499
504
>>> res = eddy.run() # doctest: +SKIP
500
505
501
506
"""
507
+ _cmd = 'eddy_openmp'
502
508
input_spec = EddyInputSpec
503
509
output_spec = EddyOutputSpec
504
510
@@ -511,6 +517,9 @@ def __init__(self, **inputs):
511
517
self .inputs .num_threads = self ._num_threads
512
518
else :
513
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 ()
514
523
515
524
def _num_threads_update (self ):
516
525
self ._num_threads = self .inputs .num_threads
@@ -521,27 +530,22 @@ def _num_threads_update(self):
521
530
self .inputs .environ ['OMP_NUM_THREADS' ] = str (
522
531
self .inputs .num_threads )
523
532
524
- @staticmethod
525
- def _eddycmd (use_cuda ):
526
- logger = logging .getLogger ('interface' )
527
- if 'FSLDIR' not in os .environ :
528
- logger .warn ("FSLDIR not set: assuming command 'eddy'" )
529
- return 'eddy'
530
-
531
- FSLDIR = os .environ ['FSLDIR' ]
532
- if use_cuda and os .path .exists (os .path .join (FSLDIR , 'eddy_cuda' )):
533
- return 'eddy_cuda'
534
- elif os .path .exists (os .path .join (FSLDIR , 'eddy_openmp' )):
535
- return 'eddy_openmp'
536
- elif not os .path .exists (os .path .join (FSLDIR , 'eddy' )):
537
- logger .warn ("No eddy binary found in FSLDIR; assuming command "
538
- "'eddy'\n FSLDIR: '{}'" .format (FSLDIR ))
539
- return 'eddy'
540
-
541
- @property
542
- def _cmd (self ):
543
- return self ._eddycmd (isdefined (self .inputs .use_cuda ) and
544
- self .inputs .use_cuda )
533
+ def _use_cuda (self ):
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
545
549
546
550
def _format_arg (self , name , spec , value ):
547
551
if name == 'in_topup_fieldcoef' :
0 commit comments