2024-11-26 05:43:11 -05:00
|
|
|
from hub.imports.energy_systems_factory import EnergySystemsFactory
|
2024-10-03 18:28:35 -04:00
|
|
|
from hub.imports.geometry_factory import GeometryFactory
|
|
|
|
from hub.helpers.dictionaries import Dictionaries
|
2024-10-09 12:11:39 -04:00
|
|
|
from hub.imports.construction_factory import ConstructionFactory
|
|
|
|
from hub.imports.results_factory import ResultFactory
|
2024-11-26 05:43:11 -05:00
|
|
|
from hub.exports.exports_factory import ExportsFactory
|
|
|
|
from hub.imports.weather_factory import WeatherFactory
|
|
|
|
from pv_assessment.electricity_demand_calculator import HourlyElectricityDemand
|
|
|
|
from pv_assessment.pv_system_assessment import PvSystemAssessment
|
|
|
|
from pv_assessment.solar_calculator import SolarCalculator
|
2024-12-03 10:40:50 -05:00
|
|
|
import random_assignation
|
|
|
|
import subprocess
|
|
|
|
from pathlib import Path
|
2024-10-03 18:28:35 -04:00
|
|
|
|
2024-12-03 10:40:50 -05:00
|
|
|
input_file = "data/selected_buildings.geojson"
|
2024-10-09 12:11:39 -04:00
|
|
|
demand_file = "data/energy_demand_data.csv"
|
2024-12-03 10:40:50 -05:00
|
|
|
|
2024-11-26 05:43:11 -05:00
|
|
|
# Define specific paths for outputs from SRA (Simplified Radiosity Algorith) and PV calculation processes
|
2024-12-03 10:40:50 -05:00
|
|
|
output_path = (Path(__file__).parent.parent / 'hub/out_files').resolve()
|
2024-11-26 05:43:11 -05:00
|
|
|
output_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
sra_output_path = output_path / 'sra_outputs'
|
|
|
|
sra_output_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
pv_assessment_path = output_path / 'pv_outputs'
|
|
|
|
pv_assessment_path.mkdir(parents=True, exist_ok=True)
|
2024-12-03 10:40:50 -05:00
|
|
|
|
2024-10-03 18:28:35 -04:00
|
|
|
city = GeometryFactory(
|
2024-10-09 12:11:39 -04:00
|
|
|
"geojson",
|
|
|
|
input_file,
|
|
|
|
height_field="height",
|
|
|
|
year_of_construction_field="contr_year",
|
|
|
|
function_field="function_c",
|
|
|
|
adjacency_field="adjacency",
|
2024-12-04 14:32:17 -05:00
|
|
|
lot_area_field='lot_area',
|
|
|
|
build_area_field='build_area',
|
2024-10-09 12:11:39 -04:00
|
|
|
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
|
|
|
|
ConstructionFactory('nrcan', city).enrich()
|
2024-11-26 05:43:11 -05:00
|
|
|
WeatherFactory('epw', city).enrich()
|
2024-10-09 12:11:39 -04:00
|
|
|
ResultFactory('archetypes', city, demand_file).enrich()
|
2024-12-03 10:40:50 -05:00
|
|
|
|
2024-11-26 05:43:11 -05:00
|
|
|
# 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()
|
2024-12-03 10:40:50 -05:00
|
|
|
# Initialize solar calculation parameters (e.g., azimuth, altitude) and compute irradiance and solar angles
|
2024-11-26 05:43:11 -05:00
|
|
|
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
|
|
|
|
# Assignation of Energy System Archetypes to Buildings
|
2024-12-03 10:40:50 -05:00
|
|
|
random_assignation.call_random(city.buildings, random_assignation.residential_systems_percentage)
|
2024-11-26 05:43:11 -05:00
|
|
|
EnergySystemsFactory('montreal_future', city).enrich()
|
|
|
|
for building in city.buildings:
|
|
|
|
PvSystemAssessment(building=building,
|
|
|
|
pv_system=None,
|
|
|
|
battery=None,
|
2024-12-03 10:40:50 -05:00
|
|
|
electricity_demand=None,
|
2024-11-26 05:43:11 -05:00
|
|
|
tilt_angle=tilt_angle,
|
|
|
|
solar_angles=solar_angles,
|
|
|
|
pv_installation_type='rooftop',
|
|
|
|
simulation_model_type='explicit',
|
|
|
|
module_model_name=None,
|
|
|
|
inverter_efficiency=0.95,
|
|
|
|
system_catalogue_handler=None,
|
|
|
|
roof_percentage_coverage=0.75,
|
|
|
|
facade_coverage_percentage=0,
|
|
|
|
csv_output=False,
|
|
|
|
output_path=pv_assessment_path).enrich()
|
|
|
|
|
2024-12-04 14:32:17 -05:00
|
|
|
r = []
|
|
|
|
for building in city.buildings:
|
|
|
|
r.append((building.build_area - building.lot_area) / building.thermal_zones_from_internal_zones[0].total_floor_area)
|
2024-12-03 10:40:50 -05:00
|
|
|
|
2024-12-04 14:32:17 -05:00
|
|
|
print("done")
|
2024-12-03 10:40:50 -05:00
|
|
|
|
2024-12-04 14:32:17 -05:00
|
|
|
# PLOTTING #
|
2024-12-03 10:40:50 -05:00
|
|
|
import geopandas as gpd
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
from matplotlib.colors import Normalize
|
|
|
|
|
|
|
|
gdf = gpd.read_file(input_file)
|
|
|
|
|
|
|
|
self_sufficiency_values = [building.self_sufficiency['year'] / 1000 for building in city.buildings]
|
|
|
|
|
|
|
|
gdf['self_sufficiency'] = self_sufficiency_values
|
|
|
|
|
2024-12-04 14:32:17 -05:00
|
|
|
vmin = min(0, gdf['self_sufficiency'].min())
|
|
|
|
vmax = max(0, gdf['self_sufficiency'].max())
|
2024-12-03 10:40:50 -05:00
|
|
|
|
|
|
|
fig, ax = plt.subplots(1, 1, figsize=(14, 10))
|
|
|
|
|
|
|
|
cmap = plt.cm.viridis
|
|
|
|
norm = Normalize(vmin=vmin, vmax=vmax)
|
|
|
|
|
|
|
|
gdf.plot(column='self_sufficiency',
|
|
|
|
cmap=cmap,
|
|
|
|
linewidth=0.8,
|
2024-12-04 14:32:17 -05:00
|
|
|
edgecolor='grey',
|
|
|
|
legend=False,
|
2024-12-03 10:40:50 -05:00
|
|
|
ax=ax)
|
|
|
|
|
|
|
|
sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm)
|
2024-12-04 14:32:17 -05:00
|
|
|
sm._A = []
|
2024-12-03 10:40:50 -05:00
|
|
|
cbar = fig.colorbar(sm, ax=ax, fraction=0.03, pad=0.04)
|
|
|
|
cbar.set_label('Self-Sufficiency (kWh/year)', fontsize=12)
|
|
|
|
|
|
|
|
ax.grid(color='lightgrey', linestyle='--', linewidth=0.5, alpha=0.7)
|
|
|
|
ax.set_title('Building Self-Sufficiency Levels', fontsize=16, fontweight='bold', pad=20)
|
|
|
|
ax.set_xlabel('Longitude', fontsize=12)
|
|
|
|
ax.set_ylabel('Latitude', fontsize=12)
|
|
|
|
|
|
|
|
plt.tight_layout()
|
|
|
|
plt.show()
|