Skip to content

Commit

Permalink
MNT: Replace cKDTree with KDTree.
Browse files Browse the repository at this point in the history
SciPy 1.6 merged cKDTree and KDTree, with the former
name now an alias for the latter.
  • Loading branch information
DWesl committed Oct 18, 2024
1 parent ad73a27 commit 21e1b24
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/metpy/calc/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import numpy.ma as ma
from pyproj import CRS, Geod, Proj
from scipy.spatial import cKDTree
from scipy.spatial import KDTree
import xarray as xr

from .. import _warnings
Expand Down Expand Up @@ -300,7 +300,7 @@ def reduce_point_density(points, radius, priority=None):
points = np.where(good_vals, points, 0)

# Make a kd-tree to speed searching of data.
tree = cKDTree(points)
tree = KDTree(points)

# Need to use sorted indices rather than sorting the position
# so that the keep mask matches *original* order.
Expand Down
8 changes: 4 additions & 4 deletions src/metpy/interpolate/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import math

import numpy as np
from scipy.spatial import cKDTree
from scipy.spatial import KDTree

log = logging.getLogger(__name__)

Expand All @@ -33,7 +33,7 @@ def get_points_within_r(center_points, target_points, r):
order as, center_points
"""
tree = cKDTree(target_points)
tree = KDTree(target_points)
indices = tree.query_ball_point(center_points, r)
return tree.data[indices].T

Expand All @@ -59,7 +59,7 @@ def get_point_count_within_r(center_points, target_points, r):
order as, center_points
"""
tree = cKDTree(target_points)
tree = KDTree(target_points)
indices = tree.query_ball_point(center_points, r)
return np.array([len(x) for x in indices])

Expand Down Expand Up @@ -255,7 +255,7 @@ def find_natural_neighbors(tri, grid_points):
"""
# Used for fast identification of points with a radius of another point
tree = cKDTree(grid_points)
tree = KDTree(grid_points)

# Mask for points that are outside the triangulation
in_triangulation = tri.find_simplex(tree.data) >= 0
Expand Down
4 changes: 2 additions & 2 deletions src/metpy/interpolate/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import numpy as np
from scipy.interpolate import griddata, Rbf
from scipy.spatial import cKDTree, ConvexHull, Delaunay, QhullError
from scipy.spatial import KDTree, ConvexHull, Delaunay, QhullError

Check failure on line 11 in src/metpy/interpolate/points.py

View workflow job for this annotation

GitHub Actions / Run Lint Tools

[flake8] reported by reviewdog 🐶 I001 isort found an import in the wrong position Raw Output: ./src/metpy/interpolate/points.py:11:1: I001 isort found an import in the wrong position

Check failure on line 12 in src/metpy/interpolate/points.py

View workflow job for this annotation

GitHub Actions / Run Lint Tools

[flake8] reported by reviewdog 🐶 I005 isort found an unexpected missing import Raw Output: ./src/metpy/interpolate/points.py:12:1: I005 isort found an unexpected missing import
from . import geometry, tools
from ..package_tools import Exporter
Expand Down Expand Up @@ -260,7 +260,7 @@ def inverse_distance_to_points(points, values, xi, r, gamma=None, kappa=None, mi
else:
raise ValueError(f'{kind} interpolation not supported.')

obs_tree = cKDTree(points)
obs_tree = KDTree(points)
indices = obs_tree.query_ball_point(xi, r=r)

if hasattr(values, 'units'):
Expand Down

0 comments on commit 21e1b24

Please sign in to comment.