.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_postprocessing/plot_variables.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_variables.py: Variable presets and data transformation ======================================== .. sectionauthor:: Florian Zill (Helmholtz Centre for Environmental Research GmbH - UFZ) :py:mod:`ogstools.variables` provides classes (Scalar, Vector, Matrix) which encapsulate unit handling and data transformation for simplified processing of mesh data. There are also several predefined variables. .. GENERATED FROM PYTHON SOURCE LINES 13-18 .. code-block:: Python import ogstools as ogs from ogstools import examples ogs.variables.get_dataframe() .. raw:: html
data_name data_unit output_unit output_name type
preset
heatflowrate HeatFlowRate HeatFlowRate Scalar
massflowrate MassFlowRate MassFlowRate Scalar
material_id MaterialIDs MaterialIDs Scalar
nodal_forces NodalForces NodalForces Vector
... ... ... ... ... ...
fluid_pressure_crit sigma Pa MPa fluid_pressure_criterion Scalar
stress sigma Pa MPa stress Matrix
temperature temperature K °C temperature Scalar
velocity velocity m/s m/s darcy_velocity Vector

18 rows × 5 columns



.. GENERATED FROM PYTHON SOURCE LINES 19-23 Scalar, Vector and Matrix inherit from the class Variable with its :meth:`~ogstools.variables.variable.Variable.transform` function. This function converts the argument from data_unit to output_unit and applies a function if specified. In this case we convert from K to °C: .. GENERATED FROM PYTHON SOURCE LINES 25-27 .. code-block:: Python ogs.variables.temperature.transform(273.15, strip_unit=False) .. raw:: html
0.0 °C


.. GENERATED FROM PYTHON SOURCE LINES 28-30 You can also create your own variables by creating a Scalar, Vector or Matrix variable. The following doesn't do any unit conversion. .. GENERATED FROM PYTHON SOURCE LINES 32-37 .. code-block:: Python custom_temperature = ogs.variables.Scalar( data_name="temperature", data_unit="K", output_unit="K" ) custom_temperature.transform(273.15, strip_unit=False) .. raw:: html
273.15 K


.. GENERATED FROM PYTHON SOURCE LINES 38-39 Or use existing presets as a template and replace some parameters: .. GENERATED FROM PYTHON SOURCE LINES 39-42 .. code-block:: Python custom_temperature = ogs.variables.temperature.replace(output_unit="°F") custom_temperature.transform(273.15, strip_unit=False) .. raw:: html
31.999999999999936 °F


.. GENERATED FROM PYTHON SOURCE LINES 43-48 Components of Vector variables and Matrix variables can be accessed with bracket indexing. :class:`~ogstools.variables.vector.Vector` variables should be of length 2 or 3 corresponding to the dimension. :class:`~ogstools.variables.matrix.Matrix` variables likewise should be of length 4 [xx, yy, zz, xy] or 6 [xx, yy, zz, xy, yz, xz]. .. GENERATED FROM PYTHON SOURCE LINES 50-52 .. code-block:: Python ogs.variables.displacement[1].transform([0.01, 0.02, 0.03], strip_unit=False) .. raw:: html
0.02 m


.. GENERATED FROM PYTHON SOURCE LINES 53-57 .. code-block:: Python ogs.variables.strain["xx"].transform( [0.01, 0.02, 0.03, 0.04, 0.05, 0.06], strip_unit=False ) .. raw:: html
1.0 %


.. GENERATED FROM PYTHON SOURCE LINES 58-59 Magnitude of a 2D displacement vector: .. GENERATED FROM PYTHON SOURCE LINES 61-63 .. code-block:: Python ogs.variables.displacement.magnitude.transform([0.03, 0.04], strip_unit=False) .. raw:: html
0.05 m


.. GENERATED FROM PYTHON SOURCE LINES 64-68 We suggest specifying the variables and their transformations once. These can be reused in different kind of post processing. When plotting with :py:mod:`ogstools.plot` we can use these presets to simplify the task of processing the data (e.g. calculate the von Mises stress): .. GENERATED FROM PYTHON SOURCE LINES 70-74 .. code-block:: Python fig = ogs.plot.contourf( examples.load_mesh_mechanics_2D(), ogs.variables.stress.von_Mises ) .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_variables_001.png :alt: plot variables :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_variables_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 75-77 Have a look at :ref:`sphx_glr_auto_examples_howto_plot` for more examples. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.254 seconds) .. _sphx_glr_download_auto_examples_howto_postprocessing_plot_variables.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_variables.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_variables.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_variables.zip `