refactoring workflow. This project depends now only on the hub and no other projects

This commit is contained in:
Pilar Monsalvete 2023-03-23 13:31:36 -04:00
parent 2864e8e59c
commit 813449799e
8 changed files with 123 additions and 8934 deletions

View File

@ -1,22 +0,0 @@
from pathlib import Path
import json
try:
file_path = (Path(__file__).parent / 'input_files' / 'part.geojson')
output_file_path = (Path(__file__).parent / 'input_files' / 'selected_building.geojson').resolve()
selected_building = 5755
with open(file_path) as json_file:
_geojson = json.loads(json_file.read())
features = [_geojson['features'][selected_building - 1]]
output_json = {"type": "FeatureCollection",
"features": features
}
json_object = json.dumps(output_json, indent=4)
with open(output_file_path, "w") as outfile:
outfile.write(json_object)
except Exception as ex:
print(ex)
print('error: ', ex)

27
main.py
View File

@ -4,9 +4,10 @@ from hub.imports.geometry_factory import GeometryFactory
from hub.imports.construction_factory import ConstructionFactory
from hub.imports.usage_factory import UsageFactory
from hub.imports.weather_factory import WeatherFactory
from simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
from monthly_energy_balance import MonthlyEnergyBalance
from hub.helpers.dictionaries import Dictionaries
from results import Results
from monthly_energy_balance_engine import MonthlyEnergyBalanceEngine
from sra_engine import SraEngine
try:
@ -20,6 +21,7 @@ try:
basement_heated_case = 1
out_path = (Path(__file__).parent / 'output_files')
tmp_folder = (Path(__file__).parent / 'tmp')
print('[simulation start]')
city = GeometryFactory('geojson',
@ -29,7 +31,7 @@ try:
function_field='CODE_UTILI',
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
city.climate_reference_city = climate_reference_city
city.climate_file = (Path(__file__).parent / 'tmp' / f'{climate_reference_city}.cli').resolve()
city.climate_file = (tmp_folder / f'{climate_reference_city}.cli').resolve()
print(f'city created from {file_path}')
WeatherFactory(weather_format, city, file_name=weather_file).enrich()
print('enrich weather... done')
@ -39,17 +41,22 @@ try:
print('enrich usage... done')
print('exporting:')
sra = SimplifiedRadiosityAlgorithm(city, Path(__file__).parent, weather_file)
print(' sra exported...')
sra.call_sra(weather_format, keep_files=True)
sra.set_irradiance_surfaces(city)
sra.set_irradiance_surfaces(city, mode=1)
sra_file = (tmp_folder / f'{city.name}_sra.xml').resolve()
SraEngine(city, sra_file, tmp_folder, weather_file)
# Assign radiation to the city
print(' sra processed...')
MonthlyEnergyBalance(city, out_path, attic_heated_case, basement_heated_case, weather_format)
for building in city.buildings:
building.attic_heated = attic_heated_case
building.basement_heated = basement_heated_case
MonthlyEnergyBalanceEngine(city, tmp_folder)
print(' insel processed...')
results = Results(city, out_path)
results.print()
print('print results...')
print('[simulation end]')
except Exception as ex:

View File

@ -0,0 +1,29 @@
import subprocess
from subprocess import SubprocessError, TimeoutExpired, CalledProcessError
import glob
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
from hub.imports.results_factory import ResultFactory
class MonthlyEnergyBalanceEngine:
def __init__(self, city, file_path):
"""
MEB class
:param file_path: insel file path
"""
self._city = city
self._file_path = file_path
EnergyBuildingsExportsFactory('insel_monthly_energy_balance', self._city, self._file_path).export()
ResultFactory('insel_meb', self._city, self._file_path).enrich()
self._run()
def _run(self):
"""
Calls the software
"""
try:
_insel_files = glob.glob(f'{self._file_path}/*.insel')
for insel_file in _insel_files:
subprocess.run(['insel', str(insel_file)], stdout=subprocess.DEVNULL)
except (SubprocessError, TimeoutExpired, CalledProcessError) as error:
raise Exception(error)

38
results.py Normal file
View File

@ -0,0 +1,38 @@
from pathlib import Path
import pandas as pd
import hub.helpers.constants as cte
class Results:
def __init__(self, city, path):
self._city = city
self._path = path
def print(self):
print_results = None
file = 'city name: ' + self._city.name + '\n'
for building in self._city.buildings:
heating_results = building.heating[cte.MONTH].rename(columns={'INSEL': f'{building.name} heating Wh'})
cooling_results = building.cooling[cte.MONTH].rename(columns={'INSEL': f'{building.name} cooling Wh'})
if print_results is None:
print_results = heating_results
else:
print_results = pd.concat([print_results, heating_results], axis='columns')
print_results = pd.concat([print_results, cooling_results,
building.lighting_electrical_demand,
building.appliances_electrical_demand,
building.domestic_hot_water_heat_demand], axis='columns')
file += '\n'
file += 'name: ' + building.name + '\n'
file += 'year of construction: ' + str(building.year_of_construction) + '\n'
file += 'function: ' + building.function + '\n'
file += 'floor area: ' + str(building.floor_area) + '\n'
file += 'storeys: ' + str(int(building.eave_height / building.average_storey_height)) + '\n'
file += 'heated_volume: ' + str(0.85 * building.volume) + '\n'
file += 'volume: ' + str(building.volume) + '\n'
full_path_results = Path(self._path / 'demand.csv').resolve()
print_results.to_csv(full_path_results)
full_path_metadata = Path(self._path / 'metadata.csv').resolve()
with open(full_path_metadata, 'w') as metadata_file:
metadata_file.write(file)

35
sra_engine.py Normal file
View File

@ -0,0 +1,35 @@
import subprocess
from subprocess import SubprocessError, TimeoutExpired, CalledProcessError
import platform
from hub.exports.exports_factory import ExportsFactory
from hub.imports.results_factory import ResultFactory
class SraEngine:
def __init__(self, city, file_path, output_file_path, weather_file):
"""
SRA class
:param file_path: _sra.xml file path
:param output_file_path: path to output the sra calculation
"""
self._city = city
self._file_path = file_path
self._output_file_path = output_file_path
self._weather_file = weather_file
if platform.system() == 'Linux':
self._executable = 'citysim_sra'
elif platform.system() == 'Windows':
self._executable = 'shortwave_integer'
ExportsFactory('sra', self._city, output_file_path, weather_file=self._weather_file, weather_format='epw').export()
self._run()
ResultFactory('sra', self._city, output_file_path).enrich()
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)

4
tmp/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

File diff suppressed because it is too large Load Diff

View File

@ -1,138 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<CitySim name="Montréal_sra.xml">
<Simulation beginMonth="1" beginDay="1" endMonth="12" endDay="31"/>
<Climate location="C:\Users\Pilar\PycharmProjects\monthly_energy_balance_workflow\tmp\Montreal.cli" city="Montreal Int'l"/>
<District>
<FarFieldObstructions/>
<Building Name="1_part_0_zone_0" id="0" key="1_part_0_zone_0" Simulate="true">
<Wall id="2" ShortWaveReflectance="0.30000000000000004">
<V0 x="252.80846728943288" y="89.8574255798012" z="0.0"/>
<V1 x="181.8214726387523" y="194.92937748879194" z="0.0"/>
<V2 x="181.8214726387523" y="194.92937748879194" z="21.824"/>
<V3 x="252.80846728943288" y="89.8574255798012" z="21.824"/>
</Wall>
<Wall id="3" ShortWaveReflectance="0.30000000000000004">
<V0 x="181.8214726387523" y="194.92937748879194" z="0.0"/>
<V1 x="107.93012678297237" y="145.00856194645166" z="0.0"/>
<V2 x="107.93012678297237" y="145.00856194645166" z="21.824"/>
<V3 x="181.8214726387523" y="194.92937748879194" z="21.824"/>
</Wall>
<Wall id="4" ShortWaveReflectance="0.30000000000000004">
<V0 x="107.93012678297237" y="145.00856194645166" z="0.0"/>
<V1 x="178.91501986188814" y="39.936042411252856" z="0.0"/>
<V2 x="178.91501986188814" y="39.936042411252856" z="21.824"/>
<V3 x="107.93012678297237" y="145.00856194645166" z="21.824"/>
</Wall>
<Wall id="5" ShortWaveReflectance="0.30000000000000004">
<V0 x="178.91501986188814" y="39.936042411252856" z="0.0"/>
<V1 x="252.80846728943288" y="89.8574255798012" z="0.0"/>
<V2 x="252.80846728943288" y="89.8574255798012" z="21.824"/>
<V3 x="178.91501986188814" y="39.936042411252856" z="21.824"/>
</Wall>
<Roof id="1" ShortWaveReflectance="0.15000000000000002">
<V0 x="252.80846728943288" y="89.8574255798012" z="21.824"/>
<V1 x="181.8214726387523" y="194.92937748879194" z="21.824"/>
<V2 x="107.93012678297237" y="145.00856194645166" z="21.824"/>
<V3 x="178.91501986188814" y="39.936042411252856" z="21.824"/>
</Roof>
<Floor id="0" ShortWaveReflectance="0.4">
<V0 x="178.91501986188814" y="39.936042411252856" z="0.0"/>
<V1 x="107.93012678297237" y="145.00856194645166" z="0.0"/>
<V2 x="181.8214726387523" y="194.92937748879194" z="0.0"/>
<V3 x="252.80846728943288" y="89.8574255798012" z="0.0"/>
</Floor>
</Building>
<Building Name="2_part_0_zone_0" id="1" key="2_part_0_zone_0" Simulate="true">
<Wall id="2" ShortWaveReflectance="0.30000000000000004">
<V0 x="178.91501986188814" y="39.936042411252856" z="0.0"/>
<V1 x="122.12714234692976" y="123.9941468378529" z="0.0"/>
<V2 x="122.12714234692976" y="123.9941468378529" z="21.644"/>
<V3 x="178.91501986188814" y="39.936042411252856" z="21.644"/>
</Wall>
<Wall id="3" ShortWaveReflectance="0.30000000000000004">
<V0 x="122.12714234692976" y="123.9941468378529" z="0.0"/>
<V1 x="63.01344200363383" y="84.05846768151969" z="0.0"/>
<V2 x="63.01344200363383" y="84.05846768151969" z="21.644"/>
<V3 x="122.12714234692976" y="123.9941468378529" z="21.644"/>
</Wall>
<Wall id="4" ShortWaveReflectance="0.30000000000000004">
<V0 x="63.01344200363383" y="84.05846768151969" z="0.0"/>
<V1 x="119.79997452534735" y="0.0" z="0.0"/>
<V2 x="119.79997452534735" y="0.0" z="21.644"/>
<V3 x="63.01344200363383" y="84.05846768151969" z="21.644"/>
</Wall>
<Wall id="5" ShortWaveReflectance="0.30000000000000004">
<V0 x="119.79997452534735" y="0.0" z="0.0"/>
<V1 x="178.91501986188814" y="39.936042411252856" z="0.0"/>
<V2 x="178.91501986188814" y="39.936042411252856" z="21.644"/>
<V3 x="119.79997452534735" y="0.0" z="21.644"/>
</Wall>
<Roof id="1" ShortWaveReflectance="0.15000000000000002">
<V0 x="178.91501986188814" y="39.936042411252856" z="21.644"/>
<V1 x="122.12714234692976" y="123.9941468378529" z="21.644"/>
<V2 x="63.01344200363383" y="84.05846768151969" z="21.644"/>
<V3 x="119.79997452534735" y="0.0" z="21.644"/>
</Roof>
<Floor id="0" ShortWaveReflectance="0.4">
<V0 x="119.79997452534735" y="0.0" z="0.0"/>
<V1 x="63.01344200363383" y="84.05846768151969" z="0.0"/>
<V2 x="122.12714234692976" y="123.9941468378529" z="0.0"/>
<V3 x="178.91501986188814" y="39.936042411252856" z="0.0"/>
</Floor>
</Building>
<Building Name="3_part_0_zone_0" id="2" key="3_part_0_zone_0" Simulate="true">
<Wall id="2" ShortWaveReflectance="0.30000000000000004">
<V0 x="85.1811095699668" y="99.03423652239144" z="0.0"/>
<V1 x="122.12714234692976" y="123.9941468378529" z="0.0"/>
<V2 x="122.12714234692976" y="123.9941468378529" z="21.916"/>
<V3 x="85.1811095699668" y="99.03423652239144" z="21.916"/>
</Wall>
<Wall id="3" ShortWaveReflectance="0.30000000000000004">
<V0 x="122.12714234692976" y="123.9941468378529" z="0.0"/>
<V1 x="107.93012678297237" y="145.00856194645166" z="0.0"/>
<V2 x="107.93012678297237" y="145.00856194645166" z="21.916"/>
<V3 x="122.12714234692976" y="123.9941468378529" z="21.916"/>
</Wall>
<Wall id="4" ShortWaveReflectance="0.30000000000000004">
<V0 x="107.93012678297237" y="145.00856194645166" z="0.0"/>
<V1 x="144.87584961066023" y="169.96878497768193" z="0.0"/>
<V2 x="144.87584961066023" y="169.96878497768193" z="21.916"/>
<V3 x="107.93012678297237" y="145.00856194645166" z="21.916"/>
</Wall>
<Wall id="5" ShortWaveReflectance="0.30000000000000004">
<V0 x="144.87584961066023" y="169.96878497768193" z="0.0"/>
<V1 x="73.88944391626865" y="275.03991070203483" z="0.0"/>
<V2 x="73.88944391626865" y="275.03991070203483" z="21.916"/>
<V3 x="144.87584961066023" y="169.96878497768193" z="21.916"/>
</Wall>
<Wall id="6" ShortWaveReflectance="0.30000000000000004">
<V0 x="73.88944391626865" y="275.03991070203483" z="0.0"/>
<V1 x="0.0" y="225.12040176987648" z="0.0"/>
<V2 x="0.0" y="225.12040176987648" z="21.916"/>
<V3 x="73.88944391626865" y="275.03991070203483" z="21.916"/>
</Wall>
<Wall id="7" ShortWaveReflectance="0.30000000000000004">
<V0 x="0.0" y="225.12040176987648" z="0.0"/>
<V1 x="85.1811095699668" y="99.03423652239144" z="0.0"/>
<V2 x="85.1811095699668" y="99.03423652239144" z="21.916"/>
<V3 x="0.0" y="225.12040176987648" z="21.916"/>
</Wall>
<Roof id="1" ShortWaveReflectance="0.15000000000000002">
<V0 x="85.1811095699668" y="99.03423652239144" z="21.916"/>
<V1 x="122.12714234692976" y="123.9941468378529" z="21.916"/>
<V2 x="107.93012678297237" y="145.00856194645166" z="21.916"/>
<V3 x="144.87584961066023" y="169.96878497768193" z="21.916"/>
<V4 x="73.88944391626865" y="275.03991070203483" z="21.916"/>
<V5 x="0.0" y="225.12040176987648" z="21.916"/>
</Roof>
<Floor id="0" ShortWaveReflectance="0.4">
<V0 x="0.0" y="225.12040176987648" z="0.0"/>
<V1 x="73.88944391626865" y="275.03991070203483" z="0.0"/>
<V2 x="144.87584961066023" y="169.96878497768193" z="0.0"/>
<V3 x="107.93012678297237" y="145.00856194645166" z="0.0"/>
<V4 x="122.12714234692976" y="123.9941468378529" z="0.0"/>
<V5 x="85.1811095699668" y="99.03423652239144" z="0.0"/>
</Floor>
</Building>
</District>
</CitySim>