.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/examples/03_flowsheet/02_flowsheet_from_file.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_examples_03_flowsheet_02_flowsheet_from_file.py: Flowsheet from File =================== It is possible to create a Flowsheet object from a file. This example demonstrates how to create a Flowsheet object from a file. .. GENERATED FROM PYTHON SOURCE LINES 9-21 .. code-block:: Python import inspect from pathlib import Path import pandas as pd from matplotlib import pyplot as plt from elphick.geomet.flowsheet import Flowsheet from elphick.geomet.flowsheet.stream import Stream from elphick.geomet.utils.data import sample_data __file__ = Path(inspect.getfile(inspect.currentframe())).resolve() .. GENERATED FROM PYTHON SOURCE LINES 22-26 YAML file --------- The yaml file needs to follow this structure. .. GENERATED FROM PYTHON SOURCE LINES 27-32 .. code-block:: Python yaml_filepath: Path = Path(__file__).parents[2] / 'elphick/geomet/config/flowsheet_example_simple.yaml' yaml_config: str = yaml_filepath.read_text() yaml_config .. rst-class:: sphx-glr-script-out .. code-block:: none 'FLOWSHEET:\n flowsheet:\n name: Flowsheet\n streams: # graph edges\n Feed:\n name: Feed\n node_in: feed\n node_out: screen\n Coarse:\n name: Coarse\n node_in: screen\n node_out: lump\n Fine:\n name: Fine\n node_in: screen\n node_out: fines\n operations: # graph nodes\n feed:\n name: feed\n screen:\n name: screen\n lump:\n name: lump\n fines:\n name: fines\n' .. GENERATED FROM PYTHON SOURCE LINES 33-35 Create Flowsheet ---------------- .. GENERATED FROM PYTHON SOURCE LINES 35-39 .. code-block:: Python fs: Flowsheet = Flowsheet.from_yaml(yaml_filepath) fs .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 40-42 The Flowsheet object can be visualized as a network. The streams are not yet populated, so are shown in red. .. GENERATED FROM PYTHON SOURCE LINES 42-45 .. code-block:: Python fs.plot() plt .. image-sg:: /auto_examples/examples/03_flowsheet/images/sphx_glr_02_flowsheet_from_file_001.png :alt: Flowsheet Nodes Healthy: True, Streams Healthy: False :srcset: /auto_examples/examples/03_flowsheet/images/sphx_glr_02_flowsheet_from_file_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 46-49 Load the data ------------- Load data onto two of the three streams. .. GENERATED FROM PYTHON SOURCE LINES 49-61 .. code-block:: Python df_feed: pd.DataFrame = sample_data() obj_feed: Stream = Stream(df_feed, name='Feed') # assume the Coarse stream is 0.4 of the Feed stream mass df_coarse: pd.DataFrame = df_feed.copy() df_coarse['wet_mass'] = df_coarse['wet_mass'] * 0.4 df_coarse['mass_dry'] = df_coarse['mass_dry'] * 0.4 obj_coarse: Stream = Stream(df_coarse, name='Coarse') fs.set_stream_data(stream_data={'Feed': obj_feed, 'Coarse': obj_coarse}) .. GENERATED FROM PYTHON SOURCE LINES 62-65 .. code-block:: Python fs.plot() plt .. image-sg:: /auto_examples/examples/03_flowsheet/images/sphx_glr_02_flowsheet_from_file_002.png :alt: Flowsheet Nodes Healthy: False, Streams Healthy: False :srcset: /auto_examples/examples/03_flowsheet/images/sphx_glr_02_flowsheet_from_file_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 66-68 Solve the flowsheet ------------------- .. GENERATED FROM PYTHON SOURCE LINES 68-73 .. code-block:: Python fs.solve() fs.plot() plt .. image-sg:: /auto_examples/examples/03_flowsheet/images/sphx_glr_02_flowsheet_from_file_003.png :alt: Flowsheet Nodes Healthy: True, Streams Healthy: True :srcset: /auto_examples/examples/03_flowsheet/images/sphx_glr_02_flowsheet_from_file_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 74-76 Plot the mass balance --------------------- .. GENERATED FROM PYTHON SOURCE LINES 76-79 .. code-block:: Python fig = fs.table_plot(plot_type='network') fig .. raw:: html


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.091 seconds) .. _sphx_glr_download_auto_examples_examples_03_flowsheet_02_flowsheet_from_file.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 02_flowsheet_from_file.ipynb <02_flowsheet_from_file.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 02_flowsheet_from_file.py <02_flowsheet_from_file.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_