From cbc9911a9fea0a3cf678eb70d3109686d94e583e Mon Sep 17 00:00:00 2001 From: Lesley De Cruz Date: Sun, 28 Aug 2022 15:24:45 +0200 Subject: [PATCH] Proper rounding of the x/y values Use numpy.round instead of casting to int. See issue #297 --- pysteps/feature/tstorm.py | 4 ++-- pysteps/tracking/tdating.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pysteps/feature/tstorm.py b/pysteps/feature/tstorm.py index 49f830e7a..13732b6d0 100644 --- a/pysteps/feature/tstorm.py +++ b/pysteps/feature/tstorm.py @@ -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 diff --git a/pysteps/tracking/tdating.py b/pysteps/tracking/tdating.py index c709014e5..a093631d8 100644 --- a/pysteps/tracking/tdating.py +++ b/pysteps/tracking/tdating.py @@ -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