diff --git a/life_cycle_costs.py b/life_cycle_costs.py index fa632b1..dc293b1 100644 --- a/life_cycle_costs.py +++ b/life_cycle_costs.py @@ -12,9 +12,11 @@ from datetime import date import hub.helpers.constants as cte + class LifeCycleCosts: def __init__(self, building, archetype, number_of_years, consumer_price_index, discount_rate, - retrofitting_scenario, heating_scop, cooling_seer, peak_electricity_demand, factor_pv,factor_peak_lights): + retrofitting_scenario, heating_scop, cooling_seer, peak_electricity_demand, + factor_pv, factor_peak_lights): self._building = building self._number_of_years = number_of_years self._consumer_price_index = consumer_price_index @@ -38,13 +40,13 @@ class LifeCycleCosts: self._peak_lights = factor_peak_lights #todo: revise if it works rng = range(40) - self._yearly_capital_costs = pd.DataFrame(index=rng , columns=['B2010_opaque_walls', 'B2020_transparent', + self._yearly_capital_costs = pd.DataFrame(index=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', 'D_services'], dtype='float') - self._yearly_capital_costs.replace(np.nan,0) + self._yearly_capital_costs.replace(np.nan, 0) def calculate_capital_costs(self): building = self._building @@ -57,7 +59,6 @@ class LifeCycleCosts: surface_ground = 0 total_floor_area = self._total_floor_area - for internal_zone in building.internal_zones: for thermal_zone in internal_zone.thermal_zones: for thermal_boundary in thermal_zone.thermal_boundaries: @@ -153,9 +154,8 @@ class LifeCycleCosts: reposition_cost_total = reposition_cost_subtotal * (1+chapters.design_allowance) * (1+chapters.overhead_and_profit) life_cycle_cost_capital_total = capital_cost_total + reposition_cost_total - self._yearly_capital_costs.fillna(0,inplace=True) - return life_cycle_cost_capital_total + return life_cycle_cost_capital_total, self._yearly_capital_costs def calculate_end_of_life_costs(self): archetype = self._archetype diff --git a/main.py b/main.py index b6bc701..94aaa5f 100644 --- a/main.py +++ b/main.py @@ -32,8 +32,8 @@ def _search_archetype(costs_catalog, building_function): return building_archetype raise KeyError('archetype not found') + file_path = (Path(__file__).parent.parent/'costs_workflow'/'input_files'/'selected_building_2864.geojson') -file_path2 = (Path(__file__).parent.parent/'costs_workflow'/'input_files'/'selected_building_2864_2.geojson') climate_reference_city = 'Montreal' weather_file = 'CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw' weather_format = 'epw' @@ -44,6 +44,7 @@ basement_heated_case = 1 tmp_folder = (Path(__file__).parent.parent/'monthly_energy_balance_workflow'/'tmp') out_path = (Path(__file__).parent.parent / 'costs_workflow' / 'out_files') files = glob.glob(f'{out_path}/*') +retrofitting_year_of_construction = 2015 for file in files: if file != '.gitignore': @@ -60,125 +61,78 @@ factor_peak_lights = 0.07 retrofitting_scenarios = [0, 1, 2, 3] life_cycle_results = pd.DataFrame() for retrofitting_scenario in retrofitting_scenarios: - if retrofitting_scenario == 2 or retrofitting_scenario==3: + if retrofitting_scenario == 2 or retrofitting_scenario == 3: heating_scop = 3 cooling_seer = 4.5 else: heating_scop = 1 cooling_seer = 2.8 + print('[simulation 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}') + WeatherFactory(weather_format, city, file_name=weather_file).enrich() + print('enrich weather... done') + UsageFactory(usage_format, city).enrich() + print('enrich usage... done') + catalog = CostCatalogFactory('montreal_custom').catalog + print('costs catalog access... done') + if retrofitting_scenario == 0 or retrofitting_scenario == 2: - print('[simulation 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}') - 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') - catalog = CostCatalogFactory('montreal_custom').catalog - print('costs catalog access... done') - - # sra + monthly running - - print('exporting:') - sra_file = (tmp_folder / f'{city.name}_sra.xml').resolve() - SraEngine(city, sra_file, tmp_folder, weather_file) - # Assign radiation to the city - print(' sra processed...') - for building in city.buildings: - building.attic_heated = attic_heated_case - building.basement_heated = basement_heated_case + building.year_of_construction = retrofitting_year_of_construction - MonthlyEnergyBalanceEngine(city, tmp_folder) + ConstructionFactory(construction_format, city).enrich() + print('enrich constructions... done') - for building in city.buildings: - try: - function = Dictionaries().hub_function_to_montreal_custom_costs_function[building.function] - archetype = _search_archetype(catalog, function) - except KeyError: - logger.error(f'Building {building.name} has unknown costs archetype for building function: ' + # sra + monthly running + + print('exporting:') + sra_file = (tmp_folder / f'{city.name}_sra.xml').resolve() + SraEngine(city, sra_file, tmp_folder, weather_file) + # Assign radiation to the city + print(' sra processed...') + + for building in city.buildings: + building.attic_heated = attic_heated_case + building.basement_heated = basement_heated_case + + MonthlyEnergyBalanceEngine(city, tmp_folder) + + for building in city.buildings: + try: + function = Dictionaries().hub_function_to_montreal_custom_costs_function[building.function] + archetype = _search_archetype(catalog, function) + except KeyError: + logger.error(f'Building {building.name} has unknown costs archetype for building function: ' + f'{building.function}\n') + sys.stderr.write(f'Building {building.name} has unknown costs archetype for building function: ' f'{building.function}\n') - sys.stderr.write(f'Building {building.name} has unknown costs archetype for building function: ' - f'{building.function}\n') - continue - lcc = LifeCycleCosts(building, archetype, number_of_years, consumer_price_index, - discount_rate, retrofitting_scenario, heating_scop, cooling_seer, - peak_electricity_demand, factor_pv,factor_peak_lights) - else: - print('[simulation start]') - city = GeometryFactory('geojson', - path=file_path2, - 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}') - 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') - catalog = CostCatalogFactory('montreal_custom').catalog - print('costs catalog access... done') - - # sra + monthly running - - print('exporting:') - sra_file = (tmp_folder / f'{city.name}_sra.xml').resolve() - SraEngine(city, sra_file, tmp_folder, weather_file) - # Assign radiation to the city - print(' sra processed...') - - for building in city.buildings: - building.attic_heated = attic_heated_case - building.basement_heated = basement_heated_case - - MonthlyEnergyBalanceEngine(city, tmp_folder) - - for building in city.buildings: - try: - function = Dictionaries().hub_function_to_montreal_custom_costs_function[building.function] - archetype = _search_archetype(catalog, function) - except KeyError: - logger.error(f'Building {building.name} has unknown costs archetype for building function: ' - f'{building.function}\n') - sys.stderr.write(f'Building {building.name} has unknown costs archetype for building function: ' - f'{building.function}\n') continue lcc = LifeCycleCosts(building, archetype, number_of_years, consumer_price_index, discount_rate, retrofitting_scenario, heating_scop, cooling_seer, peak_electricity_demand, factor_pv,factor_peak_lights) - total_capital_costs = lcc.calculate_capital_costs() - end_of_life_costs = lcc.calculate_end_of_life_costs() - total_operational_costs = lcc.calculate_total_operational_costs() - total_maintenance_costs = lcc.calculate_total_maintenance_costs() - life_cycle_costs = total_capital_costs + end_of_life_costs + total_operational_costs + total_maintenance_costs - life_cycle_results[f'Scenario {retrofitting_scenario}'] = [total_capital_costs, end_of_life_costs, - total_operational_costs, total_maintenance_costs, - life_cycle_costs] -life_cycle_results.index = ['total_capital_costs','end_of_life_costs', 'total_operational_costs', - 'total_maintenance_costs','life_cycle_costs'] -life_cycle_results.to_excel(Path(__file__).parent/'out_files'/'Results.xlsx', index=True) + total_capital_costs, yearly_capital_costs = lcc.calculate_capital_costs() + end_of_life_costs = lcc.calculate_end_of_life_costs() + total_operational_costs = lcc.calculate_total_operational_costs() + total_maintenance_costs = lcc.calculate_total_maintenance_costs() + life_cycle_costs = total_capital_costs + end_of_life_costs + total_operational_costs + total_maintenance_costs + life_cycle_results[f'Scenario {retrofitting_scenario}'] = [total_capital_costs, end_of_life_costs, + total_operational_costs, total_maintenance_costs, + life_cycle_costs] + life_cycle_results.index = ['total_capital_costs', 'end_of_life_costs', 'total_operational_costs', + 'total_maintenance_costs', 'life_cycle_costs'] + life_cycle_results.to_excel(Path(__file__).parent/'out_files'/'Results.xlsx', index=True)