# pyresample.future.resamplers.nearest module

Nearest neighbor resampler.

class pyresample.future.resamplers.nearest.KDTreeNearestXarrayResampler(source_geo_def, target_geo_def, cache=None)

  Bases: `Resampler`

  Resampler using the basic nearest neighbor algorithm.

  Resampler for xarray DataArrays using a nearest neighbor algorithm.

  Parameters:

    - source_geo_def (object) – Geometry definition of source

    - target_geo_def (object) – Geometry definition of target

  __init__(source_geo_def, target_geo_def, cache=None)

    Resampler for xarray DataArrays using a nearest neighbor algorithm.

    Parameters:

      - source_geo_def (object) – Geometry definition of source

      - target_geo_def (object) – Geometry definition of target

  compute_data_mask(data)

    Generate a mask array where data is invalid.

    This is used by `resample()` to determine what `mask` to pass to `precompute()`. It may be useful for users to use this manually for special cases of wanting to call precompute manually.

  get_sample_from_neighbor_info(data, valid_input_index, index_array, neighbors=1, fill_value=nan)

    Get the pixels matching the target area.

    This method should work for any dimensionality of the provided data array as long as the geolocation dimensions match in size and name in `data.dims`. Where source area definition are AreaDefinition objects the corresponding dimensions in the data should be `('y', 'x')`.

    This method also attempts to preserve chunk sizes of dask arrays, but does require loading/sharing the fully computed source data before it can actually compute the values to write to the destination array. This can result in large memory usage for large source data arrays, but is a necessary evil until fancier indexing is supported by dask and/or pykdtree.

    Parameters:

      - data (xarray.DataArray) – Source data pixels to sample

      - valid_input_index (ArrayLike) – Index array of valid pixels in the input geolocation data.

      - index_array (ArrayLike) – Index array of nearest neighbors.

      - neighbors (int) – Number of neighbors to return for each data pixel. Currently only 1 (the default) is supported.

      - fill_value (float) – Output fill value when no source data is near the target pixel. When omitted, if the input data is an integer array then the maximum value for that integer type is used, but otherwise, NaN is used and can be detected in the result with `res.isnull()`.

    Returns:

      The resampled array. The dtype of the array will

        be the same as the input data. Pixels with no matching data from the input array will be filled (see the fill_value parameter description above).

    Return type:

      dask.array.Array

  precompute(mask=None, radius_of_influence=None, epsilon=0)

    Generate neighbor indexes using geolocation information and optional data mask.

    Parameters:

      - mask (ArrayLike, optional) – Boolean array where True represents invalid pixels in the data array to be resampled in the future. This allows the indexes computed by this method and used during resampling to filter out invalid values and produce a result with more overall valid pixels. If provided then pre-computed results will not be cached as it is assumed that the mask will likely change for every input array.

      - radius_of_influence (float, optional) – Cut off distance in geocentric meters. If not provided this will be estimated based on the source and target geometry definition.

      - epsilon (float, optional) – Allowed uncertainty in meters. Increasing uncertainty reduces execution time

  resample(data, mask_area=None, fill_value=nan, radius_of_influence=None, epsilon=0)

    Resample input `data` from the source geometry to the target geometry.

    Parameters:

      - data (ArrayLike) – Data to be resampled

      - mask_area (bool or ArrayLike) – Mask geolocation data where data values are invalid. This should be used when data values may affect what neighbors are considered valid. For complex masking behavior this can also be the mask array to use instead of the resampler computing it on the fly. This is useful for non-xarray DataArrays that don’t have related metadata like “_FillValue”. By default this is None which means a mask will be created automatically for SwathDefinition input. Set to `False` to disable any masking and `True` to ensure a mask is created. See `precompute()` for more information.

      - fill_value (int or float) – Output fill value when no source data is near the target pixel. When omitted, if the input data is an integer array then the maximum value for that integer type is used, but otherwise, NaN is used and can be detected in the result with `res.isnull()` for DataArray output and `np.isnan(res)` for dask and numpy arrays.

      - radius_of_influence (float, optional) – Passed directly to `precompute()`.

      - epsilon (float, optional) – Passed directly to `precompute()`.

    Returns:

      Array-like object of the same type as `data`, resampled to the target geographic geometry.

  property version: str

    Get the current version of this class used for hashing and caching.

pyresample.future.resamplers.nearest.query_no_distance(target_lons, target_lats, valid_output_index, mask=None, valid_input_index=None, neighbours=None, epsilon=None, radius=None, kdtree=None)

  Query the kdtree. No distances are returned.

  NOTE: Dask array arguments must always come before other keyword arguments

    for da.blockwise arguments to work.