.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/03_omf_blockmodel_to_parquet.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_03_omf_blockmodel_to_parquet.py: OMF Block Model to Parquet ========================== A parquet file is a columnar storage format, enabling column by column reading and writing. This can be used to reduce memory consumption. This example demonstrates how to convert an OMF block model to a Parquet file. .. note:: Presently there is no low-memory option for this method, so it is not suitable for very large files. As such it offers no advantage over the standard Pandas method for saving to Parquet. However, this is the first step in a series of methods that will allow for more efficient handling of large files. .. GENERATED FROM PYTHON SOURCE LINES 14-20 .. code-block:: Python from pathlib import Path import pandas as pd from omfpandas import OMFPandasReader, OMFPandasWriter .. GENERATED FROM PYTHON SOURCE LINES 21-24 Instantiate ----------- Create the object OMFPandas with the path to the OMF file. .. GENERATED FROM PYTHON SOURCE LINES 24-33 .. code-block:: Python test_omf_path: Path = Path('../assets/test_file.omf') omf_writer: OMFPandasWriter = OMFPandasWriter(filepath=test_omf_path) # Display the head of the original block model blocks: pd.DataFrame = OMFPandasReader(filepath=test_omf_path).read_blockmodel(blockmodel_name='regular') print("Original DataFrame:") blocks.head() .. rst-class:: sphx-glr-script-out .. code-block:: none Original DataFrame: .. raw:: html
random attr
x y z
10.5 10.5 -9.5 0.727986
-8.5 0.277389
-7.5 0.351741
-6.5 0.999272
-5.5 0.495092


.. GENERATED FROM PYTHON SOURCE LINES 34-37 Convert ------- View the elements in the OMF file first. .. GENERATED FROM PYTHON SOURCE LINES 37-39 .. code-block:: Python print(omf_writer.element_types) .. rst-class:: sphx-glr-script-out .. code-block:: none {'tensor': 'TensorGridBlockModel', 'regular': 'RegularBlockModel'} .. GENERATED FROM PYTHON SOURCE LINES 40-41 Convert 'Block Model' to a Parquet file. .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. code-block:: Python omf_writer.blockmodel_to_parquet(blockmodel_name='regular', out_path=Path('blocks.parquet'), allow_overwrite=True) .. GENERATED FROM PYTHON SOURCE LINES 45-48 Load the Parquet ---------------- Reload the Parquet file and display the head. .. GENERATED FROM PYTHON SOURCE LINES 48-53 .. code-block:: Python blocks_2: pd.DataFrame = pd.read_parquet('blocks.parquet') print("Reloaded DataFrame:") blocks_2.head() .. rst-class:: sphx-glr-script-out .. code-block:: none Reloaded DataFrame: .. raw:: html
random attr
x y z
10.5 10.5 -9.5 0.727986
-8.5 0.277389
-7.5 0.351741
-6.5 0.999272
-5.5 0.495092


.. GENERATED FROM PYTHON SOURCE LINES 54-57 Validate -------- Assert that the original DataFrame and the reloaded DataFrame are equivalent .. GENERATED FROM PYTHON SOURCE LINES 57-59 .. code-block:: Python assert blocks.equals(blocks_2) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.066 seconds) .. _sphx_glr_download_auto_examples_03_omf_blockmodel_to_parquet.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 03_omf_blockmodel_to_parquet.ipynb <03_omf_blockmodel_to_parquet.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 03_omf_blockmodel_to_parquet.py <03_omf_blockmodel_to_parquet.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_