From fa09b48624c2d39f429dd8cb238280079140c296 Mon Sep 17 00:00:00 2001 From: jgavalda Date: Mon, 29 May 2023 22:10:43 -0400 Subject: [PATCH] Solved all problems. Pending building peak loads, onsite production, pv surface and extra electrical consumption --- life_cycle_costs.py | 135 +++++++++++++++++++------------------------- main.py | 25 ++++---- 2 files changed, 68 insertions(+), 92 deletions(-) diff --git a/life_cycle_costs.py b/life_cycle_costs.py index e0b3039..a783a6f 100644 --- a/life_cycle_costs.py +++ b/life_cycle_costs.py @@ -44,18 +44,15 @@ class LifeCycleCosts: 'D3030_cooling_generation_systems','D3040_distribution_systems', 'D3080_other_hvac_ahu','D5020_lighting_and_branch_wiring'], dtype='float') - self._yearly_capital_costs.replace(np.nan, 0) self._yearly_end_of_life_costs = pd.DataFrame(index=rng, columns=['End_of_life_costs'], dtype='float') - self._yearly_end_of_life_costs.replace(np.nan, 0) self._yearly_operational_costs = pd.DataFrame(index=rng, columns=['Fixed_costs_electricity_peak', 'Fixed_costs_electricity_monthly', 'Variable_costs_electricity','Fixed_costs_gas', - 'Variable_costs_gas','Heating_maintenance', - 'Cooling_maintenance','PV_maintenance'], + 'Variable_costs_gas'], dtype='float') - self._yearly_operational_costs.replace(np.nan, 0) + self._yearly_maintenance_costs = pd.DataFrame(index=rng, columns=['Heating_maintenance','Cooling_maintenance', + 'PV_maintenance'], dtype='float') self._yearly_operational_incomes = pd.DataFrame(index=rng, columns=['Incomes electricity'],dtype='float') - self._yearly_operational_incomes.replace(np.nan, 0) def calculate_capital_costs(self): building = self._building @@ -87,7 +84,17 @@ class LifeCycleCosts: peak_cooling = building.cooling_peak_load[cte.YEAR].values[0] #todo: put the value of area_pv when it exists surface_pv = 10 #building.area_pv - + self._yearly_capital_costs.loc[0, 'B2010_opaque_walls'], self._yearly_capital_costs.loc[0]['B2020_transparent'], \ + self._yearly_capital_costs.loc[0, 'B3010_opaque_roof'], self._yearly_capital_costs.loc[0]['B10_superstructure'], \ + self._yearly_capital_costs.loc[0, 'B_Shell'] \ + = [0, 0, 0, 0, 0] + self._yearly_capital_costs.loc[0, 'D3020_heat_generating_systems'], \ + self._yearly_capital_costs.loc[0, 'D3030_cooling_generation_systems'], \ + self._yearly_capital_costs.loc[0, 'D3040_distribution_systems'], \ + self._yearly_capital_costs.loc[0, 'D3080_other_hvac_ahu'], \ + self._yearly_capital_costs.loc[0, 'D5020_lighting_and_branch_wiring'] \ + = [0, 0, 0, 0, 0] + self._yearly_capital_costs.fillna(0,inplace=True) if self._retrofitting_scenario == 1 or self._retrofitting_scenario == 3: chapter = chapters.chapter('B_shell') capital_cost_opaque = surface_opaque * chapter.item('B2010_opaque_walls').refurbishment[0] @@ -95,9 +102,9 @@ class LifeCycleCosts: capital_cost_roof = surface_roof * chapter.item('B3010_opaque_roof').refurbishment[0] capital_cost_ground = surface_ground * chapter.item('B10_superstructure').refurbishment[0] capital_cost_skin = capital_cost_opaque+capital_cost_transparent+capital_cost_roof+capital_cost_ground - self._yearly_capital_costs.loc[0]['B2010_opaque_walls'],self._yearly_capital_costs.loc[0]['B2020_transparent'], \ - self._yearly_capital_costs.loc[0]['B3010_opaque_roof'],self._yearly_capital_costs.loc[0]['B10_superstructure'],\ - self._yearly_capital_costs.loc[0]['B_Shell']\ + self._yearly_capital_costs.loc[0,'B2010_opaque_walls'],self._yearly_capital_costs.loc[0]['B2020_transparent'], \ + self._yearly_capital_costs.loc[0,'B3010_opaque_roof'],self._yearly_capital_costs.loc[0]['B10_superstructure'],\ + self._yearly_capital_costs.loc[0,'B_Shell']\ =[capital_cost_opaque , capital_cost_transparent , capital_cost_roof , capital_cost_ground , capital_cost_skin] if self._retrofitting_scenario == 2 or self._retrofitting_scenario == 3: @@ -116,102 +123,78 @@ class LifeCycleCosts: * 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 = total_floor_area * self._peak_lights \ - * chapter.item('D5020_lighting_and_branch_wiring').initial_investment[0] + capital_cost_lighting = total_floor_area * chapter.item('D5020_lighting_and_branch_wiring').initial_investment[0] - self._yearly_capital_costs.loc[0]['D3020_heat_generating_systems'], \ - self._yearly_capital_costs.loc[0]['D3030_cooling_generation_systems'], \ - self._yearly_capital_costs.loc[0]['D3040_distribution_systems'], \ - self._yearly_capital_costs.loc[0]['D3080_other_hvac_ahu'], \ - self._yearly_capital_costs.loc[0]['D5020_lighting_and_branch_wiring']\ + self._yearly_capital_costs.loc[0,'D3020_heat_generating_systems'], \ + self._yearly_capital_costs.loc[0,'D3030_cooling_generation_systems'], \ + self._yearly_capital_costs.loc[0,'D3040_distribution_systems'], \ + self._yearly_capital_costs.loc[0,'D3080_other_hvac_ahu'], \ + self._yearly_capital_costs.loc[0,'D5020_lighting_and_branch_wiring']\ = [capital_cost_heating_equipment, capital_cost_cooling_equipment, capital_cost_distribution_equipment, capital_cost_other_hvac_ahu, capital_cost_lighting] - - reposition_cost_heating_equipment = 0 - reposition_cost_cooling_equipment = 0 - reposition_cost_lighting = 0 - reposition_cost_hvac_ahu = 0 - - for year in range(1, self._number_of_years + 1): + for year in range(1, self._number_of_years): chapter = chapters.chapter('D_services') costs_increase = math.pow(1 + self._consumer_price_index, year) / math.pow(1 + self._discount_rate, year) 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 + 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 + 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 + 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 = 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 + self._yearly_capital_costs.loc[year,'D5020_lighting_and_branch_wiring'] = reposition_cost_lighting if self._retrofitting_scenario==2 or self._retrofitting_scenario==3 : 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 - + self._yearly_capital_costs.loc[year]['D301010_photovoltaic_system'] = surface_pv \ + * chapter.item('D301010_photovoltaic_system').reposition[0] * costs_increase return self._yearly_capital_costs def calculate_end_of_life_costs(self): archetype = self._archetype - total_floor_area = self._total_floor_area price_increase = 0 for year in range(1, self._number_of_years + 1): price_increase += math.pow(1 + self._consumer_price_index, year) if year == self._number_of_years: - self._end_of_life_cost[year]['End_of_life_costs'] = total_floor_area * archetype.end_of_life_cost*price_increase - return self._end_of_life_cost + 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 def calculate_total_operational_costs(self): building = self._building archetype = self._archetype - total_operational_costs = 0 - peak_cost = 0 - monthly_cost = 0 - variable_cost = 0 - variable_incomes = 0 total_floor_area = self._total_floor_area + #todo: split the heating between fuels electricity_heating = building.heating_consumption[cte.YEAR][0] / (1000) electricity_cooling = building.cooling_consumption[cte.YEAR][0] / (1000) electricity_lighting = building.lighting_electrical_demand[cte.YEAR]['insel meb']/1000 domestic_hot_water_demand = building.domestic_hot_water_consumption[cte.YEAR][0]/1000 electricity_plug_loads = building.appliances_electrical_demand[cte.YEAR]['insel meb']/1000 - - if (building.onsite_electrical_production[cte.YEAR][0] is None): - onsite_electricity_production = 0 - else: - onsite_electricity_production= building.onsite_electrical_production[cte.YEAR][0]/1000 - - total_electricity_consumption = electricity_cooling + electricity_heating + electricity_lighting \ - + domestic_hot_water_demand + electricity_plug_loads - - print(f'total electricity consumption: {total_electricity_consumption}') - print(f'total electricity production: {onsite_electricity_production}') - + total_electricity_consumption = electricity_heating + electricity_cooling + electricity_lighting + \ + domestic_hot_water_demand + electricity_plug_loads #todo: change when peak electricity demand is coded. Careful with factor residential peak_electricity_demand = 100 #self._peak_electricity_demand factor_residential= total_floor_area/80 variable_electricity_cost_year_0 = total_electricity_consumption * 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 - incomes_electricity_year_0 = onsite_electricity_production * archetype.operational_cost.fuels[0].variable[0] fixed_gas_cost_year_0 = archetype.operational_cost.fuels[1].fixed_monthly*12* factor_residential variable_gas_cost_year_0 = total_electricity_consumption * archetype.operational_cost.fuels[1].variable[0] - price_increase_electricity = 0 price_increase_peak_electricity = 0 price_increase_gas = 0 @@ -220,44 +203,40 @@ class LifeCycleCosts: price_increase_electricity += math.pow(1 + self._electricity_price_index, year) price_increase_peak_electricity += math.pow(1 + self._electricity_peak_index, year) price_increase_gas += math.pow(1 + self._gas_price_index, year) - - self._yearly_operational_costs[year]['Fixed_costs_electricity_peak']=peak_electricity_cost_year_0*\ + self._yearly_operational_costs.at[year,'Fixed_costs_electricity_peak']=peak_electricity_cost_year_0*\ price_increase_peak_electricity - self._yearly_operational_costs[year]['Fixed_costs_electricity_monthly'] = monthly_electricity_cost_year_0 * \ + + self._yearly_operational_costs.at[year,'Fixed_costs_electricity_monthly'] = monthly_electricity_cost_year_0 * \ price_increase_peak_electricity - self._yearly_operational_costs[year]['Variable_costs_electricity'] = variable_electricity_cost_year_0 * \ + self._yearly_operational_costs.at[year,'Variable_costs_electricity'] = variable_electricity_cost_year_0 * \ price_increase_electricity - self._yearly_operational_costs[year]['Fixed_costs_gas'] = fixed_gas_cost_year_0 * \ + self._yearly_operational_costs.at[year,'Fixed_costs_gas'] = fixed_gas_cost_year_0 * \ price_increase_gas - self._yearly_operational_costs[year]['Variable_costs_gas'] = variable_gas_cost_year_0* \ + self._yearly_operational_costs.at[year,'Variable_costs_gas'] = variable_gas_cost_year_0* \ price_increase_peak_electricity - self._yearly_operational_costs[year]['Variable_costs_gas'] = variable_gas_cost_year_0 * \ + 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 def calculate_total_operational_incomes(self): building = self._building archetype = self._archetype - variable_incomes = 0 - total_floor_area = self._total_floor_area - if (building.onsite_electrical_production[cte.YEAR][0] is None): + if (building.onsite_electrical_production is None): onsite_electricity_production = 0 else: - onsite_electricity_production= building.onsite_electrical_production[cte.YEAR][0]/1000 - - incomes_electricity_year_0 = onsite_electricity_production * archetype.operational_cost.fuels[0].variable[0] + onsite_electricity_production= 100 #building.onsite_electrical_production[cte.YEAR]/1000 price_increase_electricity = 0 for year in range(1, self._number_of_years + 1): price_increase_electricity += math.pow(1 + self._electricity_price_index, year) - self._yearly_operational_incomes[year]['Incomes electricity']=onsite_electricity_production*\ + self._yearly_operational_incomes.loc[year,'Incomes electricity']=onsite_electricity_production*\ price_increase_electricity + self._yearly_operational_incomes.fillna(0,inplace=True) return self._yearly_operational_incomes def calculate_total_maintenance_costs(self): @@ -266,19 +245,21 @@ class LifeCycleCosts: #todo: change area pv when the variable exists surface_pv = 10 #building.area_pv - peak_heating = building.heating_peak_load - peak_cooling = building.cooling_peak_load + peak_heating = 100#building.heating_peak_load[cte.YEAR][0] + peak_cooling = 100#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 - + print(f'peak_heating{peak_heating}') + print(f'maintenance_cost{archetype.operational_cost.maintenance_heating}') for year in range(1, self._number_of_years + 1): - costs_increase = math.pow(1 + self._consumer_price_index, year) / math.pow(1 + self._discount_rate, year) - self._yearly_operational_costs[year]['Heating_maintenance'] = maintenance_heating_0 * \ + costs_increase = math.pow(1 + self._consumer_price_index, year) + self._yearly_maintenance_costs.loc[year,'Heating_maintenance'] = maintenance_heating_0 * \ costs_increase - self._yearly_operational_costs[year]['Cooling_maintenance'] = maintenance_cooling_0 * \ + self._yearly_maintenance_costs.loc[year,'Cooling_maintenance'] = maintenance_cooling_0 * \ costs_increase - self._yearly_operational_costs[year]['PV_maintenance'] = maintenance_pv_0 * \ + self._yearly_maintenance_costs.loc[year,'PV_maintenance'] = maintenance_pv_0 * \ costs_increase - return self._yearly_operational_costs + self._yearly_maintenance_costs.fillna(0,inplace=True) + return self._yearly_maintenance_costs diff --git a/main.py b/main.py index 18794d7..fddb118 100644 --- a/main.py +++ b/main.py @@ -9,12 +9,11 @@ import os from pathlib import Path import sys import pandas as pd -import numpy as np +import numpy_financial as npf from hub.imports.construction_factory import ConstructionFactory from hub.helpers.dictionaries import Dictionaries -from hub.hub_logger import logger from hub.imports.geometry_factory import GeometryFactory from hub.imports.usage_factory import UsageFactory from hub.imports.weather_factory import WeatherFactory @@ -28,7 +27,7 @@ from energy_systems_sizing import EnergySystemsSizing from life_cycle_costs import LifeCycleCosts def _npv_from_list(npv_discount_rate, list_cashflow): - lcc_value = np.npv(npv_discount_rate, list_cashflow) + lcc_value = npf.npv(npv_discount_rate, list_cashflow) return lcc_value def _search_archetype(costs_catalog, building_function): @@ -55,7 +54,7 @@ for file in files: if file != '.gitignore': os.remove(file) -number_of_years = 30 +number_of_years = 31 consumer_price_index = 0.04 electricity_peak_index = 0.05 electricity_price_index = 0.05 @@ -69,11 +68,9 @@ print('[city creation start]') city = GeometryFactory('geojson', path=file_path, height_field='heightmax', - name_field='OBJECTID_12', year_of_construction_field='ANNEE_CONS', function_field='CODE_UTILI', function_to_hub=Dictionaries().montreal_function_to_hub_function).city -print(f'city created from {file_path}') 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}') @@ -100,13 +97,13 @@ for building in city.buildings: for retrofitting_scenario in retrofitting_scenarios: - if retrofitting_scenario == 1 or retrofitting_scenario==3: + if retrofitting_scenario == 1 or retrofitting_scenario == 3: for building in city.buildings: building.year_of_construction=2020 ConstructionFactory(construction_format, city).enrich() print('enrich retrofitted constructions... done') - if retrofitting_scenario==2 or retrofitting_scenario==3: + if retrofitting_scenario == 2 or retrofitting_scenario == 3: for building in city.buildings: building.energy_systems_archetype_name = 'system 6 electricity pv' EnergySystemsFactory(energy_systems_format, city).enrich() @@ -131,7 +128,6 @@ for retrofitting_scenario in retrofitting_scenarios: print('lcc for first building started') lcc = LifeCycleCosts(building, archetype, number_of_years, consumer_price_index, electricity_peak_index, electricity_price_index, gas_price_index, discount_rate, retrofitting_scenario) - df_capital_costs_skin = lcc.calculate_capital_costs()['B2010_opaque_walls']+\ lcc.calculate_capital_costs()['B2020_transparent']+\ lcc.calculate_capital_costs()['B3010_opaque_roof']+\ @@ -149,9 +145,9 @@ for retrofitting_scenario in retrofitting_scenarios: lcc.calculate_total_operational_costs()['Variable_costs_electricity']+ \ lcc.calculate_total_operational_costs()['Fixed_costs_gas']+ \ lcc.calculate_total_operational_costs()['Variable_costs_gas'] - df_maintenance_costs = lcc.calculate_total_operational_costs()['Heating_maintenance']+\ - lcc.calculate_total_operational_costs()['Cooling_maintenance']+\ - lcc.calculate_total_operational_costs()['PV_maintenance'] + df_maintenance_costs = lcc.calculate_total_maintenance_costs()['Heating_maintenance']+\ + lcc.calculate_total_maintenance_costs()['Cooling_maintenance']+\ + lcc.calculate_total_maintenance_costs()['PV_maintenance'] df_operational_incomes = lcc.calculate_total_operational_incomes()['Incomes electricity'] life_cycle_costs_capital_skin = _npv_from_list(discount_rate, df_capital_costs_skin.values.tolist()) @@ -173,9 +169,8 @@ for retrofitting_scenario in retrofitting_scenarios: life_cycle_operational_incomes] life_cycle_results.index = ['total_capital_costs_skin','total_capital_costs_systems','end_of_life_costs', - 'total_operational_costs','total_maintenance_costs','life_cycle_costs', - 'maintenance_costs'] - + 'total_operational_costs','total_maintenance_costs','operational_incomes'] + print(life_cycle_results) #life_cycle_results.to_excel(Path(__file__).parent/'out_files'/f'Results{building.name}.xlsx', index=True)