.. 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-24 .. code-block:: Python 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 mesh_property = Scalar( data_name="Si", data_unit="", output_unit="%", output_name="Saturation" ) .. GENERATED FROM PYTHON SOURCE LINES 25-35 To read your own data as a mesh series you can do: .. code-block:: python from ogstools.meshlib import MeshSeries mesh_series = MeshSeries("filepath/filename_pvd_or_xdmf") You can also use a property from the available presets instead of needing to create your own: :ref:`sphx_glr_auto_examples_howto_propertylib_plot_propertylib.py` .. GENERATED FROM PYTHON SOURCE LINES 37-38 Let's use fixed scale limits to prevent rescaling during the animation. .. GENERATED FROM PYTHON SOURCE LINES 40-44 .. code-block:: Python setup.p_min = 0 setup.p_max = 100 setup.dpi = 50 .. GENERATED FROM PYTHON SOURCE LINES 45-49 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 51-55 .. code-block:: Python timevalues = np.linspace( mesh_series.timevalues[0], mesh_series.timevalues[-1], num=25 ) .. GENERATED FROM PYTHON SOURCE LINES 56-60 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 62-65 .. code-block:: Python titles = [f"{tv/(365.25*86400):.1f} yrs" for tv in timevalues] anim = animate(mesh_series, mesh_property, timevalues, titles) .. container:: sphx-glr-animation .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 66-73 The animation can be saved (as mp4) like so: .. code-block:: python from ogstools.meshplotlib.animation import save_animation save_animation(anim, "Saturation", fps=5) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 10.567 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-jupyter :download:`Download Jupyter notebook: plot_animation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_animation.py `