Skip to content

Optimize Point in Face Computation #1249

Merged
philipc2 merged 16 commits intomainfrom
optimize-point-in-face
May 16, 2025
Merged

Optimize Point in Face Computation #1249
philipc2 merged 16 commits intomainfrom
optimize-point-in-face

Conversation

@philipc2
Copy link
Member

@philipc2 philipc2 commented May 13, 2025

Overview

  • Optimizes Grid.get_faces_containing_point()
  • Uses a SciPy KDTree, with similar benefits as seen in Refactor & Optimize Remapping (NN & IDW) #1244
  • Enables batched point queries by passing in an array of points, allowing for a single call to the KDTree
  • Implements a spherical winding number approach for determining if a point contains a face

@philipc2 philipc2 self-assigned this May 13, 2025
@philipc2 philipc2 added the scalability Related to scalability & performance efforts label May 13, 2025
@philipc2 philipc2 marked this pull request as ready for review May 15, 2025 04:04
@philipc2 philipc2 changed the title DRAFT: Optimize Point in Face Computation Optimize Point in Face Computation May 15, 2025
@philipc2 philipc2 requested a review from Copilot May 15, 2025 22:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes how grid faces containing a point are found by introducing a SciPy KDTree cull and Numba-accelerated spherical winding‐number tests, and refactors legacy implementations.

  • Adds uxarray/grid/point_in_face.py with Numba functions for single and batched point‐in‐face queries using spherical winding numbers.
  • Updates Grid.get_faces_containing_point to a keyword‐only API that delegates to the new batched query path.
  • Replaces legacy geometry routines in uxarray/grid/geometry.py with parallelized Euclidean radius and winding‐number implementations and removes deprecated functions.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
uxarray/grid/point_in_face.py New Numba routines for fast face‐in‐point queries, batched support
uxarray/grid/grid.py Refactored get_faces_containing_point signature and call path
uxarray/grid/geometry.py Replaced old point‐in‐face and radius logic with parallel versions
test/test_point_in_face.py Added tests for new point‐in‐face behavior and return_counts
test/test_grid.py Removed outdated face containment tests
test/test_geometry.py Updated tests to call _face_contains_point and normalize coords
Comments suppressed due to low confidence (3)

uxarray/grid/geometry.py:1082

  • The code uses math.sqrt but math is not imported in this module. Add import math at the top.
return math.sqrt(global_max2)

uxarray/grid/grid.py:2610

  • The function _lonlat_rad_to_xyz is not imported in this file. Add from uxarray.grid.coordinates import _lonlat_rad_to_xyz to the imports.
point_xyz = _lonlat_rad_to_xyz(lon, lat)

uxarray/grid/point_in_face.py:216

  • [nitpick] Casting lists to int64 may cause a later implicit conversion to INT_DTYPE (e.g., int32) in the Numba call. Cast directly to INT_DTYPE for consistency and to avoid extra copies.
flat_cands = np.concatenate([np.array(lst, dtype=np.int64) for lst in cand_lists])

@philipc2 philipc2 requested a review from Copilot May 16, 2025 01:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes the point‐in‐face computation by introducing a SciPy KDTree for candidate culling and a new spherical winding‑number approach accelerated with Numba.

  • Implements new functions (_face_contains_point, _batch_point_in_face, etc.) for efficient point‐in‐face querying.
  • Updates Grid.get_faces_containing_point to support batched queries and both Cartesian and spherical inputs.
  • Refactors related utility and test functions to align with the new implementation.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
uxarray/grid/point_in_face.py Introduces optimized functions with KDTree culling and winding tests.
uxarray/grid/grid.py Updates the API and docstring for get_faces_containing_point.
uxarray/grid/geometry.py Revises max face radius calculation with parallel Numba implementation.
uxarray/grid/coordinates.py Adds _prepare_points_for_kdtree and updates error handling.
test/* Updates and adds tests to cover the new behavior and edge cases.
Comments suppressed due to low confidence (2)

uxarray/grid/coordinates.py:873

  • The error message contains a typo ('One one can be provided'). Please change it to 'Only one can be provided at a time' for clarity.
Both Cartesian (xyz) and Spherical (lonlat) coordinates were provided. One one can be provided at a time.

uxarray/grid/geometry.py:1082

  • The math module is used here but it is not imported. Add 'import math' at the top of the module to ensure math.sqrt is available.
return math.sqrt(global_max2)

@philipc2 philipc2 merged commit 7309e50 into main May 16, 2025
20 checks passed
@erogluorhan erogluorhan deleted the optimize-point-in-face branch September 26, 2025 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scalability Related to scalability & performance efforts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant