added operational co2 emissions-> NOT WORKING
This commit is contained in:
parent
a519b0e01c
commit
41b9fe4049
80
costs/co2_emission.py
Normal file
80
costs/co2_emission.py
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
"""
|
||||||
|
CO2 emission module
|
||||||
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||||
|
Copyright © 2023 Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||||
|
"""
|
||||||
|
|
||||||
|
from hub.city_model_structure.building import Building
|
||||||
|
import hub.helpers.constants as cte
|
||||||
|
|
||||||
|
|
||||||
|
class Co2Emission:
|
||||||
|
"""
|
||||||
|
Cost class
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, building: Building, emissions_factor=None):
|
||||||
|
if emissions_factor is None:
|
||||||
|
emissions_factor = {cte.GAS: 1,
|
||||||
|
cte.ELECTRICITY: 1,
|
||||||
|
cte.WOOD: 1,
|
||||||
|
cte.DIESEL: 1,
|
||||||
|
cte.RENEWABLE: 0}
|
||||||
|
self._emissions_factor = emissions_factor
|
||||||
|
self._building = building
|
||||||
|
|
||||||
|
@property
|
||||||
|
def building(self) -> Building:
|
||||||
|
"""
|
||||||
|
Get current building.
|
||||||
|
"""
|
||||||
|
return self._building
|
||||||
|
|
||||||
|
@property
|
||||||
|
def operational_co2(self) -> dict:
|
||||||
|
"""
|
||||||
|
Get operational_co2
|
||||||
|
:return: dict
|
||||||
|
"""
|
||||||
|
results = {}
|
||||||
|
for energy_system in self._building.energy_systems:
|
||||||
|
fuel_type = energy_system.generation_system.generic_generation_system.fuel_type
|
||||||
|
for demand_type in energy_system.demand_types:
|
||||||
|
results_by_time_period = {}
|
||||||
|
if str(demand_type).lower() == str(cte.HEATING).lower():
|
||||||
|
for time_period in self._building.heating_consumption:
|
||||||
|
values = []
|
||||||
|
for value in self._building.heating_consumption[time_period]:
|
||||||
|
values.append(value * self._emissions_factor[fuel_type])
|
||||||
|
results_by_time_period[time_period] = values
|
||||||
|
if demand_type == cte.COOLING:
|
||||||
|
for time_period in self._building.cooling_consumption:
|
||||||
|
values = []
|
||||||
|
for value in self._building.cooling_consumption[time_period]:
|
||||||
|
values.append(value * self._emissions_factor[fuel_type])
|
||||||
|
results_by_time_period[time_period] = values
|
||||||
|
if demand_type == cte.DOMESTIC_HOT_WATER:
|
||||||
|
for time_period in self._building.domestic_hot_water_consumption:
|
||||||
|
values = []
|
||||||
|
for value in self._building.domestic_hot_water_consumption[time_period]:
|
||||||
|
values.append(value * self._emissions_factor[fuel_type])
|
||||||
|
results_by_time_period[time_period] = values
|
||||||
|
results[demand_type] = results_by_time_period
|
||||||
|
|
||||||
|
results_by_time_period = {}
|
||||||
|
for time_period in self._building.lighting_electrical_demand:
|
||||||
|
values = []
|
||||||
|
for value in self._building.lighting_electrical_demand[time_period]:
|
||||||
|
values.append(value * self._emissions_factor[cte.ELECTRICITY])
|
||||||
|
results_by_time_period[time_period] = values
|
||||||
|
results[cte.LIGHTING] = results_by_time_period
|
||||||
|
|
||||||
|
results_by_time_period = {}
|
||||||
|
for time_period in self._building.appliances_electrical_demand:
|
||||||
|
values = []
|
||||||
|
for value in self._building.appliances_electrical_demand[time_period]:
|
||||||
|
values.append(value * self._emissions_factor[cte.ELECTRICITY])
|
||||||
|
results_by_time_period[time_period] = values
|
||||||
|
results[cte.APPLIANCES] = results_by_time_period
|
||||||
|
|
||||||
|
return results
|
|
@ -62,13 +62,6 @@ class Cost:
|
||||||
"""
|
"""
|
||||||
return self._building
|
return self._building
|
||||||
|
|
||||||
@building.setter
|
|
||||||
def building(self, value: Building):
|
|
||||||
"""
|
|
||||||
Set current building.
|
|
||||||
"""
|
|
||||||
self._building = value
|
|
||||||
|
|
||||||
def _npv_from_list(self, list_cashflow):
|
def _npv_from_list(self, list_cashflow):
|
||||||
return npf.npv(self._configuration.discount_rate, list_cashflow)
|
return npf.npv(self._configuration.discount_rate, list_cashflow)
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ from hub.helpers.dictionaries import Dictionaries
|
||||||
|
|
||||||
from costs.cost import Cost
|
from costs.cost import Cost
|
||||||
from costs.constants import SKIN_RETROFIT, SKIN_RETROFIT_AND_SYSTEM_RETROFIT_AND_PV, SYSTEM_RETROFIT_AND_PV
|
from costs.constants import SKIN_RETROFIT, SKIN_RETROFIT_AND_SYSTEM_RETROFIT_AND_PV, SYSTEM_RETROFIT_AND_PV
|
||||||
|
from costs.co2_emission import Co2Emission
|
||||||
|
|
||||||
|
|
||||||
class Initialize:
|
class Initialize:
|
||||||
|
@ -81,6 +82,11 @@ class UnitTests(unittest.TestCase):
|
||||||
result = Cost(building, retrofit_scenario=SKIN_RETROFIT_AND_SYSTEM_RETROFIT_AND_PV).life_cycle
|
result = Cost(building, retrofit_scenario=SKIN_RETROFIT_AND_SYSTEM_RETROFIT_AND_PV).life_cycle
|
||||||
self.assertIsNotNone(result)
|
self.assertIsNotNone(result)
|
||||||
|
|
||||||
|
def test_co2_emission(self):
|
||||||
|
for building in self.init.city.buildings:
|
||||||
|
result = Co2Emission(building).operational_co2
|
||||||
|
self.assertIsNotNone(result)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
files = glob.glob('output/[!.]*')
|
files = glob.glob('output/[!.]*')
|
||||||
for file in files:
|
for file in files:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user