Basetree

The BaseTree abstract base class for all astroQTpy quadtree types.

class astroqtpy.basetree.BaseTree(x_min: float, x_max: float, y_min: float, y_max: float, split_threshold: float = 0.2, node_statistic: str = 'mean', N_points: int = 20, min_depth: int = 3, max_depth: int = 6, N_proc: int = 1, verbose: bool = False, filename_points: str = 'points.txt', filename_nodes: str = 'nodes.txt')

Base quadtree.

The abstract base class for all types of astroQTpy quadtrees.

Parameters:
  • x_min (float) – Minimum x value for this quadtree.

  • x_max (float) – Maximum x value for this quadtree.

  • y_min (float) – Minimum y value for this quadtree.

  • y_max (float) – Maximum y value for this quadtree.

  • split_threshold (float, optional) – Threshold discrepancy in order to split nodes. Defaults to 0.2.

  • node_statistic (str, optional) – Statistic to compute node values [‘mean’, ‘std’, or ‘median’]. Defaults to ‘mean’.

  • N_points (int, optional) – Maximum number of points per node. Defaults to 20.

  • min_depth (int, optional) – Minimum quadtree depth. Defaults to 3.

  • max_depth (int, optional) – Maximum quadtree depth. Defaults to 6.

  • N_proc (int, optional) – Number of cores for multiprocessing. Defaults to 1.

  • verbose (bool, optional) – Option to print node values in real time. Defaults to False.

  • filename_points (str, optional) – Name of output file to save points. Defaults to ‘points.txt’.

  • filename_nodes (str, optional) – Name of output file to save nodes. Defaults to ‘nodes.txt’.

draw_tree(ax: Axes, cmap: str = 'RdYlGn_r', vmin: float = None, vmax: float = None, show_lines: float = True, show_points: bool = False, show_values: bool = False) ScalarMappable

Draw quadtree.

Plot the entire quadtree on a given axis.

Parameters:
  • ax (matplotlib.axes.Axes) – Matplotlib axis for plotting.

  • cmap (str, optional) – Matplotlib colormap. Defaults to ‘RdYlGn_r’.

  • vmin (float, optional) – Minimum value for colorbar. Defaults to None.

  • vmax (float, optional) – Maximum value for colorbar. Defaults to None.

  • show_lines (float, optional) – Option to plot node boundary lines. Defaults to True.

  • show_points (bool, optional) – Option to plot node points. Defaults to False.

  • show_values (bool, optional) – Option to print node values on plot. Defaults to False.

Returns:

Matplotlib ScalarMappable.

Return type:

matplotlib.cm.ScalarMappable

evaluate_multiple_points(node: QuadNode, N_points: int) None

Evaulate multiple points.

Evaluate multiple points contained within a given node in parallel.

Parameters:
  • node (QuadNode) – Node in which to evaulate points.

  • N_points (int) – Maximum number of points to evaulate within this node.

abstract evaluate_point(node: QuadNode, rng_seed: int = 123456) QuadPoint

Evaluate point.

Abstract method to calculate the value of one point within a given node.

Parameters:
  • node (QuadNode) – Node in which to evaulate point.

  • rng_seed (int, optional) – Random number generator seed. Defaults to 123456.

Returns:

A QuadPoint object that has been evaluated.

Return type:

QuadPoint

fill(node: QuadNode, N_points: int) None

Fill.

Fill a given node with points.

Parameters:
  • node (QuadNode) – The quadtree node to be filled.

  • N_points (int) – Number of points to put inside this node.

load_points() None

Load points.

Load all points from a previously saved quadtree.

print_all_nodes() None

Print all nodes.

Print all current quadtree node values to a file (‘filename_nodes’).

print_all_points() None

Print all points.

Print all current quadtree points to a file (‘filename_points’).

run_quadtree() None

Run quadtree.

Run the quadtree from a previously saved run, or start a new run.

squeeze_node(node: QuadNode) None

Squeeze node.

Distribute quadtree points from parent to children.