133 lines
8.5 KiB
Python
133 lines
8.5 KiB
Python
from pathlib import Path
|
|
import pandas as pd
|
|
from building_modelling.ep_run_enrich import energy_plus_workflow
|
|
from hub.helpers.dictionaries import Dictionaries
|
|
from hub.imports.construction_factory import ConstructionFactory
|
|
from hub.imports.energy_systems_factory import EnergySystemsFactory
|
|
from hub.imports.geometry_factory import GeometryFactory
|
|
from hub.imports.usage_factory import UsageFactory
|
|
from hub.imports.weather_factory import WeatherFactory
|
|
from energy_system_modelling_package import random_assignation
|
|
from energy_system_modelling_package.energy_system_modelling_factories.pv_assessment.electricity_demand_calculator import HourlyElectricityDemand
|
|
import hub.helpers.constants as cte
|
|
import json
|
|
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'
|
|
city = GeometryFactory(file_type='geojson',
|
|
path=geojson_path,
|
|
aliases_field=['address'],
|
|
height_field='height',
|
|
year_of_construction_field='year_of_construction',
|
|
function_field='function',
|
|
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
|
|
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()
|
|
residential_buildings = []
|
|
non_residential_buildings = []
|
|
for building in city.buildings:
|
|
if building.function == cte.RESIDENTIAL:
|
|
residential_buildings.append(building)
|
|
else:
|
|
non_residential_buildings.append(building)
|
|
# random_assignation.call_random(residential_buildings, random_assignation.residential_systems_percentage)
|
|
# random_assignation.call_random(non_residential_buildings, random_assignation.non_residential_systems_percentage)
|
|
# EnergySystemsFactory('montreal_future', city).enrich()
|
|
base_results = pd.read_csv(output_files_path / 'results_summary.csv')
|
|
energy_system_archetypes = base_results['energy_system_archetype_name'].to_list()
|
|
for (i, building) in enumerate(city.buildings):
|
|
building.energy_systems_archetype_name = energy_system_archetypes[i]
|
|
EnergySystemsFactory('montreal_future', city).enrich()
|
|
energy_plus_workflow(city, energy_plus_output_path)
|
|
# hourly_simulation_results = {}
|
|
# hourly_elec_consumption = pd.DataFrame()
|
|
# hourly_lighting_appliance_consumption = pd.DataFrame()
|
|
# for building in city.buildings:
|
|
# hourly_electricity_consumption = HourlyElectricityDemand(building).calculate()
|
|
# heating_electricity_consumption = building.heating_consumption[
|
|
# cte.HOUR] if 'electricity' in building.energy_systems_archetype_name else [0] * len(
|
|
# building.heating_demand[cte.HOUR])
|
|
# dhw_electricity_consumption = building.domestic_hot_water_consumption[
|
|
# cte.HOUR] if 'electricity' in building.energy_systems_archetype_name else [0] * len(
|
|
# building.domestic_hot_water_heat_demand[cte.HOUR])
|
|
# if building.cooling_consumption[cte.YEAR][0] == 0:
|
|
# cooling_electricity_consumption = [building.cooling_demand[cte.HOUR][i] / (2 * 3.23) for i in
|
|
# range(len(building.cooling_consumption[cte.HOUR]))]
|
|
# hourly_electricity_consumption = [hourly_electricity_consumption[i] + cooling_electricity_consumption[i] for i in range(len(hourly_electricity_consumption))]
|
|
# else:
|
|
# cooling_electricity_consumption = building.cooling_consumption[cte.HOUR]
|
|
# lighting = building.lighting_electrical_demand[cte.HOUR]
|
|
# appliance = building.appliances_electrical_demand[cte.HOUR]
|
|
#
|
|
# results = pd.DataFrame()
|
|
# results['heating_electricity_consumption_kWh'] = [x / (cte.WATTS_HOUR_TO_JULES * 1000) for x in
|
|
# heating_electricity_consumption]
|
|
# results['cooling_electricity_consumption_kWh'] = [x / (cte.WATTS_HOUR_TO_JULES * 1000) for x in
|
|
# cooling_electricity_consumption]
|
|
# results['dhw_electricity_consumption_kWh'] = [x / (cte.WATTS_HOUR_TO_JULES * 1000) for x in
|
|
# dhw_electricity_consumption]
|
|
# results['lighting_kWh'] = [x / (cte.WATTS_HOUR_TO_JULES * 1000) for x in lighting]
|
|
#
|
|
# results['appliance_kWh'] = [x / (cte.WATTS_HOUR_TO_JULES * 1000) for x in appliance]
|
|
# results['lighting_appliance_total_kWh'] = [(lighting[i] + appliance[i]) / (cte.WATTS_HOUR_TO_JULES * 1000)
|
|
# for i in range(len(lighting))]
|
|
# results['total_electricity_consumption_kWh'] = [x / (cte.WATTS_HOUR_TO_JULES * 1000) for x in hourly_electricity_consumption]
|
|
# results.to_csv(output_files_path / 'paper_results' / 'individual_building_simulation_results' / f'{building.name}.csv')
|
|
# hourly_elec_consumption[f'{building.name}'] = [x / (cte.WATTS_HOUR_TO_JULES * 1000) for x in hourly_electricity_consumption]
|
|
# hourly_lighting_appliance_consumption[f'{building.name}'] = [(lighting[i] + appliance[i]) / (cte.WATTS_HOUR_TO_JULES * 1000)
|
|
# for i in range(len(lighting))]
|
|
#
|
|
# hourly_elec_consumption.to_csv(output_files_path / 'paper_results' / 'total_hourly_electricity_consumption.csv')
|
|
# hourly_lighting_appliance_consumption.to_csv(output_files_path / 'paper_results' / 'total_lighting_appliance.csv')
|
|
building_names = [building.name for building in city.buildings]
|
|
building_addresses = [building.aliases[0] for building in city.buildings]
|
|
building_heights = [building.max_height for building in city.buildings]
|
|
buildings_total_floor_areas = [building.thermal_zones_from_internal_zones[0].total_floor_area
|
|
for building in city.buildings]
|
|
buildings_roof_areas = [building.roofs[0].perimeter_area for building in city.buildings]
|
|
building_energy_system_archetype_names = [building.energy_systems_archetype_name for building in city.buildings]
|
|
building_yearly_heating_electricity_consumptions = []
|
|
building_yearly_dhw_electricity_consumptions = []
|
|
for building in city.buildings:
|
|
if 'electricity' in building.energy_systems_archetype_name:
|
|
building_yearly_heating_electricity_consumptions.append(building.heating_consumption[cte.YEAR][0] /
|
|
(cte.WATTS_HOUR_TO_JULES * 1000))
|
|
building_yearly_dhw_electricity_consumptions.append(building.domestic_hot_water_consumption[cte.YEAR][0] /
|
|
(cte.WATTS_HOUR_TO_JULES * 1000))
|
|
else:
|
|
building_yearly_heating_electricity_consumptions.append(0)
|
|
building_yearly_dhw_electricity_consumptions.append(0)
|
|
|
|
building_yearly_cooling_consumptions = []
|
|
for building in city.buildings:
|
|
if building.cooling_consumption[cte.YEAR][0] == 0:
|
|
building_yearly_cooling_consumptions.append(building.cooling_demand[cte.YEAR][0] / (2 * 3.23 * cte.WATTS_HOUR_TO_JULES * 1000))
|
|
else:
|
|
building_yearly_cooling_consumptions.append(building.cooling_consumption[cte.YEAR][0] / (cte.WATTS_HOUR_TO_JULES * 1000))
|
|
building_yearly_lighting_demands = [building.lighting_electrical_demand[cte.YEAR][0] / (cte.WATTS_HOUR_TO_JULES * 1000)
|
|
for building in city.buildings]
|
|
building_yearly_appliance_demands = [building.appliances_electrical_demand[cte.YEAR][0] / (cte.WATTS_HOUR_TO_JULES * 1000)
|
|
for building in city.buildings]
|
|
summary = pd.DataFrame()
|
|
summary['building_name'] = building_names
|
|
summary['building_address'] = building_addresses
|
|
summary['building_height_m'] = building_heights
|
|
summary['total_floor_area_m2'] = buildings_total_floor_areas
|
|
summary['roof_area_m2'] = buildings_roof_areas
|
|
summary['energy_system_archetype_name'] = building_energy_system_archetype_names
|
|
summary['yearly_heating_electricity_consumption_kWh'] = building_yearly_heating_electricity_consumptions
|
|
summary['yearly_cooling_electricity_consumption_kWh'] = building_yearly_cooling_consumptions
|
|
summary['yearly_dhw_electricity_consumption_kWh'] = building_yearly_dhw_electricity_consumptions
|
|
summary['yearly_lighting_consumption_kWh'] = building_yearly_lighting_demands
|
|
summary['yearly_appliance_consumption_kWh'] = building_yearly_appliance_demands
|
|
summary.to_csv(output_files_path / 'yearly_results.csv', index=False)
|