from pathlib import Path import subprocess import pandas as pd from energy_system_modelling_package import random_assignation from energy_system_modelling_package.energy_system_modelling_factories.pv_assessment.pv_system_assessment import \ PvSystemAssessment from energy_system_modelling_package.energy_system_modelling_factories.pv_assessment.solar_calculator import \ SolarCalculator from hub.imports.energy_systems_factory import EnergySystemsFactory 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 from hub.imports.results_factory import ResultFactory from hub.exports.exports_factory import ExportsFactory import hub.helpers.constants as cte # Define paths for input and output directories, ensuring directories are created if they do not exist base_path = Path(__file__).parent.resolve() input_files_path = base_path / 'input_files' input_files_path.mkdir(parents=True, exist_ok=True) output_files_path = base_path / 'out_files' output_files_path.mkdir(exist_ok=True, parents=True) energy_plus_output_path = output_files_path / 'energy_plus_outputs' energy_plus_output_path.mkdir(parents=True, exist_ok=True) geojson_path = input_files_path / 'selected_buildings.geojson' sra_output_path = output_files_path / 'sra_outputs' sra_output_path.mkdir(parents=True, exist_ok=True) pv_assessment_path = output_files_path / 'pv_outputs' pv_assessment_path.mkdir(parents=True, exist_ok=True) # Generate a GeoJSON file for city buildings based on latitude, longitude, and building dimensions # Initialize a city object from the geojson file, mapping building functions using a predefined dictionary city = GeometryFactory(file_type='geojson', path=geojson_path, height_field='height', year_of_construction_field='year_of_construction', function_field='function', function_to_hub=Dictionaries().montreal_function_to_hub_function).city # Enrich city data with construction, usage, and weather information specific to the location for building in city.buildings: if Dictionaries().hub_function_to_nrcan_construction_function[building.function] == 'n/a': building.function = cte.WAREHOUSE ConstructionFactory('nrcan', city).enrich() UsageFactory('nrcan', city).enrich() WeatherFactory('epw', city).enrich() # Execute the EnergyPlus workflow to simulate building energy performance and generate output # energy_plus_workflow(city, energy_plus_output_path) # Export the city data in SRA-compatible format to facilitate solar radiation assessment ExportsFactory('sra', city, sra_output_path).export() # Run SRA simulation using an external command, passing the generated SRA XML file path as input sra_path = (sra_output_path / f'{city.name}_sra.xml').resolve() subprocess.run(['sra', str(sra_path)]) # Enrich city data with SRA simulation results for subsequent analysis ResultFactory('sra', city, sra_output_path).enrich() # Assign PV system archetype name to the buildings in city random_assignation.call_random(city.buildings, random_assignation.residential_new_systems_percentage) # Enrich city model with Montreal future systems parameters EnergySystemsFactory('montreal_future', city).enrich() # # Initialize solar calculation parameters (e.g., azimuth, altitude) and compute irradiance and solar angles tilt_angle = 37 solar_parameters = SolarCalculator(city=city, surface_azimuth_angle=180, tilt_angle=tilt_angle, standard_meridian=-75) solar_angles = solar_parameters.solar_angles # Obtain solar angles for further analysis solar_parameters.tilted_irradiance_calculator() # Calculate the solar radiation on a tilted surface # # PV modelling building by building # List of available PV modules ['RE400CAA Pure 2', 'RE410CAA Pure 2', 'RE420CAA Pure 2', 'RE430CAA Pure 2', # 'REC600AA Pro M', 'REC610AA Pro M', 'REC620AA Pro M', 'REC630AA Pro M', 'REC640AA Pro M'] building_names = [] hourly_pv_outputs = pd.DataFrame() for building in city.buildings: building_names.append(building.name) pv_modeller = PvSystemAssessment(building=building, pv_system=None, battery=None, tilt_angle=tilt_angle, solar_angles=solar_angles, pv_installation_type='rooftop', simulation_model_type='explicit', module_model_name='CS7N650MS', inverter_efficiency=0.95, system_catalogue_handler='montreal_future', roof_percentage_coverage=0.75, facade_coverage_percentage=0, csv_output=False, output_path=pv_assessment_path) pv_modeller.enrich() results = pv_modeller.results pv_output = [x / 1000 for x in results['total_hourly_pv_system_output_W']] hourly_pv_outputs[f'{building.name}'] = pv_output hourly_pv_outputs.to_csv(output_files_path / 'paper_results' / 'hourly_pv_outputs.csv')