KD-Tree

Classes for constructing k-nearest neighbour trees.

class fiesta.kdtree.KDTree1D
build_tree(x: ndarray, boxsize: float | None = None) None

Function for building the KDTree.

Parameters:
  • x (array) – X coordinates.

  • boxsize (float, optional) – Periodic boundary boxsize.

clean() None

Reinitilises the class.

find_points_in_r(x: ndarray, r: float) ndarray

Returns the nearest index (and distance) of a point from the KDTree.

Parameters:
  • x (array) – X coordinates.

  • r (float) – Radial distance to find points in KDTree from input coordinates.

Returns:

ind – Index of points in the KDTree that are within a distance r of the input coordinates..

Return type:

int

nearest(x: ndarray, k: int = 1, return_dist: bool = False) Tuple[ndarray, ndarray]

Returns the nearest index (and distance) of a point from the KDTree.

Parameters:
  • x (array) – X coordinates.

  • k (int) – Number of nearest points.

  • return_dist (bool, optional) – If True the distance to the nearest point will also be supplied.

Returns:

  • nind (int) – Index of nearest point.

  • ndist (float, optional) – Distance to nearest point.

class fiesta.kdtree.KDTree2D
build_tree(x: ndarray, y: ndarray, boxsize: float | None = None) None

Function for building the KDTree.

Parameters:
  • x (array) – X coordinates.

  • y (array) – Y coordinates.

  • boxsize (float, optional) – Periodic boundary boxsize.

clean() None

Reinitilises the class.

find_points_in_r(x: ndarray, y: ndarray, r: float) ndarray

Returns the nearest index (and distance) of a point from the KDTree.

Parameters:
  • x (array) – X coordinates.

  • y (array) – Y coordinates.

  • r (float) – Radial distance to find points in KDTree from input coordinates.

Returns:

ind – Index of points in the KDTree that are within a distance r of the input coordinates..

Return type:

int

nearest(x: ndarray, y: ndarray, k: int = 1, return_dist: bool = False) Tuple[ndarray, ndarray]

Returns the nearest index (and distance) of a point from the KDTree.

Parameters:
  • x (array) – X coordinates.

  • y (array) – Y coordinates.

  • k (int) – Number of nearest points.

  • return_dist (bool, optional) – If True the distance to the nearest point will also be supplied.

Returns:

  • nind (int) – Index of nearest point.

  • ndist (float, optional) – Distance to nearest point.

class fiesta.kdtree.KDTree3D
build_tree(x: ndarray, y: ndarray, z: ndarray, boxsize: float | None = None) None

Function for building the KDTree.

Parameters:
  • x (array) – X coordinates.

  • y (array) – Y coordinates.

  • z (array) – Z coordinates.

  • boxsize (float, optional) – Periodic boundary boxsize.

clean() None

Reinitilises the class.

find_points_in_r(x: ndarray, y: ndarray, z: ndarray, r: float) ndarray

Returns the nearest index (and distance) of a point from the KDTree.

Parameters:
  • x (array) – X coordinates.

  • y (array) – Y coordinates.

  • z (array) – Z coordinates.

  • r (float) – Radial distance to find points in KDTree from input coordinates.

Returns:

ind – Index of points in the KDTree that are within a distance r of the input coordinates..

Return type:

int

nearest(x: ndarray, y: ndarray, z: ndarray, k: int = 1, return_dist: bool = False) Tuple[ndarray, ndarray]

Returns the nearest index (and distance) of a point from the KDTree

Parameters:
  • x (array) – X coordinates.

  • y (array) – Y coordinates.

  • z (array) – Z coordinates.

  • k (int) – Number of nearest points.

  • return_dist (bool, optional) – If True the distance to the nearest point will also be supplied.

Returns:

  • nind (int) – Index of nearest point.

  • ndist (float, optional) – Distance to nearest point.