ó
Ë½÷Xc           @` s¡   d  Z  d d l m Z m Z m Z d d l Z d d l m Z m	 Z	 m
 Z
 m Z d d l m Z d d d	 d
 g Z d e	 f d „  ƒ  YZ d e j e d „ Z d S(   sD   
Convenience interface to N-D interpolation

.. versionadded:: 0.9

i    (   t   divisiont   print_functiont   absolute_importNi   (   t   LinearNDInterpolatort   NDInterpolatorBaset   CloughTocher2DInterpolatort   _ndim_coords_from_arrays(   t   cKDTreet   griddatat   NearestNDInterpolatorR   R   c           B` s&   e  Z d  Z e d d „ Z d „  Z RS(   s  
    NearestNDInterpolator(points, values)

    Nearest-neighbour interpolation in N dimensions.

    .. versionadded:: 0.9

    Methods
    -------
    __call__

    Parameters
    ----------
    x : (Npoints, Ndims) ndarray of floats
        Data point coordinates.
    y : (Npoints,) ndarray of float or complex
        Data values.
    rescale : boolean, optional
        Rescale points to unit cube before performing interpolation.
        This is useful if some of the input dimensions have
        incommensurable units and differ by many orders of magnitude.

        .. versionadded:: 0.14.0
    tree_options : dict, optional
        Options passed to the underlying ``cKDTree``.

        .. versionadded:: 0.17.0


    Notes
    -----
    Uses ``scipy.spatial.cKDTree``

    c      
   C` s_   t  j |  | | d | d t d t ƒ| d  k r= t ƒ  } n  t |  j |  |  _ | |  _ d  S(   Nt   rescalet   need_contiguoust   need_values(	   R   t   __init__t   Falset   Nonet   dictR   t   pointst   treet   values(   t   selft   xt   yR
   t   tree_options(    (    s;   /tmp/pip-build-7oUkmx/scipy/scipy/interpolate/ndgriddata.pyR   :   s    c         G` s]   t  | d |  j j d ƒ} |  j | ƒ } |  j | ƒ } |  j j | ƒ \ } } |  j | S(   sÂ   
        Evaluate interpolator at given points.

        Parameters
        ----------
        xi : ndarray of float, shape (..., ndim)
            Points where to interpolate data at.

        t   ndimi   (   R   R   t   shapet   _check_call_shapet   _scale_xR   t   queryR   (   R   t   argst   xit   distt   i(    (    s;   /tmp/pip-build-7oUkmx/scipy/scipy/interpolate/ndgriddata.pyt   __call__C   s
    
N(   t   __name__t
   __module__t   __doc__R   R   R   R!   (    (    (    s;   /tmp/pip-build-7oUkmx/scipy/scipy/interpolate/ndgriddata.pyR	      s   "	t   linearc   
      C` sÀ  t  |  ƒ }  |  j d k  r' |  j } n |  j d } | d k r| d k rd d l m } |  j ƒ  }  t | t ƒ r¤ t | ƒ d k r˜ t	 d ƒ ‚ n  | \ } n  t
 j |  ƒ } |  | }  | | } | d k rÜ d	 } n  | |  | d
 | d d d t d | ƒ}	 |	 | ƒ S| d k r8t |  | d | ƒ}	 |	 | ƒ S| d k rit |  | d | d | ƒ}	 |	 | ƒ S| d k r¦| d k r¦t |  | d | d | ƒ}	 |	 | ƒ St	 d | | f ƒ ‚ d S(   sV  
    Interpolate unstructured D-dimensional data.

    Parameters
    ----------
    points : ndarray of floats, shape (n, D)
        Data point coordinates. Can either be an array of
        shape (n, D), or a tuple of `ndim` arrays.
    values : ndarray of float or complex, shape (n,)
        Data values.
    xi : 2-D ndarray of float or tuple of 1-D array, shape (M, D)
        Points at which to interpolate data.
    method : {'linear', 'nearest', 'cubic'}, optional
        Method of interpolation. One of

        ``nearest``
          return the value at the data point closest to
          the point of interpolation.  See `NearestNDInterpolator` for
          more details.

        ``linear``
          tesselate the input point set to n-dimensional
          simplices, and interpolate linearly on each simplex.  See
          `LinearNDInterpolator` for more details.

        ``cubic`` (1-D)
          return the value determined from a cubic
          spline.

        ``cubic`` (2-D)
          return the value determined from a
          piecewise cubic, continuously differentiable (C1), and
          approximately curvature-minimizing polynomial surface. See
          `CloughTocher2DInterpolator` for more details.
    fill_value : float, optional
        Value used to fill in for requested points outside of the
        convex hull of the input points.  If not provided, then the
        default is ``nan``. This option has no effect for the
        'nearest' method.
    rescale : bool, optional
        Rescale points to unit cube before performing interpolation.
        This is useful if some of the input dimensions have
        incommensurable units and differ by many orders of magnitude.

        .. versionadded:: 0.14.0

    Notes
    -----

    .. versionadded:: 0.9

    Examples
    --------

    Suppose we want to interpolate the 2-D function

    >>> def func(x, y):
    ...     return x*(1-x)*np.cos(4*np.pi*x) * np.sin(4*np.pi*y**2)**2

    on a grid in [0, 1]x[0, 1]

    >>> grid_x, grid_y = np.mgrid[0:1:100j, 0:1:200j]

    but we only know its values at 1000 data points:

    >>> points = np.random.rand(1000, 2)
    >>> values = func(points[:,0], points[:,1])

    This can be done with `griddata` -- below we try out all of the
    interpolation methods:

    >>> from scipy.interpolate import griddata
    >>> grid_z0 = griddata(points, values, (grid_x, grid_y), method='nearest')
    >>> grid_z1 = griddata(points, values, (grid_x, grid_y), method='linear')
    >>> grid_z2 = griddata(points, values, (grid_x, grid_y), method='cubic')

    One can see that the exact result is reproduced by all of the
    methods to some degree, but for this smooth function the piecewise
    cubic interpolant gives the best results:

    >>> import matplotlib.pyplot as plt
    >>> plt.subplot(221)
    >>> plt.imshow(func(grid_x, grid_y).T, extent=(0,1,0,1), origin='lower')
    >>> plt.plot(points[:,0], points[:,1], 'k.', ms=1)
    >>> plt.title('Original')
    >>> plt.subplot(222)
    >>> plt.imshow(grid_z0.T, extent=(0,1,0,1), origin='lower')
    >>> plt.title('Nearest')
    >>> plt.subplot(223)
    >>> plt.imshow(grid_z1.T, extent=(0,1,0,1), origin='lower')
    >>> plt.title('Linear')
    >>> plt.subplot(224)
    >>> plt.imshow(grid_z2.T, extent=(0,1,0,1), origin='lower')
    >>> plt.title('Cubic')
    >>> plt.gcf().set_size_inches(6, 6)
    >>> plt.show()

    i   iÿÿÿÿi   t   nearestR%   t   cubic(   t   interp1ds"   invalid number of dimensions in xit   extrapolatet   kindt   axisi    t   bounds_errort
   fill_valueR
   s7   Unknown interpolation method %r for %d dimensional dataN(   R&   R%   R'   (   R   R   R   t   interpolateR(   t   ravelt
   isinstancet   tuplet   lent
   ValueErrort   npt   argsortR   R	   R   R   (
   R   R   R   t   methodR-   R
   R   R(   t   idxt   ip(    (    s;   /tmp/pip-build-7oUkmx/scipy/scipy/interpolate/ndgriddata.pyR   X   s@    e

		

	
	
(   R$   t
   __future__R    R   R   t   numpyR4   t   interpndR   R   R   R   t   scipy.spatialR   t   __all__R	   t   nanR   R   (    (    (    s;   /tmp/pip-build-7oUkmx/scipy/scipy/interpolate/ndgriddata.pyt   <module>   s   "		B	