.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_meshplotlib/plot_animation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_howto_meshplotlib_plot_animation.py: How to create Animations ======================== .. sectionauthor:: Florian Zill (Helmholtz Centre for Environmental Research GmbH - UFZ) To demonstrate the creation of an animated plot we use a component transport example from the ogs benchmark gallery (https://www.opengeosys.org/docs/benchmarks/hydro-component/elder/). .. GENERATED FROM PYTHON SOURCE LINES 12-23 .. code-block:: default import numpy as np from ogstools.meshplotlib import examples, setup from ogstools.meshplotlib.animation import animate from ogstools.propertylib import Scalar setup.reset() mesh_series = examples.meshseries_CT_2D # alternatively: # from ogstools.meshlib import MeshSeries # mesh_series = MeshSeries("filepath/filename_pvd_or_xdmf") .. GENERATED FROM PYTHON SOURCE LINES 24-25 Let's use fixed scale limits to prevent rescaling during the animation. .. GENERATED FROM PYTHON SOURCE LINES 25-28 .. code-block:: default setup.p_min = 0 setup.p_max = 100 .. GENERATED FROM PYTHON SOURCE LINES 29-33 You can choose which timesteps to render by passing either an int array corresponding to the indices, or a float array corresponding to the timevalues to render. If a requested timevalue is not part of the timeseries it will be interpolated. In this case every second frame will be interpolated. .. GENERATED FROM PYTHON SOURCE LINES 33-37 .. code-block:: default timevalues = np.linspace( mesh_series.timevalues[0], mesh_series.timevalues[-1], num=25 ) .. GENERATED FROM PYTHON SOURCE LINES 38-42 Now, let's animate the saturation solution. A timescale at the top indicates existing timesteps and the position of the current timevalue. Note that rendering many frames in conjunction with large meshes might take a really long time. .. GENERATED FROM PYTHON SOURCE LINES 42-49 .. code-block:: default titles = [f"{tv/(365.25*86400):.1f} yrs" for tv in timevalues] si = Scalar("Si", "", "%", "Saturation") anim = animate(mesh_series, si, timevalues, titles) # the animation can be saved (as mp4) like so: # from ogstools.meshplotlib.animation import save_animation # save_animation(anim, "Saturation", fps=5) .. container:: sphx-glr-animation .. raw:: html
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 12.252 seconds) .. _sphx_glr_download_auto_examples_howto_meshplotlib_plot_animation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_animation.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_animation.ipynb `