§
    fŠtjz/  ã                   ór   — d Z ddlZddlmZmZmZmZ ddlm	Z	 g d¢Z
 G d„ de¦  «        Zd	ej        d
fd„ZdS )zD
Convenience interface to N-D interpolation

.. versionadded:: 0.9

é    Né   )ÚLinearNDInterpolatorÚNDInterpolatorBaseÚCloughTocher2DInterpolatorÚ_ndim_coords_from_arrays)ÚcKDTree)ÚgriddataÚNearestNDInterpolatorr   r   c                   ó    — e Zd ZdZdd„Zd„ ZdS )r
   ae  Nearest-neighbor interpolator in N > 1 dimensions.

    Methods
    -------
    __call__

    Parameters
    ----------
    x : (npoints, ndims) 2-D ndarray of floats
        Data point coordinates.
    y : (npoints, ...) N-D ndarray of float or complex
        Data values. The length of `y` along the first axis must be equal to
        the length of `x`.
    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

    See Also
    --------
    griddata :
        Interpolate unstructured D-D data.
    LinearNDInterpolator :
        Piecewise linear interpolator in N dimensions.
    CloughTocher2DInterpolator :
        Piecewise cubic, C1 smooth, curvature-minimizing interpolator in 2D.
    interpn : Interpolation on a regular grid or rectilinear grid.
    RegularGridInterpolator : Interpolator on a regular or rectilinear grid
                              in arbitrary dimensions (`interpn` wraps this
                              class).

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

    .. note:: For data on a regular grid use `interpn` instead.

    Examples
    --------
    We can interpolate values on a 2D plane:

    >>> from scipy.interpolate import NearestNDInterpolator
    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> rng = np.random.default_rng()
    >>> x = rng.random(10) - 0.5
    >>> y = rng.random(10) - 0.5
    >>> z = np.hypot(x, y)
    >>> X = np.linspace(min(x), max(x))
    >>> Y = np.linspace(min(y), max(y))
    >>> X, Y = np.meshgrid(X, Y)  # 2D grid for interpolation
    >>> interp = NearestNDInterpolator(list(zip(x, y)), z)
    >>> Z = interp(X, Y)
    >>> plt.pcolormesh(X, Y, Z, shading='auto')
    >>> plt.plot(x, y, "ok", label="input point")
    >>> plt.legend()
    >>> plt.colorbar()
    >>> plt.axis("equal")
    >>> plt.show()

    FNc                 óº   — t          j        | |||dd¬¦  «         |€t          ¦   «         }t          | j        fi |¤Ž| _        t          j        |¦  «        | _        d S )NF)ÚrescaleÚneed_contiguousÚneed_values)	r   Ú__init__Údictr   ÚpointsÚtreeÚnpÚasarrayÚvalues)ÚselfÚxÚyr   Útree_optionss        ú[/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/scipy/interpolate/_ndgriddata.pyr   zNearestNDInterpolator.__init__Y   sg   € ÝÔ# D¨!¨Q¸Ø49Ø05ð	7ñ 	7ô 	7ð 	7ð ÐÝ™6œ6ˆLÝ˜DœKÐ8Ð8¨<Ð8Ð8ˆŒ	Ý”j ‘m”mˆŒˆˆó    c                 óx  — t          || j        j        d         ¬¦  «        }|                      |¦  «        }|                      |¦  «        }|                     d|j        d         ¦  «        }|j        }|j        } | j        j        |fi |¤Ž\  }}t          j	        |¦  «        }	| j
        j        dk    r |dd…         | j
        j        dd…         z   }
n
|dd…         }
t          j        | j
        j        t          j        ¦  «        r,t          j        |
t          j        | j
        j        ¬¦  «        }nt          j        |
t          j        ¦  «        }| j
        ||	         df         ||	<   | j
        j        dk    r |dd…         | j
        j        dd…         z   }n
|dd…         }|                     |¦  «        }|S )a�  
        Evaluate interpolator at given points.

        Parameters
        ----------
        x1, x2, ... xn : array-like of float
            Points where to interpolate data at.
            x1, x2, ... xn can be array-like of float with broadcastable shape.
            or x1 can be array-like of float with shape ``(..., ndim)``
        **query_options
            This allows ``eps``, ``p``, ``distance_upper_bound``, and ``workers``
            being passed to the cKDTree's query function to be explicitly set.
            See `scipy.spatial.cKDTree.query` for an overview of the different options.

            .. versionadded:: 1.12.0

        r   )ÚndiméÿÿÿÿN)Údtype.)r   r   ÚshapeÚ_check_call_shapeÚ_scale_xÚreshaper   Úqueryr   Úisfiniter   r   Ú
issubdtyper    ÚcomplexfloatingÚfullÚnan)r   ÚargsÚquery_optionsÚxiÚxi_flatÚoriginal_shapeÚflattened_shapeÚdistÚiÚ
valid_maskÚinterp_shapeÚinterp_valuesÚ	new_shapes                r   Ú__call__zNearestNDInterpolator.__call__b   s¢  € õ* & d°´Ô1BÀ1Ô1EÐFÑFÔFˆØ×#Ò# BÑ'Ô'ˆØ�]Š]˜2ÑÔˆð —*’*˜R ¤¨"¤Ñ.Ô.ˆØœˆØ!œ-ˆð "�$”)”/ 'Ð;Ð;¨]Ð;Ð;‰ˆˆaÝ”[ Ñ&Ô&ˆ
ð Œ;Ô˜aÒÐØ*¨3¨B¨3Ô/°$´+Ô2CÀAÀBÀBÔ2GÑGˆLˆLà*¨3¨B¨3Ô/ˆLåŒ=˜œÔ*­BÔ,>Ñ?Ô?ð 	:ÝœG Lµ"´&ÀÄÔ@QÐRÑRÔRˆMˆMåœG Lµ"´&Ñ9Ô9ˆMà$(¤K°°*´¸sÐ0BÔ$Cˆ�jÑ!àŒ;Ô˜aÒÐØ& s¨ sÔ+¨d¬kÔ.?ÀÀÀÔ.CÑCˆIˆIà& s¨ sÔ+ˆIØ%×-Ò-¨iÑ8Ô8ˆàÐr   )FN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r7   © r   r   r
   r
      sI   € € € € € ðBð BðH$ð $ð $ð $ðAð Að Að Að Ar   r
   ÚlinearFc                 ó¼  — t          | ¦  «        } | j        dk     r| j        }n| j        d         }|dk    r¡|dv r�ddlm} |                      ¦   «         } t          |t          ¦  «        r&t          |¦  «        dk    rt          d¦  «        ‚|\  }t          j        | ¦  «        }| |         } ||         }|dk    rd} || ||d	d
|¬¦  «        }	 |	|¦  «        S |dk    rt          | ||¬¦  «        }	 |	|¦  «        S |dk    rt          | |||¬¦  «        }	 |	|¦  «        S |dk    r$|dk    rt          | |||¬¦  «        }	 |	|¦  «        S t          d|›d|› d�¦  «        ‚)a†  
    Convenience function for interpolating unstructured data in multiple dimensions.

    Parameters
    ----------
    points : 2-D ndarray of floats with shape (n, D), or length D tuple of 1-D ndarrays with shape (n,).
        Data point coordinates.
    values : ndarray of float or complex, shape (n,)
        Data values.
    xi : 2-D ndarray of floats with shape (m, D), or length D tuple of ndarrays broadcastable to the same shape.
        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``
          tessellate the input point set to N-D
          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

    Returns
    -------
    ndarray
        Array of interpolated values.

    See Also
    --------
    LinearNDInterpolator :
        Piecewise linear interpolator in N dimensions.
    NearestNDInterpolator :
        Nearest-neighbor interpolator in N dimensions.
    CloughTocher2DInterpolator :
        Piecewise cubic, C1 smooth, curvature-minimizing interpolator in 2D.
    interpn : Interpolation on a regular grid or rectilinear grid.
    RegularGridInterpolator : Interpolator on a regular or rectilinear grid
                              in arbitrary dimensions (`interpn` wraps this
                              class).

    Notes
    -----

    .. versionadded:: 0.9

    .. note:: For data on a regular grid use `interpn` instead.

    Examples
    --------

    Suppose we want to interpolate the 2-D function

    >>> import numpy as np
    >>> 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:

    >>> rng = np.random.default_rng()
    >>> points = rng.random((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()

    é   r   r   )Únearestr=   Úcubic)Úinterp1dz"invalid number of dimensions in xir@   Úextrapolater   F)ÚkindÚaxisÚbounds_errorÚ
fill_value)r   r=   )rG   r   rA   zUnknown interpolation method z for z dimensional data)r   r   r!   Ú_interpolaterB   ÚravelÚ
isinstanceÚtupleÚlenÚ
ValueErrorr   Úargsortr
   r   r   )
r   r   r-   ÚmethodrG   r   r   rB   ÚidxÚips
             r   r	   r	   «   sÃ  € õt & fÑ-Ô-€Fà„{�Q‚€ØŒ{ˆˆàŒ|˜BÔˆàˆq‚y€y�VÐ=Ð=Ð=Ø*Ð*Ð*Ð*Ð*Ð*Ø—’‘”ˆÝ�b�%Ñ Ô ð 	Ý�2‰wŒw˜!Š|ˆ|Ý Ð!EÑFÔFÐFØ‰CˆBåŒj˜Ñ Ô ˆØ˜”ˆØ˜”ˆØ�YÒÐØ&ˆJØˆX�f˜f¨6¸ÈØ!+ð-ñ -ô -ˆàˆr�"‰vŒvˆØ	�9Ò	Ð	Ý" 6¨6¸7ÐCÑCÔCˆØˆr�"‰vŒvˆØ	�8Ò	Ð	Ý! &¨&¸ZØ*1ð3ñ 3ô 3ˆàˆr�"‰vŒvˆØ	�7Ò	Ð	˜t qšy˜yÝ'¨°À:Ø07ð9ñ 9ô 9ˆàˆr�"‰vŒvˆåØR¨FÐRÐR¸4ÐRÐRÐRñ
ô 
ð 	
r   )r;   Únumpyr   Ú	_interpndr   r   r   r   Úscipy.spatialr   Ú__all__r
   r*   r	   r<   r   r   ú<module>rV      sà   ððð ð Ð Ð Ð ð;ð ;ð ;ð ;ð ;ð ;ð ;ð ;ð ;ð ;ð ;ð ;à !Ð !Ð !Ð !Ð !Ð !ð)ð )ð )€ðOð Oð Oð Oð OÐ.ñ Oô Oð Oðn )1¸R¼VØð_
ð _
ð _
ð _
ð _
ð _
r   