From 5e969986fbc75e2603a268563bbf29048a44e0e0 Mon Sep 17 00:00:00 2001 From: guille Date: Mon, 5 Jun 2023 11:53:47 -0400 Subject: [PATCH] Refactor in building. heating and cooling are now heating_demand and cooling_demand --- hub/city_model_structure/building.py | 46 +++++++++---------- .../results/insel_monthly_energry_balance.py | 10 ++-- tests/test_construction_factory.py | 4 +- tests/test_db_factory.py | 10 ++-- tests/test_exports.py | 8 ++-- tests/test_geometry_factory.py | 4 +- tests/test_results_import.py | 12 ++--- tests/test_systems_factory.py | 2 +- tests/test_usage_factory.py | 4 +- 9 files changed, 50 insertions(+), 50 deletions(-) diff --git a/hub/city_model_structure/building.py b/hub/city_model_structure/building.py index 9f9ef7d8..c21b1621 100644 --- a/hub/city_model_structure/building.py +++ b/hub/city_model_structure/building.py @@ -46,8 +46,8 @@ class Building(CityObject): self._aliases = None self._type = 'building' self._cold_water_temperature = {} - self._heating = {} - self._cooling = {} + self._heating_demand = {} + self._cooling_demand = {} self._lighting_electrical_demand = {} self._appliances_electrical_demand = {} self._domestic_hot_water_heat_demand = {} @@ -291,15 +291,15 @@ class Building(CityObject): self._cold_water_temperature = value @property - def heating(self) -> dict: + def heating_demand(self) -> dict: """ Get heating demand in Wh :return: dict{DataFrame(float)} """ - return self._heating + return self._heating_demand - @heating.setter - def heating(self, value): + @heating_demand.setter + def heating_demand(self, value): """ Set heating demand in Wh :param value: dict{DataFrame(float)} @@ -307,15 +307,15 @@ class Building(CityObject): self._heating = value @property - def cooling(self) -> dict: + def cooling_demand(self) -> dict: """ Get cooling demand in Wh :return: dict{DataFrame(float)} """ - return self._cooling + return self._cooling_demand - @cooling.setter - def cooling(self, value): + @cooling_demand.setter + def cooling_demand(self, value): """ Set cooling demand in Wh :param value: dict{DataFrame(float)} @@ -377,9 +377,9 @@ class Building(CityObject): :return: dict{DataFrame(float)} """ results = {} - if cte.HOUR in self.heating: + if cte.HOUR in self.heating_demand: monthly_values = PeakLoads().\ - peak_loads_from_hourly(self.heating[cte.HOUR][next(iter(self.heating[cte.HOUR]))]) + peak_loads_from_hourly(self.heating_demand[cte.HOUR][next(iter(self.heating_demand[cte.HOUR]))]) else: monthly_values = PeakLoads(self).heating_peak_loads_from_methodology if monthly_values is None: @@ -395,8 +395,8 @@ class Building(CityObject): :return: dict{DataFrame(float)} """ results = {} - if cte.HOUR in self.cooling: - monthly_values = PeakLoads().peak_loads_from_hourly(self.cooling[cte.HOUR][next(iter(self.cooling[cte.HOUR]))]) + if cte.HOUR in self.cooling_demand: + monthly_values = PeakLoads().peak_loads_from_hourly(self.cooling_demand[cte.HOUR][next(iter(self.cooling_demand[cte.HOUR]))]) else: monthly_values = PeakLoads(self).cooling_peak_loads_from_methodology if monthly_values is None: @@ -562,8 +562,8 @@ class Building(CityObject): return: dict """ if len(self._heating_consumption) == 0: - for heating_demand_key in self.heating: - demand = self.heating[heating_demand_key][cte.INSEL_MEB] + for heating_demand_key in self.heating_demand: + demand = self.heating_demand[heating_demand_key][cte.INSEL_MEB] consumption_type = cte.HEATING final_energy_consumed = self._calculate_consumption(consumption_type, demand) if final_energy_consumed is None: @@ -578,8 +578,8 @@ class Building(CityObject): return: dict """ if len(self._cooling_consumption) == 0: - for cooling_demand_key in self.cooling: - demand = self.cooling[cooling_demand_key][cte.INSEL_MEB] + for cooling_demand_key in self.cooling_demand: + demand = self.cooling_demand[cooling_demand_key][cte.INSEL_MEB] consumption_type = cte.COOLING final_energy_consumed = self._calculate_consumption(consumption_type, demand) if final_energy_consumed is None: @@ -658,18 +658,18 @@ class Building(CityObject): if demand_type.lower() == cte.HEATING.lower(): if _peak_load_type == cte.HEATING.lower(): _consumption_fix_flow = distribution_system.distribution_consumption_fix_flow - for heating_demand_key in self.heating: - _consumption = [0]*len(self.heating[heating_demand_key][cte.INSEL_MEB]) - _demand = self.heating[heating_demand_key][cte.INSEL_MEB] + for heating_demand_key in self.heating_demand: + _consumption = [0]*len(self.heating_demand[heating_demand_key][cte.INSEL_MEB]) + _demand = self.heating_demand[heating_demand_key][cte.INSEL_MEB] for i, _ in enumerate(_consumption): _consumption[i] += (parasitic_energy_consumption + consumption_variable_flow) * _demand[i] self._distribution_systems_electrical_consumption[heating_demand_key] = _consumption if demand_type.lower() == cte.COOLING.lower(): if _peak_load_type == cte.COOLING.lower(): _consumption_fix_flow = distribution_system.distribution_consumption_fix_flow - for demand_key in self.cooling: + for demand_key in self.cooling_demand: _consumption = self._distribution_systems_electrical_consumption[demand_key] - _demand = self.cooling[demand_key][cte.INSEL_MEB] + _demand = self.cooling_demand[demand_key][cte.INSEL_MEB] for i, _ in enumerate(_consumption): _consumption[i] += (parasitic_energy_consumption + consumption_variable_flow) * _demand[i] self._distribution_systems_electrical_consumption[demand_key] = _consumption diff --git a/hub/imports/results/insel_monthly_energry_balance.py b/hub/imports/results/insel_monthly_energry_balance.py index 3446a44c..4450991d 100644 --- a/hub/imports/results/insel_monthly_energry_balance.py +++ b/hub/imports/results/insel_monthly_energry_balance.py @@ -117,11 +117,11 @@ class InselMonthlyEnergyBalance: file_name = building.name + '.out' insel_output_file_path = Path(self._base_path / file_name).resolve() if insel_output_file_path.is_file(): - building.heating[cte.MONTH], building.cooling[cte.MONTH] = self._conditioning_demand(insel_output_file_path) - building.heating[cte.YEAR] = pd.DataFrame( - [building.heating[cte.MONTH][cte.INSEL_MEB].astype(float).sum()], columns=[cte.INSEL_MEB] + building.heating_demand[cte.MONTH], building.cooling_demand[cte.MONTH] = self._conditioning_demand(insel_output_file_path) + building.heating_demand[cte.YEAR] = pd.DataFrame( + [building.heating_demand[cte.MONTH][cte.INSEL_MEB].astype(float).sum()], columns=[cte.INSEL_MEB] ) - building.cooling[cte.YEAR] = pd.DataFrame( - [building.cooling[cte.MONTH][cte.INSEL_MEB].astype(float).sum()], columns=[cte.INSEL_MEB] + building.cooling_demand[cte.YEAR] = pd.DataFrame( + [building.cooling_demand[cte.MONTH][cte.INSEL_MEB].astype(float).sum()], columns=[cte.INSEL_MEB] ) self._dhw_and_electric_demand() diff --git a/tests/test_construction_factory.py b/tests/test_construction_factory.py index fe2fbda1..b5438581 100644 --- a/tests/test_construction_factory.py +++ b/tests/test_construction_factory.py @@ -96,8 +96,8 @@ class TestConstructionFactory(TestCase): self.assertIsNotNone(building.function, 'building function is none') self.assertIsNotNone(building.average_storey_height, 'building average_storey_height is none') self.assertIsNotNone(building.storeys_above_ground, 'building storeys_above_ground is none') - self.assertEqual(len(building.heating), 0, 'building heating is not none') - self.assertEqual(len(building.cooling), 0, 'building cooling is not none') + self.assertEqual(len(building.heating_demand), 0, 'building heating is not none') + self.assertEqual(len(building.cooling_demand), 0, 'building cooling is not none') self.assertIsNotNone(building.eave_height, 'building eave height is none') self.assertIsNotNone(building.roof_type, 'building roof type is none') self.assertIsNotNone(building.floor_area, 'building floor_area is none') diff --git a/tests/test_db_factory.py b/tests/test_db_factory.py index 30c19651..8f3d5b00 100644 --- a/tests/test_db_factory.py +++ b/tests/test_db_factory.py @@ -198,17 +198,17 @@ TestDBFactory city_objects_id = [] for building in control.city.buildings: _building = control.database.building_info(building.name, city_id) - if cte.MONTH not in building.cooling: + if cte.MONTH not in building.cooling_demand: print(f'building {building.name} not calculated') continue monthly_cooling_peak_load = building.cooling_peak_load[cte.MONTH] yearly_cooling_peak_load = building.cooling_peak_load[cte.YEAR] monthly_heating_peak_load = building.heating_peak_load[cte.MONTH] yearly_heating_peak_load = building.heating_peak_load[cte.YEAR] - monthly_cooling_demand = building.cooling[cte.MONTH][cte.INSEL_MEB] - yearly_cooling_demand = building.cooling[cte.YEAR][cte.INSEL_MEB] - monthly_heating_demand = building.heating[cte.MONTH][cte.INSEL_MEB] - yearly_heating_demand = building.heating[cte.YEAR][cte.INSEL_MEB] + monthly_cooling_demand = building.cooling_demand[cte.MONTH][cte.INSEL_MEB] + yearly_cooling_demand = building.cooling_demand[cte.YEAR][cte.INSEL_MEB] + monthly_heating_demand = building.heating_demand[cte.MONTH][cte.INSEL_MEB] + yearly_heating_demand = building.heating_demand[cte.YEAR][cte.INSEL_MEB] monthly_lighting_electrical_demand = building.lighting_electrical_demand[cte.MONTH][cte.INSEL_MEB] yearly_lighting_electrical_demand = building.lighting_electrical_demand[cte.YEAR][cte.INSEL_MEB] monthly_appliances_electrical_demand = building.appliances_electrical_demand[cte.MONTH][cte.INSEL_MEB] diff --git a/tests/test_exports.py b/tests/test_exports.py index ff53a8a6..82aeb8a1 100644 --- a/tests/test_exports.py +++ b/tests/test_exports.py @@ -58,10 +58,10 @@ class TestExports(TestCase): self._complete_city.climate_reference_city = 'Summerland' dummy_measures = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] for building in self._complete_city.buildings: - building.heating[cte.MONTH] = pd.DataFrame({'INSEL': dummy_measures}) - building.cooling[cte.MONTH] = pd.DataFrame({'INSEL': dummy_measures}) - building.heating[cte.YEAR] = pd.DataFrame({'INSEL': [0.0]}) - building.cooling[cte.YEAR] = pd.DataFrame({'INSEL': [0.0]}) + building.heating_demand[cte.MONTH] = pd.DataFrame({'INSEL': dummy_measures}) + building.cooling_demand[cte.MONTH] = pd.DataFrame({'INSEL': dummy_measures}) + building.heating_demand[cte.YEAR] = pd.DataFrame({'INSEL': [0.0]}) + building.cooling_demand[cte.YEAR] = pd.DataFrame({'INSEL': [0.0]}) return self._complete_city def _export(self, export_type, from_pickle=False): diff --git a/tests/test_geometry_factory.py b/tests/test_geometry_factory.py index fbcc1827..55634c06 100644 --- a/tests/test_geometry_factory.py +++ b/tests/test_geometry_factory.py @@ -68,8 +68,8 @@ class TestGeometryFactory(TestCase): self.assertIsNone(building.terrains, 'building terrains is not none') self.assertIsNone(building.average_storey_height, 'building average_storey_height is not none') self.assertIsNone(building.storeys_above_ground, 'building storeys_above_ground is not none') - self.assertEqual(len(building.heating), 0, 'building heating is not none') - self.assertEqual(len(building.cooling), 0, 'building cooling is not none') + self.assertEqual(len(building.heating_demand), 0, 'building heating is not none') + self.assertEqual(len(building.cooling_demand), 0, 'building cooling is not none') self.assertIsNotNone(building.eave_height, 'building eave height is none') self.assertIsNotNone(building.roof_type, 'building roof type is none') self.assertIsNotNone(building.floor_area, 'building floor_area is none') diff --git a/tests/test_results_import.py b/tests/test_results_import.py index 30f8b5b4..f86f000f 100644 --- a/tests/test_results_import.py +++ b/tests/test_results_import.py @@ -62,10 +62,10 @@ class TestResultsImport(TestCase): ResultFactory('insel_monthly_energy_balance', self._city, self._output_path).enrich() # Check that all the buildings have heating and cooling values for building in self._city.buildings: - self.assertIsNotNone(building.heating[cte.MONTH][cte.INSEL_MEB]) - self.assertIsNotNone(building.cooling[cte.MONTH][cte.INSEL_MEB]) - self.assertIsNotNone(building.heating[cte.YEAR][cte.INSEL_MEB]) - self.assertIsNotNone(building.cooling[cte.YEAR][cte.INSEL_MEB]) + self.assertIsNotNone(building.heating_demand[cte.MONTH][cte.INSEL_MEB]) + self.assertIsNotNone(building.cooling_demand[cte.MONTH][cte.INSEL_MEB]) + self.assertIsNotNone(building.heating_demand[cte.YEAR][cte.INSEL_MEB]) + self.assertIsNotNone(building.cooling_demand[cte.YEAR][cte.INSEL_MEB]) def test_peak_loads(self): # todo: this is not technically a import @@ -83,7 +83,7 @@ class TestResultsImport(TestCase): expected_monthly_list = [0 for _ in range(12)] expected_monthly_list[0] = 1000 for building in self._city.buildings: - building.heating[cte.HOUR] = pd.DataFrame(values, columns=['dummy']) - building.cooling[cte.HOUR] = pd.DataFrame(values, columns=['dummy']) + building.heating_demand[cte.HOUR] = pd.DataFrame(values, columns=['dummy']) + building.cooling_demand[cte.HOUR] = pd.DataFrame(values, columns=['dummy']) self.assertIsNotNone(building.heating_peak_load) self.assertIsNotNone(building.cooling_peak_load) diff --git a/tests/test_systems_factory.py b/tests/test_systems_factory.py index 05b73f00..ac322c88 100644 --- a/tests/test_systems_factory.py +++ b/tests/test_systems_factory.py @@ -109,6 +109,6 @@ class TestSystemsFactory(TestCase): for building in self._city.buildings: self.assertLess(0, building.heating_consumption[cte.YEAR][0]) - self.assertEqual(0, building.cooling_consumption[cte.YEAR][0]) + self.assertLess(0, building.cooling_consumption[cte.YEAR][0]) self.assertLess(0, building.domestic_hot_water_consumption[cte.YEAR][0]) self.assertLess(0, building.onsite_electrical_production[cte.YEAR][0]) diff --git a/tests/test_usage_factory.py b/tests/test_usage_factory.py index cbd0eb6e..506debed 100644 --- a/tests/test_usage_factory.py +++ b/tests/test_usage_factory.py @@ -59,8 +59,8 @@ class TestUsageFactory(TestCase): self.assertIsNone(building.terrains, 'building terrains is not none') self.assertIsNotNone(building.year_of_construction, 'building year_of_construction is none') self.assertIsNotNone(building.function, 'building function is none') - self.assertEqual(len(building.heating), 0, 'building heating is not none') - self.assertEqual(len(building.cooling), 0, 'building cooling is not none') + self.assertEqual(len(building.heating_demand), 0, 'building heating is not none') + self.assertEqual(len(building.cooling_demand), 0, 'building cooling is not none') self.assertIsNotNone(building.eave_height, 'building eave height is none') self.assertIsNotNone(building.roof_type, 'building roof type is none') self.assertIsNotNone(building.floor_area, 'building floor_area is none')