20240801 added SRA to main

This commit is contained in:
Andrea Gabaldon Moreno 2024-08-01 12:46:40 -04:00
parent 3e5c54e7cf
commit 8294109a09

74
main.py
View File

@ -9,13 +9,37 @@ from hub.imports.weather_factory import WeatherFactory
import hub.helpers.constants as cte
from hub.imports.energy_systems_factory import EnergySystemsFactory
from hub.helpers.peak_loads import PeakLoads
from pathlib import Path
import subprocess
from hub.imports.results_factory import ResultFactory
from hub.imports.energy_systems_factory import EnergySystemsFactory
from scripts.energy_system_sizing_and_simulation_factory import EnergySystemsSimulationFactory
import hub.helpers.constants as cte
from hub.exports.exports_factory import ExportsFactory
from scripts.solar_angles import CitySolarAngles
from scripts.radiation_tilted import RadiationTilted
import geopandas as gpd
import json
#%% # -----------------------------------------------
# Specify the GeoJSON file path
#%% # -----------------------------------------------
input_files_path = (Path(__file__).parent / 'input_files')
output_path = (Path(__file__).parent / 'out_files').resolve()
output_path.mkdir(parents=True, exist_ok=True)
energy_plus_output_path = output_path / 'energy_plus_outputs'
energy_plus_output_path.mkdir(parents=True, exist_ok=True)
simulation_results_path = (Path(__file__).parent / 'out_files' / 'simulation_results').resolve()
simulation_results_path.mkdir(parents=True, exist_ok=True)
sra_output_path = output_path / 'sra_outputs'
sra_output_path.mkdir(parents=True, exist_ok=True)
cost_analysis_output_path = output_path / 'cost_analysis'
cost_analysis_output_path.mkdir(parents=True, exist_ok=True)
#%%-----------------------------------------------
#"""add geojson paths and create city for Baseline"""
#%% # -----------------------------------------------
geojson_file_path_baseline = output_path / 'updated_buildings_with_all_data_baseline.geojson'
geojson_file_path_2024 = output_path / 'updated_buildings_with_all_data.geojson'
with open(geojson_file_path_baseline , 'r') as f:
@ -30,15 +54,50 @@ city = GeometryFactory('geojson',
year_of_construction_field='year_built',
function_field='building_type',
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
#%%-----------------------------------------------
# Enrich city data
#%% # -----------------------------------------------
ConstructionFactory('nrcan', city).enrich()
UsageFactory('nrcan', city).enrich()
WeatherFactory('epw', city).enrich()
# #energy plus is not going to be processed here, as demand has been obtained before
# energy_plus_workflow(city)
#%%-----------------------------------------------
# """SRA"""
#%% # -----------------------------------------------
ExportsFactory('sra', city, sra_output_path).export()
sra_path = (sra_output_path / f'{city.name}_sra.xml').resolve()
subprocess.run(['sra', str(sra_path)])
ResultFactory('sra', city, sra_output_path).enrich()
solar_angles = CitySolarAngles(city.name,
city.latitude,
city.longitude,
tilt_angle=45,
surface_azimuth_angle=180).calculate
for building in city.buildings:
ghi = [x / cte.WATTS_HOUR_TO_JULES for x in building.roofs[0].global_irradiance[cte.HOUR]]
RadiationTilted(building,
solar_angles,
tilt_angle=45,
ghi=ghi).enrich()
# building_names = []
# for building in city.buildings:
# building_names.append(building.name)
#
# df = pd.DataFrame(columns=building_names)
# df1 = pd.DataFrame(columns=building_names)
# print('test')
# for building in city.buildings:
# # if building.name in selected_buildings_list:
# df[f'{building.name}'] = building.roofs[0].global_irradiance[cte.HOUR]
# df1[f'{building.name}'] = building.roofs[0].global_irradiance_tilted[cte.HOUR]
#
# df.to_csv('solar_radiation_horizontal_selected_buildings.csv')
# df1.to_csv('solar_radiation_tilted_selected_buildings.csv')
#SRA algorithm
#%% # -----------------------------------------------
#"""Enrich city with geojson file data"""
#%% # -----------------------------------------------
percentage_data = {
1646: {"type1_%": 1, "type2_%": 0, "type3_%": 0, "roof_area": 2672.550473, "total_floor_area": 26725.50473},
1647: {"type1_%": 1, "type2_%": 0, "type3_%": 0, "roof_area": 2653.626087, "total_floor_area": 26536.26087},
@ -104,6 +163,11 @@ def enrich_buildings_with_geojson_data (building_type_data, city):
enrich_buildings_with_geojson_data (building_type_data, city)
print('test')
#%%-----------------------------------------------
# """ADD energy systems"""
#%% # -----------------------------------------------
for building in city.buildings:
building.energy_systems_archetype_name = 'system 1 electricity pv'
@ -146,3 +210,9 @@ for building in city.buildings:
# total_floor_area += thermal_zone.total_floor_area
# print(building.heating_demand[cte.YEAR][0] / (3.6e6 * total_floor_area))
# for building in city.buildings:
# building.energy_systems_archetype_name = 'PV+4Pipe+DHW'
# EnergySystemsFactory('montreal_future', city).enrich()
# for building in city.buildings:
# EnergySystemsSimulationFactory('archetype13', building=building, output_path=simulation_results_path).enrich()