|
5 | 5 | Run in a terminal this script, which allow to watch eddy evolution
|
6 | 6 |
|
7 | 7 | """
|
| 8 | +import re |
| 9 | + |
8 | 10 | import py_eddy_tracker_sample
|
9 | 11 | from matplotlib.animation import FuncAnimation
|
10 | 12 | from numpy import arange
|
11 | 13 |
|
12 | 14 | from py_eddy_tracker.appli.gui import Anim
|
13 | 15 | from py_eddy_tracker.observations.tracking import TrackEddiesObservations
|
14 | 16 |
|
| 17 | +# sphinx_gallery_thumbnail_path = '_static/no_image.png' |
| 18 | + |
| 19 | + |
| 20 | +# %% |
| 21 | +class VideoAnimation(FuncAnimation): |
| 22 | + def _repr_html_(self, *args, **kwargs): |
| 23 | + """To get video in html and have a player""" |
| 24 | + content = self.to_html5_video() |
| 25 | + return re.sub( |
| 26 | + r'width="[0-9]*"\sheight="[0-9]*"', 'width="100%" height="100%"', content |
| 27 | + ) |
| 28 | + |
| 29 | + def save(self, *args, **kwargs): |
| 30 | + if args[0].endswith("gif"): |
| 31 | + # In this case gif is use to create thumbnail which are not use but consume same time than video |
| 32 | + # So we create an empty file, to save time |
| 33 | + with open(args[0], "w") as _: |
| 34 | + pass |
| 35 | + return |
| 36 | + return super().save(*args, **kwargs) |
| 37 | + |
| 38 | + |
15 | 39 | # %%
|
16 | 40 | # Load experimental atlas, and we select one eddy
|
17 | 41 | a = TrackEddiesObservations.load_file(
|
|
21 | 45 |
|
22 | 46 | # %%
|
23 | 47 | # Run animation
|
24 |
| -a = Anim(eddy, intern=True, figsize=(8, 3.5), cmap="magma_r", nb_step=6) |
| 48 | +a = Anim(eddy, intern=True, figsize=(8, 3.5), cmap="magma_r", nb_step=5, dpi=50) |
25 | 49 | a.txt.set_position((17, 34.6))
|
26 | 50 | a.ax.set_xlim(16.5, 23)
|
27 | 51 | a.ax.set_ylim(34.5, 37)
|
28 | 52 |
|
29 | 53 | # arguments to get full animation
|
30 |
| -# kwargs = dict(frames=arange(*a.period), interval=50) |
31 |
| -# arguments to reduce compute cost for doucmentation, we display only every 10 days |
32 |
| -kwargs = dict(frames=arange(*a.period)[200:800:10], save_count=60, interval=200) |
| 54 | +kwargs = dict(frames=arange(*a.period)[300:800], interval=90) |
33 | 55 |
|
34 |
| -ani = FuncAnimation(a.fig, a.func_animation, **kwargs) |
| 56 | +ani = VideoAnimation(a.fig, a.func_animation, **kwargs) |
0 commit comments