Skip to content

Commit 960a374

Browse files
committed
Added package_check for nipy in new Similarity4D
Additionally, docstrings have been improved for several methods, especially indicating deprecated classes.
1 parent 7c8846f commit 960a374

File tree

3 files changed

+56
-26
lines changed

3 files changed

+56
-26
lines changed

nipype/algorithms/metrics.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import scipy.stats as stats
2929

3030
from .. import logging
31+
from ..utils.misc import package_check
3132

3233
from ..interfaces.base import (BaseInterface, traits, TraitedSpec, File,
3334
InputMultiPath, OutputMultiPath,
@@ -69,9 +70,8 @@ class DistanceOutputSpec(TraitedSpec):
6970

7071

7172
class Distance(BaseInterface):
72-
'''
73-
Calculates distance between two volumes.
74-
'''
73+
"""Calculates distance between two volumes.
74+
"""
7575
input_spec = DistanceInputSpec
7676
output_spec = DistanceOutputSpec
7777

@@ -232,8 +232,7 @@ class OverlapOutputSpec(TraitedSpec):
232232

233233

234234
class Overlap(BaseInterface):
235-
"""
236-
Calculates various overlap measures between two maps.
235+
"""Calculates various overlap measures between two maps.
237236
238237
Example
239238
-------
@@ -313,7 +312,7 @@ class FuzzyOverlapOutputSpec(TraitedSpec):
313312

314313

315314
class FuzzyOverlap(BaseInterface):
316-
""" Calculates various overlap measures between two maps, using the fuzzy
315+
"""Calculates various overlap measures between two maps, using the fuzzy
317316
definition proposed in: Crum et al., Generalized Overlap Measures for
318317
Evaluation and Validation in Medical Image Analysis, IEEE Trans. Med.
319318
Ima. 25(11),pp 1451-1461, Nov. 2006.
@@ -524,8 +523,9 @@ class Similarity(BaseInterface):
524523
the same coordinate system, same space within that coordinate system and
525524
with the same voxel dimensions.
526525
527-
.. note:: This interface is an extension of nipype.interfaces.nipy.utils.Similarity
528-
to support 4D files.
526+
.. note:: This interface is an extension of
527+
:py:class:`nipype.interfaces.nipy.utils.Similarity` to support 4D files.
528+
Requires :py:mod:`nipy`
529529
530530
Example
531531
-------
@@ -541,8 +541,22 @@ class Similarity(BaseInterface):
541541

542542
input_spec = SimilarityInputSpec
543543
output_spec = SimilarityOutputSpec
544+
_have_nipy = True
545+
546+
def __init__(self, **inputs):
547+
try:
548+
package_check('nipy')
549+
except Exception, e:
550+
self._have_nipy = False
551+
super(Similarity,self).__init__(**inputs)
552+
544553

545554
def _run_interface(self, runtime):
555+
if not self._have_nipy:
556+
raise RuntimeError('nipy is not installed')
557+
558+
from nipy.algorithms.registration.histogram_registration import HistogramRegistration
559+
from nipy.algorithms.registration.affine import Affine
546560

547561
vol1_nii = nb.load(self.inputs.volume1)
548562
vol2_nii = nb.load(self.inputs.volume2)

nipype/algorithms/misc.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ class PickAtlasOutputSpec(TraitedSpec):
6464

6565

6666
class PickAtlas(BaseInterface):
67-
'''
68-
Returns ROI masks given an atlas and a list of labels. Supports dilation
67+
"""Returns ROI masks given an atlas and a list of labels. Supports dilation
6968
and left right masking (assuming the atlas is properly aligned).
70-
'''
69+
"""
70+
7171
input_spec = PickAtlasInputSpec
7272
output_spec = PickAtlasOutputSpec
7373

@@ -132,6 +132,8 @@ class SimpleThresholdOutputSpec(TraitedSpec):
132132

133133

134134
class SimpleThreshold(BaseInterface):
135+
"""Applies a threshold to input volumes
136+
"""
135137
input_spec = SimpleThresholdInputSpec
136138
output_spec = SimpleThresholdOutputSpec
137139

@@ -182,10 +184,9 @@ class ModifyAffineOutputSpec(TraitedSpec):
182184

183185

184186
class ModifyAffine(BaseInterface):
185-
'''
186-
Left multiplies the affine matrix with a specified values. Saves the volume
187+
"""Left multiplies the affine matrix with a specified values. Saves the volume
187188
as a nifti file.
188-
'''
189+
"""
189190
input_spec = ModifyAffineInputSpec
190191
output_spec = ModifyAffineOutputSpec
191192

@@ -225,6 +226,8 @@ class CreateNiftiOutputSpec(TraitedSpec):
225226

226227

227228
class CreateNifti(BaseInterface):
229+
"""Creates a nifti volume
230+
"""
228231
input_spec = CreateNiftiInputSpec
229232
output_spec = CreateNiftiOutputSpec
230233

@@ -344,8 +347,7 @@ class GunzipOutputSpec(TraitedSpec):
344347

345348

346349
class Gunzip(BaseInterface):
347-
"""
348-
350+
"""Gunzip wrapper
349351
"""
350352
input_spec = GunzipInputSpec
351353
output_spec = GunzipOutputSpec
@@ -409,8 +411,7 @@ class Matlab2CSVOutputSpec(TraitedSpec):
409411

410412

411413
class Matlab2CSV(BaseInterface):
412-
"""
413-
Simple interface to save the components of a MATLAB .mat file as a text
414+
"""Simple interface to save the components of a MATLAB .mat file as a text
414415
file with comma-separated values (CSVs).
415416
416417
CSV files are easily loaded in R, for use in statistical processing.
@@ -602,8 +603,7 @@ class MergeCSVFilesOutputSpec(TraitedSpec):
602603

603604

604605
class MergeCSVFiles(BaseInterface):
605-
"""
606-
This interface is designed to facilitate data loading in the R environment.
606+
"""This interface is designed to facilitate data loading in the R environment.
607607
It takes input CSV files and merges them into a single CSV file.
608608
If provided, it will also incorporate column heading names into the
609609
resulting CSV file.
@@ -738,8 +738,7 @@ class AddCSVColumnOutputSpec(TraitedSpec):
738738

739739

740740
class AddCSVColumn(BaseInterface):
741-
"""
742-
Short interface to add an extra column and field to a text file
741+
"""Short interface to add an extra column and field to a text file
743742
744743
Example
745744
-------
@@ -799,8 +798,7 @@ class CalculateNormalizedMomentsOutputSpec(TraitedSpec):
799798

800799

801800
class CalculateNormalizedMoments(BaseInterface):
802-
"""
803-
Calculates moments of timeseries.
801+
"""Calculates moments of timeseries.
804802
805803
Example
806804
-------
@@ -827,8 +825,7 @@ def _list_outputs(self):
827825

828826

829827
def calc_moments(timeseries_file, moment):
830-
"""
831-
Returns nth moment (3 for skewness, 4 for kurtosis) of timeseries
828+
"""Returns nth moment (3 for skewness, 4 for kurtosis) of timeseries
832829
(list of values; one per timeseries).
833830
834831
Keyword arguments:
@@ -844,13 +841,23 @@ def calc_moments(timeseries_file, moment):
844841

845842
# Deprecated interfaces ---------------------------------------------------------
846843
class Distance( nam.Distance ):
844+
"""Calculates distance between two volumes.
845+
846+
.. deprecated:: 0.10.0
847+
Use :py:class:`nipype.algorithms.metrics.Distance` instead.
848+
"""
847849
def __init__(self, **inputs):
848850
super(nam.Distance, self).__init__(**inputs)
849851
warnings.warn(("This interface has been deprecated since 0.10.0,"
850852
" please use nipype.algorithms.metrics.Distance"),
851853
DeprecationWarning)
852854

853855
class Overlap( nam.Overlap ):
856+
"""Calculates various overlap measures between two maps.
857+
858+
.. deprecated:: 0.10.0
859+
Use :py:class:`nipype.algorithms.metrics.Overlap` instead.
860+
"""
854861
def __init__(self, **inputs):
855862
super(nam.Overlap, self).__init__(**inputs)
856863
warnings.warn(("This interface has been deprecated since 0.10.0,"
@@ -859,6 +866,12 @@ def __init__(self, **inputs):
859866

860867

861868
class FuzzyOverlap( nam.FuzzyOverlap ):
869+
"""Calculates various overlap measures between two maps, using a fuzzy
870+
definition.
871+
872+
.. deprecated:: 0.10.0
873+
Use :py:class:`nipype.algorithms.metrics.FuzzyOverlap` instead.
874+
"""
862875
def __init__(self, **inputs):
863876
super(nam.FuzzyOverlap, self).__init__(**inputs)
864877
warnings.warn(("This interface has been deprecated since 0.10.0,"

nipype/interfaces/nipy/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class Similarity(BaseInterface):
5151
the same coordinate system, same space within that coordinate system and
5252
with the same voxel dimensions.
5353
54+
.. deprecated:: 0.10.0
55+
Use :py:class:`nipype.algorithms.metrics.Similarity` instead.
56+
5457
Example
5558
-------
5659
>>> from nipype.interfaces.nipy.utils import Similarity

0 commit comments

Comments
 (0)