city_retrofit/results.py
2024-11-03 10:28:34 +01:00

55 lines
3.4 KiB
Python

import pandas as pd
from pathlib import Path
from hub.imports.geometry_factory import GeometryFactory
from hub.helpers.dictionaries import Dictionaries
import json
import hub.helpers.constants as cte
from hub.imports.results_factory import ResultFactory
out_path = Path(__file__).parent / 'out_files'
ep_output_path = out_path / 'ep_outputs'
ep_output_path.mkdir(parents=True, exist_ok=True)
original_results = pd.read_csv(out_path / 'updated_simulation_results.csv')
results = pd.DataFrame(original_results)
input_files_path = (Path(__file__).parent / 'input_files')
geojson_file_path = input_files_path / 'omhm_selected_buildings.geojson'
with open(out_path / 'air_to_air_hp_buildings_data.json') as file:
current_status_results = json.load(file)
month_names = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
# Create city object from GeoJSON file
city = GeometryFactory('geojson',
path=geojson_file_path,
height_field='Hieght_LiD',
year_of_construction_field='ANNEE_CONS',
function_field='CODE_UTILI',
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
ResultFactory('energy_plus_multiple_buildings', city, ep_output_path).enrich()
for building in city.buildings:
for building_data in current_status_results:
if building.name == current_status_results[building_data]['id']:
for (i, month) in enumerate(month_names):
monthly_heating = current_status_results[building_data]['monthly_heating_consumption_kWh'][month] * 0.0036
monthly_cooling = current_status_results[building_data]['monthly_cooling_consumption_kWh'][month] * 0.0036
monthly_dhw = current_status_results[building_data]['monthly_dhw_consumption_kWh'][month] * 0.0036
monthly_lighting = building.lighting_electrical_demand[cte.MONTH][i] / 1e9
monthly_appliance = building.appliances_electrical_demand[cte.MONTH][i] / 1e9
total_monthly = monthly_heating + monthly_cooling + monthly_dhw + monthly_appliance + monthly_lighting
results.loc[results['ID_UEV'] == float(building.name), f'current_status_consumption_{i+1}'] = total_monthly
# yearly_heating = current_status_results[building_data]['yearly_heating_consumption_kWh'] * 0.0036
# yearly_cooling = current_status_results[building_data]['yearly_cooling_consumption_kWh'] * 0.0036
# yearly_dhw = current_status_results[building_data]['yearly_dhw_consumption_kWh'] * 0.0036
# yearly_lighting = current_status_results[building_data]['yearly_lighting_electricity_consumption_kWh'] * 0.0036
# yearly_appliance = current_status_results[building_data]['yearly_appliance_electricity_consumption_kWh'] * 0.0036
# total_consumption = yearly_heating + yearly_cooling + yearly_dhw + yearly_lighting + yearly_lighting
# results.loc[results['ID_UEV'] == float(building.name), 'scenario_2_12'] = total_consumption
# for building in city.buildings:
# print(building.name)
# consumption = results.loc[results['ID_UEV'] == float(building.name), 'Annual consumption scenario 2']
# print(consumption.values[0] if not consumption.empty else f"No data for building ID: {building.name}")
updated_results = pd.DataFrame(results)
# Specify the output path for the new CSV file
output_csv_path = out_path / 'updated_simulation_results.csv'
# Write the DataFrame to a CSV file
updated_results.to_csv(output_csv_path, index=False)