Skip to content

KDTree Data Structure for Center and Corner Nodes - #518

Merged
philipc2 merged 17 commits into
mainfrom
zedwick/kdtree
Nov 2, 2023
Merged

KDTree Data Structure for Center and Corner Nodes#518
philipc2 merged 17 commits into
mainfrom
zedwick/kdtree

Conversation

@aaronzedwick

@aaronzedwick aaronzedwick commented Oct 19, 2023

Copy link
Copy Markdown
Member

Closes #496

Overview

Adds a KDTree data structure for center nodes (Mesh2_face_cart_x, Mesh2_face_cart_y, Mesh2_face_cart_z) and corner nodes (Mesh2_node_cart_x, Mesh2_node_cart_y, Mesh2_node_cart_z) for grid files. This can be used for nearest neighbor queries as well as querying in a specific radius. This implementation mirrors the BallTree data structure #406 and uses sklearn.neighbors.KDTree with a minkowski distance for querying.

Expected Usage

import uxarray as ux

grid_path = "/path/to/grid.nc"

uxgrid = ux.open_grid(grid_path)

# find the nearest neighbor to (0.0, 0.0, 1.0) using corner nodes
d, ind = uxgrid.get_kd_tree(tree_type="nodes").query([0.0, 0.0, 1.0])

# find the 5 nearest neighbors to (0.0, 0.0, 1.0) using face centers
d, ind = uxgrid.get_kd_tree(tree_type="face centers").query([1.0, 0.0, 0.0], k=5)

# find all face centers within a radius of 80.00 from (0.0, 0.0, 1.0)
d, ind = uxgrid.get_kd_tree(tree_type="face centers").query_radius([0.0, 0.0, 1.0], r=80.00)

PR Checklist

General

  • An issue is linked created and linked
  • Add appropriate labels
  • Filled out Overview and Expected Usage (if applicable) sections

Testing

  • Adequate tests are created if there is new functionality
  • Tests cover all possible logical paths in your function
  • Tests are not too basic (such as simply calling a function and nothing else)

Documentation

  • Docstrings have been added to all new functions
  • Docstrings have updated with any function changes
  • Internal functions have a preceding underscore (_) and have been added to docs/internal_api/index.rst
  • User functions have been added to docs/user_api/index.rst

Examples

  • Any new notebook examples added to docs/examples/ folder
  • Clear the output of all cells before committing
  • New notebook files added to docs/examples.rst toctree
  • New notebook files added to new entry in docs/gallery.yml with appropriate thumbnail photo in docs/_static/thumbnails/

@aaronzedwick aaronzedwick self-assigned this Oct 19, 2023
@aaronzedwick aaronzedwick added the new feature New user-facing functionality label Oct 19, 2023
@aaronzedwick aaronzedwick added this to the Regridding milestone Oct 19, 2023
Comment thread uxarray/grid/neighbors.py Outdated
Comment thread uxarray/grid/neighbors.py Outdated
Comment thread uxarray/grid/neighbors.py Outdated
Comment thread uxarray/grid/neighbors.py Outdated
@aaronzedwick

Copy link
Copy Markdown
Member Author

@philipc2 I think I updated the user api incorrectly causing the docs to fail, anything you see that would be causing the problem? I just added what you did from the balltree, but using the kdtree instead.

Comment thread docs/user_api/index.rst Outdated
Comment thread docs/user_api/index.rst Outdated
aaronzedwick and others added 4 commits October 26, 2023 12:29

@philipc2 philipc2 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Please run the pre-commit though!

@philipc2
philipc2 merged commit d5f61da into main Nov 2, 2023
@erogluorhan
erogluorhan deleted the zedwick/kdtree branch December 7, 2023 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature New user-facing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement KdTree built from Cartesian x/y/z Coordinates

3 participants