Oceananigans.jl icon indicating copy to clipboard operation
Oceananigans.jl copied to clipboard

Create `MovieMaker`

Open tomchor opened this issue 9 months ago • 1 comments

Closes https://github.com/CliMA/Oceananigans.jl/issues/4110

cc @glwagner

Note that at the moment some of the functionality is not yet there due to something weird that's going on with the extensions. See https://github.com/CliMA/Oceananigans.jl/issues/4120.

tomchor avatar Feb 22 '25 00:02 tomchor

At the moment the user has to define Figure and a plotting function to create a movie maker, such as:

using CairoMakie
fig = Figure(size = (800, 400))
ax1 = Axis(fig[1, 1])
ax2 = Axis(fig[1, 2])

function update_plot(sim, fig)
    heatmap!(fig[1, 1], ω; colormap = :balance, colorrange = (-2, 2))
    heatmap!(fig[1, 2], s; colormap = :balance, colorrange = (-2, 2))
end 
    
maker = MovieMaker(fig, update_plot; filename, format="mp4", framerate=12, compression=20)
add_callback!(simulation, maker, TimeInterval(1))

And I also added a convenience function that automatically adds it as a callback:

add_movie_maker!(simulation, TimeInterval(0.6), fig, update_plot; filename="2d_turbulence.mp4", format="mp4", framerate=12, compression=20)

@glwagner I think this already is a pretty good quality of life improvement if you just want to plot things (i.e., no need to create a Writer anymore). Thus, I'd like to merge this PR with this interface, and then consider expanding on it at a later PR (e.g. with an interface where a user would only pass a list of variables and indices for slicing). What do you think?

If you agree, I'll go ahead and clean up the validation script and include some tests (it looks like we don't test Makie at all at the moment btw...).

tomchor avatar Mar 07 '25 03:03 tomchor