adapted to no dataframes results

This commit is contained in:
Pilar Monsalvete 2023-08-11 15:44:25 -04:00
parent 5cb01fc74c
commit 428b31354e
3 changed files with 81 additions and 234 deletions

11
main.py
View File

@ -12,10 +12,9 @@ from sra_engine import SraEngine
try: try:
file_path = (Path(__file__).parent / 'input_files' / 'eilat.geojson') file_path = (Path(__file__).parent / 'input_files' / '228730.geojson')
climate_reference_city = 'Montreal'
construction_format = 'nrcan' construction_format = 'nrcan'
usage_format = 'eilat' usage_format = 'nrcan'
energy_systems_format = 'montreal_custom' energy_systems_format = 'montreal_custom'
out_path = (Path(__file__).parent / 'output_files') out_path = (Path(__file__).parent / 'output_files')
@ -27,7 +26,7 @@ try:
height_field='heightmax', height_field='heightmax',
year_of_construction_field='ANNEE_CONS', year_of_construction_field='ANNEE_CONS',
function_field='CODE_UTILI', function_field='CODE_UTILI',
function_to_hub=Dictionaries().eilat_function_to_hub_function).city function_to_hub=Dictionaries().montreal_function_to_hub_function).city
print(f'city created from {file_path}') print(f'city created from {file_path}')
ConstructionFactory(construction_format, city).enrich() ConstructionFactory(construction_format, city).enrich()
@ -40,10 +39,8 @@ try:
print('enrich systems... done') print('enrich systems... done')
print('exporting:') print('exporting:')
sra_file = (tmp_folder / f'{city.name}_sra.xml').resolve() SraEngine(city, tmp_folder)
SraEngine(city, sra_file, tmp_folder)
print(' sra processed...') print(' sra processed...')
MonthlyEnergyBalanceEngine(city, tmp_folder) MonthlyEnergyBalanceEngine(city, tmp_folder)
print(' insel processed...') print(' insel processed...')

View File

@ -9,68 +9,50 @@ class Results:
self._path = path self._path = path
def print(self): def print(self):
print_results = None
file = 'city name: ' + self._city.name + '\n' file = 'city name: ' + self._city.name + '\n'
array = [None] * 12
for building in self._city.buildings: for building in self._city.buildings:
if cte.MONTH in building.heating_demand.keys(): if cte.MONTH in building.heating_demand.keys():
heating_results = building.heating_demand[cte.MONTH].rename(columns={cte.INSEL_MEB: f'{building.name} heating Wh'}) heating_results = building.heating_demand[cte.MONTH]
else: else:
heating_results = pd.DataFrame(array, columns=[f'{building.name} heating demand Wh']) heating_results = [None] * 12
if cte.MONTH in building.cooling_demand.keys(): if cte.MONTH in building.cooling_demand.keys():
cooling_results = building.cooling_demand[cte.MONTH].rename(columns={cte.INSEL_MEB: f'{building.name} cooling Wh'}) cooling_results = building.cooling_demand[cte.MONTH]
else: else:
cooling_results = pd.DataFrame(array, columns=[f'{building.name} cooling demand Wh']) cooling_results = [None] * 12
if cte.MONTH in building.lighting_electrical_demand.keys(): if cte.MONTH in building.lighting_electrical_demand.keys():
lighting_results = building.lighting_electrical_demand[cte.MONTH]\ lighting_results = building.lighting_electrical_demand[cte.MONTH]
.rename(columns={cte.INSEL_MEB: f'{building.name} lighting electrical demand Wh'})
else: else:
lighting_results = pd.DataFrame(array, columns=[f'{building.name} lighting electrical demand Wh']) lighting_results = [None] * 12
if cte.MONTH in building.appliances_electrical_demand.keys(): if cte.MONTH in building.appliances_electrical_demand.keys():
appliances_results = building.appliances_electrical_demand[cte.MONTH]\ appliances_results = building.appliances_electrical_demand[cte.MONTH]
.rename(columns={cte.INSEL_MEB: f'{building.name} appliances electrical demand Wh'})
else: else:
appliances_results = pd.DataFrame(array, columns=[f'{building.name} appliances electrical demand Wh']) appliances_results = [None] * 12
if cte.MONTH in building.domestic_hot_water_heat_demand.keys(): if cte.MONTH in building.domestic_hot_water_heat_demand.keys():
dhw_results = building.domestic_hot_water_heat_demand[cte.MONTH]\ dhw_results = building.domestic_hot_water_heat_demand[cte.MONTH]
.rename(columns={cte.INSEL_MEB: f'{building.name} domestic hot water demand Wh'})
else: else:
dhw_results = pd.DataFrame(array, columns=[f'{building.name} domestic hot water demand Wh']) dhw_results = [None] * 12
if cte.MONTH in building.heating_consumption.keys(): if cte.MONTH in building.heating_consumption.keys():
heating_consumption_results = pd.DataFrame(building.heating_consumption[cte.MONTH], heating_consumption_results = building.heating_consumption[cte.MONTH]
columns=[f'{building.name} heating consumption Wh'])
else: else:
heating_consumption_results = pd.DataFrame(array, columns=[f'{building.name} heating consumption Wh']) heating_consumption_results = [None] * 12
if cte.MONTH in building.cooling_consumption.keys(): if cte.MONTH in building.cooling_consumption.keys():
cooling_consumption_results = pd.DataFrame(building.cooling_consumption[cte.MONTH], cooling_consumption_results = building.cooling_consumption[cte.MONTH]
columns=[f'{building.name} cooling consumption Wh'])
else: else:
cooling_consumption_results = pd.DataFrame(array, columns=[f'{building.name} cooling consumption Wh']) cooling_consumption_results = [None] * 12
if cte.MONTH in building.domestic_hot_water_consumption.keys(): if cte.MONTH in building.domestic_hot_water_consumption.keys():
dhw_consumption_results = pd.DataFrame(building.domestic_hot_water_consumption[cte.MONTH], dhw_consumption_results = building.domestic_hot_water_consumption[cte.MONTH]
columns=[f'{building.name} domestic hot water consumption Wh'])
else: else:
dhw_consumption_results = pd.DataFrame(array, columns=[f'{building.name} domestic hot water consumption Wh']) dhw_consumption_results = [None] * 12
if cte.MONTH in building.heating_peak_load.keys(): if cte.MONTH in building.heating_peak_load.keys():
heating_peak_load_results = pd.DataFrame(building.heating_peak_load[cte.MONTH], heating_peak_load_results = building.heating_peak_load[cte.MONTH]
columns=[f'{building.name} heating peak load W'])
else: else:
heating_peak_load_results = pd.DataFrame(array, columns=[f'{building.name} heating peak load W']) heating_peak_load_results = [None] * 12
if cte.MONTH in building.cooling_peak_load.keys(): if cte.MONTH in building.cooling_peak_load.keys():
cooling_peak_load_results = pd.DataFrame(building.cooling_peak_load[cte.MONTH], cooling_peak_load_results = building.cooling_peak_load[cte.MONTH]
columns=[f'{building.name} cooling peak load W'])
else: else:
cooling_peak_load_results = pd.DataFrame(array, columns=[f'{building.name} cooling peak load W']) cooling_peak_load_results = [None] * 12
if cte.MONTH in building.onsite_electrical_production.keys():
monthly_onsite_electrical_production = building.onsite_electrical_production[cte.MONTH]
onsite_electrical_production = pd.DataFrame(monthly_onsite_electrical_production,
columns=[f'{building.name} onsite electrical production Wh'])
else:
onsite_electrical_production = pd.DataFrame(array, columns=[f'{building.name} onsite electrical production Wh'])
heating = 0 heating = 0
cooling = 0 cooling = 0
for system in building.energy_systems: for system in building.energy_systems:
@ -82,7 +64,7 @@ class Results:
if cte.MONTH in building.heating_peak_load.keys() and cte.MONTH in building.cooling_peak_load.keys(): if cte.MONTH in building.heating_peak_load.keys() and cte.MONTH in building.cooling_peak_load.keys():
peak_lighting = 0 peak_lighting = 0
peak_appliances = 0 peak_appliances = 0
for thermal_zone in building.internal_zones[0].thermal_zones: thermal_zone = building.thermal_zones_from_internal_zones[0]
lighting = thermal_zone.lighting lighting = thermal_zone.lighting
for schedule in lighting.schedules: for schedule in lighting.schedules:
for value in schedule.values: for value in schedule.values:
@ -103,170 +85,36 @@ class Results:
conditioning_peak.append(heating * value) conditioning_peak.append(heating * value)
monthly_electricity_peak[i] += 0.8 * conditioning_peak[i] monthly_electricity_peak[i] += 0.8 * conditioning_peak[i]
electricity_peak_load_results = pd.DataFrame(monthly_electricity_peak electricity_peak_load_results = monthly_electricity_peak
, columns=[f'{building.name} electricity peak load W'])
else: else:
electricity_peak_load_results = pd.DataFrame(array, columns=[f'{building.name} electricity peak load W']) electricity_peak_load_results = [None] * 12
if cte.MONTH in building.distribution_systems_electrical_consumption.keys():
extra_electrical_consumption = pd.DataFrame(building.distribution_systems_electrical_consumption[cte.MONTH],
columns=[
f'{building.name} electrical consumption for distribution Wh'])
else:
extra_electrical_consumption = pd.DataFrame(array,
columns=[
f'{building.name} electrical consumption for distribution 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,
lighting_results,
appliances_results,
dhw_results,
heating_consumption_results,
cooling_consumption_results,
dhw_consumption_results,
heating_peak_load_results,
cooling_peak_load_results,
electricity_peak_load_results,
onsite_electrical_production,
extra_electrical_consumption], axis='columns')
file += '\n'
file += f'name: {building.name}\n'
file += f'year of construction: {building.year_of_construction}\n'
file += f'function: {building.function}\n'
file += f'floor area: {building.floor_area}\n'
if building.average_storey_height is not None and building.eave_height is not None:
file += f'storeys: {int(building.eave_height / building.average_storey_height)}\n'
else:
file += f'storeys: n/a\n'
file += f'volume: {building.volume}\n'
full_path_results = Path(self._path / 'demand.csv').resolve()
print_results.to_csv(full_path_results, na_rep='null')
full_path_metadata = Path(self._path / 'metadata.csv').resolve()
with open(full_path_metadata, 'w') as metadata_file:
metadata_file.write(file)
def outputsforgraph(self):
file = 'city name: ' + self._city.name + '\n'
array = [None] * 12
for building in self._city.buildings:
if cte.MONTH in building.heating_demand.keys():
heating_results = building.heating_demand[cte.MONTH].rename(
columns={cte.INSEL_MEB: f'{building.name} heating Wh'})
else:
heating_results = pd.DataFrame(array, columns=[f'{building.name} heating demand Wh'])
if cte.MONTH in building.cooling_demand.keys():
cooling_results = building.cooling_demand[cte.MONTH].rename(
columns={cte.INSEL_MEB: f'{building.name} cooling Wh'})
else:
cooling_results = pd.DataFrame(array, columns=[f'{building.name} cooling demand Wh'])
if cte.MONTH in building.lighting_electrical_demand.keys():
lighting_results = building.lighting_electrical_demand[cte.MONTH] \
.rename(columns={cte.INSEL_MEB: f'{building.name} lighting electrical demand Wh'})
else:
lighting_results = pd.DataFrame(array, columns=[f'{building.name} lighting electrical demand Wh'])
if cte.MONTH in building.appliances_electrical_demand.keys():
appliances_results = building.appliances_electrical_demand[cte.MONTH] \
.rename(columns={cte.INSEL_MEB: f'{building.name} appliances electrical demand Wh'})
else:
appliances_results = pd.DataFrame(array, columns=[f'{building.name} appliances electrical demand Wh'])
if cte.MONTH in building.domestic_hot_water_heat_demand.keys():
dhw_results = building.domestic_hot_water_heat_demand[cte.MONTH] \
.rename(columns={cte.INSEL_MEB: f'{building.name} domestic hot water demand Wh'})
else:
dhw_results = pd.DataFrame(array, columns=[f'{building.name} domestic hot water demand Wh'])
if cte.MONTH in building.heating_consumption.keys():
heating_consumption_results = pd.DataFrame(building.heating_consumption[cte.MONTH],
columns=[f'{building.name} heating consumption Wh'])
else:
heating_consumption_results = pd.DataFrame(array, columns=[f'{building.name} heating consumption Wh'])
if cte.MONTH in building.cooling_consumption.keys():
cooling_consumption_results = pd.DataFrame(building.cooling_consumption[cte.MONTH],
columns=[f'{building.name} cooling consumption Wh'])
else:
cooling_consumption_results = pd.DataFrame(array, columns=[f'{building.name} cooling consumption Wh'])
if cte.MONTH in building.domestic_hot_water_consumption.keys():
dhw_consumption_results = pd.DataFrame(building.domestic_hot_water_consumption[cte.MONTH],
columns=[f'{building.name} domestic hot water consumption Wh'])
else:
dhw_consumption_results = pd.DataFrame(array, columns=[f'{building.name} domestic hot water consumption Wh'])
if cte.MONTH in building.heating_peak_load.keys():
heating_peak_load_results = pd.DataFrame(building.heating_peak_load[cte.MONTH],
columns=[f'{building.name} heating peak load W'])
else:
heating_peak_load_results = pd.DataFrame(array, columns=[f'{building.name} heating peak load W'])
if cte.MONTH in building.cooling_peak_load.keys():
cooling_peak_load_results = pd.DataFrame(building.cooling_peak_load[cte.MONTH],
columns=[f'{building.name} cooling peak load W'])
else:
cooling_peak_load_results = pd.DataFrame(array, columns=[f'{building.name} cooling peak load W'])
if cte.MONTH in building.onsite_electrical_production.keys(): if cte.MONTH in building.onsite_electrical_production.keys():
monthly_onsite_electrical_production = building.onsite_electrical_production[cte.MONTH] monthly_onsite_electrical_production = building.onsite_electrical_production[cte.MONTH]
onsite_electrical_production = pd.DataFrame(monthly_onsite_electrical_production, onsite_electrical_production = monthly_onsite_electrical_production
columns=[f'{building.name} onsite electrical production Wh'])
else: else:
onsite_electrical_production = pd.DataFrame(array, onsite_electrical_production = [None] * 12
columns=[f'{building.name} onsite electrical production Wh'])
heating = 0
cooling = 0
for system in building.energy_systems:
for demand_type in system.demand_types:
if demand_type == cte.HEATING:
heating = 1
if demand_type == cte.COOLING:
cooling = 1
if cte.MONTH in building.heating_peak_load.keys() and cte.MONTH in building.cooling_peak_load.keys():
peak_lighting = 0
peak_appliances = 0
for thermal_zone in building.internal_zones[0].thermal_zones:
lighting = thermal_zone.lighting
for schedule in lighting.schedules:
for value in schedule.values:
if value * lighting.density * thermal_zone.total_floor_area > peak_lighting:
peak_lighting = value * lighting.density * thermal_zone.total_floor_area
appliances = thermal_zone.appliances
for schedule in appliances.schedules:
for value in schedule.values:
if value * appliances.density * thermal_zone.total_floor_area > peak_appliances:
peak_appliances = value * appliances.density * thermal_zone.total_floor_area
monthly_electricity_peak = [0.9 * peak_lighting + 0.7 * peak_appliances] * 12
conditioning_peak = []
for i, value in enumerate(building.heating_peak_load[cte.MONTH]):
if cooling * building.cooling_peak_load[cte.MONTH][i] > heating * value:
conditioning_peak.append(cooling * building.cooling_peak_load[cte.MONTH][i])
else:
conditioning_peak.append(heating * value)
monthly_electricity_peak[i] += 0.8 * conditioning_peak[i]
electricity_peak_load_results = pd.DataFrame(monthly_electricity_peak
, columns=[f'{building.name} electricity peak load W'])
else:
electricity_peak_load_results = pd.DataFrame(array, columns=[f'{building.name} electricity peak load W'])
if cte.MONTH in building.distribution_systems_electrical_consumption.keys(): if cte.MONTH in building.distribution_systems_electrical_consumption.keys():
extra_electrical_consumption = pd.DataFrame(building.distribution_systems_electrical_consumption[cte.MONTH], extra_electrical_consumption = building.distribution_systems_electrical_consumption[cte.MONTH]
columns=[
f'{building.name} electrical consumption for distribution Wh'])
else: else:
extra_electrical_consumption = pd.DataFrame(array, extra_electrical_consumption = [None] * 12
columns=[
f'{building.name} electrical consumption for distribution Wh'])
if print_results is None: columns_names = [f'{building.name} heating demand J',
print_results = heating_results f'{building.name} cooling demand J',
else: f'{building.name} lighting demand J',
print_results = pd.concat([print_results, heating_results], axis='columns') f'{building.name} appliances demand J',
print_results = pd.concat([print_results, f'{building.name} domestic hot water demand J',
f'{building.name} heating consumption J',
f'{building.name} cooling consumption J',
f'{building.name} domestic hot water consumption J',
f'{building.name} heating peak load W',
f'{building.name} cooling peak load W',
f'{building.name} electricity peak load W',
f'{building.name} onsite electrical production J',
f'{building.name} extra electrical consumption J'
]
print_results = pd.DataFrame([heating_results,
cooling_results, cooling_results,
lighting_results, lighting_results,
appliances_results, appliances_results,
@ -278,7 +126,8 @@ class Results:
cooling_peak_load_results, cooling_peak_load_results,
electricity_peak_load_results, electricity_peak_load_results,
onsite_electrical_production, onsite_electrical_production,
extra_electrical_consumption], axis='columns') extra_electrical_consumption]).T
print_results.columns = columns_names
file += '\n' file += '\n'
file += f'name: {building.name}\n' file += f'name: {building.name}\n'
file += f'year of construction: {building.year_of_construction}\n' file += f'year of construction: {building.year_of_construction}\n'
@ -290,7 +139,7 @@ class Results:
file += f'storeys: n/a\n' file += f'storeys: n/a\n'
file += f'volume: {building.volume}\n' file += f'volume: {building.volume}\n'
full_path_results = Path(self._path / 'demand.csv').resolve() full_path_results = Path(self._path / f'demand_{building.name}.csv').resolve()
print_results.to_csv(full_path_results, na_rep='null') print_results.to_csv(full_path_results, na_rep='null')
full_path_metadata = Path(self._path / 'metadata.csv').resolve() full_path_metadata = Path(self._path / 'metadata.csv').resolve()
with open(full_path_metadata, 'w') as metadata_file: with open(full_path_metadata, 'w') as metadata_file:

View File

@ -7,14 +7,13 @@ from hub.imports.results_factory import ResultFactory
class SraEngine: class SraEngine:
def __init__(self, city, file_path, output_file_path): def __init__(self, city, output_file_path):
""" """
SRA class SRA class
:param file_path: _sra.xml file path :param city: City
:param output_file_path: path to output the sra calculation :param output_file_path: path to output the sra calculation
""" """
self._city = city self._city = city
self._file_path = file_path
self._output_file_path = output_file_path self._output_file_path = output_file_path
if platform.system() == 'Linux': if platform.system() == 'Linux':
self._executable = 'sra' self._executable = 'sra'
@ -29,6 +28,8 @@ class SraEngine:
Calls the software Calls the software
""" """
try: try:
subprocess.run([self._executable, str(self._file_path)], stdout=subprocess.DEVNULL) subprocess.run([self._executable,
(self._output_file_path / f'{self._city.name}_sra.xml')],
stdout=subprocess.DEVNULL)
except (SubprocessError, TimeoutExpired, CalledProcessError) as error: except (SubprocessError, TimeoutExpired, CalledProcessError) as error:
raise Exception(error) raise Exception(error)