Costing initiated

The classes and scripts of costs library are copied in scripts folder
This commit is contained in:
Saeed Ranjbar 2024-04-10 10:27:10 -04:00
parent cfaa783bac
commit 70826837cf
13 changed files with 1002 additions and 2 deletions

View File

@ -1,5 +1,3 @@
import os
from scripts.geojson_creator import process_geojson
from pathlib import Path
import subprocess

View File

@ -0,0 +1,239 @@
"""
Capital costs module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Code contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
Code contributor Oriol Gavalda Torrellas oriol.gavalda@concordia.ca
"""
import math
import pandas as pd
import numpy_financial as npf
from hub.city_model_structure.building import Building
import hub.helpers.constants as cte
from costs.configuration import Configuration
from costs.constants import SKIN_RETROFIT, SKIN_RETROFIT_AND_SYSTEM_RETROFIT_AND_PV, SYSTEM_RETROFIT_AND_PV
from costs.cost_base import CostBase
class CapitalCosts(CostBase):
"""
Capital costs class
"""
def __init__(self, building: Building, configuration: Configuration):
super().__init__(building, configuration)
self._yearly_capital_costs = pd.DataFrame(
index=self._rng,
columns=[
'B2010_opaque_walls',
'B2020_transparent',
'B3010_opaque_roof',
'B10_superstructure',
'D301010_photovoltaic_system',
'D3020_heat_generating_systems',
'D3030_cooling_generation_systems',
'D3040_distribution_systems',
'D3080_other_hvac_ahu',
'D5020_lighting_and_branch_wiring'
],
dtype='float'
)
self._yearly_capital_costs.loc[0, 'B2010_opaque_walls'] = 0
self._yearly_capital_costs.loc[0]['B2020_transparent'] = 0
self._yearly_capital_costs.loc[0, 'B3010_opaque_roof'] = 0
self._yearly_capital_costs.loc[0]['B10_superstructure'] = 0
self._yearly_capital_costs.loc[0, 'D3020_heat_generating_systems'] = 0
self._yearly_capital_costs.loc[0, 'D3030_cooling_generation_systems'] = 0
self._yearly_capital_costs.loc[0, 'D3040_distribution_systems'] = 0
self._yearly_capital_costs.loc[0, 'D3080_other_hvac_ahu'] = 0
self._yearly_capital_costs.loc[0, 'D5020_lighting_and_branch_wiring'] = 0
self._yearly_capital_incomes = pd.DataFrame(
index=self._rng,
columns=[
'Subsidies construction',
'Subsidies HVAC',
'Subsidies PV'
],
dtype='float'
)
self._yearly_capital_incomes.loc[0, 'Subsidies construction'] = 0
self._yearly_capital_incomes.loc[0, 'Subsidies HVAC'] = 0
self._yearly_capital_incomes.loc[0, 'Subsidies PV'] = 0
def calculate(self) -> tuple[pd.DataFrame, pd.DataFrame]:
"""
Calculate capital cost
:return: pd.DataFrame, pd.DataFrame
"""
surface_opaque = 0
surface_transparent = 0
surface_roof = 0
surface_ground = 0
capital_cost_pv = 0
capital_cost_opaque = 0
capital_cost_ground = 0
capital_cost_transparent = 0
capital_cost_roof = 0
capital_cost_heating_equipment = 0
capital_cost_cooling_equipment = 0
capital_cost_distribution_equipment = 0
capital_cost_other_hvac_ahu = 0
capital_cost_lighting = 0
for thermal_zone in self._building.thermal_zones_from_internal_zones:
for thermal_boundary in thermal_zone.thermal_boundaries:
if thermal_boundary.type == 'Ground':
surface_ground += thermal_boundary.opaque_area
elif thermal_boundary.type == 'Roof':
surface_roof += thermal_boundary.opaque_area
elif thermal_boundary.type == 'Wall':
surface_opaque += thermal_boundary.opaque_area * (1 - thermal_boundary.window_ratio)
surface_transparent += thermal_boundary.opaque_area * thermal_boundary.window_ratio
peak_heating = self._building.heating_peak_load[cte.YEAR][0] / 1000
peak_cooling = self._building.cooling_peak_load[cte.YEAR][0] / 1000
surface_pv = 0
for roof in self._building.roofs:
surface_pv += roof.solid_polygon.area * roof.solar_collectors_area_reduction_factor
self._yearly_capital_costs.fillna(0, inplace=True)
own_capital = 1 - self._configuration.percentage_credit
if self._configuration.retrofit_scenario in (SKIN_RETROFIT, SKIN_RETROFIT_AND_SYSTEM_RETROFIT_AND_PV):
chapter = self._capital_costs_chapter.chapter('B_shell')
capital_cost_opaque = surface_opaque * chapter.item('B2010_opaque_walls').refurbishment[0]
capital_cost_transparent = surface_transparent * chapter.item('B2020_transparent').refurbishment[0]
capital_cost_roof = surface_roof * chapter.item('B3010_opaque_roof').refurbishment[0]
capital_cost_ground = surface_ground * chapter.item('B10_superstructure').refurbishment[0]
self._yearly_capital_costs.loc[0, 'B2010_opaque_walls'] = capital_cost_opaque * own_capital
self._yearly_capital_costs.loc[0]['B2020_transparent'] = capital_cost_transparent * own_capital
self._yearly_capital_costs.loc[0, 'B3010_opaque_roof'] = capital_cost_roof * own_capital
self._yearly_capital_costs.loc[0]['B10_superstructure'] = capital_cost_ground * own_capital
if self._configuration.retrofit_scenario in (SYSTEM_RETROFIT_AND_PV, SKIN_RETROFIT_AND_SYSTEM_RETROFIT_AND_PV):
chapter = self._capital_costs_chapter.chapter('D_services')
capital_cost_pv = surface_pv * chapter.item('D301010_photovoltaic_system').initial_investment[0]
capital_cost_heating_equipment = peak_heating * chapter.item('D3020_heat_generating_systems').initial_investment[0]
capital_cost_cooling_equipment = peak_cooling * chapter.item('D3030_cooling_generation_systems').initial_investment[0]
capital_cost_distribution_equipment = peak_cooling * chapter.item('D3040_distribution_systems').initial_investment[0]
capital_cost_other_hvac_ahu = peak_cooling * chapter.item('D3080_other_hvac_ahu').initial_investment[0]
capital_cost_lighting = self._total_floor_area * chapter.item('D5020_lighting_and_branch_wiring').initial_investment[0]
self._yearly_capital_costs.loc[0]['D301010_photovoltaic_system'] = capital_cost_pv
self._yearly_capital_costs.loc[0, 'D3020_heat_generating_systems'] = capital_cost_heating_equipment * own_capital
self._yearly_capital_costs.loc[0, 'D3030_cooling_generation_systems'] = capital_cost_cooling_equipment * own_capital
self._yearly_capital_costs.loc[0, 'D3040_distribution_systems'] = capital_cost_distribution_equipment * own_capital
self._yearly_capital_costs.loc[0, 'D3080_other_hvac_ahu'] = capital_cost_other_hvac_ahu * own_capital
self._yearly_capital_costs.loc[0, 'D5020_lighting_and_branch_wiring'] = capital_cost_lighting * own_capital
for year in range(1, self._configuration.number_of_years):
chapter = self._capital_costs_chapter.chapter('D_services')
costs_increase = math.pow(1 + self._configuration.consumer_price_index, year)
self._yearly_capital_costs.loc[year, 'B2010_opaque_walls'] = (
-npf.pmt(
self._configuration.interest_rate,
self._configuration.credit_years,
capital_cost_opaque * self._configuration.percentage_credit
)
)
self._yearly_capital_costs.loc[year, 'B2020_transparent'] = (
-npf.pmt(
self._configuration.interest_rate,
self._configuration.credit_years,
capital_cost_transparent * self._configuration.percentage_credit
)
)
self._yearly_capital_costs.loc[year, 'B3010_opaque_roof'] = (
-npf.pmt(
self._configuration.interest_rate,
self._configuration.credit_years,
capital_cost_roof * self._configuration.percentage_credit
)
)
self._yearly_capital_costs.loc[year, 'B10_superstructure'] = (
-npf.pmt(
self._configuration.interest_rate,
self._configuration.credit_years,
capital_cost_ground * self._configuration.percentage_credit
)
)
self._yearly_capital_costs.loc[year, 'D3020_heat_generating_systems'] = (
-npf.pmt(
self._configuration.interest_rate,
self._configuration.credit_years,
capital_cost_heating_equipment * self._configuration.percentage_credit
)
)
self._yearly_capital_costs.loc[year, 'D3030_cooling_generation_systems'] = (
-npf.pmt(
self._configuration.interest_rate,
self._configuration.credit_years,
capital_cost_cooling_equipment * self._configuration.percentage_credit
)
)
self._yearly_capital_costs.loc[year, 'D3040_distribution_systems'] = (
-npf.pmt(
self._configuration.interest_rate,
self._configuration.credit_years,
capital_cost_distribution_equipment * self._configuration.percentage_credit
)
)
self._yearly_capital_costs.loc[year, 'D3080_other_hvac_ahu'] = (
-npf.pmt(
self._configuration.interest_rate,
self._configuration.credit_years,
capital_cost_other_hvac_ahu * self._configuration.percentage_credit
)
)
self._yearly_capital_costs.loc[year, 'D5020_lighting_and_branch_wiring'] = (
-npf.pmt(
self._configuration.interest_rate,
self._configuration.credit_years,
capital_cost_lighting * self._configuration.percentage_credit
)
)
if (year % chapter.item('D3020_heat_generating_systems').lifetime) == 0:
reposition_cost_heating_equipment = (
peak_heating * chapter.item('D3020_heat_generating_systems').reposition[0] * costs_increase
)
self._yearly_capital_costs.loc[year, 'D3020_heat_generating_systems'] += reposition_cost_heating_equipment
if (year % chapter.item('D3030_cooling_generation_systems').lifetime) == 0:
reposition_cost_cooling_equipment = (
peak_cooling * chapter.item('D3030_cooling_generation_systems').reposition[0] * costs_increase
)
self._yearly_capital_costs.loc[year, 'D3030_cooling_generation_systems'] += reposition_cost_cooling_equipment
if (year % chapter.item('D3080_other_hvac_ahu').lifetime) == 0:
reposition_cost_hvac_ahu = (
peak_cooling * chapter.item('D3080_other_hvac_ahu').reposition[0] * costs_increase
)
self._yearly_capital_costs.loc[year, 'D3080_other_hvac_ahu'] = reposition_cost_hvac_ahu
if (year % chapter.item('D5020_lighting_and_branch_wiring').lifetime) == 0:
reposition_cost_lighting = (
self._total_floor_area * chapter.item('D5020_lighting_and_branch_wiring').reposition[0] * costs_increase
)
self._yearly_capital_costs.loc[year, 'D5020_lighting_and_branch_wiring'] += reposition_cost_lighting
if self._configuration.retrofit_scenario in (SYSTEM_RETROFIT_AND_PV, SKIN_RETROFIT_AND_SYSTEM_RETROFIT_AND_PV):
if (year % chapter.item('D301010_photovoltaic_system').lifetime) == 0:
self._yearly_capital_costs.loc[year]['D301010_photovoltaic_system'] += (
surface_pv * chapter.item('D301010_photovoltaic_system').reposition[0] * costs_increase
)
capital_cost_skin = capital_cost_opaque + capital_cost_ground + capital_cost_transparent + capital_cost_roof
capital_cost_hvac = (
capital_cost_heating_equipment +
capital_cost_cooling_equipment +
capital_cost_distribution_equipment +
capital_cost_other_hvac_ahu + capital_cost_lighting
)
self._yearly_capital_incomes.loc[0, 'Subsidies construction'] = (
capital_cost_skin * self._archetype.income.construction_subsidy/100
)
self._yearly_capital_incomes.loc[0, 'Subsidies HVAC'] = capital_cost_hvac * self._archetype.income.hvac_subsidy/100
self._yearly_capital_incomes.loc[0, 'Subsidies PV'] = capital_cost_pv * self._archetype.income.photovoltaic_subsidy/100
self._yearly_capital_incomes.fillna(0, inplace=True)
return self._yearly_capital_costs, self._yearly_capital_incomes

View File

@ -0,0 +1,229 @@
"""
Configuration module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Code contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
Code contributor Oriol Gavalda Torrellas oriol.gavalda@concordia.ca
"""
from hub.catalog_factories.costs_catalog_factory import CostsCatalogFactory
from hub.catalog_factories.catalog import Catalog
class Configuration:
"""
Configuration class
"""
def __init__(self,
number_of_years,
percentage_credit,
interest_rate,
credit_years,
consumer_price_index,
electricity_peak_index,
electricity_price_index,
gas_price_index,
discount_rate,
retrofitting_year_construction,
factories_handler,
retrofit_scenario,
fuel_type,
dictionary
):
self._number_of_years = number_of_years
self._percentage_credit = percentage_credit
self._interest_rate = interest_rate
self._credit_years = credit_years
self._consumer_price_index = consumer_price_index
self._electricity_peak_index = electricity_peak_index
self._electricity_price_index = electricity_price_index
self._gas_price_index = gas_price_index
self._discount_rate = discount_rate
self._retrofitting_year_construction = retrofitting_year_construction
self._factories_handler = factories_handler
self._costs_catalog = CostsCatalogFactory(factories_handler).catalog
self._retrofit_scenario = retrofit_scenario
self._fuel_type = fuel_type
self._dictionary = dictionary
@property
def number_of_years(self):
"""
Get number of years
"""
return self._number_of_years
@number_of_years.setter
def number_of_years(self, value):
"""
Set number of years
"""
self._number_of_years = value
@property
def percentage_credit(self):
"""
Get percentage credit
"""
return self._percentage_credit
@percentage_credit.setter
def percentage_credit(self, value):
"""
Set percentage credit
"""
self._percentage_credit = value
@property
def interest_rate(self):
"""
Get interest rate
"""
return self._interest_rate
@interest_rate.setter
def interest_rate(self, value):
"""
Set interest rate
"""
self._interest_rate = value
@property
def credit_years(self):
"""
Get credit years
"""
return self._credit_years
@credit_years.setter
def credit_years(self, value):
"""
Set credit years
"""
self._credit_years = value
@property
def consumer_price_index(self):
"""
Get consumer price index
"""
return self._consumer_price_index
@consumer_price_index.setter
def consumer_price_index(self, value):
"""
Set consumer price index
"""
self._consumer_price_index = value
@property
def electricity_peak_index(self):
"""
Get electricity peak index
"""
return self._electricity_peak_index
@electricity_peak_index.setter
def electricity_peak_index(self, value):
"""
Set electricity peak index
"""
self._electricity_peak_index = value
@property
def electricity_price_index(self):
"""
Get electricity price index
"""
return self._electricity_price_index
@electricity_price_index.setter
def electricity_price_index(self, value):
"""
Set electricity price index
"""
self._electricity_price_index = value
@property
def gas_price_index(self):
"""
Get gas price index
"""
return self._gas_price_index
@gas_price_index.setter
def gas_price_index(self, value):
"""
Set gas price index
"""
self._gas_price_index = value
@property
def discount_rate(self):
"""
Get discount rate
"""
return self._discount_rate
@discount_rate.setter
def discount_rate(self, value):
"""
Set discount rate
"""
self._discount_rate = value
@property
def retrofitting_year_construction(self):
"""
Get retrofitting year construction
"""
return self._retrofitting_year_construction
@retrofitting_year_construction.setter
def retrofitting_year_construction(self, value):
"""
Set retrofitting year construction
"""
self._retrofitting_year_construction = value
@property
def factories_handler(self):
"""
Get factories handler
"""
return self._factories_handler
@factories_handler.setter
def factories_handler(self, value):
"""
Set factories handler
"""
self._factories_handler = value
@property
def costs_catalog(self) -> Catalog:
"""
Get costs catalog
"""
return self._costs_catalog
@property
def retrofit_scenario(self):
"""
Get retrofit scenario
"""
return self._retrofit_scenario
@property
def fuel_type(self):
"""
Get fuel type (0: Electricity, 1: Gas)
"""
return self._fuel_type
@property
def dictionary(self):
"""
Get hub function to cost function dictionary
"""
return self._dictionary

View File

@ -0,0 +1,19 @@
"""
Constants module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Code contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
Code contributor Oriol Gavalda Torrellas oriol.gavalda@concordia.ca
"""
# constants
CURRENT_STATUS = 0
SKIN_RETROFIT = 1
SYSTEM_RETROFIT_AND_PV = 2
SKIN_RETROFIT_AND_SYSTEM_RETROFIT_AND_PV = 3
RETROFITTING_SCENARIOS = [
CURRENT_STATUS,
SKIN_RETROFIT,
SYSTEM_RETROFIT_AND_PV,
SKIN_RETROFIT_AND_SYSTEM_RETROFIT_AND_PV
]

155
scripts/costs/cost.py Normal file
View File

@ -0,0 +1,155 @@
"""
Cost module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Code contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
Code contributor Oriol Gavalda Torrellas oriol.gavalda@concordia.ca
"""
import datetime
import pandas as pd
import numpy_financial as npf
from hub.city_model_structure.building import Building
from hub.helpers.dictionaries import Dictionaries
from costs.configuration import Configuration
from costs import CapitalCosts, EndOfLifeCosts, TotalMaintenanceCosts, TotalOperationalCosts, TotalOperationalIncomes
from costs.constants import CURRENT_STATUS
class Cost:
"""
Cost class
"""
def __init__(self,
building: Building,
number_of_years=31,
percentage_credit=0,
interest_rate=0.04,
credit_years=15,
consumer_price_index=0.04,
electricity_peak_index=0.05,
electricity_price_index=0.05,
gas_price_index=0.05,
discount_rate=0.03,
retrofitting_year_construction=2020,
factories_handler='montreal_custom',
retrofit_scenario=CURRENT_STATUS,
dictionary=None):
if dictionary is None:
dictionary = Dictionaries().hub_function_to_montreal_custom_costs_function
self._building = building
fuel_type = 0
if "gas" in building.energy_systems_archetype_name:
fuel_type = 1
self._configuration = Configuration(number_of_years,
percentage_credit,
interest_rate, credit_years,
consumer_price_index,
electricity_peak_index,
electricity_price_index,
gas_price_index,
discount_rate,
retrofitting_year_construction,
factories_handler,
retrofit_scenario,
fuel_type,
dictionary)
@property
def building(self) -> Building:
"""
Get current building.
"""
return self._building
def _npv_from_list(self, list_cashflow):
return npf.npv(self._configuration.discount_rate, list_cashflow)
@property
def life_cycle(self) -> pd.DataFrame:
"""
Get complete life cycle costs
:return: DataFrame
"""
results = pd.DataFrame()
global_capital_costs, global_capital_incomes = CapitalCosts(self._building, self._configuration).calculate()
global_end_of_life_costs = EndOfLifeCosts(self._building, self._configuration).calculate()
global_operational_costs = TotalOperationalCosts(self._building, self._configuration).calculate()
global_maintenance_costs = TotalMaintenanceCosts(self._building, self._configuration).calculate()
global_operational_incomes = TotalOperationalIncomes(self._building, self._configuration).calculate()
df_capital_costs_skin = (
global_capital_costs['B2010_opaque_walls'] +
global_capital_costs['B2020_transparent'] +
global_capital_costs['B3010_opaque_roof'] +
global_capital_costs['B10_superstructure']
)
df_capital_costs_systems = (
global_capital_costs['D3020_heat_generating_systems'] +
global_capital_costs['D3030_cooling_generation_systems'] +
global_capital_costs['D3080_other_hvac_ahu'] +
global_capital_costs['D5020_lighting_and_branch_wiring'] +
global_capital_costs['D301010_photovoltaic_system']
)
df_end_of_life_costs = global_end_of_life_costs['End_of_life_costs']
df_operational_costs = (
global_operational_costs['Fixed_costs_electricity_peak'] +
global_operational_costs['Fixed_costs_electricity_monthly'] +
global_operational_costs['Variable_costs_electricity'] +
global_operational_costs['Fixed_costs_gas'] +
global_operational_costs['Variable_costs_gas']
)
df_maintenance_costs = (
global_maintenance_costs['Heating_maintenance'] +
global_maintenance_costs['Cooling_maintenance'] +
global_maintenance_costs['PV_maintenance']
)
df_operational_incomes = global_operational_incomes['Incomes electricity']
df_capital_incomes = (
global_capital_incomes['Subsidies construction'] +
global_capital_incomes['Subsidies HVAC'] +
global_capital_incomes['Subsidies PV']
)
life_cycle_costs_capital_skin = self._npv_from_list(df_capital_costs_skin.values.tolist())
life_cycle_costs_capital_systems = self._npv_from_list(df_capital_costs_systems.values.tolist())
life_cycle_costs_end_of_life_costs = self._npv_from_list(df_end_of_life_costs.values.tolist())
life_cycle_operational_costs = self._npv_from_list(df_operational_costs.values.tolist())
life_cycle_maintenance_costs = self._npv_from_list(df_maintenance_costs.values.tolist())
life_cycle_operational_incomes = self._npv_from_list(df_operational_incomes.values.tolist())
life_cycle_capital_incomes = self._npv_from_list(df_capital_incomes.values.tolist())
results[f'Scenario {self._configuration.retrofit_scenario}'] = [
life_cycle_costs_capital_skin,
life_cycle_costs_capital_systems,
life_cycle_costs_end_of_life_costs,
life_cycle_operational_costs,
life_cycle_maintenance_costs,
life_cycle_operational_incomes,
life_cycle_capital_incomes,
global_capital_costs,
global_capital_incomes,
global_end_of_life_costs,
global_operational_costs,
global_maintenance_costs,
global_operational_incomes
]
results.index = [
'total_capital_costs_skin',
'total_capital_costs_systems',
'end_of_life_costs',
'total_operational_costs',
'total_maintenance_costs',
'operational_incomes',
'capital_incomes',
'global_capital_costs',
'global_capital_incomes',
'global_end_of_life_costs',
'global_operational_costs',
'global_maintenance_costs',
'global_operational_incomes'
]
return results

View File

@ -0,0 +1,40 @@
"""
Cost base module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Code contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
Code contributor Oriol Gavalda Torrellas oriol.gavalda@concordia.ca
"""
from hub.city_model_structure.building import Building
from costs.configuration import Configuration
class CostBase:
"""
Abstract base class for the costs
"""
def __init__(self, building: Building, configuration: Configuration):
self._building = building
self._configuration = configuration
self._total_floor_area = 0
for thermal_zone in building.thermal_zones_from_internal_zones:
self._total_floor_area += thermal_zone.total_floor_area
self._archetype = None
self._capital_costs_chapter = None
for archetype in self._configuration.costs_catalog.entries().archetypes:
if configuration.dictionary[str(building.function)] == str(archetype.function):
self._archetype = archetype
self._capital_costs_chapter = self._archetype.capital_cost
break
if not self._archetype:
raise KeyError(f'archetype not found for function {building.function}')
self._rng = range(configuration.number_of_years)
def calculate(self):
"""
Raises not implemented exception
"""
raise NotImplementedError()

View File

@ -0,0 +1,38 @@
"""
End of life costs module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Code contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
Code contributor Oriol Gavalda Torrellas oriol.gavalda@concordia.ca
"""
import math
import pandas as pd
from hub.city_model_structure.building import Building
from costs.configuration import Configuration
from costs.cost_base import CostBase
class EndOfLifeCosts(CostBase):
"""
End of life costs class
"""
def __init__(self, building: Building, configuration: Configuration):
super().__init__(building, configuration)
self._yearly_end_of_life_costs = pd.DataFrame(index=self._rng, columns=['End_of_life_costs'], dtype='float')
def calculate(self):
"""
Calculate end of life costs
:return: pd.DataFrame
"""
archetype = self._archetype
total_floor_area = self._total_floor_area
for year in range(1, self._configuration.number_of_years + 1):
price_increase = math.pow(1 + self._configuration.consumer_price_index, year)
if year == self._configuration.number_of_years:
self._yearly_end_of_life_costs.at[year, 'End_of_life_costs'] = (
total_floor_area * archetype.end_of_life_cost * price_increase
)
self._yearly_end_of_life_costs.fillna(0, inplace=True)
return self._yearly_end_of_life_costs

View File

@ -0,0 +1,56 @@
"""
Peak load module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Code contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
Code contributor Oriol Gavalda Torrellas oriol.gavalda@concordia.ca
"""
import pandas as pd
import hub.helpers.constants as cte
class PeakLoad:
"""
Peak load class
"""
def __init__(self, building):
self._building = building
@property
def electricity_peak_load(self):
"""
Get the electricity peak load in W
"""
array = [None] * 12
heating = 0
cooling = 0
for system in self._building.energy_systems:
if cte.HEATING in system.demand_types:
heating = 1
if cte.COOLING in system.demand_types:
cooling = 1
if cte.MONTH in self._building.heating_peak_load.keys() and cte.MONTH in self._building.cooling_peak_load.keys():
peak_lighting = self._building.lighting_peak_load[cte.YEAR][0]
peak_appliances = self._building.appliances_peak_load[cte.YEAR][0]
monthly_electricity_peak = [0.9 * peak_lighting + 0.7 * peak_appliances] * 12
conditioning_peak = max(self._building.heating_peak_load[cte.MONTH], self._building.cooling_peak_load[cte.MONTH])
for i in range(len(conditioning_peak)):
if cooling == 1 and heating == 1:
conditioning_peak[i] = conditioning_peak[i]
continue
elif cooling == 0:
conditioning_peak[i] = self._building.heating_peak_load[cte.MONTH][i] * heating
else:
conditioning_peak[i] = self._building.cooling_peak_load[cte.MONTH][i] * cooling
monthly_electricity_peak[i] += 0.8 * conditioning_peak[i]
electricity_peak_load_results = pd.DataFrame(
monthly_electricity_peak,
columns=[f'electricity peak load W']
)
else:
electricity_peak_load_results = pd.DataFrame(array, columns=[f'electricity peak load W'])
return electricity_peak_load_results

View File

@ -0,0 +1,65 @@
"""
Total maintenance costs module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Code contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
Code contributor Oriol Gavalda Torrellas oriol.gavalda@concordia.ca
"""
import math
import pandas as pd
from hub.city_model_structure.building import Building
import hub.helpers.constants as cte
from costs.configuration import Configuration
from costs.cost_base import CostBase
class TotalMaintenanceCosts(CostBase):
"""
Total maintenance costs class
"""
def __init__(self, building: Building, configuration: Configuration):
super().__init__(building, configuration)
self._yearly_maintenance_costs = pd.DataFrame(
index=self._rng,
columns=[
'Heating_maintenance',
'Cooling_maintenance',
'PV_maintenance'
],
dtype='float'
)
def calculate(self) -> pd.DataFrame:
"""
Calculate total maintenance costs
:return: pd.DataFrame
"""
building = self._building
archetype = self._archetype
# todo: change area pv when the variable exists
roof_area = 0
for roof in building.roofs:
roof_area += roof.solid_polygon.area
surface_pv = roof_area * 0.5
peak_heating = building.heating_peak_load[cte.YEAR][0]
peak_cooling = building.cooling_peak_load[cte.YEAR][0]
maintenance_heating_0 = peak_heating * archetype.operational_cost.maintenance_heating
maintenance_cooling_0 = peak_cooling * archetype.operational_cost.maintenance_cooling
maintenance_pv_0 = surface_pv * archetype.operational_cost.maintenance_pv
for year in range(1, self._configuration.number_of_years + 1):
costs_increase = math.pow(1 + self._configuration.consumer_price_index, year)
self._yearly_maintenance_costs.loc[year, 'Heating_maintenance'] = (
maintenance_heating_0 * costs_increase
)
self._yearly_maintenance_costs.loc[year, 'Cooling_maintenance'] = (
maintenance_cooling_0 * costs_increase
)
self._yearly_maintenance_costs.loc[year, 'PV_maintenance'] = (
maintenance_pv_0 * costs_increase
)
self._yearly_maintenance_costs.fillna(0, inplace=True)
return self._yearly_maintenance_costs

View File

@ -0,0 +1,107 @@
"""
Total operational costs module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Code contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
Code contributor Oriol Gavalda Torrellas oriol.gavalda@concordia.ca
"""
import math
import pandas as pd
from hub.city_model_structure.building import Building
import hub.helpers.constants as cte
from costs.configuration import Configuration
from costs.cost_base import CostBase
from costs.peak_load import PeakLoad
class TotalOperationalCosts(CostBase):
"""
End of life costs class
"""
def __init__(self, building: Building, configuration: Configuration):
super().__init__(building, configuration)
self._yearly_operational_costs = pd.DataFrame(
index=self._rng,
columns=[
'Fixed_costs_electricity_peak',
'Fixed_costs_electricity_monthly',
'Variable_costs_electricity',
'Fixed_costs_gas',
'Variable_costs_gas'
],
dtype='float'
)
def calculate(self) -> pd.DataFrame:
"""
Calculate total operational costs
:return: pd.DataFrame
"""
building = self._building
archetype = self._archetype
total_floor_area = self._total_floor_area
factor_residential = total_floor_area / 80
# todo: split the heating between fuels
fixed_gas_cost_year_0 = 0
variable_gas_cost_year_0 = 0
electricity_heating = 0
domestic_hot_water_electricity = 0
# todo: each fuel has different units that have to be processed
if self._configuration.fuel_type == 1:
fixed_gas_cost_year_0 = archetype.operational_cost.fuels[1].fixed_monthly * 12 * factor_residential
variable_gas_cost_year_0 = (
(building.heating_consumption[cte.YEAR][0] + building.domestic_hot_water_consumption[cte.YEAR][0])
/ (1000 * cte.WATTS_HOUR_TO_JULES) * archetype.operational_cost.fuels[1].variable[0]
)
if self._configuration.fuel_type == 0:
electricity_heating = building.heating_consumption[cte.YEAR][0] / 1000
domestic_hot_water_electricity = building.domestic_hot_water_consumption[cte.YEAR][0] / 1000
electricity_cooling = building.cooling_consumption[cte.YEAR][0] / 1000
electricity_lighting = building.lighting_electrical_demand[cte.YEAR][0] / 1000
electricity_plug_loads = building.appliances_electrical_demand[cte.YEAR][0] / 1000
electricity_distribution = 0
total_electricity_consumption = (
electricity_heating + electricity_cooling + electricity_lighting + domestic_hot_water_electricity +
electricity_plug_loads + electricity_distribution
)
# todo: change when peak electricity demand is coded. Careful with factor residential
peak_electricity_load = PeakLoad(building).electricity_peak_load
peak_load_value = peak_electricity_load.max(axis=1)
peak_electricity_demand = peak_load_value[1] / 1000 # self._peak_electricity_demand adapted to kW
variable_electricity_cost_year_0 = (
total_electricity_consumption / cte.WATTS_HOUR_TO_JULES * archetype.operational_cost.fuels[0].variable[0]
)
peak_electricity_cost_year_0 = peak_electricity_demand * archetype.operational_cost.fuels[0].fixed_power * 12
monthly_electricity_cost_year_0 = archetype.operational_cost.fuels[0].fixed_monthly * 12 * factor_residential
for year in range(1, self._configuration.number_of_years + 1):
price_increase_electricity = math.pow(1 + self._configuration.electricity_price_index, year)
price_increase_peak_electricity = math.pow(1 + self._configuration.electricity_peak_index, year)
price_increase_gas = math.pow(1 + self._configuration.gas_price_index, year)
self._yearly_operational_costs.at[year, 'Fixed_costs_electricity_peak'] = (
peak_electricity_cost_year_0 * price_increase_peak_electricity
)
self._yearly_operational_costs.at[year, 'Fixed_costs_electricity_monthly'] = (
monthly_electricity_cost_year_0 * price_increase_peak_electricity
)
if not isinstance(variable_electricity_cost_year_0, pd.DataFrame):
variable_costs_electricity = variable_electricity_cost_year_0 * price_increase_electricity
else:
variable_costs_electricity = float(variable_electricity_cost_year_0.iloc[0] * price_increase_electricity)
self._yearly_operational_costs.at[year, 'Variable_costs_electricity'] = (
variable_costs_electricity
)
self._yearly_operational_costs.at[year, 'Fixed_costs_gas'] = fixed_gas_cost_year_0 * price_increase_gas
self._yearly_operational_costs.at[year, 'Variable_costs_gas'] = (
variable_gas_cost_year_0 * price_increase_peak_electricity
)
self._yearly_operational_costs.at[year, 'Variable_costs_gas'] = (
variable_gas_cost_year_0 * price_increase_peak_electricity
)
self._yearly_operational_costs.fillna(0, inplace=True)
return self._yearly_operational_costs

View File

@ -0,0 +1,46 @@
"""
Total operational incomes module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Code contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
Code contributor Oriol Gavalda Torrellas oriol.gavalda@concordia.ca
"""
import math
import pandas as pd
from hub.city_model_structure.building import Building
import hub.helpers.constants as cte
from costs.configuration import Configuration
from costs.cost_base import CostBase
class TotalOperationalIncomes(CostBase):
"""
Total operational incomes class
"""
def __init__(self, building: Building, configuration: Configuration):
super().__init__(building, configuration)
self._yearly_operational_incomes = pd.DataFrame(index=self._rng, columns=['Incomes electricity'], dtype='float')
def calculate(self) -> pd.DataFrame:
"""
Calculate total operational incomes
:return: pd.DataFrame
"""
building = self._building
archetype = self._archetype
if cte.YEAR not in building.onsite_electrical_production:
onsite_electricity_production = 0
else:
onsite_electricity_production = building.onsite_electrical_production[cte.YEAR][0]
for year in range(1, self._configuration.number_of_years + 1):
price_increase_electricity = math.pow(1 + self._configuration.electricity_price_index, year)
# todo: check the adequate assignation of price. Pilar
price_export = archetype.income.electricity_export * cte.WATTS_HOUR_TO_JULES * 1000 # to account for unit change
self._yearly_operational_incomes.loc[year, 'Incomes electricity'] = (
onsite_electricity_production * price_export * price_increase_electricity
)
self._yearly_operational_incomes.fillna(0, inplace=True)
return self._yearly_operational_incomes

8
scripts/costs/version.py Normal file
View File

@ -0,0 +1,8 @@
"""
Cost version number
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Code contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
Code contributor Oriol Gavalda Torrellas oriol.gavalda@concordia.ca
"""
__version__ = '0.1.0.5'