Skip to content

Commit

Permalink
fix interface
Browse files Browse the repository at this point in the history
  • Loading branch information
bpinsard committed May 16, 2024
1 parent fb04e5d commit 9e3ae7e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
26 changes: 10 additions & 16 deletions niworkflows/interfaces/gradunwarp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,11 @@
SimpleInterface
)

has_gradunwarp = False
try:
from gradunwarp.core.gradient_unwarp import GradientUnwarpRunner
has_gradunwarp = True
except ImportError:
pass


class _GradUnwarpInputSpec(TraitedSpec):
infile = File(exists=True, mandatory=True, desc="input image to be corrected")
gradfile = File(exists=True, default=None, desc="gradient file")
coeffile = File(exists=True, default=None, desc="coefficients file")
outfile = File(
name_source=['in_file'],
name_template=['%s_gradunwarped'],
keep_extension=True,
desc="output corrected image"
)
outfile = File("gradunwarped.nii.gz", mandatory=True, usedefault=True, desc="output corrected image")
vendor = traits.Enum("siemens", "ge", usedefault=True, desc="scanner vendor")
warp = traits.Bool(desc="warp a volume (as opposed to unwarping)")
nojac = traits.Bool(desc="Do not perform Jacobian intensity correction")
Expand All @@ -68,11 +55,18 @@ class GradUnwarp(SimpleInterface):
input_spec = _GradUnwarpInputSpec
output_spec = _GradUnwarpOutputSpec

def version():
try:
import gradunwarp
except ImportError:
return
return gradunwarp.__version__

def _run_interface(self, runtime):

if not has_gradunwarp:
if not GradUnwarp.version():
raise RuntimeError('missing gradunwarp dependency')

from gradunwarp.core.gradient_unwarp import GradientUnwarpRunner
gur = GradientUnwarpRunner(self.inputs)
gur.run()
gur.write()
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ def wrapper(*args, **kwargs):
has_fsl = fsl.Info.version() is not None
has_freesurfer = fs.Info.version() is not None
has_afni = afni.Info.version() is not None
has_gradunwarp = gradunwarp.has_gradunwarp
has_gradunwarp = gradunwarp.GradUnwarp.version()

0 comments on commit 9e3ae7e

Please sign in to comment.