2022-11-02 17:28:51 -04:00
|
|
|
"""
|
|
|
|
Costs Workflow
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
2023-05-30 15:08:11 -04:00
|
|
|
Copyright © 2022 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
|
|
|
Code contributor Oriol Gavalda Torrellas oriol.gavalda@concordia.ca
|
2022-11-02 17:28:51 -04:00
|
|
|
"""
|
|
|
|
|
2023-04-25 09:22:44 -04:00
|
|
|
import glob
|
|
|
|
import os
|
2023-04-26 16:26:06 -04:00
|
|
|
from pathlib import Path
|
2023-05-01 16:38:45 -04:00
|
|
|
|
2023-05-30 14:42:49 -04:00
|
|
|
import numpy_financial as npf
|
|
|
|
import pandas as pd
|
|
|
|
from energy_systems_sizing import EnergySystemsSizing
|
|
|
|
from hub.catalog_factories.costs_catalog_factory import CostCatalogFactory
|
2023-04-25 09:22:44 -04:00
|
|
|
from hub.helpers.dictionaries import Dictionaries
|
2023-05-30 14:42:49 -04:00
|
|
|
from hub.imports.construction_factory import ConstructionFactory
|
|
|
|
from hub.imports.energy_systems_factory import EnergySystemsFactory
|
2023-04-25 09:22:44 -04:00
|
|
|
from hub.imports.geometry_factory import GeometryFactory
|
2023-05-01 16:38:45 -04:00
|
|
|
from hub.imports.usage_factory import UsageFactory
|
|
|
|
from hub.imports.weather_factory import WeatherFactory
|
2023-05-31 11:23:23 -04:00
|
|
|
from hub.helpers import constants as cte
|
2023-05-01 16:38:45 -04:00
|
|
|
from monthly_energy_balance_engine import MonthlyEnergyBalanceEngine
|
|
|
|
from sra_engine import SraEngine
|
2022-11-02 17:28:51 -04:00
|
|
|
|
2023-04-26 16:26:06 -04:00
|
|
|
from life_cycle_costs import LifeCycleCosts
|
|
|
|
|
2023-05-30 14:42:49 -04:00
|
|
|
|
2023-05-29 09:17:07 -04:00
|
|
|
def _npv_from_list(npv_discount_rate, list_cashflow):
|
2023-05-29 22:10:43 -04:00
|
|
|
lcc_value = npf.npv(npv_discount_rate, list_cashflow)
|
2023-05-29 09:17:07 -04:00
|
|
|
return lcc_value
|
2023-05-29 09:08:06 -04:00
|
|
|
|
2023-05-30 15:08:11 -04:00
|
|
|
|
2023-04-26 16:26:06 -04:00
|
|
|
def _search_archetype(costs_catalog, building_function):
|
|
|
|
costs_archetypes = costs_catalog.entries('archetypes').archetypes
|
|
|
|
for building_archetype in costs_archetypes:
|
|
|
|
if str(building_function) == str(building_archetype.function):
|
|
|
|
return building_archetype
|
|
|
|
raise KeyError('archetype not found')
|
|
|
|
|
2023-05-30 15:08:11 -04:00
|
|
|
|
|
|
|
file_path = (Path(__file__).parent.parent / 'costs_workflow' / 'input_files' / 'selected_building_2864.geojson')
|
2023-05-01 16:38:45 -04:00
|
|
|
climate_reference_city = 'Montreal'
|
|
|
|
weather_file = 'CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw'
|
|
|
|
weather_format = 'epw'
|
|
|
|
construction_format = 'nrcan'
|
2023-05-27 09:32:42 -04:00
|
|
|
usage_format = 'comnet'
|
|
|
|
energy_systems_format = 'montreal_custom'
|
2023-05-01 16:38:45 -04:00
|
|
|
attic_heated_case = 0
|
|
|
|
basement_heated_case = 1
|
2023-05-30 15:08:11 -04:00
|
|
|
tmp_folder = (Path(__file__).parent.parent / 'monthly_energy_balance_workflow' / 'tmp')
|
2023-04-25 09:22:44 -04:00
|
|
|
out_path = (Path(__file__).parent.parent / 'costs_workflow' / 'out_files')
|
|
|
|
files = glob.glob(f'{out_path}/*')
|
2023-05-01 16:38:45 -04:00
|
|
|
|
2023-04-25 09:22:44 -04:00
|
|
|
for file in files:
|
|
|
|
if file != '.gitignore':
|
|
|
|
os.remove(file)
|
2022-11-02 17:28:51 -04:00
|
|
|
|
2023-05-29 22:10:43 -04:00
|
|
|
number_of_years = 31
|
2023-04-25 18:33:09 -04:00
|
|
|
consumer_price_index = 0.04
|
2023-05-29 08:06:58 -04:00
|
|
|
electricity_peak_index = 0.05
|
|
|
|
electricity_price_index = 0.05
|
|
|
|
gas_price_index = 0.05
|
2023-04-25 21:00:19 -04:00
|
|
|
discount_rate = 0.03
|
2023-05-30 15:08:11 -04:00
|
|
|
retrofitting_year_of_construction = 2020
|
2023-04-27 10:20:14 -04:00
|
|
|
|
2023-04-26 16:26:06 -04:00
|
|
|
retrofitting_scenarios = [0, 1, 2, 3]
|
2023-05-01 16:38:45 -04:00
|
|
|
life_cycle_results = pd.DataFrame()
|
2023-05-27 09:32:42 -04:00
|
|
|
print('[city creation start]')
|
|
|
|
city = GeometryFactory('geojson',
|
|
|
|
path=file_path,
|
|
|
|
height_field='heightmax',
|
|
|
|
year_of_construction_field='ANNEE_CONS',
|
|
|
|
function_field='CODE_UTILI',
|
|
|
|
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
|
|
|
|
city.climate_reference_city = climate_reference_city
|
|
|
|
city.climate_file = (tmp_folder / f'{climate_reference_city}.cli').resolve()
|
|
|
|
print(f'city created from {file_path}')
|
|
|
|
WeatherFactory(weather_format, city, file_name=weather_file).enrich()
|
|
|
|
print('enrich weather... done')
|
|
|
|
ConstructionFactory(construction_format, city).enrich()
|
|
|
|
print('enrich constructions... done')
|
|
|
|
UsageFactory(usage_format, city).enrich()
|
|
|
|
print('enrich usage... done')
|
|
|
|
for building in city.buildings:
|
|
|
|
building.energy_systems_archetype_name = 'system 1 gas'
|
|
|
|
EnergySystemsFactory(energy_systems_format, city).enrich()
|
|
|
|
print('enrich systems... done')
|
|
|
|
print('exporting:')
|
|
|
|
catalog = CostCatalogFactory('montreal_custom').catalog
|
|
|
|
print('costs catalog access... done')
|
|
|
|
sra_file = (tmp_folder / f'{city.name}_sra.xml').resolve()
|
|
|
|
SraEngine(city, sra_file, tmp_folder, weather_file)
|
|
|
|
print(' sra processed...')
|
|
|
|
|
|
|
|
for building in city.buildings:
|
|
|
|
building.attic_heated = attic_heated_case
|
|
|
|
building.basement_heated = basement_heated_case
|
2023-05-01 16:38:45 -04:00
|
|
|
|
2023-05-27 09:32:42 -04:00
|
|
|
for retrofitting_scenario in retrofitting_scenarios:
|
2023-05-01 16:38:45 -04:00
|
|
|
|
2023-05-29 22:10:43 -04:00
|
|
|
if retrofitting_scenario == 1 or retrofitting_scenario == 3:
|
2023-05-30 15:08:11 -04:00
|
|
|
for building in city.buildings:
|
2023-05-31 12:26:01 -04:00
|
|
|
building.year_of_construction = retrofitting_year_of_construction
|
2023-05-30 15:08:11 -04:00
|
|
|
ConstructionFactory(construction_format, city).enrich()
|
|
|
|
print('enrich retrofitted constructions... done')
|
2023-05-02 10:49:53 -04:00
|
|
|
|
2023-05-29 22:10:43 -04:00
|
|
|
if retrofitting_scenario == 2 or retrofitting_scenario == 3:
|
2023-05-02 10:49:53 -04:00
|
|
|
for building in city.buildings:
|
2023-05-27 09:32:42 -04:00
|
|
|
building.energy_systems_archetype_name = 'system 6 electricity pv'
|
|
|
|
EnergySystemsFactory(energy_systems_format, city).enrich()
|
|
|
|
print('enrich systems... done')
|
|
|
|
|
|
|
|
MonthlyEnergyBalanceEngine(city, tmp_folder)
|
2023-05-31 11:23:23 -04:00
|
|
|
lightingdemand = city.buildings[0].lighting_electrical_demand[cte.YEAR]['insel meb'] / 1000
|
|
|
|
print(f'lighting first {lightingdemand}')
|
2023-05-27 09:32:42 -04:00
|
|
|
EnergySystemsSizing(city).enrich()
|
|
|
|
|
|
|
|
print(f'beginning costing scenario {retrofitting_scenario} systems... done')
|
|
|
|
|
|
|
|
for building in city.buildings:
|
2023-05-30 15:08:11 -04:00
|
|
|
|
2023-05-27 09:32:42 -04:00
|
|
|
function = Dictionaries().hub_function_to_montreal_custom_costs_function[building.function]
|
|
|
|
archetype = _search_archetype(catalog, function)
|
|
|
|
print('lcc for first building started')
|
2023-05-30 11:15:33 -04:00
|
|
|
if "gas" in building.energy_systems_archetype_name:
|
|
|
|
fuel_type = 1
|
|
|
|
else:
|
|
|
|
fuel_type = 0
|
|
|
|
|
|
|
|
print(f'fuel type {fuel_type}')
|
2023-05-29 08:06:58 -04:00
|
|
|
lcc = LifeCycleCosts(building, archetype, number_of_years, consumer_price_index, electricity_peak_index,
|
2023-05-30 15:08:11 -04:00
|
|
|
electricity_price_index, gas_price_index, discount_rate, retrofitting_scenario, fuel_type)
|
2023-05-31 12:26:01 -04:00
|
|
|
global_capital_costs, global_capital_incomes = lcc.calculate_capital_costs()
|
2023-05-30 08:15:44 -04:00
|
|
|
global_end_of_life_costs = lcc.calculate_end_of_life_costs()
|
|
|
|
global_operational_costs = lcc.calculate_total_operational_costs()
|
|
|
|
global_maintenance_costs = lcc.calculate_total_maintenance_costs()
|
|
|
|
global_operational_incomes = lcc.calculate_total_operational_incomes()
|
2023-05-31 10:38:16 -04:00
|
|
|
full_path_output = Path(out_path / f'output {retrofitting_scenario} {building.name}.xlsx').resolve()
|
|
|
|
with pd.ExcelWriter(full_path_output) as writer:
|
|
|
|
global_capital_costs.to_excel(writer, sheet_name='global_capital_costs')
|
|
|
|
global_end_of_life_costs.to_excel(writer, sheet_name='global_end_of_life_costs')
|
|
|
|
global_operational_costs.to_excel(writer, sheet_name='global_operational_costs')
|
|
|
|
global_maintenance_costs.to_excel(writer, sheet_name='global_maintenance_costs')
|
|
|
|
global_operational_incomes.to_excel(writer, sheet_name='global_operational_incomes')
|
2023-05-31 12:26:01 -04:00
|
|
|
global_capital_incomes.to_excel(writer, sheet_name='global_capital_incomes')
|
2023-05-31 10:38:16 -04:00
|
|
|
|
2023-05-30 15:08:11 -04:00
|
|
|
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']
|
|
|
|
)
|
2023-05-30 08:15:44 -04:00
|
|
|
df_end_of_life_costs = global_end_of_life_costs['End_of_life_costs']
|
2023-05-30 15:08:11 -04:00
|
|
|
df_operational_costs = (
|
|
|
|
global_operational_costs['Fixed_costs_electricity_peak'] +
|
|
|
|
global_operational_costs['Fixed_costs_electricity_monthly'] +
|
|
|
|
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']
|
|
|
|
)
|
2023-05-30 08:15:44 -04:00
|
|
|
df_operational_incomes = global_operational_incomes['Incomes electricity']
|
2023-05-29 09:08:06 -04:00
|
|
|
|
2023-05-31 12:26:01 -04:00
|
|
|
df_capital_incomes = global_capital_incomes['Subsidies construction'] + global_capital_incomes['Subsidies HVAC'] + \
|
|
|
|
global_capital_incomes['Subsidies PV']
|
|
|
|
|
2023-05-29 09:17:07 -04:00
|
|
|
life_cycle_costs_capital_skin = _npv_from_list(discount_rate, df_capital_costs_skin.values.tolist())
|
|
|
|
life_cycle_costs_capital_systems = _npv_from_list(discount_rate, df_capital_costs_systems.values.tolist())
|
2023-05-29 09:08:06 -04:00
|
|
|
life_cycle_costs_end_of_life_costs = _npv_from_list(discount_rate, df_end_of_life_costs.values.tolist())
|
|
|
|
life_cycle_operational_costs = _npv_from_list(discount_rate, df_operational_costs.values.tolist())
|
|
|
|
life_cycle_maintenance_costs = _npv_from_list(discount_rate, df_maintenance_costs.values.tolist())
|
|
|
|
life_cycle_operational_incomes = _npv_from_list(discount_rate, df_operational_incomes.values.tolist())
|
2023-05-31 12:26:01 -04:00
|
|
|
life_cycle_capital_incomes = _npv_from_list(discount_rate, df_capital_incomes.values.tolist())
|
2023-05-29 09:08:06 -04:00
|
|
|
|
2023-05-30 15:08:11 -04:00
|
|
|
life_cycle_costs = (
|
|
|
|
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 -
|
2023-05-31 12:26:01 -04:00
|
|
|
life_cycle_operational_incomes -
|
|
|
|
life_cycle_capital_incomes
|
2023-05-30 15:08:11 -04:00
|
|
|
)
|
2023-05-29 09:08:06 -04:00
|
|
|
|
|
|
|
life_cycle_results[f'Scenario {retrofitting_scenario}'] = [life_cycle_costs_capital_skin,
|
2023-05-30 15:08:11 -04:00
|
|
|
life_cycle_costs_capital_systems,
|
2023-05-29 09:08:06 -04:00
|
|
|
life_cycle_costs_end_of_life_costs,
|
|
|
|
life_cycle_operational_costs,
|
|
|
|
life_cycle_maintenance_costs,
|
2023-05-31 12:26:01 -04:00
|
|
|
life_cycle_operational_incomes,
|
|
|
|
life_cycle_capital_incomes]
|
2023-05-29 09:08:06 -04:00
|
|
|
|
2023-05-30 08:31:57 -04:00
|
|
|
life_cycle_results.index = [f'total_capital_costs_skin',
|
|
|
|
f'total_capital_costs_systems', f'end_of_life_costs',
|
|
|
|
f'total_operational_costs', f'total_maintenance_costs',
|
2023-05-31 12:26:01 -04:00
|
|
|
f'operational_incomes', f'capital_incomes']
|
2023-05-29 09:17:07 -04:00
|
|
|
|
2023-05-29 22:10:43 -04:00
|
|
|
print(life_cycle_results)
|
2023-05-30 11:15:33 -04:00
|
|
|
print(f'Scenario {retrofitting_scenario} {life_cycle_costs}')
|