Skip to content

Commit c40b673

Browse files
committed
removing base.py and using niftyreg base.py class/fct. Renaming functions as well
1 parent ef14ef5 commit c40b673

19 files changed

+65
-178
lines changed

nipype/interfaces/niftyreg/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Top-level namespace for niftyreg.
1010
"""
1111

12-
from .base import no_niftyreg, get_custom_path
12+
from .base import no_nifty_package, get_custom_path
1313
from .reg import RegAladin, RegF3D
1414
from .regutils import (RegResample, RegJacobian, RegAverage, RegTools,
1515
RegTransform, RegMeasure)

nipype/interfaces/niftyreg/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
from ...utils.filemanip import split_filename
3131

3232

33-
def get_custom_path(command):
34-
return os.path.join(os.getenv('NIFTYREGDIR', ''), command)
33+
def get_custom_path(command, env_dir='NIFTYREGDIR'):
34+
return os.path.join(os.getenv(env_dir, ''), command)
3535

3636

37-
def no_niftyreg(cmd='reg_f3d'):
37+
def no_nifty_package(cmd='reg_f3d'):
3838
try:
3939
return shutil.which(cmd) is None
4040
except AttributeError: # Python < 3.3
@@ -89,7 +89,7 @@ def check_version(self):
8989
raise ValueError(err % (_version, self.required_version))
9090

9191
def get_version(self):
92-
if no_niftyreg(cmd=self.cmd):
92+
if no_nifty_package(cmd=self.cmd):
9393
return None
9494
exec_cmd = ''.join((self.cmd, ' -v'))
9595
return subprocess.check_output(exec_cmd, shell=True).strip()

nipype/interfaces/niftyreg/tests/test_reg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
import pytest
66

7-
from nipype.interfaces.niftyreg import (no_niftyreg, get_custom_path,
7+
from nipype.interfaces.niftyreg import (no_nifty_package, get_custom_path,
88
RegAladin, RegF3D)
99
from nipype.testing import example_data
1010

1111

1212
@pytest.mark.skipif(
13-
no_niftyreg(cmd='reg_aladin'),
13+
no_nifty_package(cmd='reg_aladin'),
1414
reason="niftyreg is not installed. reg_aladin not found.")
1515
def test_reg_aladin():
1616
""" tests for reg_aladin interface"""
@@ -48,7 +48,7 @@ def test_reg_aladin():
4848

4949

5050
@pytest.mark.skipif(
51-
no_niftyreg(cmd='reg_f3d'),
51+
no_nifty_package(cmd='reg_f3d'),
5252
reason="niftyreg is not installed. reg_f3d not found.")
5353
def test_reg_f3d():
5454
""" tests for reg_f3d interface"""

nipype/interfaces/niftyreg/tests/test_regutils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
33
# vi: set ft=python sts=4 ts=4 sw=4 et:
44

5-
from nipype.interfaces.niftyreg import (no_niftyreg, get_custom_path,
5+
from nipype.interfaces.niftyreg import (no_nifty_package, get_custom_path,
66
RegAverage, RegResample, RegJacobian,
77
RegTools, RegMeasure, RegTransform)
88
from nipype.testing import example_data
@@ -11,7 +11,7 @@
1111

1212

1313
@pytest.mark.skipif(
14-
no_niftyreg(cmd='reg_resample'),
14+
no_nifty_package(cmd='reg_resample'),
1515
reason="niftyreg is not installed. reg_resample not found.")
1616
def test_reg_resample_res():
1717
""" tests for reg_resample interface """
@@ -68,7 +68,7 @@ def test_reg_resample_res():
6868

6969

7070
@pytest.mark.skipif(
71-
no_niftyreg(cmd='reg_jacobian'),
71+
no_nifty_package(cmd='reg_jacobian'),
7272
reason="niftyreg is not installed. reg_jacobian not found.")
7373
def test_reg_jacobian_jac():
7474
""" Test interface for RegJacobian """
@@ -132,7 +132,7 @@ def test_reg_jacobian_jac():
132132

133133

134134
@pytest.mark.skipif(
135-
no_niftyreg(cmd='reg_tools'),
135+
no_nifty_package(cmd='reg_tools'),
136136
reason="niftyreg is not installed. reg_tools not found.")
137137
def test_reg_tools_mul():
138138
""" tests for reg_tools interface """
@@ -175,7 +175,7 @@ def test_reg_tools_mul():
175175

176176

177177
@pytest.mark.skipif(
178-
no_niftyreg(cmd='reg_average'),
178+
no_nifty_package(cmd='reg_average'),
179179
reason="niftyreg is not installed. reg_average not found.")
180180
def test_reg_average():
181181
""" tests for reg_average interface """
@@ -318,7 +318,7 @@ def test_reg_average():
318318

319319

320320
@pytest.mark.skipif(
321-
no_niftyreg(cmd='reg_transform'),
321+
no_nifty_package(cmd='reg_transform'),
322322
reason="niftyreg is not installed. reg_transform not found.")
323323
def test_reg_transform_def():
324324
""" tests for reg_transform interface """
@@ -427,7 +427,7 @@ def test_reg_transform_def():
427427

428428

429429
@pytest.mark.skipif(
430-
no_niftyreg(cmd='reg_measure'),
430+
no_nifty_package(cmd='reg_measure'),
431431
reason="niftyreg is not installed. reg_measure not found.")
432432
def test_reg_measure():
433433
""" tests for reg_measure interface """

nipype/interfaces/niftyseg/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
Top-level namespace for niftyseg.
99
"""
1010

11-
from .base import no_niftyseg, get_custom_path
1211
from .em import EM
1312
from .label_fusion import LabelFusion, CalcTopNCC
1413
from .lesions import FillLesions

nipype/interfaces/niftyseg/base.py

Lines changed: 0 additions & 91 deletions
This file was deleted.

nipype/interfaces/niftyseg/em.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from ..base import (TraitedSpec, File, traits, CommandLineInputSpec,
2222
InputMultiPath)
23-
from .base import NiftySegCommand, get_custom_path
23+
from ..niftyreg.base import NiftyRegCommand, get_custom_path
2424

2525

2626
class EMInputSpec(CommandLineInputSpec):
@@ -47,10 +47,9 @@ class EMInputSpec(CommandLineInputSpec):
4747
desc='4D file containing the priors',
4848
xor=['no_prior', 'priors'])
4949

50-
desc = 'List of priors filepaths.'
5150
priors = InputMultiPath(argstr='%s',
5251
mandatory=True,
53-
desc=desc,
52+
desc='List of priors filepaths.',
5453
xor=['no_prior', 'prior_4D'])
5554

5655
# iterations
@@ -110,7 +109,7 @@ class EMOutputSpec(TraitedSpec):
110109
out_outlier_file = File(desc='Output outlierness image')
111110

112111

113-
class EM(NiftySegCommand):
112+
class EM(NiftyRegCommand):
114113
"""Interface for executable seg_EM from NiftySeg platform.
115114
116115
seg_EM is a general purpose intensity based image segmentation tool. In
@@ -132,7 +131,7 @@ class EM(NiftySegCommand):
132131
-out im1_em.nii.gz -out_outlier im1_outlier_em.nii.gz'
133132
134133
"""
135-
_cmd = get_custom_path('seg_EM')
134+
_cmd = get_custom_path('seg_EM', env_dir='NIFTYSEGDIR')
136135
_suffix = '_em'
137136
input_spec = EMInputSpec
138137
output_spec = EMOutputSpec

nipype/interfaces/niftyseg/label_fusion.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from ..base import (TraitedSpec, File, traits, isdefined, CommandLineInputSpec,
2020
NipypeInterfaceError)
21-
from .base import NiftySegCommand, get_custom_path
21+
from ..niftyreg.base import get_custom_path, NiftyRegCommand
2222
from ...utils.filemanip import load_json, save_json, split_filename
2323

2424

@@ -111,7 +111,7 @@ class LabelFusionOutput(TraitedSpec):
111111
out_file = File(exists=True, desc='image written after calculations')
112112

113113

114-
class LabelFusion(NiftySegCommand):
114+
class LabelFusion(NiftyRegCommand):
115115
"""Interface for executable seg_LabelFusion from NiftySeg platform using
116116
type STEPS as classifier Fusion.
117117
@@ -151,7 +151,7 @@ class LabelFusion(NiftySegCommand):
151151
im1_steps.nii'
152152
153153
"""
154-
_cmd = get_custom_path('seg_LabFusion')
154+
_cmd = get_custom_path('seg_LabFusion', env_dir='NIFTYSEGDIR')
155155
input_spec = LabelFusionInput
156156
output_spec = LabelFusionOutput
157157
_suffix = '_label_fused'
@@ -197,7 +197,7 @@ def get_staple_args(self, ranking):
197197
return None
198198

199199
if ranking == 'ALL':
200-
return '-%s' % ranking
200+
return '-ALL'
201201

202202
if not isdefined(self.inputs.template_file):
203203
err = "LabelFusion requires a value for input 'tramplate_file' \
@@ -288,7 +288,7 @@ class CalcTopNCCOutputSpec(TraitedSpec):
288288
out_files = traits.Any(File(exists=True))
289289

290290

291-
class CalcTopNCC(NiftySegCommand):
291+
class CalcTopNCC(NiftyRegCommand):
292292
"""Interface for executable seg_CalcTopNCC from NiftySeg platform.
293293
294294
Examples
@@ -303,7 +303,7 @@ class CalcTopNCC(NiftySegCommand):
303303
'seg_CalcTopNCC -target im1.nii -templates 2 im2.nii im3.nii -n 1'
304304
305305
"""
306-
_cmd = get_custom_path('seg_CalcTopNCC')
306+
_cmd = get_custom_path('seg_CalcTopNCC', env_dir='NIFTYSEGDIR')
307307
_suffix = '_topNCC'
308308
input_spec = CalcTopNCCInputSpec
309309
output_spec = CalcTopNCCOutputSpec
@@ -312,7 +312,7 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None):
312312
outputs = self._outputs()
313313
# local caching for backward compatibility
314314
outfile = os.path.join(os.getcwd(), 'CalcTopNCC.json')
315-
if runtime is None:
315+
if runtime is None or not runtime.stdout:
316316
try:
317317
out_files = load_json(outfile)['files']
318318
except IOError:

nipype/interfaces/niftyseg/lesions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import warnings
2222

2323
from ..base import TraitedSpec, File, traits, CommandLineInputSpec
24-
from .base import NiftySegCommand, get_custom_path
24+
from ..niftyreg.base import NiftyRegCommand, get_custom_path
2525

2626

2727
warn = warnings.warn
@@ -93,7 +93,7 @@ class FillLesionsOutputSpec(TraitedSpec):
9393
out_file = File(desc="Output segmentation")
9494

9595

96-
class FillLesions(NiftySegCommand):
96+
class FillLesions(NiftyRegCommand):
9797
"""Interface for executable seg_FillLesions from NiftySeg platform.
9898
9999
Fill all the masked lesions with WM intensity average.
@@ -112,6 +112,6 @@ class FillLesions(NiftySegCommand):
112112
'seg_FillLesions -i im1.nii -l im2.nii -o im1_lesions_filled.nii.gz'
113113
114114
"""
115-
_cmd = get_custom_path('seg_FillLesions')
115+
_cmd = get_custom_path('seg_FillLesions', env_dir='NIFTYSEGDIR')
116116
input_spec = FillLesionsInputSpec
117117
output_spec = FillLesionsOutputSpec

nipype/interfaces/niftyseg/maths.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from ..base import (TraitedSpec, File, traits, isdefined, CommandLineInputSpec,
2424
NipypeInterfaceError)
25-
from .base import NiftySegCommand, get_custom_path
25+
from ..niftyreg.base import NiftyRegCommand, get_custom_path
2626
from ...utils.filemanip import split_filename
2727

2828

@@ -40,10 +40,9 @@ class MathsInput(CommandLineInputSpec):
4040
argstr='%s',
4141
desc='image to write')
4242

43-
_dtypes = ['float', 'char', 'int', 'short', 'double', 'input']
44-
4543
desc = 'datatype to use for output (default uses input type)'
46-
output_datatype = traits.Enum(*_dtypes,
44+
output_datatype = traits.Enum('float', 'char', 'int', 'short',
45+
'double', 'input',
4746
position=-3,
4847
argstr='-odt %s',
4948
desc=desc)
@@ -54,7 +53,7 @@ class MathsOutput(TraitedSpec):
5453
out_file = File(desc='image written after calculations')
5554

5655

57-
class MathsCommand(NiftySegCommand):
56+
class MathsCommand(NiftyRegCommand):
5857
"""
5958
Base Command Interface for seg_maths interfaces.
6059
@@ -71,7 +70,7 @@ class MathsCommand(NiftySegCommand):
7170
into several 3D images, to estimating the maximum, minimum and average
7271
over all time-points, etc.
7372
"""
74-
_cmd = get_custom_path('seg_maths')
73+
_cmd = get_custom_path('seg_maths', env_dir='NIFTYSEGDIR')
7574
input_spec = MathsInput
7675
output_spec = MathsOutput
7776
_suffix = '_maths'

0 commit comments

Comments
 (0)