Skip to content

Commit d5b460d

Browse files
committed
Save anim in video
1 parent 16438f2 commit d5b460d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Added
2020
filter
2121
- Add **EddyQuickCompare** to have few figures about several datasets in comparison based on match function
2222
- Color field for contour in **EddyAnim** could be choose
23+
- Save EddyAnim in mp4
2324

2425
[3.3.0] - 2020-12-03
2526
--------------------

src/py_eddy_tracker/appli/gui.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
from itertools import chain
99

1010
from matplotlib import pyplot
11+
from matplotlib.animation import FuncAnimation
1112
from matplotlib.collections import LineCollection
12-
from numpy import where
13+
from numpy import arange, where
1314

1415
from .. import EddyParser
1516
from ..gui import GUI
@@ -20,7 +21,6 @@
2021

2122

2223
class Anim:
23-
2424
def __init__(
2525
self, eddy, intern=False, sleep_event=0.1, graphic_information=False, **kwargs
2626
):
@@ -262,6 +262,7 @@ def anim():
262262
parser.add_argument(
263263
"--vmax", default=None, type=float, help="Upper bound to color contour"
264264
)
265+
parser.add_argument("--avi", help="Filename to save animation (avi)")
265266
args = parser.parse_args()
266267
variables = ["time", "track", "longitude", "latitude", args.field]
267268
variables.extend(TrackEddiesObservations.intern(args.intern, public_label=True))
@@ -293,7 +294,12 @@ def anim():
293294
range_color=(args.vmin, args.vmax),
294295
graphic_information=logger.getEffectiveLevel() == logging.DEBUG,
295296
)
296-
a.show(infinity_loop=args.infinity_loop)
297+
if args.avi is None:
298+
a.show(infinity_loop=args.infinity_loop)
299+
else:
300+
kwargs = dict(frames=arange(*a.period), interval=50)
301+
ani = FuncAnimation(a.fig, a.func_animation, **kwargs)
302+
ani.save(args.avi, fps=30, extra_args=["-vcodec", "libx264"])
297303

298304

299305
def gui_parser():

0 commit comments

Comments
 (0)