system_assignation/MEB_test.py

67 lines
2.8 KiB
Python
Raw Normal View History

2024-03-05 17:29:05 -05:00
from geojson_creator import process_geojson
from pathlib import Path
import subprocess
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
from hub.helpers.dictionaries import Dictionaries
from hub.imports.construction_factory import ConstructionFactory
from hub.imports.geometry_factory import GeometryFactory
from hub.imports.weather_factory import WeatherFactory
from hub.imports.results_factory import ResultFactory
from hub.imports.usage_factory import UsageFactory
from hub.exports.exports_factory import ExportsFactory
from scripts.ep_workflow import energy_plus_workflow
import matplotlib.pyplot as plt
import random
import matplotlib.colors as mcolors
import hub.helpers.constants as cte
2024-03-05 17:29:05 -05:00
# Process geojson
2024-03-05 17:29:05 -05:00
geojson_file = process_geojson(x=-73.5681295982132, y=45.49218262677643, diff=0.0001)
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October',
'November', 'December']
2024-03-05 17:29:05 -05:00
out_path = (Path(__file__).parent / 'out_files')
file_path = (Path(__file__).parent.parent / 'input_files' / f'{geojson_file}')
print('[simulation start]')
city = GeometryFactory('geojson',
path=file_path,
height_field='height',
year_of_construction_field='year_of_construction',
function_field='function',
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
print(f'city created from {file_path}')
# Enrich city data
2024-03-05 17:29:05 -05:00
ConstructionFactory('nrcan', city).enrich()
UsageFactory('nrcan', city).enrich()
WeatherFactory('epw', city).enrich()
ExportsFactory('sra', city, out_path).export()
sra_path = (out_path / f'{city.name}_sra.xml').resolve()
subprocess.run(['sra', str(sra_path)])
ResultFactory('sra', city, out_path).enrich()
EnergyBuildingsExportsFactory('insel_monthly_energy_balance', city, out_path).export_debug()
# Create grid of plots
fig, axs = plt.subplots(3, 2, figsize=(12, 12))
# Plot monthly heating demands from Monthly Energy Balance
for i, building in enumerate(city.buildings):
monthly_heating_demand = [peak / 3.6e6 for peak in building.heating_peak_load[cte.MONTH]]
ax = axs[i, 0] # Select subplot in the first column
ax.plot(months, monthly_heating_demand)
ax.set_title(f'Monthly Heating Demand (Building {i+1})')
ax.set_xlabel('Month')
ax.set_ylabel('Heating Demand')
# Plot monthly heating demands from EnergyPlus
energy_plus_workflow(city)
for i, ep in enumerate(city.buildings):
monthly_heating_demand = [peak / 3.6e6 for peak in ep.heating_peak_load[cte.MONTH]]
ax = axs[i, 1] # Select subplot in the second column
ax.plot(months, monthly_heating_demand)
ax.set_title(f'Monthly Heating Demand (Building {i+1})')
ax.set_xlabel('Month')
ax.set_ylabel('Heating Demand')
plt.tight_layout()
plt.show()