baccuslab / pyret

Python tools for analysis of neurophysiology data
https://pyret.readthedocs.io/en/master/
MIT License
35 stars 8 forks source link

Allowing playsta to save a movie to disk + display in ipython notebooks #74

Closed nirum closed 7 years ago

bnaecker commented 7 years ago

This actually seems like something that's already baked into matplotlib's animations. The FuncAnimation object returned by visualizations.playsta() has a to_html5_video() method, which returns an HTML <video> tag containing the encoded movie. It can be directly viewed in a browser.

There a pretty straightforward solution on SO for playing a local video in an IPython notebook: https://stackoverflow.com/questions/18019477/how-can-i-play-a-local-video-in-my-ipython-notebook

It can also be made automatic, in the sense that just creating the animation will make it automatically embedded in the notebook. See here for details: https://jakevdp.github.io/blog/2013/05/12/embedding-matplotlib-animations/.

bnaecker commented 7 years ago

Just tested this, and the following is all that's needed to get this to work in a Jupyter notebook:

from IPython.display import HTML
anim = pyret.visualizations.playsta(sta)
HTML(anim.to_html5_video())

Closing.

nirum commented 7 years ago

We could add a helper function that runs those three lines of code. or a flag in playsta (html=True or something) thoughts?

bnaecker commented 7 years ago

Helper function sounds good to me. I'm not big on returning different types from a function, if we can avoid it. I'll reopen this and add it back now.

bnaecker commented 7 years ago

Should we now list IPython as an explicit dependency?

bnaecker commented 7 years ago

Looks like we can put it in setup.py in the extras_require kwarg to setup. See this SO post and the setuptools docs. https://stackoverflow.com/questions/19096155/setuptools-and-pip-choice-of-minimal-and-complete-install https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies

Not sure if we then need to include anything in the requirements file, though.

bnaecker commented 7 years ago

Closed in 59a0405.