Refactor in building.

heating and cooling are now heating_demand and cooling_demand
This commit is contained in:
Guille Gutierrez 2023-06-05 11:53:47 -04:00
parent c6b986ad1b
commit 5e969986fb
9 changed files with 50 additions and 50 deletions

View File

@ -46,8 +46,8 @@ class Building(CityObject):
self._aliases = None self._aliases = None
self._type = 'building' self._type = 'building'
self._cold_water_temperature = {} self._cold_water_temperature = {}
self._heating = {} self._heating_demand = {}
self._cooling = {} self._cooling_demand = {}
self._lighting_electrical_demand = {} self._lighting_electrical_demand = {}
self._appliances_electrical_demand = {} self._appliances_electrical_demand = {}
self._domestic_hot_water_heat_demand = {} self._domestic_hot_water_heat_demand = {}
@ -291,15 +291,15 @@ class Building(CityObject):
self._cold_water_temperature = value self._cold_water_temperature = value
@property @property
def heating(self) -> dict: def heating_demand(self) -> dict:
""" """
Get heating demand in Wh Get heating demand in Wh
:return: dict{DataFrame(float)} :return: dict{DataFrame(float)}
""" """
return self._heating return self._heating_demand
@heating.setter @heating_demand.setter
def heating(self, value): def heating_demand(self, value):
""" """
Set heating demand in Wh Set heating demand in Wh
:param value: dict{DataFrame(float)} :param value: dict{DataFrame(float)}
@ -307,15 +307,15 @@ class Building(CityObject):
self._heating = value self._heating = value
@property @property
def cooling(self) -> dict: def cooling_demand(self) -> dict:
""" """
Get cooling demand in Wh Get cooling demand in Wh
:return: dict{DataFrame(float)} :return: dict{DataFrame(float)}
""" """
return self._cooling return self._cooling_demand
@cooling.setter @cooling_demand.setter
def cooling(self, value): def cooling_demand(self, value):
""" """
Set cooling demand in Wh Set cooling demand in Wh
:param value: dict{DataFrame(float)} :param value: dict{DataFrame(float)}
@ -377,9 +377,9 @@ class Building(CityObject):
:return: dict{DataFrame(float)} :return: dict{DataFrame(float)}
""" """
results = {} results = {}
if cte.HOUR in self.heating: if cte.HOUR in self.heating_demand:
monthly_values = PeakLoads().\ 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: else:
monthly_values = PeakLoads(self).heating_peak_loads_from_methodology monthly_values = PeakLoads(self).heating_peak_loads_from_methodology
if monthly_values is None: if monthly_values is None:
@ -395,8 +395,8 @@ class Building(CityObject):
:return: dict{DataFrame(float)} :return: dict{DataFrame(float)}
""" """
results = {} results = {}
if cte.HOUR in self.cooling: if cte.HOUR in self.cooling_demand:
monthly_values = PeakLoads().peak_loads_from_hourly(self.cooling[cte.HOUR][next(iter(self.cooling[cte.HOUR]))]) monthly_values = PeakLoads().peak_loads_from_hourly(self.cooling_demand[cte.HOUR][next(iter(self.cooling_demand[cte.HOUR]))])
else: else:
monthly_values = PeakLoads(self).cooling_peak_loads_from_methodology monthly_values = PeakLoads(self).cooling_peak_loads_from_methodology
if monthly_values is None: if monthly_values is None:
@ -562,8 +562,8 @@ class Building(CityObject):
return: dict return: dict
""" """
if len(self._heating_consumption) == 0: if len(self._heating_consumption) == 0:
for heating_demand_key in self.heating: for heating_demand_key in self.heating_demand:
demand = self.heating[heating_demand_key][cte.INSEL_MEB] demand = self.heating_demand[heating_demand_key][cte.INSEL_MEB]
consumption_type = cte.HEATING consumption_type = cte.HEATING
final_energy_consumed = self._calculate_consumption(consumption_type, demand) final_energy_consumed = self._calculate_consumption(consumption_type, demand)
if final_energy_consumed is None: if final_energy_consumed is None:
@ -578,8 +578,8 @@ class Building(CityObject):
return: dict return: dict
""" """
if len(self._cooling_consumption) == 0: if len(self._cooling_consumption) == 0:
for cooling_demand_key in self.cooling: for cooling_demand_key in self.cooling_demand:
demand = self.cooling[cooling_demand_key][cte.INSEL_MEB] demand = self.cooling_demand[cooling_demand_key][cte.INSEL_MEB]
consumption_type = cte.COOLING consumption_type = cte.COOLING
final_energy_consumed = self._calculate_consumption(consumption_type, demand) final_energy_consumed = self._calculate_consumption(consumption_type, demand)
if final_energy_consumed is None: if final_energy_consumed is None:
@ -658,18 +658,18 @@ class Building(CityObject):
if demand_type.lower() == cte.HEATING.lower(): if demand_type.lower() == cte.HEATING.lower():
if _peak_load_type == cte.HEATING.lower(): if _peak_load_type == cte.HEATING.lower():
_consumption_fix_flow = distribution_system.distribution_consumption_fix_flow _consumption_fix_flow = distribution_system.distribution_consumption_fix_flow
for heating_demand_key in self.heating: for heating_demand_key in self.heating_demand:
_consumption = [0]*len(self.heating[heating_demand_key][cte.INSEL_MEB]) _consumption = [0]*len(self.heating_demand[heating_demand_key][cte.INSEL_MEB])
_demand = self.heating[heating_demand_key][cte.INSEL_MEB] _demand = self.heating_demand[heating_demand_key][cte.INSEL_MEB]
for i, _ in enumerate(_consumption): for i, _ in enumerate(_consumption):
_consumption[i] += (parasitic_energy_consumption + consumption_variable_flow) * _demand[i] _consumption[i] += (parasitic_energy_consumption + consumption_variable_flow) * _demand[i]
self._distribution_systems_electrical_consumption[heating_demand_key] = _consumption self._distribution_systems_electrical_consumption[heating_demand_key] = _consumption
if demand_type.lower() == cte.COOLING.lower(): if demand_type.lower() == cte.COOLING.lower():
if _peak_load_type == cte.COOLING.lower(): if _peak_load_type == cte.COOLING.lower():
_consumption_fix_flow = distribution_system.distribution_consumption_fix_flow _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] _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): for i, _ in enumerate(_consumption):
_consumption[i] += (parasitic_energy_consumption + consumption_variable_flow) * _demand[i] _consumption[i] += (parasitic_energy_consumption + consumption_variable_flow) * _demand[i]
self._distribution_systems_electrical_consumption[demand_key] = _consumption self._distribution_systems_electrical_consumption[demand_key] = _consumption

View File

@ -117,11 +117,11 @@ class InselMonthlyEnergyBalance:
file_name = building.name + '.out' file_name = building.name + '.out'
insel_output_file_path = Path(self._base_path / file_name).resolve() insel_output_file_path = Path(self._base_path / file_name).resolve()
if insel_output_file_path.is_file(): if insel_output_file_path.is_file():
building.heating[cte.MONTH], building.cooling[cte.MONTH] = self._conditioning_demand(insel_output_file_path) building.heating_demand[cte.MONTH], building.cooling_demand[cte.MONTH] = self._conditioning_demand(insel_output_file_path)
building.heating[cte.YEAR] = pd.DataFrame( building.heating_demand[cte.YEAR] = pd.DataFrame(
[building.heating[cte.MONTH][cte.INSEL_MEB].astype(float).sum()], columns=[cte.INSEL_MEB] [building.heating_demand[cte.MONTH][cte.INSEL_MEB].astype(float).sum()], columns=[cte.INSEL_MEB]
) )
building.cooling[cte.YEAR] = pd.DataFrame( building.cooling_demand[cte.YEAR] = pd.DataFrame(
[building.cooling[cte.MONTH][cte.INSEL_MEB].astype(float).sum()], columns=[cte.INSEL_MEB] [building.cooling_demand[cte.MONTH][cte.INSEL_MEB].astype(float).sum()], columns=[cte.INSEL_MEB]
) )
self._dhw_and_electric_demand() self._dhw_and_electric_demand()

View File

@ -96,8 +96,8 @@ class TestConstructionFactory(TestCase):
self.assertIsNotNone(building.function, 'building function is none') self.assertIsNotNone(building.function, 'building function is none')
self.assertIsNotNone(building.average_storey_height, 'building average_storey_height 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.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.heating_demand), 0, 'building heating is not none')
self.assertEqual(len(building.cooling), 0, 'building cooling 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.eave_height, 'building eave height is none')
self.assertIsNotNone(building.roof_type, 'building roof type is none') self.assertIsNotNone(building.roof_type, 'building roof type is none')
self.assertIsNotNone(building.floor_area, 'building floor_area is none') self.assertIsNotNone(building.floor_area, 'building floor_area is none')

View File

@ -198,17 +198,17 @@ TestDBFactory
city_objects_id = [] city_objects_id = []
for building in control.city.buildings: for building in control.city.buildings:
_building = control.database.building_info(building.name, city_id) _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') print(f'building {building.name} not calculated')
continue continue
monthly_cooling_peak_load = building.cooling_peak_load[cte.MONTH] monthly_cooling_peak_load = building.cooling_peak_load[cte.MONTH]
yearly_cooling_peak_load = building.cooling_peak_load[cte.YEAR] yearly_cooling_peak_load = building.cooling_peak_load[cte.YEAR]
monthly_heating_peak_load = building.heating_peak_load[cte.MONTH] monthly_heating_peak_load = building.heating_peak_load[cte.MONTH]
yearly_heating_peak_load = building.heating_peak_load[cte.YEAR] yearly_heating_peak_load = building.heating_peak_load[cte.YEAR]
monthly_cooling_demand = building.cooling[cte.MONTH][cte.INSEL_MEB] monthly_cooling_demand = building.cooling_demand[cte.MONTH][cte.INSEL_MEB]
yearly_cooling_demand = building.cooling[cte.YEAR][cte.INSEL_MEB] yearly_cooling_demand = building.cooling_demand[cte.YEAR][cte.INSEL_MEB]
monthly_heating_demand = building.heating[cte.MONTH][cte.INSEL_MEB] monthly_heating_demand = building.heating_demand[cte.MONTH][cte.INSEL_MEB]
yearly_heating_demand = building.heating[cte.YEAR][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] 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] 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] monthly_appliances_electrical_demand = building.appliances_electrical_demand[cte.MONTH][cte.INSEL_MEB]

View File

@ -58,10 +58,10 @@ class TestExports(TestCase):
self._complete_city.climate_reference_city = 'Summerland' 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] 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: for building in self._complete_city.buildings:
building.heating[cte.MONTH] = pd.DataFrame({'INSEL': dummy_measures}) building.heating_demand[cte.MONTH] = pd.DataFrame({'INSEL': dummy_measures})
building.cooling[cte.MONTH] = pd.DataFrame({'INSEL': dummy_measures}) building.cooling_demand[cte.MONTH] = pd.DataFrame({'INSEL': dummy_measures})
building.heating[cte.YEAR] = pd.DataFrame({'INSEL': [0.0]}) building.heating_demand[cte.YEAR] = pd.DataFrame({'INSEL': [0.0]})
building.cooling[cte.YEAR] = pd.DataFrame({'INSEL': [0.0]}) building.cooling_demand[cte.YEAR] = pd.DataFrame({'INSEL': [0.0]})
return self._complete_city return self._complete_city
def _export(self, export_type, from_pickle=False): def _export(self, export_type, from_pickle=False):

View File

@ -68,8 +68,8 @@ class TestGeometryFactory(TestCase):
self.assertIsNone(building.terrains, 'building terrains is not none') 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.average_storey_height, 'building average_storey_height is not none')
self.assertIsNone(building.storeys_above_ground, 'building storeys_above_ground 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.heating_demand), 0, 'building heating is not none')
self.assertEqual(len(building.cooling), 0, 'building cooling 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.eave_height, 'building eave height is none')
self.assertIsNotNone(building.roof_type, 'building roof type is none') self.assertIsNotNone(building.roof_type, 'building roof type is none')
self.assertIsNotNone(building.floor_area, 'building floor_area is none') self.assertIsNotNone(building.floor_area, 'building floor_area is none')

View File

@ -62,10 +62,10 @@ class TestResultsImport(TestCase):
ResultFactory('insel_monthly_energy_balance', self._city, self._output_path).enrich() ResultFactory('insel_monthly_energy_balance', self._city, self._output_path).enrich()
# Check that all the buildings have heating and cooling values # Check that all the buildings have heating and cooling values
for building in self._city.buildings: for building in self._city.buildings:
self.assertIsNotNone(building.heating[cte.MONTH][cte.INSEL_MEB]) self.assertIsNotNone(building.heating_demand[cte.MONTH][cte.INSEL_MEB])
self.assertIsNotNone(building.cooling[cte.MONTH][cte.INSEL_MEB]) self.assertIsNotNone(building.cooling_demand[cte.MONTH][cte.INSEL_MEB])
self.assertIsNotNone(building.heating[cte.YEAR][cte.INSEL_MEB]) self.assertIsNotNone(building.heating_demand[cte.YEAR][cte.INSEL_MEB])
self.assertIsNotNone(building.cooling[cte.YEAR][cte.INSEL_MEB]) self.assertIsNotNone(building.cooling_demand[cte.YEAR][cte.INSEL_MEB])
def test_peak_loads(self): def test_peak_loads(self):
# todo: this is not technically a import # 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 for _ in range(12)]
expected_monthly_list[0] = 1000 expected_monthly_list[0] = 1000
for building in self._city.buildings: for building in self._city.buildings:
building.heating[cte.HOUR] = pd.DataFrame(values, columns=['dummy']) building.heating_demand[cte.HOUR] = pd.DataFrame(values, columns=['dummy'])
building.cooling[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.heating_peak_load)
self.assertIsNotNone(building.cooling_peak_load) self.assertIsNotNone(building.cooling_peak_load)

View File

@ -109,6 +109,6 @@ class TestSystemsFactory(TestCase):
for building in self._city.buildings: for building in self._city.buildings:
self.assertLess(0, building.heating_consumption[cte.YEAR][0]) 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.domestic_hot_water_consumption[cte.YEAR][0])
self.assertLess(0, building.onsite_electrical_production[cte.YEAR][0]) self.assertLess(0, building.onsite_electrical_production[cte.YEAR][0])

View File

@ -59,8 +59,8 @@ class TestUsageFactory(TestCase):
self.assertIsNone(building.terrains, 'building terrains is not none') self.assertIsNone(building.terrains, 'building terrains is not none')
self.assertIsNotNone(building.year_of_construction, 'building year_of_construction is none') self.assertIsNotNone(building.year_of_construction, 'building year_of_construction is none')
self.assertIsNotNone(building.function, 'building function 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.heating_demand), 0, 'building heating is not none')
self.assertEqual(len(building.cooling), 0, 'building cooling 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.eave_height, 'building eave height is none')
self.assertIsNotNone(building.roof_type, 'building roof type is none') self.assertIsNotNone(building.roof_type, 'building roof type is none')
self.assertIsNotNone(building.floor_area, 'building floor_area is none') self.assertIsNotNone(building.floor_area, 'building floor_area is none')