From 21a99a39c35bced4e257b2caef1a18a6770144d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Wed, 22 Jan 2014 18:46:27 -0500 Subject: [PATCH] Document params attribute for each class --- skimage/measure/fit.py | 24 ++++++---- skimage/transform/_geometric.py | 56 +++++++++++++++-------- skimage/transform/tests/test_geometric.py | 4 -- 3 files changed, 52 insertions(+), 32 deletions(-) diff --git a/skimage/measure/fit.py b/skimage/measure/fit.py index 53e98c92..8f9ceb9c 100644 --- a/skimage/measure/fit.py +++ b/skimage/measure/fit.py @@ -37,12 +37,13 @@ class LineModel(BaseModel): min{ sum((dist - x_i * cos(theta) + y_i * sin(theta))**2) } - The ``params`` attribute contains the parameters in the following order:: - - dist, theta - A minimum number of 2 points is required to solve for the parameters. + Attributes + ---------- + params : tuple + Line model parameters in the following order `dist`, `theta`. + """ def estimate(self, data): @@ -161,12 +162,13 @@ class CircleModel(BaseModel): min{ sum((r - sqrt((x_i - xc)**2 + (y_i - yc)**2))**2) } - The ``params`` attribute contains the parameters in the following order:: - - xc, yc, r - A minimum number of 3 points is required to solve for the parameters. + Attributes + ---------- + params : tuple + Circle model parameters in the following order `xc`, `yc`, `r`. + """ def estimate(self, data): @@ -292,6 +294,12 @@ class EllipseModel(BaseModel): A minimum number of 5 points is required to solve for the parameters. + Attributes + ---------- + params : tuple + Ellipse model parameters in the following order `xc`, `yc`, `a`, + `b`, `theta`. + """ def estimate(self, data): diff --git a/skimage/transform/_geometric.py b/skimage/transform/_geometric.py index bf34352b..092738bc 100644 --- a/skimage/transform/_geometric.py +++ b/skimage/transform/_geometric.py @@ -104,6 +104,11 @@ class ProjectiveTransform(GeometricTransform): matrix : (3, 3) array, optional Homogeneous transformation matrix. + Attributes + ---------- + params : (3, 3) array + Homogeneous transformation matrix. + """ _coeffs = range(8) @@ -291,6 +296,11 @@ class AffineTransform(ProjectiveTransform): translation : (tx, ty) as array, list or tuple, optional Translation parameters. + Attributes + ---------- + params : (3, 3) array + Homogeneous transformation matrix. + """ _coeffs = range(6) @@ -356,25 +366,20 @@ class PiecewiseAffineTransform(GeometricTransform): a Delaunay triangulation of the points to form a mesh. Each triangle is used to find a local affine transform. + Attributes + ---------- + affines : list of AffineTransform objects + Affine transformations for each triangle in the mesh. + inverse_affines : list of AffineTransform objects + Inverse affine transformations for each triangle in the mesh. + """ def __init__(self): self._tesselation = None self._inverse_tesselation = None - self.affines_ = None - self.inverse_affines_ = None - - @property - def affines(self): - warnings.warn('`affines` attribute is deprecated, ' - 'use `affines_` instead.') - return self.affines_ - - @property - def inverse_affines(self): - warnings.warn('`inverse_affines` attribute is deprecated, ' - 'use `inverse_affines_` instead.') - return self.inverse_affines_ + self.affines = None + self.inverse_affines = None def estimate(self, src, dst): """Set the control points with which to perform the piecewise mapping. @@ -394,21 +399,21 @@ class PiecewiseAffineTransform(GeometricTransform): # triangulate input positions into mesh self._tesselation = spatial.Delaunay(src) # find affine mapping from source positions to destination - self.affines_ = [] + self.affines = [] for tri in self._tesselation.vertices: affine = AffineTransform() affine.estimate(src[tri, :], dst[tri, :]) - self.affines_.append(affine) + self.affines.append(affine) # inverse piecewise affine # triangulate input positions into mesh self._inverse_tesselation = spatial.Delaunay(dst) # find affine mapping from source positions to destination - self.inverse_affines_ = [] + self.inverse_affines = [] for tri in self._inverse_tesselation.vertices: affine = AffineTransform() affine.estimate(dst[tri, :], src[tri, :]) - self.inverse_affines_.append(affine) + self.inverse_affines.append(affine) def __call__(self, coords): """Apply forward transformation. @@ -437,7 +442,7 @@ class PiecewiseAffineTransform(GeometricTransform): for index in range(len(self._tesselation.vertices)): # affine transform for triangle - affine = self.affines_[index] + affine = self.affines[index] # all coordinates within triangle index_mask = simplex == index @@ -472,7 +477,7 @@ class PiecewiseAffineTransform(GeometricTransform): for index in range(len(self._inverse_tesselation.vertices)): # affine transform for triangle - affine = self.inverse_affines_[index] + affine = self.inverse_affines[index] # all coordinates within triangle index_mask = simplex == index @@ -507,6 +512,11 @@ class SimilarityTransform(ProjectiveTransform): translation : (tx, ty) as array, list or tuple, optional x, y translation parameters. + Attributes + ---------- + params : (3, 3) array + Homogeneous transformation matrix. + """ def __init__(self, matrix=None, scale=None, rotation=None, @@ -638,6 +648,12 @@ class PolynomialTransform(GeometricTransform): Polynomial coefficients where `N * 2 = (order + 1) * (order + 2)`. So, a_ji is defined in `params[0, :]` and b_ji in `params[1, :]`. + Attributes + ---------- + params : (2, N) array + Polynomial coefficients where `N * 2 = (order + 1) * (order + 2)`. So, + a_ji is defined in `params[0, :]` and b_ji in `params[1, :]`. + """ def __init__(self, params=None): diff --git a/skimage/transform/tests/test_geometric.py b/skimage/transform/tests/test_geometric.py index 74997789..2a6a5c7e 100644 --- a/skimage/transform/tests/test_geometric.py +++ b/skimage/transform/tests/test_geometric.py @@ -236,10 +236,6 @@ def test_deprecated_params_attributes(): tform = estimate_transform('polynomial', SRC, DST, order=3) assert_equal(tform._params, tform.params) - tform = estimate_transform('piecewise-affine', SRC, DST) - assert_equal(tform.affines, tform.affines_) - assert_equal(tform.inverse_affines, tform.inverse_affines_) - if __name__ == "__main__": from numpy.testing import run_module_suite