From 21e1b242fb68a037d1942c1fbe0d9bc4f71b6155 Mon Sep 17 00:00:00 2001 From: DWesl <22566757+DWesl@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:59:51 -0400 Subject: [PATCH] MNT: Replace cKDTree with KDTree. SciPy 1.6 merged cKDTree and KDTree, with the former name now an alias for the latter. --- src/metpy/calc/tools.py | 4 ++-- src/metpy/interpolate/geometry.py | 8 ++++---- src/metpy/interpolate/points.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/metpy/calc/tools.py b/src/metpy/calc/tools.py index 091545d8856..4f856184b67 100644 --- a/src/metpy/calc/tools.py +++ b/src/metpy/calc/tools.py @@ -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 @@ -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. diff --git a/src/metpy/interpolate/geometry.py b/src/metpy/interpolate/geometry.py index f91f1143cd5..89f8e8f7a98 100644 --- a/src/metpy/interpolate/geometry.py +++ b/src/metpy/interpolate/geometry.py @@ -7,7 +7,7 @@ import math import numpy as np -from scipy.spatial import cKDTree +from scipy.spatial import KDTree log = logging.getLogger(__name__) @@ -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 @@ -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]) @@ -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 diff --git a/src/metpy/interpolate/points.py b/src/metpy/interpolate/points.py index 216c0545291..57a8fe82be4 100644 --- a/src/metpy/interpolate/points.py +++ b/src/metpy/interpolate/points.py @@ -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 from . import geometry, tools from ..package_tools import Exporter @@ -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'):