Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
iainrussell committed Apr 26, 2021
2 parents 9643ecc + e3356de commit 8cc2d3f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog for Metview's Python interface
========================================

1.7.1
------------------
- added automatic play and speed controls to animated plots in Jupyter notebooks


1.7.0
------------------
- added animate=True argument to plot() command for animated plots in Jupyter notebooks
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2017- ECMWF

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
39 changes: 35 additions & 4 deletions metview/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import numpy as np


__version__ = "1.7.0"
__version__ = "1.7.1"


def string_from_ffi(s):
Expand Down Expand Up @@ -1149,11 +1149,36 @@ def animate(*args, **kwargs):
readout=True,
)

play_widget = widgets.Play(
value=1,
min=1,
max=1,
step=1,
interval=500,
description="Play animation",
disabled=False,
)

speed_widget = widgets.IntSlider(
value=3,
min=1,
max=20,
step=1,
description="Speed",
disabled=False,
continuous_update=True,
readout=True,
)

widgets.jslink((play_widget, "value"), (frame_widget, "value"))
play_and_speed_widget = widgets.HBox([play_widget, speed_widget])
controls = widgets.VBox([frame_widget, play_and_speed_widget])

controls.layout.visibility = "hidden"
image_widget.layout.visibility = "hidden"
frame_widget.layout.visibility = "hidden"
waitl_widget = widgets.Label(value="Generating plots....")
frame_widget.layout.width = "800px"
display(image_widget, frame_widget, waitl_widget)
display(image_widget, controls, waitl_widget)

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

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

def on_speed_change(change):
play_widget.interval = 1500 / change["new"]

speed_widget.observe(on_speed_change, names="value")

# everything is ready now, so hide the 'waiting' label
# and reveal the plot and the frame slider
waitl_widget.layout.visibility = "hidden"
controls.layout.visibility = "visible"
image_widget.layout.visibility = "visible"
frame_widget.layout.visibility = "visible"


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

0 comments on commit 8cc2d3f

Please sign in to comment.