-
Notifications
You must be signed in to change notification settings - Fork 209
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
Should we add a MovieMaker
to Oceananigans?
#4110
Comments
Plotter
to Oceananigans?Plotter
to Oceananigans?
Before proof of concept, can you propose the user API that the proof of concept achieves? I can't quite see that clearly from the implementation. |
The way I thought this could work is to start with a flexible interface where users could write their own plotting function, like: fig = Figure()
ax1 = Axis(fig[1, 1])
ax2 = Axis(fig[1, 2])
function plotting_function(sim, fig, io)
heatmap!(fig[1, 1], u)
heatmap!(fig[1, 2], s)
recordframe!(io)
end
plotter = Plotter(plotting_function, figure=fig, filename="test.mp4")
add_callback!(simulation, plotter, TimeInterval(1))
# Do other stuff
run!(simulation)
# Animation plotted! But eventually we might want to also pre-code some common plots, like panel grids, where users can just pass a list of variables like: plotter = PanelGridPlotter((u, v, w, b), name="panels.mp4")
add_callback!(simulation, plotter, TimeInterval(1))
run!(simulation) |
Ok, that's interesting. In your example, I'm not sure how One could mirror the syntax of the output writer with |
Ah, thanks for catching that. I meant to pass
I think both are fair. In order to make it flexible I think we'd need to allow for users to create a figure themselves, but the quick-and-dirty approach of creating everything when
And yes, that's exactly what I was thinking. The proof of concept above only works because it's a 2D model. In fact, here's the full code if you're interested in playing around with it. (Although I think we should make 3D plots work as well at some point!) |
Ah sorry, I still don't really grasp what you're proposing. Not sure if this is different from what you're saying, but here is one idea: fields_to_plot = merge(model.velocities, model.tracers)
movie_maker = MovieMaker(fields_to_plot, indices=(:, 1, :), filename="test.mp4") then fig = Figure()
axes = (u = Axis(fig[1, 1]), T = Axis(fig[1, 2]))
fields = (u=model.velocities.u, T=model.tracers.T) # the keys of axes, fields have to match
movie_maker = MovieMaker(fields, indices=(:, 1, :), filename="test.mp4", figure=fig, axes=axes) I think for an interface with a custom plotting function one only needs two arguments, since the figure and axes have to be captured by a callback? # create figure, axes etc
function makeplot(sim, io)
heatmap!(axu, u)
heatmap!(axs, s)
recordframe!(io)
end
movie_maker = MovieMaker(makeplot, filename="test.mp4") I think there isn't really a point to passing Also I was wondering if there's scope for plotting a single snapshot... but that might be easier so not necessary to think about here. |
Yes, that's pretty much what I was proposing. Sorry I wasn't able to be more clear.
I'm not sure about this one. I gotta think a bit more about this. As a rule here though, I think it's good if we can make things as simple as possible on the user side, since the main use for this feature would be more of a quick check on the simulations. I do think we need to make room for
I guess we could set it up in a way that, if the user chooses, instead of |
well this seems easy enough so I support trying in the Makie extension! On naming, I think if one creates "plots" then it should be a Plotter but if we are greating animations then the name should reflect that. |
I agree with the naming :) Also, note that this technically doesn't need the Makie extension to work. A user could define a plotting function like: function makeplot(sim, io)
heatmap!(ax1, Array(u[1, :, :]))
recordframe!(io)
end Given that, should we still include this with the Makie extension? Although on the other hand, it does need Makie to be imported and used, which will activate load the extension regardless if I understand correctly? |
You'd need the Makie extension to auto-create |
Plotter
to Oceananigans?MovieMaker
to Oceananigans?
I need to be |
@glwagner if that's okay with you, I'll create a PR soon to try and implement this. I just have a question: for the video to actually be written to disk, I need to issue |
That's the first motivation I've heard to have a |
I think it would also be useful for writing a checkpoint at the end of a simulation, no? |
Adding |
that seems like a good idea too |
This issue was originally posted in tomchor/Oceanostics.jl#186.
The basic idea is that, in the early stages of assembling a simulation, we tend to spend a lot of time (relatively) coding the output writing and plotting/animating parts of the simulation. Most of that code, however, is pretty similar across simulations: setting up a writer with a couple of variables, then reading it, creating a figure, plotting heatmaps, and writing the animation loop. Lots of copy-paste. And then if we want to add other variables to the plot, several lines have to be added/modified to accommodate for that.
I think this process can be automated. As @glwagner suggested, perhaps the best way would be to avoid writing altogether and create a plotter which updates a figure periodically as the simulation is running.
Here's a quick snippet of a proof of concept I tried:
Applied to the 2D turbulence example in the docs this produces:
test.mp4
Is there interest in implementing something like this here? If so I'll close the issue on Oceanostics and open a PR here.
CC @glwagner @jbisits
The text was updated successfully, but these errors were encountered: