from pathlib import Path import subprocess from scripts.ep_workflow import energy_plus_workflow from hub.imports.geometry_factory import GeometryFactory from hub.helpers.dictionaries import Dictionaries from hub.imports.construction_factory import ConstructionFactory from hub.imports.usage_factory import UsageFactory from hub.imports.weather_factory import WeatherFactory import hub.helpers.constants as cte from hub.exports.exports_factory import ExportsFactory from hub.imports.results_factory import ResultFactory import pandas as pd from scripts.solar_angles import CitySolarAngles from scripts.radiation_tilted import RadiationTilted # Specify the GeoJSON file path input_files_path = (Path(__file__).parent / 'input_files') geojson_file_path = input_files_path / 'Lachine_New_Developments.geojson' output_path = (Path(__file__).parent / 'out_files').resolve() output_path.mkdir(parents=True, exist_ok=True) sra_output_path = output_path / 'sra_outputs' sra_output_path.mkdir(parents=True, exist_ok=True) # Create city object from GeoJSON file city = GeometryFactory('geojson', path=geojson_file_path, height_field='maximum_roof_height', year_of_construction_field='year_built', function_field='building_type', function_to_hub=Dictionaries().montreal_function_to_hub_function).city # Enrich city data WeatherFactory('epw', city).enrich() 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')