Skip to main content

Tools for producing animations and movies (FPS, NoInterrupt contexts)

Project description

MMF Contexts

Documentation Status

This package provides a set of contexts to help working with Jupyter notebooks, especially producing animations, movies, and managing signals.

Usage

The main use-case is to do your work in an FPS context:

from mmf_contexts import FPS
for n in FPS(30, fps=10):
    print(n)

This adds the following functionality:

  1. KeyboardInterrupts are suspended during the loop body and will be processed each cycle. Thus, the actions in the loop are safe from being interrupted in a sensitive location. This allows you to use Ctrl-C etc. to stop the loop without crashing your program. (If you really need to stop it immediately, you can send 3 Ctrl-C in rapid succession.)
  2. The loop will be rate limited to a maximum of approximately 10 frames per second.

A nice use-case is to make movies. The following works well in Jupyter Notebooks:

%matplotlib
import numpy as np, matplotlib.pyplot as plt

from mmf_contexts import FPS

x = np.linspace(0, 1)
fs = np.linspace(1, 30)

fig, ax = plt.subplots()
for f in FPS(fs, display=fig, embed=True, filename="mymovie.mp4"):
    ax.cla()
    ax.plot(x, np.sin(f*x))

This will make an animation while running in the Jupyter notebook, then embed this animation as a movie so you can view it even if the notebook is running. Finally, it will also save the animation to the file mymovie.mp4.

To Do: This does not yet work with standard IPython terminals since it relies on display. Support for more general use-cases is a work in progress.

Change Log

REL: 0.1.2

  • Just add README.md so PyPI has a description. No code changes.

REL: 0.1.1

  • Added README.md documentation.
  • Fixed bug with Jupyter Notebooks and movies (missing MovieWriter). *(We need to find a good way of automating tests with Jupyter notbeook.)
  • Fixed links to docs etc.

REL: 0.1.0

Initial release. Attempted to upload this as animate to PyPI, but this is not allowed, so we are renaming it mmf-contexts.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mmf_contexts-0.1.2.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mmf_contexts-0.1.2-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file mmf_contexts-0.1.2.tar.gz.

File metadata

  • Download URL: mmf_contexts-0.1.2.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.7 CPython/3.11.13 Darwin/23.6.0

File hashes

Hashes for mmf_contexts-0.1.2.tar.gz
Algorithm Hash digest
SHA256 bbaccdeda887eafbd2394d5950ef69ca7e4d0d7d42480b1f99d0b42b9bd293e4
MD5 e36b6e456212a939def3de64173dede2
BLAKE2b-256 a5d1ef78ec6047b137f80f20d07acbfed911ff25ef79b199a0dd6be33306b78b

See more details on using hashes here.

File details

Details for the file mmf_contexts-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mmf_contexts-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.7 CPython/3.11.13 Darwin/23.6.0

File hashes

Hashes for mmf_contexts-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 561c78b14f2bb5a9e189113e85f958b4bcf6202865698c2d04ec9da75ef9ddb6
MD5 a722920ad80c8973a7113380aec01524
BLAKE2b-256 b4e7fafb4a3ed4339bce4a29cedad99ccf87e53aa60c309dac8bcc73161deddc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page