Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b004914

Browse files
committed
Merge pull request matplotlib#1518 from NelleV/pep8_delaunay
PEP8 compliance on the delaunay module
2 parents c1b62af + 334ba9d commit b004914

File tree

3 files changed

+305
-265
lines changed

3 files changed

+305
-265
lines changed

lib/matplotlib/delaunay/interpolate.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from __future__ import print_function
22
import numpy as np
33

4-
from matplotlib._delaunay import compute_planes, linear_interpolate_grid, nn_interpolate_grid
4+
from matplotlib._delaunay import compute_planes, linear_interpolate_grid
5+
from matplotlib._delaunay import nn_interpolate_grid
56
from matplotlib._delaunay import nn_interpolate_unstructured
67

78
__all__ = ['LinearInterpolator', 'NNInterpolator']
89

10+
911
def slice2gridspec(key):
1012
"""Convert a 2-tuple of slices to start,stop,steps for x and y.
1113
@@ -34,6 +36,7 @@ def slice2gridspec(key):
3436

3537
return x0, x1, xstep, y0, y1, ystep
3638

39+
3740
class LinearInterpolator(object):
3841
"""Interpolate a function defined on the nodes of a triangulation by
3942
using the planes defined by the three function values at each corner of
@@ -60,10 +63,10 @@ class LinearInterpolator(object):
6063
6164
Linear Interpolation
6265
--------------------
63-
Given the Delauany triangulation (or indeed *any* complete triangulation) we
64-
can interpolate values inside the convex hull by locating the enclosing
65-
triangle of the interpolation point and returning the value at that point of
66-
the plane defined by the three node values.
66+
Given the Delauany triangulation (or indeed *any* complete triangulation)
67+
we can interpolate values inside the convex hull by locating the enclosing
68+
triangle of the interpolation point and returning the value at that point
69+
of the plane defined by the three node values.
6770
6871
f = planes[tri,0]*x + planes[tri,1]*y + planes[tri,2]
6972
@@ -81,11 +84,14 @@ def __init__(self, triangulation, z, default_value=np.nan):
8184

8285
def __getitem__(self, key):
8386
x0, x1, xstep, y0, y1, ystep = slice2gridspec(key)
84-
grid = linear_interpolate_grid(x0, x1, xstep, y0, y1, ystep, self.default_value,
87+
grid = linear_interpolate_grid(
88+
x0, x1, xstep, y0, y1, ystep, self.default_value,
8589
self.planes, self.triangulation.x, self.triangulation.y,
86-
self.triangulation.triangle_nodes, self.triangulation.triangle_neighbors)
90+
self.triangulation.triangle_nodes,
91+
self.triangulation.triangle_neighbors)
8792
return grid
8893

94+
8995
class NNInterpolator(object):
9096
"""Interpolate a function defined on the nodes of a triangulation by
9197
the natural neighbors method.
@@ -109,23 +115,23 @@ class NNInterpolator(object):
109115
-------------------------------
110116
One feature of the Delaunay triangulation is that for each triangle, its
111117
circumcircle contains no other point (although in degenerate cases, like
112-
squares, other points may be *on* the circumcircle). One can also construct
113-
what is called the Voronoi diagram from a Delaunay triangulation by
114-
connecting the circumcenters of the triangles to those of their neighbors to
115-
form a tesselation of irregular polygons covering the plane and containing
116-
only one node from the triangulation. Each point in one node's Voronoi
117-
polygon is closer to that node than any other node.
118+
squares, other points may be *on* the circumcircle). One can also
119+
construct what is called the Voronoi diagram from a Delaunay triangulation
120+
by connecting the circumcenters of the triangles to those of their
121+
neighbors to form a tesselation of irregular polygons covering the plane
122+
and containing only one node from the triangulation. Each point in one
123+
node's Voronoi polygon is closer to that node than any other node.
118124
119125
To compute the Natural Neighbors interpolant, we consider adding the
120-
interpolation point to the triangulation. We define the natural neighbors of
121-
this point as the set of nodes participating in Delaunay triangles whose
122-
circumcircles contain the point. To restore the Delaunay-ness of the
126+
interpolation point to the triangulation. We define the natural neighbors
127+
of this point as the set of nodes participating in Delaunay triangles
128+
whose circumcircles contain the point. To restore the Delaunay-ness of the
123129
triangulation, one would only have to alter those triangles and Voronoi
124-
polygons. The new Voronooi diagram would have a polygon around the inserted
125-
point. This polygon would "steal" area from the original Voronoi polygons.
126-
For each node i in the natural neighbors set, we compute the area stolen
127-
from its original Voronoi polygon, stolen[i]. We define the natural
128-
neighbors coordinates
130+
polygons. The new Voronoi diagram would have a polygon around the
131+
inserted point. This polygon would "steal" area from the original Voronoi
132+
polygons. For each node i in the natural neighbors set, we compute the
133+
area stolen from its original Voronoi polygon, stolen[i]. We define the
134+
natural neighbors coordinates
129135
130136
phi[i] = stolen[i] / sum(stolen,axis=0)
131137
@@ -134,8 +140,8 @@ class NNInterpolator(object):
134140
135141
The interpolated surface is C1-continuous except at the nodes themselves
136142
across the convex hull of the input points. One can find the set of points
137-
that a given node will affect by computing the union of the areas covered by
138-
the circumcircles of each Delaunay triangle that node participates in.
143+
that a given node will affect by computing the union of the areas covered
144+
by the circumcircles of each Delaunay triangle that node participates in.
139145
"""
140146

141147
def __init__(self, triangulation, z, default_value=np.nan):
@@ -145,7 +151,8 @@ def __init__(self, triangulation, z, default_value=np.nan):
145151

146152
def __getitem__(self, key):
147153
x0, x1, xstep, y0, y1, ystep = slice2gridspec(key)
148-
grid = nn_interpolate_grid(x0, x1, xstep, y0, y1, ystep, self.default_value,
154+
grid = nn_interpolate_grid(
155+
x0, x1, xstep, y0, y1, ystep, self.default_value,
149156
self.triangulation.x, self.triangulation.y, self.z,
150157
self.triangulation.circumcenters,
151158
self.triangulation.triangle_nodes,

0 commit comments

Comments
 (0)