.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_quickstart/plot_meshseries.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_quickstart_plot_meshseries.py: Read mesh from file (vtu or xdmf) into pyvista mesh ===================================================== .. GENERATED FROM PYTHON SOURCE LINES 8-12 .. code-block:: Python import numpy as np from ogstools import examples .. GENERATED FROM PYTHON SOURCE LINES 13-20 To read your own data as a MeshSeries you can do: .. code-block:: python from ogstools.meshlib import MeshSeries mesh_series = MeshSeries("filepath/filename_pvd_or_xdmf") .. GENERATED FROM PYTHON SOURCE LINES 22-25 MeshSeries takes as mandatory argument a str OR pathlib.Path that represents the location of the pvd or xdmf file. Here, we load example data and print the meta information: .. GENERATED FROM PYTHON SOURCE LINES 27-31 .. code-block:: Python ms = examples.load_meshseries_HT_2D_XDMF() ms .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 32-37 Accessing time values ===================== Time values (and spatial coordinates) can be unit transformed via :meth:`~ogstools.meshlib.mesh_series.MeshSeries.scale`. Either pass a tuple to convert from the first to the second unit or pass a scaling factor. .. GENERATED FROM PYTHON SOURCE LINES 39-45 .. code-block:: Python print(f"First 3 time values are: {ms.timevalues[:3]} s.") ms = ms.scale(time=("s", "h")) print(f"Last time value is: {ms.timevalues[-1]} h.") ms = ms.scale(time=3600.0) print(f"Last time value is: {ms.timevalues[-1]} s.") .. rst-class:: sphx-glr-script-out .. code-block:: none First 3 time values are: [ 0. 900. 1800.] s. Last time value is: 24.0 h. Last time value is: 86400.0 s. .. GENERATED FROM PYTHON SOURCE LINES 46-53 Accessing meshes ================ To get a single mesh at a specified timestep you can use the mesh() method of a MeshSeries object (in this example: ms). Another way to to do so is by indexing the MeshSeries object with brackets (ms[timestep]). Besides custom ogstools functions you can use all available pyvista functions. Here we use pyvista's plot function. .. GENERATED FROM PYTHON SOURCE LINES 55-58 .. code-block:: Python mesh_ts10 = ms.mesh(10) # or ms[10] mesh_ts10.plot(show_edges=True) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /auto_examples/howto_quickstart/images/sphx_glr_plot_meshseries_001.png :alt: plot meshseries :srcset: /auto_examples/howto_quickstart/images/sphx_glr_plot_meshseries_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /builds/ogs/tools/ogstools/docs/auto_examples/howto_quickstart/images/sphx_glr_plot_meshseries_001.vtksz .. GENERATED FROM PYTHON SOURCE LINES 59-74 Indexing ======== `MeshSeries.values("")`` returns a `numpy ndarray `_. It allows `multidimensional indexing on ndarrays `_. Typically, the first dimension is the time step, second dimension is the number of points/cells, and the last dimension is the number of components of the variable. By default, ``values`` would read the entire dataset. If only a subset of the MeshSeries should be read you can select the relevant timesteps by indexing / slicing the MeshSeries directly. This selection will also be adhered to if you read individual meshes. .. GENERATED FROM PYTHON SOURCE LINES 76-84 .. code-block:: Python ms = examples.load_meshseries_HT_2D_XDMF() # Temperature is a scalar, Darcy velocity is a vector with 2 components. # Both are defined at points. print("Entire dataset:", np.shape(ms.values("temperature"))) print("Every second timestep:", np.shape(ms[::2].values("temperature"))) print("Last two steps:", np.shape(ms[-2:].values("darcy_velocity"))) .. rst-class:: sphx-glr-script-out .. code-block:: none Entire dataset: (97, 190) Every second timestep: (49, 190) Last two steps: (2, 190, 2) .. GENERATED FROM PYTHON SOURCE LINES 85-87 To select points or cells you can use the ``extract`` method to specify the corresponding ids. .. GENERATED FROM PYTHON SOURCE LINES 89-93 .. code-block:: Python temp_at_points = ms.extract([2, 3, 4]).values("temperature") print("Data on extracted points:", np.shape(temp_at_points)) print("Temperatures at last timestep:", temp_at_points[-1]) .. rst-class:: sphx-glr-script-out .. code-block:: none Data on extracted points: (97, 3) Temperatures at last timestep: [352.9994477 303. 353.00000001] .. GENERATED FROM PYTHON SOURCE LINES 94-96 You can also use pyvista dataset filters to ``transform`` the domain for the entire MeshSeries. .. GENERATED FROM PYTHON SOURCE LINES 98-104 .. code-block:: Python ms_right_half = ms.transform( lambda mesh: mesh.clip("x", mesh.center, crinkle=True) ) temp_right_half = ms_right_half.values("temperature") print("Data on clipped domain:", np.shape(temp_right_half)) .. rst-class:: sphx-glr-script-out .. code-block:: none Data on clipped domain: (97, 114) .. GENERATED FROM PYTHON SOURCE LINES 105-106 Let's plot the last timestep of the transformed MeshSeries. .. GENERATED FROM PYTHON SOURCE LINES 108-109 .. code-block:: Python fig = ms_right_half[-1].plot_contourf("temperature") .. image-sg:: /auto_examples/howto_quickstart/images/sphx_glr_plot_meshseries_002.png :alt: plot meshseries :srcset: /auto_examples/howto_quickstart/images/sphx_glr_plot_meshseries_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.633 seconds) .. _sphx_glr_download_auto_examples_howto_quickstart_plot_meshseries.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_meshseries.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_meshseries.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_meshseries.zip `