Metadata-Version: 2.4
Name: mmf-contexts
Version: 0.1.2
Summary: Tools for producing animations and movies (FPS, NoInterrupt contexts)
Author-Email: Michael McNeil Forbes <michael.forbes+python@gmail.com>
License-Expression: BSD
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Project-URL: Documentation, http://mmf-contexts.readthedocs.org/
Project-URL: Source, https://gitlab.com/ColdAtoms/utilities/mmf-contexts
Project-URL: Issues, https://gitlab.com/coldatoms/utilities/mmf-contexts/-/issues
Requires-Python: <3.15,>=3.9
Provides-Extra: all
Requires-Dist: matplotlib; extra == "all"
Provides-Extra: test
Requires-Dist: pytest>=7.2.2; extra == "test"
Requires-Dist: pytest-cov>=4.0.0; extra == "test"
Requires-Dist: pytest-xdist>=3.2.1; extra == "test"
Requires-Dist: psutil>=5.9.4; extra == "test"
Requires-Dist: pytest-rerunfailures>=11.1.2; extra == "test"
Requires-Dist: pytest-missing-modules>=0.2.2; extra == "test"
Requires-Dist: mmf_contexts[all]; extra == "test"
Requires-Dist: ipython>=8.18.1; extra == "test"
Provides-Extra: doc
Description-Content-Type: text/markdown

# MMF Contexts

[![Documentation Status](https://readthedocs.org/projects/mmf-contexts/badge/?version=latest)](https://mmf-contexts.readthedocs.io/en/latest/?badge=latest)

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:

```python
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:

```ipython
%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`.
