diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fe047ff..5ae14771 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,15 @@ All notable changes to this project will be documented in this file. For future The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [2.2.1] - 2024 + +## Added +- Equal functions for HourlyGeothermalLoad and MonthlyGeothermalLoadAbsolute (issue #189). + +## fixed +- Bug in load-duration curve when not working with optimize load profile (issue # 189). + + ## [2.2.0] - 2023-10-17 ## Added diff --git a/GHEtool/VariableClasses/LoadData/GeothermalLoad/HourlyGeothermalLoad.py b/GHEtool/VariableClasses/LoadData/GeothermalLoad/HourlyGeothermalLoad.py index a204832c..357bf7eb 100644 --- a/GHEtool/VariableClasses/LoadData/GeothermalLoad/HourlyGeothermalLoad.py +++ b/GHEtool/VariableClasses/LoadData/GeothermalLoad/HourlyGeothermalLoad.py @@ -353,7 +353,7 @@ def load_hourly_profile(self, file_path: str, header: bool = True, separator: st ghe_logger.info("Hourly profile loaded!") - def __eq__(self, other): + def __eq__(self, other) -> bool: if not isinstance(other, HourlyGeothermalLoad): return False if not np.array_equal(self.hourly_cooling_load, other.hourly_cooling_load): diff --git a/GHEtool/VariableClasses/LoadData/GeothermalLoad/MonthlyGeothermalLoadAbsolute.py b/GHEtool/VariableClasses/LoadData/GeothermalLoad/MonthlyGeothermalLoadAbsolute.py index 36f3bdb3..66ccddd3 100644 --- a/GHEtool/VariableClasses/LoadData/GeothermalLoad/MonthlyGeothermalLoadAbsolute.py +++ b/GHEtool/VariableClasses/LoadData/GeothermalLoad/MonthlyGeothermalLoadAbsolute.py @@ -328,3 +328,18 @@ def set_peak_heating(self, load: Union[np.ndarray, list, tuple]) -> None: values """ self.peak_heating = np.array(load) + + def __eq__(self, other) -> bool: + if not isinstance(other, MonthlyGeothermalLoadAbsolute): + return False + if not np.array_equal(self.baseload_heating, other.baseload_heating): + return False + if not np.array_equal(self.baseload_cooling, other.baseload_cooling): + return False + if not np.array_equal(self.peak_heating, other.peak_heating): + return False + if not np.array_equal(self.peak_cooling, other.peak_cooling): + return False + if not self.simulation_period == other.simulation_period: + return False + return True diff --git a/GHEtool/test/unit-tests/test_hourly_load_data.py b/GHEtool/test/unit-tests/test_hourly_load_data.py index 97dea514..14d3f1b1 100644 --- a/GHEtool/test/unit-tests/test_hourly_load_data.py +++ b/GHEtool/test/unit-tests/test_hourly_load_data.py @@ -3,7 +3,7 @@ import numpy as np from GHEtool import FOLDER -from GHEtool.VariableClasses import HourlyGeothermalLoad, HourlyGeothermalLoadMultiYear +from GHEtool.VariableClasses import HourlyGeothermalLoad, HourlyGeothermalLoadMultiYear, MonthlyGeothermalLoadAbsolute def test_load_hourly_data(): @@ -181,3 +181,29 @@ def test_dhw(): assert np.array_equal(np.full(8760, 10), load.hourly_heating_load) assert np.array_equal(np.full(12, 8760*10/12), load.baseload_heating) assert load.imbalance == -8760*10 + + +def test_eq(): + profile_1 = HourlyGeothermalLoad() + profile_2 = MonthlyGeothermalLoadAbsolute() + assert not profile_1 == profile_2 + assert profile_1 == profile_1 + + profile_2 = HourlyGeothermalLoad() + assert profile_1 == profile_2 + + profile_1.simulation_period = 55 + assert profile_1 != profile_2 + + profile_1.hourly_cooling_load = np.linspace(0, 10000, 8760) + profile_2.simulation_period = 55 + assert profile_1 != profile_2 + + profile_2.hourly_cooling_load = np.linspace(0, 10000, 8760) + assert profile_1 == profile_2 + + profile_1.hourly_heating_load = np.linspace(0, 8759, 8760) + assert profile_1 != profile_2 + + profile_2.hourly_heating_load = np.linspace(0, 8759, 8760) + assert profile_1 == profile_2 diff --git a/GHEtool/test/unit-tests/test_monthly_load_data.py b/GHEtool/test/unit-tests/test_monthly_load_data.py index 58acd2d1..b7058be9 100644 --- a/GHEtool/test/unit-tests/test_monthly_load_data.py +++ b/GHEtool/test/unit-tests/test_monthly_load_data.py @@ -219,3 +219,44 @@ def test_yearly_heating_cooling(): load = MonthlyGeothermalLoadAbsolute(*load_case(2)) assert load.yearly_heating_load == 160000 assert load.yearly_cooling_load == 240000 + + +def test_eq(): + load_1 = MonthlyGeothermalLoadAbsolute(*load_case(2)) + load_2 = MonthlyGeothermalLoadAbsolute(*load_case(2)) + + assert load_1 == load_2 + load_2.simulation_period = 55 + assert load_1 != load_2 + + load_1.simulation_period = 55 + assert load_1 == load_2 + load_1.baseload_cooling = [i + 1 for i in load_1.baseload_cooling] + + assert load_1 != load_2 + load_2.baseload_cooling = [i + 1 for i in load_2.baseload_cooling] + assert load_1 == load_2 + + load_1.simulation_period = 55 + assert load_1 == load_2 + load_1.baseload_heating = [i + 1 for i in load_1.baseload_heating] + + assert load_1 != load_2 + load_2.baseload_heating = [i + 1 for i in load_2.baseload_heating] + assert load_1 == load_2 + + load_1.simulation_period = 55 + assert load_1 == load_2 + load_1.peak_heating = [i + 1 for i in load_1.peak_heating] + + assert load_1 != load_2 + load_2.peak_heating = [i + 1 for i in load_2.peak_heating] + assert load_1 == load_2 + + load_1.simulation_period = 55 + assert load_1 == load_2 + load_1.peak_cooling = [i + 1 for i in load_1.peak_cooling] + + assert load_1 != load_2 + load_2.peak_cooling = [i + 1 for i in load_2.peak_cooling] + assert load_1 == load_2