.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gen_tutorials/tutorial_individual_sims.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_gen_tutorials_tutorial_individual_sims.py: .. _tutorial_individual_sims: ================================= Processing Individual Simulations ================================= This is an introduction to the processing API. For a more in-depth view, please refer to the :ref:`how_tos` and the API docs :ref:`api-reference-api` .. GENERATED FROM PYTHON SOURCE LINES 13-27 Introduction to processing individual simulations ================================================= First, you will need to download the `example data. `_ Extract the data into a project folder you will use for this tutorial. You should end up with a folder structure looking like this. | root | ├─ example_data | ├─ tutorials | ├─ tutorial_individual_sims.py For the rest of this tutorial, you should work in the last file: "tutorial_individual_sims.py" .. GENERATED FROM PYTHON SOURCE LINES 30-33 Required Imports ================ First, let's add the required imports to the top of the script. .. GENERATED FROM PYTHON SOURCE LINES 33-39 .. code-block:: Python import pathlib as _pl from pytrnsys_process import api .. GENERATED FROM PYTHON SOURCE LINES 40-44 Defining a processing step -------------------------- This step will use the specified columns to plot a bar chart using the monthly data. The Simulation object will be provided by the processing function which we will call later. .. GENERATED FROM PYTHON SOURCE LINES 44-55 .. code-block:: Python def plot_monthly_bar_chart(simulation: api.Simulation): columns_to_plot = ["QSnk60P", "QSnk60PauxCondSwitch_kW"] fig, _ = api.bar_chart( simulation.monthly, columns_to_plot, ) fig.show() .. GENERATED FROM PYTHON SOURCE LINES 56-63 Creating multiple processing steps ---------------------------------- It makes sense to split your plots into multiple steps. If one step fails, the others will continue to run. Let's define another step that creates a line plot using hourly data. We can customize the plot further using the `figure `_ and `axes `_ objects returned by the plot function. .. GENERATED FROM PYTHON SOURCE LINES 63-73 .. code-block:: Python def plot_hourly_line_plot(simulation: api.Simulation): columns_to_plot = ["QSrc1TIn", "QSrc1TOut"] fig, ax = api.line_plot(simulation.hourly, columns_to_plot, cmap="Paired") ax.set_ylabel("In/Out") ax.set_xlabel("Timeline") fig.show() .. GENERATED FROM PYTHON SOURCE LINES 74-82 Note ____ By setting up processing steps in this way, we enable you to take full advantage of both Pandas and MatPlotLib functionality. If you have not already, check out their respective tutorials and guides. For Pandas: `Tutorials `_ and `User's Guide `_. For MatPlotLib: `Quick start guide `_ and `User's Guide `_. .. GENERATED FROM PYTHON SOURCE LINES 84-91 Running the processing steps ---------------------------- At the end of the script, we define our entry point and specify which processing steps we would like to run. We need to pass the path to the simulation files and the processing steps we defined above to the processing function. .. GENERATED FROM PYTHON SOURCE LINES 91-98 .. code-block:: Python if __name__ == "__main__": path_to_sim = _pl.Path("../example_data/small/sim-1") sim = api.process_single_simulation( path_to_sim, [plot_monthly_bar_chart, plot_hourly_line_plot] ) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /gen_tutorials/images/sphx_glr_tutorial_individual_sims_001.png :alt: tutorial individual sims :srcset: /gen_tutorials/images/sphx_glr_tutorial_individual_sims_001.png :class: sphx-glr-multi-img * .. image-sg:: /gen_tutorials/images/sphx_glr_tutorial_individual_sims_002.png :alt: tutorial individual sims :srcset: /gen_tutorials/images/sphx_glr_tutorial_individual_sims_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - Starting processing of simulation ../example_data/small/sim-1 INFO - Processing simulation: sim-1 INFO - ================================================================================ INFO - BATCH PROCESSING SUMMARY INFO - -------------------------------------------------------------------------------- INFO - Total simulations processed: 1 | Failed: 0 INFO - ================================================================================ INFO - Total execution time: 0.19 seconds .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.441 seconds) .. _sphx_glr_download_gen_tutorials_tutorial_individual_sims.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: tutorial_individual_sims.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: tutorial_individual_sims.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: tutorial_individual_sims.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_