Skip to content

Commit 974b219

Browse files
committed
some change to speed up a little bit eddy anim
1 parent a92c87b commit 974b219

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

src/py_eddy_tracker/appli.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,14 @@ def setup(self, cmap="jet", nb_step=25, figsize=(8, 6)):
8989

9090
# plot
9191
self.fig = pyplot.figure(figsize=figsize)
92+
t0, t1 = self.period
93+
self.fig.suptitle(f'{t0} -> {t1}')
9294
self.ax = self.fig.add_axes((0.05, 0.05, 0.9, 0.9))
9395
self.ax.set_xlim(x_min, x_max), self.ax.set_ylim(y_min, y_max)
9496
self.ax.set_aspect("equal")
9597
self.ax.grid()
9698
# init mappable
97-
self.txt = self.ax.text(
98-
x_min + 0.05 * d_x,
99-
y_min + 0.05 * d_y,
100-
"",
101-
zorder=10,
102-
bbox=dict(facecolor="w", alpha=0.85),
103-
)
104-
self.display_speed = self.ax.text(
105-
x_min + 0.02 * d_x, y_max - 0.04 * d_y, "", fontsize=10
106-
)
99+
self.txt = self.ax.text(x_min + 0.05 * d_x, y_min + 0.05 * d_y, "", zorder=10)
107100
self.contour = LineCollection([], zorder=1)
108101
self.ax.add_collection(self.contour)
109102

@@ -128,7 +121,7 @@ def show(self, infinity_loop=False):
128121
dt_draw = (datetime.now() - d0).total_seconds()
129122
dt = self.sleep_event - dt_draw
130123
if dt < 0:
131-
self.sleep_event = dt_draw * 1.01
124+
# self.sleep_event = dt_draw * 1.01
132125
dt = 1e-10
133126
self.fig.canvas.start_event_loop(dt)
134127

@@ -162,11 +155,10 @@ def draw_contour(self):
162155
self.segs.append(empty((0, 2)))
163156
self.contour.set_paths(self.segs)
164157
self.contour.set_color(self.colors[-len(self.segs) :])
165-
self.txt.set_text(f"{t0} -> {self.now} -> {t1}")
166-
self.display_speed.set_text(f"{1/self.sleep_event:.0f} frame/s")
158+
self.contour.set_lw(arange(len(self.segs)) / len(self.segs) * 2.5)
159+
self.txt.set_text(f"{self.now} - {1/self.sleep_event:.0f} frame/s")
167160
self.ax.draw_artist(self.contour)
168161
self.ax.draw_artist(self.txt)
169-
self.ax.draw_artist(self.display_speed)
170162
# Remove first segment to keep only T contour
171163
if len(self.segs) > self.nb_step:
172164
self.segs.pop(0)

src/py_eddy_tracker/generic.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
interp,
3737
where,
3838
isnan,
39+
bool_,
3940
)
4041
from numba import njit, prange, types as numba_types
4142
from numpy.linalg import lstsq
@@ -291,6 +292,37 @@ def flatten_line_matrix(l_matrix):
291292
return out
292293

293294

295+
@njit(cache=True)
296+
def simplify(x, y, precision=0.1):
297+
precision2 = precision ** 2
298+
nb = x.shape[0]
299+
x_previous, y_previous = x[0], y[0]
300+
mask = ones(nb, dtype=bool_)
301+
for i in range(1, nb):
302+
x_, y_ = x[i], y[i]
303+
d_x = x_ - x_previous
304+
if d_x > precision:
305+
x_previous, y_previous = x_, y_
306+
continue
307+
d_y = y_ - y_previous
308+
if d_y > precision:
309+
x_previous, y_previous = x_, y_
310+
continue
311+
d2 = d_x ** 2 + d_y ** 2
312+
if d2 > precision2:
313+
x_previous, y_previous = x_, y_
314+
continue
315+
mask[i] = False
316+
new_nb = mask.sum()
317+
new_x, new_y = empty(new_nb, dtype=x.dtype), empty(new_nb, dtype=y.dtype)
318+
j = 0
319+
for i in range(nb):
320+
if mask[i]:
321+
new_x[j], new_y[j] = x[i], y[i]
322+
j += 1
323+
return new_x, new_y
324+
325+
294326
@njit(cache=True)
295327
def split_line(x, y, i):
296328
"""

src/py_eddy_tracker/observations/observation.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,12 +738,15 @@ def propagate(
738738
return next_obs
739739

740740
@staticmethod
741-
def intern(flag):
742-
return (
741+
def intern(flag, public_label=False):
742+
labels = (
743743
("contour_lon_s", "contour_lat_s")
744744
if flag
745745
else ("contour_lon_e", "contour_lat_e")
746746
)
747+
if public_label:
748+
labels = [VAR_DESCR[label]['nc_name'] for label in labels]
749+
return labels
747750

748751
def match(self, other, intern=False, cmin=0):
749752
"""return index and score compute with area

0 commit comments

Comments
 (0)