.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_postprocessing/plot_aggregate.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_postprocessing_plot_aggregate.py: Aggregation of Meshseries Data ============================== .. sectionauthor:: Florian Zill (Helmholtz Centre for Environmental Research GmbH - UFZ) In this example we show how to aggregate data in a model over all timesteps as well as plot differences between to timesteps. For this purpose we use a component transport example from the ogs benchmark gallery (https://www.opengeosys.org/docs/benchmarks/hydro-component/elder/). To see this benchmark results over all timesteps have a look at :ref:`sphx_glr_auto_examples_howto_plot_plot_animation.py`. .. GENERATED FROM PYTHON SOURCE LINES 17-23 .. code-block:: Python import ogstools as ogs from ogstools import examples mesh_series = examples.load_meshseries_CT_2D_XDMF() saturation = ogs.variables.saturation .. GENERATED FROM PYTHON SOURCE LINES 24-34 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 variable from the available presets instead of needing to create your own: :ref:`sphx_glr_auto_examples_howto_postprocessing_plot_variables.py` .. GENERATED FROM PYTHON SOURCE LINES 36-43 You aggregate the data in MeshSeries over all timesteps given some aggregation function, e.g. "min", "max", "var" (see: :meth:`~ogstools.meshlib.mesh_series.MeshSeries.aggregate_over_time`). The following code gets the maximum saturation for each point in the mesh over all timesteps and plots it. Note: the data in the returned mesh has a suffix equal to the aggregation functions name. The plot function will find the correct data anyway if given the original variable .. GENERATED FROM PYTHON SOURCE LINES 45-48 .. code-block:: Python mesh = mesh_series.aggregate_over_time(saturation, "max") fig = mesh.plot_contourf(saturation) .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_aggregate_001.png :alt: plot aggregate :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_aggregate_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 49-52 It is also possible to plot the time when the minimum or maximum occurs. However, here we have to use a new variable for the plot to handle the units correctly: .. GENERATED FROM PYTHON SOURCE LINES 54-57 .. code-block:: Python mesh = mesh_series.time_of_max(saturation) fig = mesh.plot_contourf(ogs.variables.Scalar("max_Saturation_time", "s", "a")) .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_aggregate_002.png :alt: plot aggregate :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_aggregate_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 58-59 Likewise we can calculate and visualize the variance of the saturation: .. GENERATED FROM PYTHON SOURCE LINES 62-65 .. code-block:: Python mesh = mesh_series.aggregate_over_time(saturation, "var") fig = mesh.plot_contourf(saturation) .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_aggregate_003.png :alt: plot aggregate :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_aggregate_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 66-67 Difference between the last and the first timestep: .. GENERATED FROM PYTHON SOURCE LINES 69-72 .. code-block:: Python mesh = mesh_series.mesh(-1).difference(mesh_series.mesh(0), saturation) fig = mesh.plot_contourf(saturation) .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_aggregate_004.png :alt: plot aggregate :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_aggregate_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 73-75 It's also possible to aggregate the data per timestep to return a timeseries of e.g. the max or mean value of a variable in the entire domain. .. GENERATED FROM PYTHON SOURCE LINES 77-78 .. code-block:: Python fig = mesh_series.plot_domain_aggregate(saturation, "mean", time_unit="a") .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_aggregate_005.png :alt: plot aggregate :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_aggregate_005.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.234 seconds) .. _sphx_glr_download_auto_examples_howto_postprocessing_plot_aggregate.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_aggregate.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_aggregate.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_aggregate.zip `