From 6cb3518628c23a2b517a0331c2e41fc565a29aa0 Mon Sep 17 00:00:00 2001 From: Doug Latornell Date: Wed, 21 Dec 2022 16:10:03 -0800 Subject: [PATCH] Chg numpy.asscalar() calls to numpy.ndarray.item() re: Deprecation of numpy.asscalar() in numpy=1.16 and its removal in numpy=1.23. --- SalishSeaTools/salishsea_tools/geo_tools.py | 8 ++++---- SalishSeaTools/salishsea_tools/nc_tools.py | 2 +- SalishSeaTools/salishsea_tools/wind_tools.py | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/SalishSeaTools/salishsea_tools/geo_tools.py b/SalishSeaTools/salishsea_tools/geo_tools.py index d8bdd79d..940e9067 100644 --- a/SalishSeaTools/salishsea_tools/geo_tools.py +++ b/SalishSeaTools/salishsea_tools/geo_tools.py @@ -212,7 +212,7 @@ def find_closest_model_point( else: return np.nan, np.nan try: - j, i = map(np.asscalar, (j_list, i_list)) + j, i = map(np.ndarray.item, (j_list, i_list)) except ValueError: # Several points within tolerance # Calculate distances for all and choose the closest @@ -226,7 +226,7 @@ def find_closest_model_point( np.array([lon] * i_list.size), np.array([lat] * j_list.size), lons, lats) n = dists.argmin() - j, i = map(np.asscalar, (j_list[n], i_list[n])) + j, i = j_list.item(n), i_list.item(n) # If point is on land and land mask is provided # try to find closest water point @@ -244,11 +244,11 @@ def find_closest_model_point( else: return _spiral_search_for_closest_water_point( j, i, land_mask, lon, lat, model_lons, model_lats) - except ValueError: + except ValueError: if raiseOutOfBounds: raise ValueError( 'lat/lon on land and no nearby water point found') - else: + else: return np.nan, np.nan def closestPointArray(lons,lats, diff --git a/SalishSeaTools/salishsea_tools/nc_tools.py b/SalishSeaTools/salishsea_tools/nc_tools.py index 37c0abae..455cb8cb 100644 --- a/SalishSeaTools/salishsea_tools/nc_tools.py +++ b/SalishSeaTools/salishsea_tools/nc_tools.py @@ -267,7 +267,7 @@ def timestamp(dataset, tindex, time_var='time_counter'): results = [] for i in tindex: try: - results.append(time_orig + timedelta(seconds=np.asscalar(time_counter[i]))) + results.append(time_orig + timedelta(seconds=time_counter[i].item())) except IndexError: raise IndexError( 'time_counter variable has no tindex={}'.format(tindex)) diff --git a/SalishSeaTools/salishsea_tools/wind_tools.py b/SalishSeaTools/salishsea_tools/wind_tools.py index c54901a8..865134e3 100644 --- a/SalishSeaTools/salishsea_tools/wind_tools.py +++ b/SalishSeaTools/salishsea_tools/wind_tools.py @@ -255,8 +255,7 @@ def calc_wind_avg_at_point(date_time, weather_path, windji, avg_hrs=-4): wind_u = np.concatenate((wind_prev_day.u, wind_u)) wind_v = np.concatenate((wind_prev_day.v, wind_v)) wind_t = np.concatenate((wind_prev_day.time, wind_t)) - i_date_time = np.asscalar( - np.where(wind_t == date_time.floor('hour'))[0]) + i_date_time = np.where(wind_t == date_time.floor('hour'))[0].item() i_date_time_p1 = i_date_time + 1 u_avg = np.mean(wind_u[(i_date_time_p1 + avg_hrs):i_date_time_p1]) v_avg = np.mean(wind_v[(i_date_time_p1 + avg_hrs):i_date_time_p1])