.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gen_examples/plot_comparison.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_examples_plot_comparison.py: Comparison plot ========================== This example demonstrates how to load simulations_data from a pickle and calculate values on the fly. The newly calculated values are then used to create a comparison plot. .. GENERATED FROM PYTHON SOURCE LINES 8-103 .. image-sg:: /gen_examples/images/sphx_glr_plot_comparison_001.png :alt: plot comparison :srcset: /gen_examples/images/sphx_glr_plot_comparison_001.png :class: sphx-glr-single-img .. code-block:: Python import pathlib as _pl import matplotlib.pyplot as _plt from pytrnsys_process import api def main(): ############################################### # Step 1: Load Data # ----------------- # Load pre-processed simulation data from pickle ############################################### simulations_data = api.load_simulations_data_from_pickle( _pl.Path("../example_data/small/simulations_data_reduced.pkl") ) for sim_name, sim in simulations_data.simulations.items(): ################################################ # Step 2: Extract Ice Storage Performance Metrics # -------------------------------------------- # Calculate maximum ice ratio from hourly data ################################################ hourly_data = sim.hourly max_ice_ratio = hourly_data["VIceRatio"].max() simulations_data.scalar.loc[sim_name, "VIceRatioMax"] = max_ice_ratio ############################################## # Step 3: Process Energy Demand Data # -------------------------------- # Sum up demands from multiple heat sinks and # convert to yearly totals in GWh ############################################## demand_columns = [ "qSysOut_QSnk131Demand", "qSysOut_QSnk183Demand", "qSysOut_QSnk191Demand", "qSysOut_QSnk225Demand", "qSysOut_QSnk243Demand", "qSysOut_QSnk266Demand", "qSysOut_QSnk322Demand", "qSysOut_QSnk335Demand", "qSysOut_QSnk358Demand", "qSysOut_QSnk417Demand", "qSysOut_QSnk448Demand", "qSysOut_QSnk469Demand", "qSysOut_QSnk488Demand", "qSysOut_QSnk524Demand", "qSysOut_QSnk539Demand", "qSysOut_QSnk558Demand", "qSysOut_QSnk579Demand", "qSysOut_QSnk60Demand", "qSysOut_QSnk85Demand", ] # Unit conversion factor: kWh to GWh kwh_to_gwh = 1e-6 # Process monthly data monthly_df = sim.monthly monthly_df["total_demand_GWh"] = ( monthly_df[demand_columns].sum(axis=1) * kwh_to_gwh ) # Calculate yearly total (excluding first 2 months) yearly_total = int(monthly_df["total_demand_GWh"].iloc[2::].sum()) simulations_data.scalar.loc[sim_name, "yearly_demand_GWh"] = ( yearly_total ) ################################################ # Step 4: Create Comparison Plot # --------------------------------------- # Scatter plot showing: # - X-axis: Scaled ice volume (VIceSscaled) # - Y-axis: Maximum ice ratio (VIceRatioMax) # - Color: Yearly demand in GWh # - Markers: DHW to space heating ratio ################################################ api.scatter_plot( simulations_data.scalar, "VIceSscaled", "VIceRatioMax", group_by_color="yearly_demand_GWh", group_by_marker="ratioDHWtoSH_allSinks", ) _plt.show() if __name__ == "__main__": main() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.170 seconds) .. _sphx_glr_download_gen_examples_plot_comparison.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_comparison.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_comparison.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_comparison.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_