Skip to content

Commit 2439fa1

Browse files
committed
fix: mesh import to enable doc building
1 parent f93f3d4 commit 2439fa1

File tree

14 files changed

+202
-211
lines changed

14 files changed

+202
-211
lines changed

nipype/algorithms/mesh.py

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,36 @@
1212
'''
1313

1414

15-
import os
16-
import os.path as op
17-
import warnings
18-
import nibabel as nb
1915
import numpy as np
2016
from scipy.spatial.distance import euclidean
21-
from nipype.utils.misc import package_check
22-
23-
try:
24-
package_check('tvtk')
25-
except Exception, e:
26-
warnings.warn('tvtk or vtk not installed')
27-
else:
28-
from tvtk.api import tvtk
29-
3017

3118
from .. import logging
3219

3320
from ..interfaces.base import (BaseInterface, traits, TraitedSpec, File,
34-
InputMultiPath, OutputMultiPath,
35-
BaseInterfaceInputSpec, isdefined)
36-
from ..utils.filemanip import fname_presuffix, split_filename
21+
BaseInterfaceInputSpec)
3722
iflogger = logging.getLogger('interface')
3823

3924

4025
class P2PDistanceInputSpec(BaseInterfaceInputSpec):
4126
surface1 = File(exists=True, mandatory=True,
42-
desc="Reference surface (vtk format) to which compute distance.")
27+
desc=("Reference surface (vtk format) to which compute "
28+
"distance."))
4329
surface2 = File(exists=True, mandatory=True,
44-
desc="Test surface (vtk format) from which compute distance.")
45-
weighting = traits.Enum("none", "surface", desc='""none": no weighting is performed\
46-
"surface": edge distance is weighted by the corresponding surface area',usedefault=True)
30+
desc=("Test surface (vtk format) from which compute "
31+
"distance."))
32+
weighting = traits.Enum("none", "surface", usedefault=True,
33+
desc=('"none": no weighting is performed, '
34+
'"surface": edge distance is weighted by the '
35+
'corresponding surface area'))
4736

4837
class P2PDistanceOutputSpec(TraitedSpec):
4938
distance = traits.Float(desc="computed distance")
5039

5140
class P2PDistance(BaseInterface):
52-
"""
53-
Calculates a point-to-point (p2p) distance between two corresponding meshes or contours.
54-
Therefore, a point-to-point correspondence between nodes is required
41+
"""Calculates a point-to-point (p2p) distance between two corresponding
42+
VTK-readable meshes or contours.
43+
44+
A point-to-point correspondence between nodes is required
5545
5646
Example
5747
-------
@@ -74,6 +64,7 @@ def _triangle_area(self, A, B, C):
7464
return area
7565

7666
def _run_interface(self, runtime):
67+
from tvtk.api import tvtk
7768
r1 = tvtk.PolyDataReader( file_name=self.inputs.surface1 )
7869
r2 = tvtk.PolyDataReader( file_name=self.inputs.surface2 )
7970
vtk1 = r1.output
@@ -83,7 +74,7 @@ def _run_interface(self, runtime):
8374
assert( len(vtk1.points) == len(vtk2.points) )
8475
d = 0.0
8576
totalWeight = 0.0
86-
77+
8778
points = vtk1.points
8879
faces = vtk1.polys.to_array().reshape(-1,4).astype(int)[:,1:]
8980

@@ -110,4 +101,4 @@ def _list_outputs(self):
110101
outputs = self._outputs().get()
111102
outputs['distance'] = self._distance
112103
return outputs
113-
104+

nipype/algorithms/misc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ def _run_interface(self, runtime):
514514
ncomp = len(self.inputs.in_ref)
515515
assert( ncomp == len(self.inputs.in_tst) )
516516
weights = np.ones( shape=ncomp )
517-
517+
518518
img_ref = np.array( [ nb.load( fname ).get_data() for fname in self.inputs.in_ref ] )
519519
img_tst = np.array( [ nb.load( fname ).get_data() for fname in self.inputs.in_tst ] )
520520

@@ -558,11 +558,11 @@ def _run_interface(self, runtime):
558558
for w,ch in zip(weights,diff_im):
559559
ch[msk==0] = 0
560560
diff+= w* ch
561-
561+
562562
nb.save(nb.Nifti1Image(diff, nb.load( self.inputs.in_ref[0]).get_affine(),
563563
nb.load( self.inputs.in_ref[0]).get_header()), self.inputs.out_file )
564564

565-
565+
566566
return runtime
567567

568568
def _list_outputs(self):

nipype/external/provcopy.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def provn_representation(self):
355355

356356
def json_representation(self):
357357
return {'$': self._uri, 'type': u'xsd:anyURI'}
358-
358+
359359
def rdf_representation(self):
360360
return URIRef(self.get_uri())
361361

@@ -757,7 +757,7 @@ def rdf(self, graph=None, subj=None):
757757
obj = RDFLiteral(value)
758758
graph.add((subj, pred, obj))
759759
return graph
760-
760+
761761
def is_asserted(self):
762762
return self._asserted
763763

@@ -772,7 +772,7 @@ def is_relation(self):
772772
class ProvElement(ProvRecord):
773773
def is_element(self):
774774
return True
775-
775+
776776
def rdf(self, graph=None):
777777
if graph is None:
778778
graph = Graph()
@@ -1626,15 +1626,15 @@ def rdf(self, graph=None):
16261626
# graph should not None here
16271627
uri = self.get_identifier().rdf_representation()
16281628
graph = Graph(graph.store, uri)
1629-
1629+
16301630
for prefix, namespace in self._namespaces.items():
16311631
graph.bind(prefix, namespace.get_uri())
1632-
1632+
16331633
for record in self._records:
16341634
if record.is_asserted():
16351635
record.rdf(graph)
16361636
return graph
1637-
1637+
16381638
def get_provjson(self, **kw):
16391639
"""Return the `PROV-JSON <http://www.w3.org/Submission/prov-json/>`_ representation for the bundle/document.
16401640

nipype/interfaces/afni/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
33
"""The afni module provides classes for interfacing with the `AFNI
4-
<http://afni.nimh.nih.gov/afni>`_ command line tools.
4+
<http://afni.nimh.nih.gov/afni>`_ command line tools.
55
66
Top-level namespace for afni.
77
"""

nipype/interfaces/afni/preprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1849,7 +1849,7 @@ class AFNItoNIFTI(AFNICommand):
18491849
18501850
see AFNI Documentation: <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dAFNItoNIFTI.html>
18511851
this can also convert 2D or 1D data, which you can numpy.squeeze() to remove extra dimensions
1852-
1852+
18531853
Examples
18541854
========
18551855

nipype/interfaces/camino/calib.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ class SFPICOCalibDataInputSpec(StdOutCommandLineInputSpec):
2020
scheme_file = File(exists=True, argstr='-schemefile %s', mandatory=True,
2121
desc='Specifies the scheme file for the diffusion MRI data')
2222
info_file = File(desc='The name to be given to the information output filename.',
23-
argstr='-infooutputfile %s', mandatory=True, genfile=True,
23+
argstr='-infooutputfile %s', mandatory=True, genfile=True,
2424
hash_files=False) # Genfile and hash_files?
2525
trace = traits.Float(argstr='-trace %f', units='NA',
26-
desc='Trace of the diffusion tensor(s) used in the test function.')
27-
onedtfarange = traits.List(traits.Float, argstr='-onedtfarange %s',
26+
desc='Trace of the diffusion tensor(s) used in the test function.')
27+
onedtfarange = traits.List(traits.Float, argstr='-onedtfarange %s',
2828
minlen=2, maxlen=2, units='NA',
2929
desc=('Minimum and maximum FA for the single tensor '
3030
'synthetic data.'))
3131
onedtfastep = traits.Float(argstr='-onedtfastep %f', units='NA',
3232
desc=('FA step size controlling how many steps there are '
3333
'between the minimum and maximum FA settings.'))
34-
twodtfarange = traits.List(traits.Float, argstr='-twodtfarange %s',
34+
twodtfarange = traits.List(traits.Float, argstr='-twodtfarange %s',
3535
minlen=2, maxlen=2, units='NA',
3636
desc=('Minimum and maximum FA for the two tensor '
3737
'synthetic data. FA is varied for both tensors '
@@ -40,7 +40,7 @@ class SFPICOCalibDataInputSpec(StdOutCommandLineInputSpec):
4040
desc=('FA step size controlling how many steps there are '
4141
'between the minimum and maximum FA settings '
4242
'for the two tensor cases.'))
43-
twodtanglerange = traits.List(traits.Float, argstr='-twodtanglerange %s',
43+
twodtanglerange = traits.List(traits.Float, argstr='-twodtanglerange %s',
4444
minlen=2, maxlen=2, units='NA',
4545
desc=('Minimum and maximum crossing angles '
4646
'between the two fibres.'))
@@ -55,7 +55,7 @@ class SFPICOCalibDataInputSpec(StdOutCommandLineInputSpec):
5555
desc=('Mixing parameter step size for the two tensor cases. '
5656
'Specify how many mixing parameter increments to use.'))
5757
seed = traits.Float(argstr='-seed %f', units='NA',
58-
desc='Specifies the random seed to use for noise generation in simulation trials.')
58+
desc='Specifies the random seed to use for noise generation in simulation trials.')
5959

6060
class SFPICOCalibDataOutputSpec(TraitedSpec):
6161
PICOCalib = File(exists=True, desc='Calibration dataset')
@@ -64,37 +64,37 @@ class SFPICOCalibDataOutputSpec(TraitedSpec):
6464
class SFPICOCalibData(StdOutCommandLine):
6565
"""
6666
Generates Spherical Function PICo Calibration Data.
67-
68-
SFPICOCalibData creates synthetic data for use with SFLUTGen. The
69-
synthetic data is generated using a mixture of gaussians, in the
70-
same way datasynth generates data. Each voxel of data models a
67+
68+
SFPICOCalibData creates synthetic data for use with SFLUTGen. The
69+
synthetic data is generated using a mixture of gaussians, in the
70+
same way datasynth generates data. Each voxel of data models a
7171
slightly different fibre configuration (varying FA and fibre-
72-
crossings) and undergoes a random rotation to help account for any
73-
directional bias in the chosen acquisition scheme. A second file,
72+
crossings) and undergoes a random rotation to help account for any
73+
directional bias in the chosen acquisition scheme. A second file,
7474
which stores information about the datafile, is generated along with
7575
the datafile.
7676
7777
Example 1
7878
---------
7979
To create a calibration dataset using the default settings
80-
80+
8181
>>> import nipype.interfaces.camino as cam
8282
>>> calib = cam.SFPICOCalibData()
8383
>>> calib.inputs.scheme_file = 'A.scheme'
8484
>>> calib.inputs.snr = 20
8585
>>> calib.inputs.info_file = 'PICO_calib.info'
86-
>>> calib.run() # doctest: +SKIP
87-
88-
The default settings create a large dataset (249,231 voxels), of
89-
which 3401 voxels contain a single fibre population per voxel and
90-
the rest of the voxels contain two fibre-populations. The amount of
91-
data produced can be varied by specifying the ranges and steps of
86+
>>> calib.run() # doctest: +SKIP
87+
88+
The default settings create a large dataset (249,231 voxels), of
89+
which 3401 voxels contain a single fibre population per voxel and
90+
the rest of the voxels contain two fibre-populations. The amount of
91+
data produced can be varied by specifying the ranges and steps of
9292
the parameters for both the one and two fibre datasets used.
93-
93+
9494
Example 2
9595
---------
9696
To create a custom calibration dataset
97-
97+
9898
>>> import nipype.interfaces.camino as cam
9999
>>> calib = cam.SFPICOCalibData()
100100
>>> calib.inputs.scheme_file = 'A.scheme'
@@ -106,11 +106,11 @@ class SFPICOCalibData(StdOutCommandLine):
106106
>>> calib.inputs.twodtanglestep = 0.03925
107107
>>> calib.inputs.twodtmixmax = 0.8
108108
>>> calib.inputs.twodtmixstep = 0.1
109-
>>> calib.run() # doctest: +SKIP
110-
109+
>>> calib.run() # doctest: +SKIP
110+
111111
This would provide 76,313 voxels of synthetic data, where 3401 voxels
112-
simulate the one fibre cases and 72,912 voxels simulate the various
113-
two fibre cases. However, care should be taken to ensure that enough
112+
simulate the one fibre cases and 72,912 voxels simulate the various
113+
two fibre cases. However, care should be taken to ensure that enough
114114
data is generated for calculating the LUT. # doctest: +SKIP
115115
"""
116116
_cmd = 'sfpicocalibdata'
@@ -140,7 +140,7 @@ class SFLUTGenInputSpec(StdOutCommandLineInputSpec):
140140
'[outputstem]_oneFibreSurfaceCoeffs.Bdouble and '
141141
'[outputstem]_twoFibreSurfaceCoeffs.Bdouble'),
142142
usedefault=True)
143-
pdf = traits.Enum('bingham', 'watson', argstr='-pdf %s',
143+
pdf = traits.Enum('bingham', 'watson', argstr='-pdf %s',
144144
desc=('Sets the distribution to use for the calibration. The default is the Bingham '
145145
'distribution, which allows elliptical probability density contours. '
146146
'Currently supported options are: '
@@ -160,7 +160,7 @@ class SFLUTGenInputSpec(StdOutCommandLineInputSpec):
160160
'number per bin to get things running in quick tests, but the sta- '
161161
'tistics will not be reliable and for serious applications, you need '
162162
'to increase the size of the calibration data set until the error goes.'))
163-
directmap = traits.Bool(argstr='-directmap',
163+
directmap = traits.Bool(argstr='-directmap',
164164
desc=('Use direct mapping between the eigenvalues and the distribution parameters '
165165
'instead of the log of the eigenvalues.'))
166166
order = traits.Int(argstr='-order %d', units='NA',
@@ -170,21 +170,21 @@ class SFLUTGenInputSpec(StdOutCommandLineInputSpec):
170170
class SFLUTGenOutputSpec(TraitedSpec):
171171
lut_one_fibre = File(exists=True, desc='PICo lut for one-fibre model')
172172
lut_two_fibres = File(exists=True, desc='PICo lut for two-fibre model')
173-
173+
174174
class SFLUTGen(StdOutCommandLine):
175175
"""
176176
Generates PICo lookup tables (LUT) for multi-fibre methods such as
177177
PASMRI and Q-Ball.
178-
178+
179179
SFLUTGen creates the lookup tables for the generalized multi-fibre
180180
implementation of the PICo tractography algorithm. The outputs of
181181
this utility are either surface or line coefficients up to a given
182182
order. The calibration can be performed for different distributions,
183183
such as the Bingham and Watson distributions.
184-
184+
185185
This utility uses calibration data generated from SFPICOCalibData
186186
and peak information created by SFPeaks.
187-
187+
188188
The utility outputs two lut's, *_oneFibreSurfaceCoeffs.Bdouble and
189189
*_twoFibreSurfaceCoeffs.Bdouble. Each of these files contains big-
190190
endian doubles as standard. The format of the output is:
@@ -194,9 +194,9 @@ class SFLUTGen(StdOutCommandLine):
194194
coefficient_2
195195
...
196196
coefficient_N
197-
In the case of the Watson, there is a single set of coefficients,
198-
which are ordered:
199-
constant, x, x^2, ..., x^order.
197+
In the case of the Watson, there is a single set of coefficients,
198+
which are ordered:
199+
constant, x, x^2, ..., x^order.
200200
In the case of the Bingham, there are two sets of coefficients (one
201201
for each surface), ordered so that:
202202
for j = 1 to order
@@ -207,12 +207,12 @@ class SFLUTGen(StdOutCommandLine):
207207
Example
208208
---------
209209
To create a calibration dataset using the default settings
210-
210+
211211
>>> import nipype.interfaces.camino as cam
212212
>>> lutgen = cam.SFLUTGen()
213213
>>> lutgen.inputs.in_file = 'QSH_peaks.Bdouble'
214214
>>> lutgen.inputs.info_file = 'PICO_calib.info'
215-
>>> lutgen.run() # doctest: +SKIP
215+
>>> lutgen.run() # doctest: +SKIP
216216
"""
217217
_cmd = 'sflutgen'
218218
input_spec=SFLUTGenInputSpec

0 commit comments

Comments
 (0)