Skip to content

Commit

Permalink
Proper rounding of the x/y values (#305)
Browse files Browse the repository at this point in the history
Use numpy.round instead of casting to int. See issue #297
  • Loading branch information
ladc committed Aug 30, 2022
1 parent 94a11b3 commit 8c378d9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pysteps/feature/tstorm.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ def get_profile(areas, binary, ref, loc_max, time, minref):
maxref = np.nanmax(ref[cells_id.y[n], cells_id.x[n]])
contours = skime.find_contours(cell_unique, 0.8)
cells_id.cont.iloc[n] = contours
cells_id.cen_x.iloc[n] = int(np.nanmean(cells_id.x[n])) # int(x[0])
cells_id.cen_y.iloc[n] = int(np.nanmean(cells_id.y[n])) # int(y[0])
cells_id.cen_x.iloc[n] = np.round(np.nanmean(cells_id.x[n])).astype(int)
cells_id.cen_y.iloc[n] = np.round(np.nanmean(cells_id.y[n])).astype(int)
cells_id.max_ref.iloc[n] = maxref
cells_id.area.iloc[n] = len(cells_id.x.iloc[n])
labels[cells == cell_labels[n]] = ID
Expand Down
4 changes: 2 additions & 2 deletions pysteps/tracking/tdating.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ def advect(cells_id, labels, V1):
for ID, cell in cells_id.iterrows():
if cell.ID == 0 or np.isnan(cell.ID):
continue
ad_x = int(np.nanmean(V1[0, cell.y, cell.x]))
ad_y = int(np.nanmean(V1[1, cell.y, cell.x]))
ad_x = np.round(np.nanmean(V1[0, cell.y, cell.x])).astype(int)
ad_y = np.round(np.nanmean(V1[1, cell.y, cell.x])).astype(int)
new_x = cell.x + ad_x
new_y = cell.y + ad_y
new_x[new_x > labels.shape[1] - 1] = labels.shape[1] - 1
Expand Down

0 comments on commit 8c378d9

Please sign in to comment.