Changes to extract the monthly calculation as a class for the game
This commit is contained in:
parent
c254c42608
commit
81b46fb5c4
68
main.py
68
main.py
|
@ -9,16 +9,15 @@ from pathlib import Path
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
import ast
|
import ast
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
import datetime
|
||||||
|
|
||||||
from helpers import monthly_values as mv
|
from helpers import monthly_values as mv
|
||||||
from populate import Populate
|
from populate import Populate
|
||||||
from insel.insel import Insel
|
|
||||||
from insel.templates.monthly_energy_balance import MonthlyEnergyBalance as templates
|
|
||||||
from simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
|
from simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
|
||||||
from imports.geometry_factory import GeometryFactory
|
from imports.geometry_factory import GeometryFactory
|
||||||
from imports.weather_factory import WeatherFactory
|
from imports.weather_factory import WeatherFactory
|
||||||
from city_model_structure.city import City
|
from city_model_structure.city import City
|
||||||
import datetime
|
from monthly_demand_calculation import MonthlyDemandCalculation
|
||||||
|
|
||||||
parser = ArgumentParser(description='Monthly energy balance workflow v0.1.')
|
parser = ArgumentParser(description='Monthly energy balance workflow v0.1.')
|
||||||
required = parser.add_argument_group('required arguments')
|
required = parser.add_argument_group('required arguments')
|
||||||
|
@ -52,6 +51,12 @@ else:
|
||||||
file = Path(args.input_geometry_file).resolve()
|
file = Path(args.input_geometry_file).resolve()
|
||||||
pickle_file = Path(str(file).replace('.gml', '.pickle'))
|
pickle_file = Path(str(file).replace('.gml', '.pickle'))
|
||||||
city = GeometryFactory(args.geometry_type, file).city
|
city = GeometryFactory(args.geometry_type, file).city
|
||||||
|
print(len(city.buildings))
|
||||||
|
for building in city.buildings:
|
||||||
|
volume = building.volume
|
||||||
|
if str(volume) == 'inf':
|
||||||
|
sys.stderr.write(f'Building {building.name} has geometry errors. It has been removed from the city\n')
|
||||||
|
city.remove_city_object(building)
|
||||||
city.save(pickle_file)
|
city.save(pickle_file)
|
||||||
|
|
||||||
print('begin_populating_time', datetime.datetime.now())
|
print('begin_populating_time', datetime.datetime.now())
|
||||||
|
@ -95,51 +100,43 @@ if not weather_step_in_pickle:
|
||||||
else:
|
else:
|
||||||
total_number_of_buildings = len(city.buildings)
|
total_number_of_buildings = len(city.buildings)
|
||||||
if total_number_of_buildings > max_buildings_handled_by_sra:
|
if total_number_of_buildings > max_buildings_handled_by_sra:
|
||||||
radius = 100
|
radius = 80
|
||||||
for building in city.buildings:
|
for building in city.buildings:
|
||||||
new_city = city.region(building.location, radius)
|
new_city = city.region(building.centroid, radius)
|
||||||
sra_new = SimplifiedRadiosityAlgorithm(city, Path(args.project_folder).resolve(), args.weather_file_name)
|
sra_new = SimplifiedRadiosityAlgorithm(new_city, Path(args.project_folder).resolve(), args.weather_file_name)
|
||||||
sra_new.call_sra(keep_files=True)
|
sra_new.call_sra(keep_files=True)
|
||||||
sra_new.set_irradiance_surfaces(city, building_name=building.name)
|
sra_new.set_irradiance_surfaces(populated_city, building_name=building.name)
|
||||||
else:
|
else:
|
||||||
sra.call_sra(keep_files=keep_files)
|
sra.call_sra(keep_files=keep_files)
|
||||||
sra.set_irradiance_surfaces(populated_city)
|
sra.set_irradiance_surfaces(populated_city)
|
||||||
pickle_file = Path(str(pickle_file).replace('.pickle', '_weather.pickle'))
|
pickle_file = Path(str(pickle_file).replace('.pickle', '_weather.pickle'))
|
||||||
populated_city.save(pickle_file)
|
populated_city.save(pickle_file)
|
||||||
|
|
||||||
print('begin_insel_time', datetime.datetime.now())
|
weather_format = 'epw'
|
||||||
# Step 4: Demand calculation (one model per building)
|
|
||||||
print_results = None
|
print('begin_user_assignment_time', datetime.datetime.now())
|
||||||
file = 'city name: ' + city.name + '\n'
|
# Step 4: Assign user defined parameters
|
||||||
|
|
||||||
for building in populated_city.buildings:
|
for building in populated_city.buildings:
|
||||||
if building.name != 'BLD122177':
|
|
||||||
# todo: default values to be defined at each specific workflow!
|
|
||||||
building.heated = True
|
building.heated = True
|
||||||
building.cooled = False
|
building.cooled = False
|
||||||
building.attic_heated = 1
|
building.attic_heated = 2
|
||||||
building.basement_heated = 1
|
building.basement_heated = 0
|
||||||
building.usage_zones[0].internal_gains[0].average_internal_gain = 10.45
|
# for value in building.heating['month']['INSEL']:
|
||||||
full_path_out = Path(args.project_folder + '/outputs/' + building.name + '_insel.out').resolve()
|
|
||||||
full_path_out.parent.mkdir(parents=True, exist_ok=True)
|
print('begin_insel_time', datetime.datetime.now())
|
||||||
|
MonthlyDemandCalculation(city, args.project_folder, weather_format).monthly_demand()
|
||||||
|
|
||||||
|
print('begin_write_results_time', datetime.datetime.now())
|
||||||
|
print_results = None
|
||||||
|
file = 'city name: ' + city.name + '\n'
|
||||||
|
for building in populated_city.buildings:
|
||||||
insel_file_name = building.name + '.insel'
|
insel_file_name = building.name + '.insel'
|
||||||
try:
|
building_results = building.heating['month'].rename(columns={'INSEL': building.name})
|
||||||
key = 'epw'
|
|
||||||
content = templates.generate_meb_template(building, full_path_out, key)
|
|
||||||
insel = Insel(Path(args.project_folder).resolve(), insel_file_name, content, mode=2, keep_files=keep_files).run()
|
|
||||||
building.heating['month'], building.cooling['month'] = templates.demand(full_path_out)
|
|
||||||
new_building = building.heating['month'].rename(columns={'INSEL': building.name})
|
|
||||||
demand_year = 0
|
|
||||||
for value in building.heating['month']['INSEL']:
|
|
||||||
if value == 'NaN':
|
|
||||||
value = '0'
|
|
||||||
demand_year += float(value)
|
|
||||||
yearly_heating = pd.DataFrame([demand_year], columns=['INSEL'])
|
|
||||||
building.heating['year'] = yearly_heating
|
|
||||||
if print_results is None:
|
if print_results is None:
|
||||||
print_results = new_building
|
print_results = building_results
|
||||||
else:
|
else:
|
||||||
print_results = pd.concat([print_results, new_building], axis='columns')
|
print_results = pd.concat([print_results, building_results], axis='columns')
|
||||||
file += '\n'
|
file += '\n'
|
||||||
file += 'name: ' + building.name + '\n'
|
file += 'name: ' + building.name + '\n'
|
||||||
file += 'year of construction: ' + building.year_of_construction + '\n'
|
file += 'year of construction: ' + building.year_of_construction + '\n'
|
||||||
|
@ -149,11 +146,6 @@ for building in populated_city.buildings:
|
||||||
file += 'heated_volume: ' + str(building.volume) + '\n'
|
file += 'heated_volume: ' + str(building.volume) + '\n'
|
||||||
file += 'volume: ' + str(building.volume) + '\n'
|
file += 'volume: ' + str(building.volume) + '\n'
|
||||||
|
|
||||||
except ValueError:
|
|
||||||
print(sys.exc_info()[1])
|
|
||||||
print('Building ' + building.name + ' could not be processed')
|
|
||||||
continue
|
|
||||||
|
|
||||||
full_path_results = Path(args.project_folder + '/outputs/heating_demand.csv').resolve()
|
full_path_results = Path(args.project_folder + '/outputs/heating_demand.csv').resolve()
|
||||||
print_results.to_csv(full_path_results)
|
print_results.to_csv(full_path_results)
|
||||||
full_path_metadata = Path(args.project_folder + '/outputs/metadata.csv').resolve()
|
full_path_metadata = Path(args.project_folder + '/outputs/metadata.csv').resolve()
|
||||||
|
|
49
monthly_demand_calculation.py
Normal file
49
monthly_demand_calculation.py
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
"""
|
||||||
|
Monthly demand calculation using the monthly energy balance methodology based on the norm...
|
||||||
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||||
|
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||||
|
"""
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
import pandas as pd
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from insel.templates.monthly_energy_balance import MonthlyEnergyBalance as templates
|
||||||
|
from insel.insel import Insel
|
||||||
|
|
||||||
|
|
||||||
|
class MonthlyDemandCalculation:
|
||||||
|
def __init__(self, city, main_path, weather_format):
|
||||||
|
self._city = city
|
||||||
|
self._main_path = main_path
|
||||||
|
self._weather_format = weather_format
|
||||||
|
|
||||||
|
def monthly_demand(self):
|
||||||
|
for building in self._city.buildings:
|
||||||
|
full_path_out = Path(self._main_path + '/outputs/' + building.name + '_insel.out').resolve()
|
||||||
|
full_path_out.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
insel_file_name = building.name + '.insel'
|
||||||
|
try:
|
||||||
|
content = templates.generate_meb_template(building, full_path_out, self._weather_format)
|
||||||
|
insel = Insel(Path(self._main_path).resolve(), insel_file_name, content, mode=2, keep_files=True).run()
|
||||||
|
building.heating['month'], building.cooling['month'] = templates.demand(full_path_out)
|
||||||
|
heating_year = 0
|
||||||
|
for value in building.heating['month']['INSEL']:
|
||||||
|
if value == 'NaN':
|
||||||
|
value = '0'
|
||||||
|
heating_year += float(value)
|
||||||
|
yearly_heating = pd.DataFrame([heating_year], columns=['INSEL'])
|
||||||
|
building.heating['year'] = yearly_heating
|
||||||
|
|
||||||
|
cooling_year = 0
|
||||||
|
for value in building.cooling['month']['INSEL']:
|
||||||
|
if value == 'NaN':
|
||||||
|
value = '0'
|
||||||
|
cooling_year += float(value)
|
||||||
|
yearly_cooling = pd.DataFrame([cooling_year], columns=['INSEL'])
|
||||||
|
building.cooling['year'] = yearly_cooling
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
print(sys.exc_info()[1])
|
||||||
|
print('Building ' + building.name + ' could not be processed')
|
||||||
|
continue
|
Loading…
Reference in New Issue
Block a user