.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/01-Detailed-Examples/03-explore-result-data-harmonic.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_examples_01-Detailed-Examples_03-explore-result-data-harmonic.py: .. _ref_data_data_frame_example: Explore the data of a result with the dataframe (harmonic simulation) ===================================================================== This example uses a harmonic simulation to show how to interact with the PyDPF-Post dataframe, which is the object returned by each result. .. GENERATED FROM PYTHON SOURCE LINES 33-37 Perform required imports ------------------------ Perform required imports. This example uses a supplied file that you can get by importing the DPF ``examples`` package. .. GENERATED FROM PYTHON SOURCE LINES 37-41 .. code-block:: Python from ansys.dpf import post from ansys.dpf.post import examples .. GENERATED FROM PYTHON SOURCE LINES 42-48 Get ``Simulation`` object ------------------------- Get the ``Simulation`` object that allows access to the result. The ``Simulation`` object must be instantiated with the path for the result file. For example, ``"C:/Users/user/my_result.rst"`` on Windows or ``"/home/user/my_result.rst"`` on Linux. .. GENERATED FROM PYTHON SOURCE LINES 48-56 .. code-block:: Python example_path = examples.download_harmonic_clamped_pipe() # to automatically detect the simulation type, use: simulation = post.load_simulation(example_path) # to enable auto-completion, use the equivalent: simulation = post.HarmonicMechanicalSimulation(example_path) .. GENERATED FROM PYTHON SOURCE LINES 57-59 Extract displacement over all sets ---------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 59-64 .. code-block:: Python displacement = simulation.displacement(all_sets=True) print(displacement) type(displacement) .. rst-class:: sphx-glr-script-out .. code-block:: none results U ... set_ids 1 2 3 ... complex 0 1 0 1 0 1 ... node_ids components ... 3548 X 9.3929e+01 0.0000e+00 -5.2330e+01 0.0000e+00 -1.1203e+01 0.0000e+00 ... Y -4.3312e+02 0.0000e+00 1.8810e+02 0.0000e+00 6.8681e+01 0.0000e+00 ... Z 9.6172e-01 0.0000e+00 -1.3049e+01 0.0000e+00 2.3508e+01 0.0000e+00 ... 3656 X 1.0516e+02 0.0000e+00 -5.8461e+01 0.0000e+00 -1.4575e+01 0.0000e+00 ... Y -4.6059e+02 0.0000e+00 2.0315e+02 0.0000e+00 7.4665e+01 0.0000e+00 ... Z 9.4728e-01 0.0000e+00 -1.3728e+01 0.0000e+00 2.5207e+01 0.0000e+00 ... ... ... ... ... ... ... ... ... ... .. GENERATED FROM PYTHON SOURCE LINES 65-67 Loop over all columns and rows to understand the dataframe and get the values for each index. .. GENERATED FROM PYTHON SOURCE LINES 67-77 .. code-block:: Python # columns for column in displacement.columns: print(f'Column with label "{column.name}" and available values {column.values}.') # rows for row in displacement.index: print(f'Row with label "{row.name}" and available values {row.values}.') .. rst-class:: sphx-glr-script-out .. code-block:: none Column with label "results" and available values ['U']. Column with label "set_ids" and available values [1, 2, 3, 4, 5]. Column with label "complex" and available values [0, 1]. Row with label "node_ids" and available values [3548 3656 4099 ... 3260 9942 9943]. Row with label "components" and available values ['X', 'Y', 'Z']. .. GENERATED FROM PYTHON SOURCE LINES 78-82 Make selections in dataframe ---------------------------- Use the labels and values shown by the preceding code to select subparts of the dataframe. .. GENERATED FROM PYTHON SOURCE LINES 82-95 .. code-block:: Python all_real_values = displacement.select(complex=0) print(all_real_values) all_imaginary_values = displacement.select(complex=1) print(all_imaginary_values) sets_values = displacement.select(set_ids=[1, 2]) print(sets_values) node_values = displacement.select(node_ids=[3548]) print(node_values) .. rst-class:: sphx-glr-script-out .. code-block:: none results U set_ids 1 2 3 4 5 complex 0 node_ids components 3548 X 9.3929e+01 -5.2330e+01 -1.1203e+01 -1.1510e+01 -1.4457e+01 Y -4.3312e+02 1.8810e+02 6.8681e+01 2.2900e+01 -6.6765e+00 Z 9.6172e-01 -1.3049e+01 2.3508e+01 1.4745e+00 -5.9568e+00 3656 X 1.0516e+02 -5.8461e+01 -1.4575e+01 -1.3822e+01 -1.7782e+01 Y -4.6059e+02 2.0315e+02 7.4665e+01 2.7874e+01 1.5223e+00 Z 9.4728e-01 -1.3728e+01 2.5207e+01 1.4487e+00 -7.3947e+00 ... ... ... ... ... ... ... results U set_ids 1 2 3 4 5 complex 1 node_ids components 3548 X 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 Y 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 Z 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3656 X 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 Y 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 Z 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 ... ... ... ... ... ... ... results U set_ids 1 2 complex 0 1 0 1 node_ids components 3548 X 9.3929e+01 0.0000e+00 -5.2330e+01 0.0000e+00 Y -4.3312e+02 0.0000e+00 1.8810e+02 0.0000e+00 Z 9.6172e-01 0.0000e+00 -1.3049e+01 0.0000e+00 3656 X 1.0516e+02 0.0000e+00 -5.8461e+01 0.0000e+00 Y -4.6059e+02 0.0000e+00 2.0315e+02 0.0000e+00 Z 9.4728e-01 0.0000e+00 -1.3728e+01 0.0000e+00 ... ... ... ... ... ... results U ... set_ids 1 2 3 ... complex 0 1 0 1 0 1 ... node_ids components ... 3548 X 9.3929e+01 0.0000e+00 -5.2330e+01 0.0000e+00 -1.1203e+01 0.0000e+00 ... Y -4.3312e+02 0.0000e+00 1.8810e+02 0.0000e+00 6.8681e+01 0.0000e+00 ... Z 9.6172e-01 0.0000e+00 -1.3049e+01 0.0000e+00 2.3508e+01 0.0000e+00 ... .. GENERATED FROM PYTHON SOURCE LINES 96-100 Make selections in dataframe by index -------------------------------------- To select values by index for each label, use the ``iselect()`` method. The index to ID order follows what is returned by the values on the preceding index method. .. GENERATED FROM PYTHON SOURCE LINES 100-107 .. code-block:: Python sets_values = displacement.iselect(set_ids=0) print(sets_values) node_values = displacement.iselect(node_ids=[0]) print(node_values) .. rst-class:: sphx-glr-script-out .. code-block:: none results U set_ids 1 complex 0 1 node_ids components 3548 X 9.3929e+01 0.0000e+00 Y -4.3312e+02 0.0000e+00 Z 9.6172e-01 0.0000e+00 3656 X 1.0516e+02 0.0000e+00 Y -4.6059e+02 0.0000e+00 Z 9.4728e-01 0.0000e+00 ... ... ... ... results U ... set_ids 1 2 3 ... complex 0 1 0 1 0 1 ... node_ids components ... 3548 X 9.3929e+01 0.0000e+00 -5.2330e+01 0.0000e+00 -1.1203e+01 0.0000e+00 ... Y -4.3312e+02 0.0000e+00 1.8810e+02 0.0000e+00 6.8681e+01 0.0000e+00 ... Z 9.6172e-01 0.0000e+00 -1.3049e+01 0.0000e+00 2.3508e+01 0.0000e+00 ... .. GENERATED FROM PYTHON SOURCE LINES 108-110 Make multiple selections in dataframe ------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 110-116 .. code-block:: Python real_values_for_one_set_onde_node = displacement.select( node_ids=[3548], set_ids=1, complex=0 ) print(real_values_for_one_set_onde_node) .. rst-class:: sphx-glr-script-out .. code-block:: none results U set_ids 1 complex 0 node_ids components 3548 X 9.3929e+01 Y -4.3312e+02 Z 9.6172e-01 .. GENERATED FROM PYTHON SOURCE LINES 117-119 Make selections to plot dataframe --------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 119-121 .. code-block:: Python displacement.plot(set_ids=1, complex=0) .. image-sg:: /examples/01-Detailed-Examples/images/sphx_glr_03-explore-result-data-harmonic_001.png :alt: 03 explore result data harmonic :srcset: /examples/01-Detailed-Examples/images/sphx_glr_03-explore-result-data-harmonic_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.017 seconds) .. _sphx_glr_download_examples_01-Detailed-Examples_03-explore-result-data-harmonic.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 03-explore-result-data-harmonic.ipynb <03-explore-result-data-harmonic.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 03-explore-result-data-harmonic.py <03-explore-result-data-harmonic.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 03-explore-result-data-harmonic.zip <03-explore-result-data-harmonic.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_