Skip to content

Commit 8cc2d3f

Browse files
committed
Merge branch 'develop'
2 parents 9643ecc + e3356de commit 8cc2d3f

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

CHANGELOG.rst

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Changelog for Metview's Python interface
33
========================================
44

5+
1.7.1
6+
------------------
7+
- added automatic play and speed controls to animated plots in Jupyter notebooks
8+
9+
510
1.7.0
611
------------------
712
- added animate=True argument to plot() command for animated plots in Jupyter notebooks

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2017- ECMWF
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

metview/bindings.py

+35-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import numpy as np
2222

2323

24-
__version__ = "1.7.0"
24+
__version__ = "1.7.1"
2525

2626

2727
def string_from_ffi(s):
@@ -1149,11 +1149,36 @@ def animate(*args, **kwargs):
11491149
readout=True,
11501150
)
11511151

1152+
play_widget = widgets.Play(
1153+
value=1,
1154+
min=1,
1155+
max=1,
1156+
step=1,
1157+
interval=500,
1158+
description="Play animation",
1159+
disabled=False,
1160+
)
1161+
1162+
speed_widget = widgets.IntSlider(
1163+
value=3,
1164+
min=1,
1165+
max=20,
1166+
step=1,
1167+
description="Speed",
1168+
disabled=False,
1169+
continuous_update=True,
1170+
readout=True,
1171+
)
1172+
1173+
widgets.jslink((play_widget, "value"), (frame_widget, "value"))
1174+
play_and_speed_widget = widgets.HBox([play_widget, speed_widget])
1175+
controls = widgets.VBox([frame_widget, play_and_speed_widget])
1176+
1177+
controls.layout.visibility = "hidden"
11521178
image_widget.layout.visibility = "hidden"
1153-
frame_widget.layout.visibility = "hidden"
11541179
waitl_widget = widgets.Label(value="Generating plots....")
11551180
frame_widget.layout.width = "800px"
1156-
display(image_widget, frame_widget, waitl_widget)
1181+
display(image_widget, controls, waitl_widget)
11571182

11581183
# plot all frames to a temporary directory owned by Metview to enure cleanup
11591184
tempdirpath = tempfile.mkdtemp(dir=os.environ.get("METVIEW_TMPDIR", None))
@@ -1173,6 +1198,7 @@ def animate(*args, **kwargs):
11731198
files = [os.path.join(tempdirpath, f) for f in sorted(filenames)]
11741199
frame_widget.max = len(files)
11751200
frame_widget.description = "Frame (" + str(len(files)) + ") :"
1201+
play_widget.max = len(files)
11761202

11771203
def plot_frame(frame_index):
11781204
im_file = open(files[frame_index - 1], "rb")
@@ -1186,11 +1212,16 @@ def on_frame_change(change):
11861212
plot_frame(1)
11871213
frame_widget.observe(on_frame_change, names="value")
11881214

1215+
def on_speed_change(change):
1216+
play_widget.interval = 1500 / change["new"]
1217+
1218+
speed_widget.observe(on_speed_change, names="value")
1219+
11891220
# everything is ready now, so hide the 'waiting' label
11901221
# and reveal the plot and the frame slider
11911222
waitl_widget.layout.visibility = "hidden"
1223+
controls.layout.visibility = "visible"
11921224
image_widget.layout.visibility = "visible"
1193-
frame_widget.layout.visibility = "visible"
11941225

11951226

11961227
# On a test system, importing IPython took approx 0.5 seconds, so to avoid that hit

0 commit comments

Comments
 (0)