Skip to content

Commit 63e49bf

Browse files
update animation example
1 parent 0f32a11 commit 63e49bf

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

examples/16_network/pet_segmentation_anim.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ def save(self, *args, **kwargs):
3737
# %%
3838
# Overlaod of class to pick up
3939
TRACKS = list()
40+
INDICES = list()
4041

4142

4243
class MyTrack(TrackEddiesObservations):
4344
@staticmethod
4445
def get_next_obs(i_current, ids, x, y, time_s, time_e, time_ref, window, **kwargs):
4546
TRACKS.append(ids["track"].copy())
47+
INDICES.append(i_current)
4648
return TrackEddiesObservations.get_next_obs(
4749
i_current, ids, x, y, time_s, time_e, time_ref, window, **kwargs
4850
)
@@ -70,9 +72,16 @@ def get_next_obs(i_current, ids, x, y, time_s, time_e, time_ref, window, **kwarg
7072
def update(i_frame):
7173
tr = TRACKS[i_frame]
7274
mappable_tracks.set_array(tr)
73-
s = 80 * ones(tr.shape)
75+
s = 40 * ones(tr.shape)
7476
s[tr == 0] = 4
7577
mappable_tracks.set_sizes(s)
78+
79+
indices_frames = INDICES[i_frame]
80+
mappable_CONTOUR.set_data(
81+
e.contour_lon_e[indices_frames],
82+
e.contour_lat_e[indices_frames],
83+
)
84+
mappable_CONTOUR.set_color(cmap.colors[tr[indices_frames] % len(cmap.colors)])
7685
return (mappable_tracks,)
7786

7887

@@ -85,6 +94,9 @@ def update(i_frame):
8594
mappable_tracks = ax.scatter(
8695
e.lon, e.lat, c=TRACKS[0], cmap=cmap, vmin=0, vmax=vmax, s=20
8796
)
97+
mappable_CONTOUR = ax.plot(
98+
e.contour_lon_e[INDICES[0]], e.contour_lat_e[INDICES[0]], color=cmap.colors[0]
99+
)[0]
88100
ani = VideoAnimation(
89101
fig, update, frames=range(1, len(TRACKS), 4), interval=125, blit=True
90102
)

0 commit comments

Comments
 (0)