ó
±éRc           @  s—   d  d l  m Z d  d l Z d  d l m Z m Z d  d l m Z d  d l m Z d d g Z	 d „  Z
 d e f d	 „  ƒ  YZ d e f d
 „  ƒ  YZ d S(   iÿÿÿÿ(   t   print_functionN(   t   compute_planest   linear_interpolate_grid(   t   nn_interpolate_grid(   t   nn_interpolate_unstructuredt   LinearInterpolatort   NNInterpolatorc         C  s9  t  |  ƒ d k s: t |  d t ƒ s: t |  d t ƒ rI t d ƒ ‚ n  |  d j } |  d j } |  d j } t | t ƒ s˜ t | j	 ƒ | j	 k r§ t d ƒ ‚ n  t | j
 ƒ } |  d j } |  d j } |  d j } t | t ƒ st | j	 ƒ | j	 k rt d ƒ ‚ n  t | j
 ƒ } | | | | | | f S(   s   Convert a 2-tuple of slices to start,stop,steps for x and y.

    key -- (slice(ystart,ystop,ystep), slice(xtart, xstop, xstep))

    For now, the only accepted step values are imaginary integers (interpreted
    in the same way numpy.mgrid, etc. do).
    i   i    i   s   only 2-D slices, pleases0   only the [start:stop:numsteps*1j] form supported(   t   lent
   isinstancet   slicet
   ValueErrort   startt   stopt   stept   complext   intt   realt   imag(   t   keyt   x0t   x1t   xstept   y0t   y1t   ystep(    (    sY   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/delaunay/interpolate.pyt   slice2gridspec   s"    ((c           B  s&   e  Z d  Z e j d „ Z d „  Z RS(   sð  Interpolate a function defined on the nodes of a triangulation by
    using the planes defined by the three function values at each corner of
    the triangles.

    LinearInterpolator(triangulation, z, default_value=numpy.nan)

    triangulation -- Triangulation instance
    z -- the function values at each node of the triangulation
    default_value -- a float giving the default value should the interpolating
      point happen to fall outside of the convex hull of the triangulation

    At the moment, the only regular rectangular grids are supported for
    interpolation.

        vals = interp[ystart:ystop:ysteps*1j, xstart:xstop:xsteps*1j]

    vals would then be a (ysteps, xsteps) array containing the interpolated
    values. These arguments are interpreted the same way as numpy.mgrid.

    Attributes:
      planes -- (ntriangles, 3) array of floats specifying the plane for each
        triangle.

    Linear Interpolation
    --------------------
    Given the Delauany triangulation (or indeed *any* complete triangulation)
    we can interpolate values inside the convex hull by locating the enclosing
    triangle of the interpolation point and returning the value at that point
    of the plane defined by the three node values.

        f = planes[tri,0]*x + planes[tri,1]*y + planes[tri,2]

    The interpolated function is C0 continuous across the convex hull of the
    input points. It is C1 continuous across the convex hull except for the
    nodes and the edges of the triangulation.
    c         C  sU   | |  _  t j | d t j ƒ|  _ | |  _ t | j | j |  j | j	 ƒ |  _
 d  S(   Nt   dtype(   t   triangulationt   npt   asarrayt   float64t   zt   default_valueR   t   xt   yt   triangle_nodest   planes(   t   selfR   R   R    (    (    sY   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/delaunay/interpolate.pyt   __init__M   s
    		c   	      C  sm   t  | ƒ \ } } } } } } t | | | | | | |  j |  j |  j j |  j j |  j j |  j j ƒ } | S(   N(	   R   R   R    R$   R   R!   R"   R#   t   triangle_neighbors(	   R%   R   R   R   R   R   R   R   t   grid(    (    sY   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/delaunay/interpolate.pyt   __getitem__U   s    	(   t   __name__t
   __module__t   __doc__R   t   nanR&   R)   (    (    (    sY   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/delaunay/interpolate.pyR   (   s   $c           B  s/   e  Z d  Z e j d „ Z d „  Z d „  Z RS(   s?
  Interpolate a function defined on the nodes of a triangulation by
    the natural neighbors method.

    NNInterpolator(triangulation, z, default_value=numpy.nan)

    triangulation -- Triangulation instance
    z -- the function values at each node of the triangulation
    default_value -- a float giving the default value should the interpolating
      point happen to fall outside of the convex hull of the triangulation

    At the moment, the only regular rectangular grids are supported for
    interpolation.

        vals = interp[ystart:ystop:ysteps*1j, xstart:xstop:xsteps*1j]

    vals would then be a (ysteps, xsteps) array containing the interpolated
    values. These arguments are interpreted the same way as numpy.mgrid.

    Natural Neighbors Interpolation
    -------------------------------
    One feature of the Delaunay triangulation is that for each triangle, its
    circumcircle contains no other point (although in degenerate cases, like
    squares, other points may be *on* the circumcircle). One can also
    construct what is called the Voronoi diagram from a Delaunay triangulation
    by connecting the circumcenters of the triangles to those of their
    neighbors to form a tesselation of irregular polygons covering the plane
    and containing only one node from the triangulation. Each point in one
    node's Voronoi polygon is closer to that node than any other node.

    To compute the Natural Neighbors interpolant, we consider adding the
    interpolation point to the triangulation. We define the natural neighbors
    of this point as the set of nodes participating in Delaunay triangles
    whose circumcircles contain the point. To restore the Delaunay-ness of the
    triangulation, one would only have to alter those triangles and Voronoi
    polygons. The new Voronoi diagram would have a polygon around the
    inserted point. This polygon would "steal" area from the original Voronoi
    polygons. For each node i in the natural neighbors set, we compute the
    area stolen from its original Voronoi polygon, stolen[i]. We define the
    natural neighbors coordinates

        phi[i] = stolen[i] / sum(stolen,axis=0)

    We then use these phi[i] to weight the corresponding function values from
    the input data z to compute the interpolated value.

    The interpolated surface is C1-continuous except at the nodes themselves
    across the convex hull of the input points. One can find the set of points
    that a given node will affect by computing the union of the areas covered
    by the circumcircles of each Delaunay triangle that node participates in.
    c         C  s1   | |  _  t j | d t j ƒ|  _ | |  _ d  S(   NR   (   R   R   R   R   R   R    (   R%   R   R   R    (    (    sY   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/delaunay/interpolate.pyR&   “   s    	c   	      C  sv   t  | ƒ \ } } } } } } t | | | | | | |  j |  j j |  j j |  j |  j j |  j j |  j j	 ƒ } | S(   N(
   R   R   R    R   R!   R"   R   t   circumcentersR#   R'   (	   R%   R   R   R   R   R   R   R   R(   (    (    sY   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/delaunay/interpolate.pyR)   ˜   s    		c      
   C  sL   t  | | |  j |  j j |  j j |  j |  j j |  j j |  j j ƒ	 } | S(   N(	   R   R    R   R!   R"   R   R.   R#   R'   (   R%   t   intxt   intyt   intz(    (    sY   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/delaunay/interpolate.pyt   __call__¢   s    		(   R*   R+   R,   R   R-   R&   R)   R2   (    (    (    sY   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/delaunay/interpolate.pyR   _   s   2	
(   t
   __future__R    t   numpyR   t   matplotlib._delaunayR   R   R   R   t   __all__R   t   objectR   R   (    (    (    sY   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/delaunay/interpolate.pyt   <module>   s   	7