forked from AntSimi/py-eddy-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpet_track_anim_matplotlib_animation.py
More file actions
60 lines (46 loc) · 1.71 KB
/
pet_track_anim_matplotlib_animation.py
File metadata and controls
60 lines (46 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
Track animation with standard matplotlib
========================================
Run in a terminal this script, which allow to watch eddy evolution.
You could use also *EddyAnim* script to display/save animation.
"""
import re
import py_eddy_tracker_sample
from matplotlib.animation import FuncAnimation
from numpy import arange
from py_eddy_tracker.appli.gui import Anim
from py_eddy_tracker.observations.tracking import TrackEddiesObservations
# sphinx_gallery_thumbnail_path = '_static/no_image.png'
# %%
class VideoAnimation(FuncAnimation):
def _repr_html_(self, *args, **kwargs):
"""To get video in html and have a player"""
content = self.to_html5_video()
return re.sub(
r'width="[0-9]*"\sheight="[0-9]*"', 'width="100%" height="100%"', content
)
def save(self, *args, **kwargs):
if args[0].endswith("gif"):
# In this case gif is used to create thumbnail which is not used but consume same time than video
# So we create an empty file, to save time
with open(args[0], "w") as _:
pass
return
return super().save(*args, **kwargs)
# %%
# Load experimental atlas, and we select one eddy
a = TrackEddiesObservations.load_file(
py_eddy_tracker_sample.get_demo_path(
"eddies_med_adt_allsat_dt2018/Anticyclonic.zarr"
)
)
eddy = a.extract_ids([9672])
# %%
# Run animation
a = Anim(eddy, intern=True, figsize=(8, 3.5), cmap="magma_r", nb_step=5, dpi=50)
a.txt.set_position((17, 34.6))
a.ax.set_xlim(16.5, 23)
a.ax.set_ylim(34.5, 37)
# arguments to get full animation
kwargs = dict(frames=arange(*a.period)[300:800], interval=90)
ani = VideoAnimation(a.fig, a.func_animation, **kwargs)