Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Ipython animation #100

Merged
merged 9 commits into from
Nov 6, 2014
Merged

[WIP] Ipython animation #100

merged 9 commits into from
Nov 6, 2014

Conversation

ketch
Copy link
Member

@ketch ketch commented Mar 13, 2014

This is work in progress. It's a very basic implementation to allow creation of animations from PyClaw output in the IPython notebook without a lot of code. Indeed, all you have to do is something like

claw = setup()
claw.run()
from clawpack.visclaw import ianimate
ianimate.ianimate(claw)

Obviously there aren't a lot of options yet. I included an optional plotdata argument, because ideally I'd like this function to be able to accept one and animate the plots that would usually come out of visclaw. The complication is that the animator needs a handle to a line or an image (for instance) in order to call set_data at later frames. I think it would be best to refactor frametools.plot_frame to return such a handle, but that looks like a substantial amount of work.

@mandli
Copy link
Member

mandli commented Mar 13, 2014

I wrote something similar to this in a notebook I was working on. I was apparently only thinking about 2D plots however it still might be useful:

def add_animation(title, cbar_label, cmap, var, limits, figsize=(8,6)):
    fig = plt.figure(figsize=figsize)
    if isinstance(var, list) or isinstance(var, tuple):
        ax_list = [fig.add_subplot(1,2,1), fig.add_subplot(1,2,2)]
    else:
        ax_list = [fig.add_subplot(1,1,1)]
        var = [var]
        title = [title]
        cbar_label = [cbar_label]

    x, y = claw.frames[0].state.grid.p_centers
    im_list = []
    for (n,ax) in enumerate(ax_list):
        im_list.append( ax.imshow(var[n](0).T, cmap=cmap, extent=[x.min(), x.max(), y.min(), y.max()],
                             vmin=limits[0], vmax=limits[1], interpolation='nearest', origin='lower') )
        ax.set_title(title[n])
        ax.set_xlabel('x')
        ax.set_ylabel('y')
        cbar = fig.colorbar(im_list[n], ax=ax)
        cbar.set_label(cbar_label[n])

    def fplot(frame_number):
        for (n,im) in enumerate(im_list):
            im.set_data(var[n](frame_number).T)
        return im

    return fig, fplot

rjleveque and others added 6 commits September 1, 2014 16:06
refer to plotdir rather than assuming _plots
…thon_animation

* 'ipython_animation' of github.com:ketch/visclaw:
  Fix typos.
  Add ianimate function for JSAnimations in the notebook.
  Improve generality by passing controller and not assuming ascii.

Conflicts:
	src/python/visclaw/ianimate.py
ketch added a commit to ketch/clawapps that referenced this pull request Nov 3, 2014
ketch added a commit that referenced this pull request Nov 6, 2014
Ipython animation.

Usage:

claw = setup()
claw.run()
from clawpack.visclaw import ianimate
ianimate.ianimate(claw)
@ketch ketch merged commit 27c4671 into clawpack:master Nov 6, 2014
@ketch ketch deleted the ipython_animation branch November 6, 2014 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants