Skip to content

Commit ffd1d40

Browse files
committed
fixed errors, added conditional doctest
1 parent 92d98bc commit ffd1d40

File tree

2 files changed

+152
-111
lines changed

2 files changed

+152
-111
lines changed

nipype/algorithms/mesh.py

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
3-
'''
3+
"""
44
Miscellaneous algorithms for 2D contours and 3D triangularized meshes handling
55
6-
Change directory to provide relative paths for doctests
7-
>>> import os
8-
>>> filepath = os.path.dirname(os.path.realpath( __file__ ))
9-
>>> datadir = os.path.realpath(os.path.join(filepath, '../testing/data'))
10-
>>> os.chdir(datadir)
6+
.. testsetup::
7+
# Change directory to provide relative paths for doctests
8+
import os
9+
filepath = os.path.dirname(os.path.realpath( __file__ ))
10+
datadir = os.path.realpath(os.path.join(filepath, '../testing/data'))
11+
os.chdir(datadir)
1112
12-
'''
13+
"""
1314
from __future__ import division
1415
from builtins import zip
1516

@@ -44,6 +45,7 @@
4445

4546

4647
class TVTKBaseInterface(BaseInterface):
48+
4749
""" A base class for interfaces using VTK """
4850

4951
_redirect_x = True
@@ -66,9 +68,9 @@ def __init__(self, **inputs):
6668

6769
class WarpPointsInputSpec(BaseInterfaceInputSpec):
6870
points = File(exists=True, mandatory=True,
69-
desc=('file containing the point set'))
71+
desc='file containing the point set')
7072
warp = File(exists=True, mandatory=True,
71-
desc=('dense deformation field to be applied'))
73+
desc='dense deformation field to be applied')
7274
interp = traits.Enum('cubic', 'nearest', 'linear', usedefault=True,
7375
mandatory=True, desc='interpolation')
7476
out_points = File(name_source='points', name_template='%s_warped',
@@ -92,11 +94,19 @@ class WarpPoints(TVTKBaseInterface):
9294
Example
9395
-------
9496
97+
>>> from nipype.algorithms.mesh import have_tvtk
9598
>>> from nipype.algorithms.mesh import WarpPoints
96-
>>> wp = WarpPoints()
97-
>>> wp.inputs.points = 'surf1.vtk'
98-
>>> wp.inputs.warp = 'warpfield.nii'
99-
>>> res = wp.run() # doctest: +SKIP
99+
>>> if not have_tvtk:
100+
... wp = WarpPoints()
101+
Traceback (most recent call last):
102+
...
103+
ImportError: This interface requires tvtk to run.
104+
>>> else:
105+
... wp = WarpPoints()
106+
... wp.inputs.points = 'surf1.vtk'
107+
... wp.inputs.warp = 'warpfield.nii'
108+
... res = wp.run() # doctest: +SKIP
109+
100110
"""
101111
input_spec = WarpPointsInputSpec
102112
output_spec = WarpPointsOutputSpec
@@ -179,7 +189,7 @@ class ComputeMeshWarpInputSpec(BaseInterfaceInputSpec):
179189
desc=('Test surface (vtk format) from which compute '
180190
'distance.'))
181191
metric = traits.Enum('euclidean', 'sqeuclidean', usedefault=True,
182-
desc=('norm used to report distance'))
192+
desc='norm used to report distance')
183193
weighting = traits.Enum(
184194
'none', 'area', usedefault=True,
185195
desc=('"none": no weighting is performed, surface": edge distance is '
@@ -256,9 +266,9 @@ def _run_interface(self, runtime):
256266
errvector = np.apply_along_axis(nla.norm, 1, diff)
257267

258268
if self.inputs.metric == 'sqeuclidean':
259-
errvector = errvector ** 2
269+
errvector **= 2
260270

261-
if (self.inputs.weighting == 'area'):
271+
if self.inputs.weighting == 'area':
262272
faces = vtk1.polys.to_array().reshape(-1, 4).astype(int)[:, 1:]
263273

264274
for i, p1 in enumerate(points2):
@@ -285,9 +295,9 @@ def _run_interface(self, runtime):
285295
file_name=op.abspath(self.inputs.out_warp))
286296

287297
if self._vtk_major <= 5:
288-
writer.input = mesh
298+
writer.input = out_mesh
289299
else:
290-
writer.set_input_data_object(mesh)
300+
writer.set_input_data_object(out_mesh)
291301

292302
writer.write()
293303

@@ -311,10 +321,10 @@ class MeshWarpMathsInputSpec(BaseInterfaceInputSpec):
311321

312322
operator = traits.Either(
313323
float_trait, File(exists=True), default=1.0, mandatory=True,
314-
desc=('image, float or tuple of floats to act as operator'))
324+
desc='image, float or tuple of floats to act as operator')
315325

316326
operation = traits.Enum('sum', 'sub', 'mul', 'div', usedefault=True,
317-
desc=('operation to be performed'))
327+
desc='operation to be performed')
318328

319329
out_warp = File('warp_maths.vtk', usedefault=True,
320330
desc='vtk file based on in_surf and warpings mapping it '
@@ -364,7 +374,7 @@ def _run_interface(self, runtime):
364374
points1 = np.array(vtk1.points)
365375

366376
if vtk1.point_data.vectors is None:
367-
raise RuntimeError(('No warping field was found in in_surf'))
377+
raise RuntimeError('No warping field was found in in_surf')
368378

369379
operator = self.inputs.operator
370380
opfield = np.ones_like(points1)

0 commit comments

Comments
 (0)