Skip to content

Commit

Permalink
Improve consistancy between load packages
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterpeere committed Feb 8, 2024
1 parent 1609f17 commit b05490d
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 217 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

import warnings

from typing import Union, Tuple, TYPE_CHECKING
from typing import Tuple, TYPE_CHECKING

from GHEtool.VariableClasses.LoadData._LoadData import _LoadData
from GHEtool.logger import ghe_logger

if TYPE_CHECKING:
from numpy.typing import ArrayLike, NDArray
from numpy.typing import ArrayLike


class HourlyGeothermalLoad(_LoadData):
Expand All @@ -27,7 +27,10 @@ class HourlyGeothermalLoad(_LoadData):
END = pd.to_datetime("2019-12-31 23:59:00")
HOURS_SERIES = pd.Series(pd.date_range(START, END, freq="1h"))

def __init__(self, heating_load: ArrayLike | None = None, cooling_load: ArrayLike | None = None, simulation_period: int = 20, dhw: float = 0.0):
def __init__(self, heating_load: ArrayLike | None = None,
cooling_load: ArrayLike | None = None,
simulation_period: int = 20,
dhw: float = 0.):
"""
Parameters
Expand All @@ -45,15 +48,15 @@ def __init__(self, heating_load: ArrayLike | None = None, cooling_load: ArrayLik
super().__init__(hourly_resolution=True, simulation_period=simulation_period)

# initiate variables
self._hourly_heating_load: NDArray[np.float64] = np.zeros(8760)
self._hourly_cooling_load: NDArray[np.float64] = np.zeros(8760)
self._hourly_heating_load: np.ndarray = np.zeros(8760)
self._hourly_cooling_load: np.ndarray = np.zeros(8760)

# set variables
self.hourly_heating_load: NDArray[np.float64] = np.zeros(8760) if heating_load is None else np.array(heating_load)
self.hourly_cooling_load: NDArray[np.float64] = np.zeros(8760) if cooling_load is None else np.array(cooling_load)
self.hourly_heating_load: np.ndarray = np.zeros(8760) if heating_load is None else np.array(heating_load)
self.hourly_cooling_load: np.ndarray = np.zeros(8760) if cooling_load is None else np.array(cooling_load)
self.dhw = dhw

def _check_input(self, input: Union[np.ndarray, list, tuple]) -> bool:
def _check_input(self, load_array: ArrayLike) -> bool:
"""
This function checks whether the input is valid or not.
The input is correct if and only if:
Expand All @@ -63,20 +66,20 @@ def _check_input(self, input: Union[np.ndarray, list, tuple]) -> bool:
Parameters
----------
input : np.ndarray, list or tuple
load_array : np.ndarray, list or tuple
Returns
-------
bool
True if the inputs are valid
"""
if not isinstance(input, (np.ndarray, list, tuple)):
if not isinstance(load_array, (np.ndarray, list, tuple)):
ghe_logger.error("The load should be of type np.ndarray, list or tuple.")
return False
if not len(input) == 8760:
if not len(load_array) == 8760:
ghe_logger.error("The length of the load should be 8760.")
return False
if np.min(input) < 0:
if np.min(load_array) < 0:
ghe_logger.error("No value in the load can be smaller than zero.")
return False
return True
Expand All @@ -94,7 +97,7 @@ def hourly_heating_load(self) -> np.ndarray:
return self.correct_for_start_month(self._hourly_heating_load + self.dhw / 8760)

@hourly_heating_load.setter
def hourly_heating_load(self, load: Union[np.ndarray, list, tuple]) -> None:
def hourly_heating_load(self, load: ArrayLike) -> None:
"""
This function sets the hourly heating load [kWh/h] after it has been checked.
Expand All @@ -118,7 +121,7 @@ def hourly_heating_load(self, load: Union[np.ndarray, list, tuple]) -> None:
return
raise ValueError

def set_hourly_heating(self, load: Union[np.ndarray, list, tuple]) -> None:
def set_hourly_heating(self, load: ArrayLike) -> None:
"""
This function sets the hourly heating load [kWh/h] after it has been checked.
Expand Down Expand Up @@ -152,7 +155,7 @@ def hourly_cooling_load(self) -> np.ndarray:
return self.correct_for_start_month(self._hourly_cooling_load)

@hourly_cooling_load.setter
def hourly_cooling_load(self, load: Union[np.ndarray, list, tuple]) -> None:
def hourly_cooling_load(self, load: ArrayLike) -> None:
"""
This function sets the hourly cooling load [kWh/h] after it has been checked.
Expand All @@ -176,7 +179,7 @@ def hourly_cooling_load(self, load: Union[np.ndarray, list, tuple]) -> None:
return
raise ValueError

def set_hourly_cooling(self, load: Union[np.ndarray, list, tuple]) -> None:
def set_hourly_cooling(self, load: ArrayLike) -> None:
"""
This function sets the hourly cooling load [kWh/h] after it has been checked.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import numpy as np

from typing import TYPE_CHECKING, Union
from typing import TYPE_CHECKING
from GHEtool.logger import ghe_logger
from GHEtool.VariableClasses.LoadData.GeothermalLoad.HourlyGeothermalLoad import HourlyGeothermalLoad

if TYPE_CHECKING:
from numpy.typing import ArrayLike, NDArray
from numpy.typing import ArrayLike


class HourlyGeothermalLoadMultiYear(HourlyGeothermalLoad):
Expand All @@ -34,7 +34,6 @@ def __init__(self, heating_load: ArrayLike | None = None, cooling_load: ArrayLik
# initiate variables
self._hourly_heating_load: np.ndarray = np.zeros(8760)
self._hourly_cooling_load: np.ndarray = np.zeros(8760)
self.range_month: range = range(0)

# set variables
heating_load = np.zeros(8760) if heating_load is None and cooling_load is None else heating_load
Expand Down Expand Up @@ -104,7 +103,6 @@ def hourly_heating_load(self, load: ArrayLike) -> None:
if self._check_input(load):
self._hourly_heating_load = load
self.simulation_period = int(len(load) / 8760)
self.range_month = range(730, len(load) + 1, 730)
return
raise ValueError

Expand Down Expand Up @@ -143,7 +141,6 @@ def hourly_cooling_load(self, load: ArrayLike) -> None:
if self._check_input(load):
self._hourly_cooling_load = load
self.simulation_period = int(len(load) / 8760)
self.range_month = range(730, len(load) + 1, 730)
return
raise ValueError

Expand Down Expand Up @@ -171,163 +168,6 @@ def hourly_heating_load_simulation_period(self) -> np.ndarray:
"""
return self._hourly_heating_load

@property
def baseload_cooling(self) -> np.ndarray:
"""
This function returns the baseload cooling in kWh/month.
Returns
-------
baseload cooling : np.ndarray
Baseload cooling values [kWh/month] for one year, so the length of the array is 12
"""
return self.resample_to_monthly(self._hourly_cooling_load)[1]

@property
def baseload_heating(self) -> np.ndarray:
"""
This function returns the baseload heating in kWh/month.
Returns
-------
baseload heating : np.ndarray
Baseload heating values [kWh/month] for one year, so the length of the array is 12
"""
return self.resample_to_monthly(self._hourly_heating_load)[1]

@property
def peak_cooling(self) -> np.ndarray:
"""
This function returns the peak cooling load in kW/month.
Returns
-------
peak cooling : np.ndarray
Peak cooling values for one year, so the length of the array is 12
"""
return self.resample_to_monthly(self._hourly_cooling_load)[0]

@property
def peak_heating(self) -> np.ndarray:
"""
This function returns the peak cooling load in kW/month.
Returns
-------
peak cooling : np.ndarray
Peak cooling values for one year, so the length of the array is 12
"""
return self.resample_to_monthly(self._hourly_heating_load)[0]

@property
def baseload_heating_power(self) -> np.ndarray:
"""
This function returns the baseload heating in kW avg/month.
Returns
-------
baseload heating : np.ndarray
"""
return self.baseload_heating / 730

@property
def baseload_cooling_power(self) -> np.ndarray:
"""
This function returns the baseload heating in kW avg/month.
Returns
-------
baseload heating : np.ndarray
"""
return self.baseload_cooling / 730

@property
def baseload_heating_simulation_period(self) -> np.ndarray:
"""
This function returns the baseload heating in kWh/month for a whole simulation period.
Returns
-------
baseload heating : np.ndarray
baseload heating for the whole simulation period
"""
return self.baseload_heating

@property
def baseload_cooling_simulation_period(self) -> np.ndarray:
"""
This function returns the baseload cooling in kWh/month for a whole simulation period.
Returns
-------
baseload cooling : np.ndarray
baseload cooling for the whole simulation period
"""
return self.baseload_cooling

@property
def peak_heating_simulation_period(self) -> np.ndarray:
"""
This function returns the peak heating in kW/month for a whole simulation period.
Returns
-------
peak heating : np.ndarray
peak heating for the whole simulation period
"""
return self.peak_heating

@property
def peak_cooling_simulation_period(self) -> np.ndarray:
"""
This function returns the peak cooling in kW/month for a whole simulation period.
Returns
-------
peak cooling : np.ndarray
peak cooling for the whole simulation period
"""
return self.peak_cooling

@property
def baseload_heating_power_simulation_period(self) -> np.ndarray:
"""
This function returns the avergae heating power in kW avg/month for a whole simulation period.
Returns
-------
average heating power : np.ndarray
average heating power for the whole simulation period
"""
return self.baseload_heating_power

@property
def baseload_cooling_power_simulation_period(self) -> np.ndarray:
"""
This function returns the average cooling power in kW avg/month for a whole simulation period.
Returns
-------
average cooling power : np.ndarray
average cooling for the whole simulation period
"""
return self.baseload_cooling_power

@property
def monthly_average_load_simulation_period(self) -> np.ndarray:
"""
This function calculates the average monthly load in kW for the whole simulation period.
Returns
-------
monthly average load : np.ndarray
"""
return self.monthly_average_load

def resample_to_monthly(self, hourly_load: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
res = np.array([hourly_load[i - 730 : i] for i in self.range_month])
return np.max(res, axis=1), np.sum(res, axis=1)

def __eq__(self, other) -> bool:
if not isinstance(other, HourlyGeothermalLoad):
return False
Expand Down
Loading

0 comments on commit b05490d

Please sign in to comment.