Skip to content

Commit

Permalink
Make compatible with v2.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterpeere committed Jan 27, 2024
1 parent 289804a commit 6254c11
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 5 deletions.
4 changes: 1 addition & 3 deletions GHEtoolGUI/data_2_borefield_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def data_2_borefield(ds: DataStorage) -> tuple[Borefield, partial[[], None]]:
from GHEtool import Borefield

# create the bore field object
borefield = Borefield(
gui=True,
)
borefield = Borefield()
_set_boreholes(ds, borefield)
# set temperature boundaries
borefield.set_max_avg_fluid_temperature(ds.option_max_temp) # maximum temperature
Expand Down
105 changes: 105 additions & 0 deletions GHEtoolGUI/start_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging

import sys
import matplotlib.pyplot as plt
from pathlib import Path
from platform import system
from sys import argv
Expand All @@ -14,6 +15,106 @@
is_frozen = getattr(sys, 'frozen', False) and os_system == 'Windows' # pragma: no cover


def _plot_temperature_profile(self, legend: bool = True, plot_hourly: bool = False):
"""
This function plots the temperature profile.
If the Borefield object exists as part of the GUI, than the figure is returned,
otherwise it is shown.
Parameters
----------
legend : bool
True if the legend should be printed
plot_hourly : bool
True if the temperature profile printed should be based on the hourly load profile.
Returns
-------
fig, ax
If the borefield object is part of the GUI, it returns the figure object
"""

# make a time array
if plot_hourly:
time_array = self.load.time_L4 / 12 / 3600 / 730
else:
time_array = self.load.time_L3 / 12 / 730. / 3600.

# plt.rc('figure')
# create new figure and axes if it not already exits otherwise clear it.
fig = plt.figure()
ax = fig.add_subplot(111)
# set axes labelsv
ax.set_xlabel(r'Time (year)')
ax.set_ylabel(r'Temperature ($^\circ C$)')
ax.yaxis.label.set_color(plt.rcParams["axes.labelcolor"])
ax.xaxis.label.set_color(plt.rcParams["axes.labelcolor"])

# plot Temperatures
ax.step(time_array, self.results.Tb, 'k-', where="post", lw=1.5, label="Tb")

if plot_hourly:
ax.step(time_array, self.results.peak_cooling, 'b-', where="post", lw=1, label='Tf')
else:
ax.step(time_array, self.results.peak_cooling, 'b-', where="post", lw=1.5, label='Tf peak cooling')
ax.step(time_array, self.results.peak_heating, 'r-', where="post", lw=1.5, label='Tf peak heating')

ax.step(time_array, self.results.monthly_cooling, color='b', linestyle="dashed", where="post", lw=1.5,
label='Tf base cooling')
ax.step(time_array, self.results.monthly_heating, color='r', linestyle="dashed", where="post", lw=1.5,
label='Tf base heating')

# define temperature bounds
ax.hlines(self.Tf_min, 0, self.simulation_period, colors='r', linestyles='dashed', label='', lw=1)
ax.hlines(self.Tf_max, 0, self.simulation_period, colors='b', linestyles='dashed', label='', lw=1)
ax.set_xticks(range(0, self.simulation_period + 1, 2))

# Plot legend
if legend:
ax.legend()
ax.set_xlim(left=0, right=self.simulation_period)
# show figure if not in gui mode
return fig, ax

def _plot_load_duration(self, legend: bool = False):
"""
This function makes a load-duration curve from the hourly values.
Parameters
----------
legend : bool
True if the figure should have a legend
Returns
----------
Tuple
plt.Figure, plt.Axes
"""
# sort heating and cooling load
heating = self._secundary_borefield_load.hourly_heating_load.copy()
heating[::-1].sort()

cooling = self._secundary_borefield_load.hourly_cooling_load.copy()
cooling.sort()
cooling = cooling * (-1)
# create new figure and axes if it not already exits otherwise clear it.
fig = plt.figure()
ax = fig.add_subplot(111)
# add sorted loads to plot
ax.step(range(0, 8760, 1), heating, 'r-', label="Heating")
ax.step(range(0, 8760, 1), cooling, 'b-', label="Cooling")
# create 0 line
ax.hlines(0, 0, 8759, color="black")
# add labels
ax.set_xlabel("Time [hours]")
ax.set_ylabel("Power [kW]")
# set x limits to 8760
ax.set_xlim(0, 8760)
# plot legend if wanted
if legend:
ax.legend() # pragma: no cover
return fig, ax

def run(path_list=None): # pragma: no cover
if is_frozen:
import pyi_splash
Expand All @@ -34,6 +135,10 @@ def run(path_list=None): # pragma: no cover
from GHEtoolGUI.gui_classes.gui_combine_window import MainWindow
import ScenarioGUI.global_settings as globs

# adapt borefield class
Borefield._plot_temperature_profile = _plot_temperature_profile
Borefield._plot_load_duration = _plot_load_duration

if is_frozen:
pyi_splash.update_text('Loading ...')

Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ install_requires =
numpy>=1.23.1
pandas>=1.4.3
pygfunction>=2.2.1
PySide6>=6.4.1
configparser>=5.3.0
scipy>=1.8.1
pytest>=7.1.2
scikit-optimize>=0.9.0
GHEtool>=2.2.0

[options.extras_require]
GUI = pyside6>=6.4.1
Expand Down

0 comments on commit 6254c11

Please sign in to comment.