Setup sra, meb, and building selection of 500 m^2 or more
This commit is contained in:
parent
0ac7f78196
commit
5deeb9c355
8768
data/CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw
Normal file
8768
data/CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -1,16 +1,29 @@
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import datetime
|
import datetime
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from hub.imports.geometry_factory import GeometryFactory
|
from hub.imports.geometry_factory import GeometryFactory
|
||||||
from hub.imports.construction_factory import ConstructionFactory
|
from hub.imports.construction_factory import ConstructionFactory
|
||||||
from hub.imports.usage_factory import UsageFactory
|
from hub.imports.usage_factory import UsageFactory
|
||||||
|
from hub.imports.results_factory import ResultFactory
|
||||||
|
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
|
||||||
|
from hub.exports.exports_factory import ExportsFactory
|
||||||
from hub.helpers.data.montreal_function_to_hub_function import MontrealFunctionToHubFunction
|
from hub.helpers.data.montreal_function_to_hub_function import MontrealFunctionToHubFunction
|
||||||
|
|
||||||
|
from sra import Sra
|
||||||
|
from meb import Meb
|
||||||
|
|
||||||
class EnergyValidation:
|
class EnergyValidation:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
self.weather_file = Path('./data/CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw').resolve()
|
||||||
|
self.climate_file_name = 'Montreal'
|
||||||
|
self.tmp_folder = Path('./tmp').resolve()
|
||||||
|
self.storage_path = Path('./storage').resolve()
|
||||||
|
self.climate_file = Path(f'{self.storage_path}/{self.climate_file_name}.cli').resolve()
|
||||||
|
self.meb_folder = Path('./results/meb').resolve()
|
||||||
|
self.ep_folder = Path('./results/ep').resolve()
|
||||||
|
|
||||||
def _sort_buildings(self, buildings_to_simulate):
|
def _sort_buildings(self, buildings_to_simulate):
|
||||||
sorted_buildings = {}
|
sorted_buildings = {}
|
||||||
for building in buildings_to_simulate:
|
for building in buildings_to_simulate:
|
||||||
|
@ -22,46 +35,76 @@ class EnergyValidation:
|
||||||
|
|
||||||
def run(self, building_set, building_quantities):
|
def run(self, building_set, building_quantities):
|
||||||
sorted_buildings = self._sort_buildings(building_set)
|
sorted_buildings = self._sort_buildings(building_set)
|
||||||
buildings_to_simulate = []
|
building_to_simulate = []
|
||||||
|
min_m2_satisfied = False
|
||||||
|
|
||||||
for code_utili in building_quantities:
|
for code_utili in building_quantities:
|
||||||
if code_utili in sorted_buildings:
|
if code_utili not in sorted_buildings:
|
||||||
for building in range(building_quantities[code_utili]):
|
print(f'CODE_UTILI:{code_utili} is not found in the provided dataset.')
|
||||||
buildings_to_simulate.append(sorted_buildings[code_utili]
|
|
||||||
[random.randrange(len(sorted_buildings[code_utili]))])
|
|
||||||
else:
|
else:
|
||||||
print(f'{code_utili} is not found in the provided dataset.')
|
for building in range(building_quantities[code_utili]):
|
||||||
|
# only select buildings with an area of 500 m^2 or more
|
||||||
|
while not min_m2_satisfied:
|
||||||
|
building_to_simulate.append(sorted_buildings[code_utili][random.randrange(
|
||||||
|
len(sorted_buildings[code_utili]))])
|
||||||
|
if building_to_simulate[0]['bldgarea'] < 500:
|
||||||
|
building_to_simulate.clear()
|
||||||
|
else:
|
||||||
|
min_m2_satisfied = True
|
||||||
|
|
||||||
|
building_id = building_to_simulate[0]['id']
|
||||||
|
|
||||||
geojson = {
|
geojson = {
|
||||||
"type": "FeatureCollection",
|
"type": "FeatureCollection",
|
||||||
"features": buildings_to_simulate
|
"features": building_to_simulate
|
||||||
}
|
}
|
||||||
|
|
||||||
geojson_file_name = f'energy_validation{datetime.datetime.now().strftime("_%Y-%m-%d_%H-%M-%S")}.geojson'
|
geojson_file = open(f'tmp/{building_id}_energy_validation.geojson', 'w')
|
||||||
geojson_file = open(geojson_file_name, 'w')
|
|
||||||
geojson_file.write(json.dumps(geojson, indent=2))
|
geojson_file.write(json.dumps(geojson, indent=2))
|
||||||
geojson_file.close()
|
geojson_file.close()
|
||||||
|
|
||||||
|
|
||||||
city = GeometryFactory('geojson',
|
city = GeometryFactory('geojson',
|
||||||
path=geojson_file_name,
|
path=f'tmp/{building_id}_energy_validation.geojson',
|
||||||
height_field='building_height',
|
height_field='building_height',
|
||||||
year_of_construction_field='ANNEE_CONS',
|
year_of_construction_field='ANNEE_CONS',
|
||||||
function_field='CODE_UTILI',
|
function_field='CODE_UTILI',
|
||||||
function_to_hub=MontrealFunctionToHubFunction().dictionary).city
|
function_to_hub=MontrealFunctionToHubFunction().dictionary).city
|
||||||
ConstructionFactory('nrcan', city).enrich()
|
ConstructionFactory('nrcan', city).enrich()
|
||||||
UsageFactory('nrcan', city).enrich(
|
UsageFactory('nrcan', city).enrich()
|
||||||
|
|
||||||
|
if city.climate_reference_city is None:
|
||||||
|
city.name = f'Concordia current status {building_id}'
|
||||||
|
city.climate_reference_city = city.location
|
||||||
|
self.climate_file_name = city.location
|
||||||
|
city.climate_file = self.climate_file
|
||||||
|
|
||||||
|
print(f'{building_id} starting sra')
|
||||||
|
start = datetime.datetime.now()
|
||||||
|
ExportsFactory('sra', city, self.tmp_folder, weather_file=self.weather_file, weather_format='epw').export()
|
||||||
|
sra_file = (self.tmp_folder / f'{city.name}_sra.xml').resolve()
|
||||||
|
Sra(sra_file, self.tmp_folder).run()
|
||||||
|
ResultFactory('sra', city, self.tmp_folder).enrich()
|
||||||
|
sra_time = datetime.datetime.now() - start
|
||||||
|
print(f"{building_id} SRA time: {sra_time}\n")
|
||||||
|
|
||||||
|
print(f'{building_id} starting meb')
|
||||||
|
start = datetime.datetime.now()
|
||||||
|
for building in city.buildings:
|
||||||
|
building.attic_heated = 0
|
||||||
|
building.basement_heated = 1
|
||||||
|
|
||||||
|
EnergyBuildingsExportsFactory('insel_monthly_energy_balance', city, self.meb_folder).export()
|
||||||
|
Meb(self.meb_folder).run()
|
||||||
|
|
||||||
|
meb_time = datetime.datetime.now() - start
|
||||||
|
print(f"{building_id} meb time: {meb_time}\n")
|
||||||
|
|
||||||
|
#print('starting energy plus')
|
||||||
|
building_to_simulate.clear()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# test_file = open('test.geojson', 'w')
|
|
||||||
# test_file.write(json.dumps(sorted_buildings, indent=2))
|
|
||||||
# test_file.close()
|
|
||||||
data_file = open('data/VMTrial_cleaned.geojson', 'r')
|
data_file = open('data/VMTrial_cleaned.geojson', 'r')
|
||||||
city = json.load(data_file)
|
city = json.load(data_file)
|
||||||
buildings = city['features']
|
buildings = city['features']
|
||||||
|
|
23
meb.py
Normal file
23
meb.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import subprocess
|
||||||
|
from subprocess import SubprocessError, TimeoutExpired, CalledProcessError
|
||||||
|
import glob
|
||||||
|
|
||||||
|
class Meb:
|
||||||
|
def __init__(self, file_path):
|
||||||
|
"""
|
||||||
|
SRA class
|
||||||
|
:param file_path: insel file path
|
||||||
|
"""
|
||||||
|
self._file_path = file_path
|
||||||
|
self._executable = 'insel'
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
"""
|
||||||
|
Calls the software
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
_insel_files = glob.glob(f'{self._file_path}/*.insel')
|
||||||
|
for insel_file in _insel_files:
|
||||||
|
subprocess.run([self._executable, str(insel_file)], stdout=subprocess.DEVNULL)
|
||||||
|
except (SubprocessError, TimeoutExpired, CalledProcessError) as error:
|
||||||
|
raise Exception(error)
|
27
sra.py
Normal file
27
sra.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import subprocess
|
||||||
|
from subprocess import SubprocessError, TimeoutExpired, CalledProcessError
|
||||||
|
import platform
|
||||||
|
|
||||||
|
class Sra:
|
||||||
|
def __init__(self, file_path, output_file_path):
|
||||||
|
"""
|
||||||
|
SRA class
|
||||||
|
:param file_path: _sra.xml file path
|
||||||
|
:param output_file_path: path to output the sra calculation
|
||||||
|
"""
|
||||||
|
self._file_path = file_path
|
||||||
|
self._output_file_path = output_file_path
|
||||||
|
if platform.system() == 'Linux':
|
||||||
|
self._executable = 'citysim_sra'
|
||||||
|
elif platform.system() == 'Windows':
|
||||||
|
self._executable = 'shortwave_integer'
|
||||||
|
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
"""
|
||||||
|
Calls the software
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
subprocess.run([self._executable, str(self._file_path)], stdout=subprocess.DEVNULL)
|
||||||
|
except (SubprocessError, TimeoutExpired, CalledProcessError) as error:
|
||||||
|
raise Exception(error)
|
Loading…
Reference in New Issue
Block a user