Skip to content

Commit

Permalink
Partly fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterpeere committed Feb 8, 2024
1 parent db00b9d commit e0890e8
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def baseload_heating_power_simulation_period(self) -> np.ndarray:
average heating power : np.ndarray
average heating power for the whole simulation period
"""
return np.divide(self.baseload_heating_simulation_period, self.UPM)
return np.divide(self.baseload_heating_simulation_period, np.tile(self.UPM, self.simulation_period))

@property
def baseload_cooling_power_simulation_period(self) -> np.ndarray:
Expand All @@ -141,7 +141,7 @@ def baseload_cooling_power_simulation_period(self) -> np.ndarray:
average cooling power : np.ndarray
average cooling for the whole simulation period
"""
return np.divide(self.baseload_cooling_simulation_period, self.UPM)
return np.divide(self.baseload_cooling_simulation_period, np.tile(self.UPM, self.simulation_period))

@property
def monthly_average_load_simulation_period(self) -> np.ndarray:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,21 @@ def test_multiple_years_L4():
borefield.set_max_avg_fluid_temperature(17)
load = pd.read_csv(FOLDER.joinpath("test/methods/hourly_data/multiple_years.csv"), sep=",")
# load["heating"][8760*25:] = 0
hourly_load = HourlyGeothermalLoadMultiYear(load["heating"].clip(0)*load_factor, load["cooling"].clip(0)*load_factor)
hourly_load = HourlyGeothermalLoadMultiYear(load["heating"].clip(0)*load_factor, load["cooling"].clip(0) * load_factor)
borefield.load = hourly_load
assert np.allclose(borefield.load.hourly_heating_load_simulation_period, load["heating"].clip(0)*load_factor)
assert np.allclose(borefield.load.hourly_heating_load_simulation_period, load["heating"].clip(0) * load_factor)
assert np.allclose(borefield.load.hourly_cooling_load_simulation_period, load["cooling"].clip(0) * load_factor)
assert np.allclose(borefield.load.hourly_load_simulation_period, load["cooling"].clip(0) * load_factor - load["heating"].clip(0)*load_factor)
assert np.allclose(borefield.load.hourly_load_simulation_period, load["cooling"].clip(0) * load_factor - load["heating"].clip(0) * load_factor)
h = borefield.size_L4(150)
assert np.isclose(h, 114.912, rtol=0.001)
load["heating"][8760*25:] = 0
hourly_load = HourlyGeothermalLoadMultiYear(load["heating"].clip(0)*load_factor, load["cooling"].clip(0)*load_factor)
hourly_load = HourlyGeothermalLoadMultiYear(load["heating"].clip(0)*load_factor, load["cooling"].clip(0) * load_factor)
borefield.load = hourly_load
assert np.allclose(borefield.load.hourly_heating_load_simulation_period, load["heating"].clip(0)*load_factor)
assert np.allclose(borefield.load.hourly_heating_load_simulation_period, load["heating"].clip(0) * load_factor)
assert np.allclose(borefield.load.hourly_cooling_load_simulation_period, load["cooling"].clip(0) * load_factor)
assert np.allclose(borefield.load.hourly_load_simulation_period, load["cooling"].clip(0) * load_factor - load["heating"].clip(0)*load_factor)
assert np.allclose(borefield.load.hourly_load_simulation_period, load["cooling"].clip(0) * load_factor - load["heating"].clip(0) * load_factor)
h = borefield.size_L4(150)
assert np.isclose(h, 101.836, rtol=0.001)
#borefield.print_temperature_profile_fixed_depth(h, plot_hourly=True)
#logging.info(h)


def test_multiple_years_L3():
Expand All @@ -49,8 +47,7 @@ def test_multiple_years_L3():
borefield.set_min_avg_fluid_temperature(0)
borefield.set_max_avg_fluid_temperature(17)
load = pd.read_csv(FOLDER.joinpath("test/methods/hourly_data/multiple_years.csv"), sep=",")
# load["heating"][8760*25:] = 0
hourly_load = HourlyGeothermalLoadMultiYear(load["heating"].clip(0)*load_factor, load["cooling"].clip(0)*load_factor)
hourly_load = HourlyGeothermalLoadMultiYear(load["heating"].clip(0)*load_factor, load["cooling"].clip(0) * load_factor)
borefield.load = hourly_load
monthly_heating_load = np.array([np.mean((load["heating"].clip(0)*load_factor)[i-730:i]) for i in range(730, len(load["heating"])+1, 730)])
monthly_cooling_load = np.array([np.mean((load["cooling"].clip(0)*load_factor)[i-730:i]) for i in range(730, len(load["cooling"])+1, 730)])
Expand All @@ -60,28 +57,25 @@ def test_multiple_years_L3():
assert np.allclose(borefield.load.baseload_cooling_power_simulation_period, monthly_cooling_load)
assert np.allclose(borefield.load.baseload_heating_simulation_period, monthly_heating_load * 730)
assert np.allclose(borefield.load.baseload_cooling_simulation_period, monthly_cooling_load * 730)
assert np.allclose(borefield.load.peak_heating, peak_heating)
assert np.allclose(borefield.load.peak_cooling, peak_cooling)
assert np.allclose(borefield.load.peak_heating_simulation_period, peak_heating)
assert np.allclose(borefield.load.peak_cooling_simulation_period, peak_cooling)
assert np.allclose(borefield.load.monthly_average_load_simulation_period, monthly_cooling_load - monthly_heating_load)
h = borefield.size_L3(150)
assert np.isclose(h, 110.233, rtol=0.001)
load["heating"][8760*25:] = 0
hourly_load = HourlyGeothermalLoadMultiYear(load["heating"].clip(0)*load_factor, load["cooling"].clip(0)*load_factor)
hourly_load = HourlyGeothermalLoadMultiYear(load["heating"].clip(0)*load_factor, load["cooling"].clip(0) * load_factor)
borefield.load = hourly_load
monthly_heating_load = np.array([np.mean((load["heating"].clip(0)*load_factor)[i-730:i]) for i in range(730, len(load["heating"])+1, 730)])
monthly_cooling_load = np.array([np.mean((load["cooling"].clip(0)*load_factor)[i-730:i]) for i in range(730, len(load["cooling"])+1, 730)])
peak_heating = [np.max((load["heating"].clip(0)*load_factor)[i-730:i]) for i in range(730, len(load["heating"])+1, 730)]
peak_cooling = [np.max((load["cooling"].clip(0)*load_factor)[i-730:i]) for i in range(730, len(load["cooling"])+1, 730)]
assert np.allclose(borefield.load.baseload_heating_power_simulation_period, monthly_heating_load)
assert np.allclose(borefield.load.baseload_cooling_power_simulation_period, monthly_cooling_load)
assert np.allclose(borefield.load.peak_heating, peak_heating)
assert np.allclose(borefield.load.peak_cooling, peak_cooling)
assert np.allclose(borefield.load.peak_heating_simulation_period, peak_heating)
assert np.allclose(borefield.load.peak_cooling_simulation_period, peak_cooling)
assert np.allclose(borefield.load.monthly_average_load_simulation_period, monthly_cooling_load - monthly_heating_load)
h = borefield.size_L3(150)
assert np.isclose(h, 100.418, rtol=0.001)
# borefield.print_temperature_profile_fixed_depth(h, plot_hourly=False)
#logging.info(borefield.load.peak_heating_duration)
#logging.info(borefield.load.peak_cooling_duration)


def test_multiple_years_L3_monthly_data():
Expand All @@ -95,25 +89,23 @@ def test_multiple_years_L3_monthly_data():
borefield.set_min_avg_fluid_temperature(0)
borefield.set_max_avg_fluid_temperature(17)
load = pd.read_csv(FOLDER.joinpath("test/methods/hourly_data/multiple_years.csv"), sep=",")
# load["heating"][8760*25:] = 0
monthly_heating_load = np.array([np.mean((load["heating"].clip(0)*load_factor)[i-730:i]) for i in range(730, len(load["heating"])+1, 730)])
monthly_cooling_load = np.array([np.mean((load["cooling"].clip(0)*load_factor)[i-730:i]) for i in range(730, len(load["cooling"])+1, 730)])
peak_heating = [np.max((load["heating"].clip(0)*load_factor)[i-730:i]) for i in range(730, len(load["heating"])+1, 730)]
peak_cooling = [np.max((load["cooling"].clip(0)*load_factor)[i-730:i]) for i in range(730, len(load["cooling"])+1, 730)]
hourly_load = MonthlyGeothermalLoadMultiYear(monthly_heating_load * 730, monthly_cooling_load * 730 ,peak_heating, peak_cooling)
borefield.load = hourly_load
monthly_load = MonthlyGeothermalLoadMultiYear(monthly_heating_load * 730, monthly_cooling_load * 730, peak_heating, peak_cooling)
borefield.load = monthly_load
assert np.allclose(borefield.load.baseload_heating_power_simulation_period, monthly_heating_load)
assert np.allclose(borefield.load.baseload_cooling_power_simulation_period, monthly_cooling_load)
assert np.allclose(borefield.load.baseload_heating_simulation_period, monthly_heating_load * 730)
assert np.allclose(borefield.load.baseload_cooling_simulation_period, monthly_cooling_load * 730)
assert np.allclose(borefield.load.peak_heating, peak_heating)
assert np.allclose(borefield.load.peak_cooling, peak_cooling)
assert np.allclose(borefield.load.peak_heating_simulation_period, peak_heating)
assert np.allclose(borefield.load.peak_cooling_simulation_period, peak_cooling)
assert np.allclose(borefield.load.monthly_average_load_simulation_period, monthly_cooling_load - monthly_heating_load)
assert borefield.load.simulation_period == 50
logging.info(borefield.load.peak_heating_duration)
logging.info(borefield.load.peak_cooling_duration)
h = borefield.size_L3(150)
# borefield.print_temperature_profile_fixed_depth(h, plot_hourly=False)
assert np.isclose(h, 110.233, rtol=0.001)
load["heating"][8760*25:] = 0
monthly_heating_load = np.array([np.mean((load["heating"].clip(0)*load_factor)[i-730:i]) for i in range(730, len(load["heating"])+1, 730)])
Expand All @@ -124,10 +116,8 @@ def test_multiple_years_L3_monthly_data():
borefield.load = hourly_load
assert np.allclose(borefield.load.baseload_heating_power_simulation_period, monthly_heating_load)
assert np.allclose(borefield.load.baseload_cooling_power_simulation_period, monthly_cooling_load)
assert np.allclose(borefield.load.peak_heating, peak_heating)
assert np.allclose(borefield.load.peak_cooling, peak_cooling)
assert np.allclose(borefield.load.peak_heating_simulation_period, peak_heating)
assert np.allclose(borefield.load.peak_cooling_simulation_period, peak_cooling)
assert np.allclose(borefield.load.monthly_average_load_simulation_period, monthly_cooling_load - monthly_heating_load)
h = borefield.size_L3(150)
assert np.isclose(h, 100.418, rtol=0.001)
# borefield.print_temperature_profile_fixed_depth(h, plot_hourly=False)
#logging.info(h)
127 changes: 45 additions & 82 deletions GHEtool/test/unit-tests/test_hourly_load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,40 @@ def test_set_hourly_values():
load.set_hourly_cooling(np.ones(10))


def test_start_month_general():
load = HourlyGeothermalLoad()
assert load.start_month == 1
with pytest.raises(ValueError):
load.start_month = 1.5
with pytest.raises(ValueError):
load.start_month = 0
with pytest.raises(ValueError):
load.start_month = 13
load.start_month = 12
assert load.start_month == 12
assert load._start_hour == 11 * 730
load.start_month = 1
assert load.start_month == 1
assert load._start_hour == 0
load.start_month = 3
assert load.start_month == 3
assert load._start_hour == 730 * 2

load.all_months_equal = False
assert load._start_hour == 1416


def test_different_start_month():
load = HourlyGeothermalLoad(np.arange(1, 8761, 1), np.arange(1, 8761, 1))
load.start_month = 3
assert load.start_month == 3
assert load.hourly_cooling_load[0] == 731 * 2 - 1
assert load.hourly_heating_load[0] == 731 * 2 - 1
load.all_months_equal = False
assert load.hourly_cooling_load[0] == 1417
assert load.hourly_heating_load[0] == 1417


### continue for multi year
def test_checks_multiyear():
load = HourlyGeothermalLoadMultiYear()
Expand Down Expand Up @@ -143,16 +177,11 @@ def test_imbalance_multi_year():

def test_set_hourly_values_multi_year():
load = HourlyGeothermalLoadMultiYear()
try:
with pytest.raises(ValueError):
load.set_hourly_heating(np.ones(10))
assert False # pragma: no cover
except ValueError:
assert True
try:
with pytest.raises(ValueError):
load.set_hourly_cooling(np.ones(10))
assert False # pragma: no cover
except ValueError:
assert True


def test_dhw():
load = HourlyGeothermalLoad()
Expand All @@ -161,16 +190,10 @@ def test_dhw():
assert load.dhw == 1000.
load.dhw = 200
assert load.dhw == 200.
try:
with pytest.raises(ValueError):
load.add_dhw('test')
assert False # pragma: no cover
except ValueError:
assert True
try:
with pytest.raises(ValueError):
load.add_dhw(-10)
assert False # pragma: no cover
except ValueError:
assert True

load.dhw = 8760*10
assert np.array_equal(np.full(12, 10), load.peak_heating)
Expand Down Expand Up @@ -243,11 +266,8 @@ def test_add():
simulation_period=30,
dhw=10000)

try:
with pytest.raises(ValueError):
load_1 + 55
assert False # pragma: no cover
except TypeError:
assert True

with pytest.warns():
result = load_1 + load_2
Expand All @@ -258,13 +278,8 @@ def test_add():
assert np.allclose(result.hourly_heating_load, load_1.hourly_heating_load + load_2.hourly_heating_load)

load_2.simulation_period = 20
try:
with pytest.warns():
result = load_1 + load_2
assert False # pragma: no cover
except:
assert True

with pytest.warns():
result = load_1 + load_2
assert result.simulation_period == 20
assert result.dhw == 30000
assert np.allclose(result.hourly_cooling_load, load_1.hourly_cooling_load + load_2.hourly_cooling_load)
Expand Down Expand Up @@ -315,17 +330,11 @@ def test_add_multiyear():
load_2 = HourlyGeothermalLoadMultiYear(cooling_load=np.arange(0, 8760*2, 1) + 1,
heating_load=np.full(8760*2, 3))

try:
with pytest.raises(ValueError):
load_1 + 55
assert False # pragma: no cover
except TypeError:
assert True

try:
with pytest.raises(ValueError):
load_1 + load_2
assert False # pragma: no cover
except ValueError:
assert True

load_1 = HourlyGeothermalLoadMultiYear(heating_load=np.arange(0, 8760 * 2, 1),
cooling_load=np.full(8760 * 2, 2))
Expand Down Expand Up @@ -357,51 +366,5 @@ def test_add_multiyear():
# monthly load
load_2 = MonthlyGeothermalLoadAbsolute(*load_case(1))

try:
with pytest.raises(ValueError):
load_1 + load_2
assert False # pragma: no cover
except TypeError:
assert True


def test_start_month_general():
load = HourlyGeothermalLoad()
assert load.start_month == 1
try:
load.start_month = 1.5
assert False # pragma: no cover
except ValueError:
assert True
try:
load.start_month = 0
assert False # pragma: no cover
except ValueError:
assert True
try:
load.start_month = 13
assert False # pragma: no cover
except ValueError:
assert True
load.start_month = 12
assert load.start_month == 12
assert load._start_hour == 11 * 730
load.start_month = 1
assert load.start_month == 1
assert load._start_hour == 0
load.start_month = 3
assert load.start_month == 3
assert load._start_hour == 730 * 2

load.all_months_equal = False
assert load._start_hour == 1416


def test_different_start_month():
load = HourlyGeothermalLoad(np.arange(1, 8761, 1), np.arange(1, 8761, 1))
load.start_month = 3
assert load.start_month == 3
assert load.hourly_cooling_load[0] == 731 * 2 - 1
assert load.hourly_heating_load[0] == 731 * 2 - 1
load.all_months_equal = False
assert load.hourly_cooling_load[0] == 1417
assert load.hourly_heating_load[0] == 1417
2 changes: 1 addition & 1 deletion GHEtool/test/unit-tests/test_main_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def test_create_custom_dataset():
with pytest.raises(ValueError):
borefield_test.create_custom_dataset([100, 1000], [50, 100])
borefield_test.create_rectangular_borefield(10, 10, 6, 6, 100, 1, 0.075)
with pytest.raises(ValueError):
with pytest.raises(AssertionError):
borefield_test.create_custom_dataset([100, 1000], [50, 100])


Expand Down
18 changes: 6 additions & 12 deletions GHEtool/test/unit-tests/test_monthly_load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,24 +298,16 @@ def test_add():
result = load_1 + load_2
assert result.peak_heating_duration == 18*3600
load_1.peak_heating_duration = 18
try:
with pytest.warns():
result = load_1 + load_2
assert False # pragma: no cover
except:
assert True
with pytest.warns():
result = load_1 + load_2

load_1.peak_cooling_duration = 18
with pytest.warns():
result = load_1 + load_2
assert result.peak_cooling_duration == 18*3600
load_2.peak_cooling_duration = 18
try:
with pytest.warns():
result = load_1 + load_2
assert False # pragma: no cover
except:
assert True
with pytest.warns():
result = load_1 + load_2

# add hourly load
load_hourly = HourlyGeothermalLoad(np.full(8760, 10), np.full(8760, 20), 30, 10000)
Expand Down Expand Up @@ -348,6 +340,7 @@ def test_different_start_month():
assert np.array_equal(load.peak_cooling, result)


### continue for multi year
def test_checks_multiyear_monthly():
load = MonthlyGeothermalLoadMultiYear()
assert not load._check_input(2)
Expand All @@ -361,3 +354,4 @@ def test_checks_multiyear_monthly():
load.baseload_heating = np.ones(13)
with pytest.raises(ValueError):
load.baseload_cooling = np.ones(13)

0 comments on commit e0890e8

Please sign in to comment.