Skip to content

Commit

Permalink
Chg numpy.asscalar() calls to numpy.ndarray.item()
Browse files Browse the repository at this point in the history
re: Deprecation of numpy.asscalar() in numpy=1.16 and its removal in numpy=1.23.
  • Loading branch information
douglatornell committed Dec 22, 2022
1 parent bcbec7a commit 6cb3518
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
8 changes: 4 additions & 4 deletions SalishSeaTools/salishsea_tools/geo_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion SalishSeaTools/salishsea_tools/nc_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions SalishSeaTools/salishsea_tools/wind_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 6cb3518

Please sign in to comment.