.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\05-file-IO\01-reduced_matrices_export.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_05-file-IO_01-reduced_matrices_export.py: .. _ref_reduced_matrices_export: Get reduced matrices and make export ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This example shows how to get reduced matrices and export them to HDF5 and CSV files. .. GENERATED FROM PYTHON SOURCE LINES 13-15 Import the ``dpf-core`` module and its examples files, and then create a temporary directory. .. GENERATED FROM PYTHON SOURCE LINES 15-20 .. code-block:: Python from ansys.dpf import core as dpf from ansys.dpf.core import examples from ansys.dpf.core import operators as ops .. GENERATED FROM PYTHON SOURCE LINES 21-22 Create the operator and connect data sources. .. GENERATED FROM PYTHON SOURCE LINES 22-28 .. code-block:: Python ds = dpf.DataSources(examples.download_sub_file()) matrices_provider = ops.result.cms_matrices_provider() matrices_provider.inputs.data_sources.connect(ds) .. GENERATED FROM PYTHON SOURCE LINES 29-30 Get result fields container that contains the reduced matrices. .. GENERATED FROM PYTHON SOURCE LINES 30-37 .. code-block:: Python fields = matrices_provider.outputs.fields_container() len(fields) fields[0].data .. rst-class:: sphx-glr-script-out .. code-block:: none DPFArray([[ 5.53476768e+11, -2.29728435e+10, 2.29728435e+10, ..., 0.00000000e+00, 0.00000000e+00, 2.91225427e+05]]) .. GENERATED FROM PYTHON SOURCE LINES 38-39 Define a temporary folder for outputs .. GENERATED FROM PYTHON SOURCE LINES 39-41 .. code-block:: Python tmpdir = dpf.core.make_tmp_dir_server(dpf.SERVER) .. GENERATED FROM PYTHON SOURCE LINES 42-43 Export the result fields container to an HDF5 file. .. GENERATED FROM PYTHON SOURCE LINES 43-49 .. code-block:: Python h5_op = ops.serialization.serialize_to_hdf5() h5_op.inputs.data1.connect(matrices_provider.outputs) h5_op.inputs.file_path.connect(dpf.path_utilities.join(tmpdir, "matrices.h5")) h5_op.run() .. GENERATED FROM PYTHON SOURCE LINES 50-51 Export the result fields container to a CSV file. .. GENERATED FROM PYTHON SOURCE LINES 51-56 .. code-block:: Python csv_op = ops.serialization.field_to_csv() csv_op.inputs.field_or_fields_container.connect(matrices_provider.outputs) csv_op.inputs.file_path.connect(dpf.path_utilities.join(tmpdir, "matrices.csv")) csv_op.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.338 seconds) .. _sphx_glr_download_examples_05-file-IO_01-reduced_matrices_export.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01-reduced_matrices_export.ipynb <01-reduced_matrices_export.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01-reduced_matrices_export.py <01-reduced_matrices_export.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_