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.

.. include:: Notes.md .. include:: Docs/Animation.md

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.3.tar.gz (19.8 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.3-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mmf_contexts-0.1.3.tar.gz
Algorithm Hash digest
SHA256 1e9be2c2a8199e5c7800e066b081d18822fdfcb613d931ef8498bd14691ae4a2
MD5 71e8910900ebf48e183ac72a1c716cc1
BLAKE2b-256 d87f770d2902382824611882c9faac4a562187f0e26df2d56ac45047fde325aa

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for mmf_contexts-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 aefeb7cdcbe874777d56fa3baa1ef506d2250123fbc606f5d93385bcb5605dfb
MD5 006478b199bafe3a6b962115a47fa20e
BLAKE2b-256 5d23a429191b740bdceb7e0fec68cf817e117567b8806ff08deb27847d145551

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