diff --git a/main.py b/main.py index 777b53a..272f211 100644 --- a/main.py +++ b/main.py @@ -12,10 +12,9 @@ from sra_engine import SraEngine try: - file_path = (Path(__file__).parent / 'input_files' / 'eilat.geojson') - climate_reference_city = 'Montreal' + file_path = (Path(__file__).parent / 'input_files' / '228730.geojson') construction_format = 'nrcan' - usage_format = 'eilat' + usage_format = 'nrcan' energy_systems_format = 'montreal_custom' out_path = (Path(__file__).parent / 'output_files') @@ -27,7 +26,7 @@ try: height_field='heightmax', year_of_construction_field='ANNEE_CONS', 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}') ConstructionFactory(construction_format, city).enrich() @@ -40,10 +39,8 @@ try: print('enrich systems... done') print('exporting:') - sra_file = (tmp_folder / f'{city.name}_sra.xml').resolve() - SraEngine(city, sra_file, tmp_folder) + SraEngine(city, tmp_folder) print(' sra processed...') - MonthlyEnergyBalanceEngine(city, tmp_folder) print(' insel processed...') diff --git a/results.py b/results.py index 793016b..b2be4c3 100644 --- a/results.py +++ b/results.py @@ -9,68 +9,50 @@ class Results: self._path = path def print(self): - print_results = None 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'}) + heating_results = building.heating_demand[cte.MONTH] 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(): - 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: - 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(): - lighting_results = building.lighting_electrical_demand[cte.MONTH]\ - .rename(columns={cte.INSEL_MEB: f'{building.name} lighting electrical demand Wh'}) + lighting_results = building.lighting_electrical_demand[cte.MONTH] 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(): - appliances_results = building.appliances_electrical_demand[cte.MONTH]\ - .rename(columns={cte.INSEL_MEB: f'{building.name} appliances electrical demand Wh'}) + appliances_results = building.appliances_electrical_demand[cte.MONTH] 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(): - dhw_results = building.domestic_hot_water_heat_demand[cte.MONTH]\ - .rename(columns={cte.INSEL_MEB: f'{building.name} domestic hot water demand Wh'}) + dhw_results = building.domestic_hot_water_heat_demand[cte.MONTH] 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(): - heating_consumption_results = pd.DataFrame(building.heating_consumption[cte.MONTH], - columns=[f'{building.name} heating consumption Wh']) + heating_consumption_results = building.heating_consumption[cte.MONTH] 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(): - cooling_consumption_results = pd.DataFrame(building.cooling_consumption[cte.MONTH], - columns=[f'{building.name} cooling consumption Wh']) + cooling_consumption_results = building.cooling_consumption[cte.MONTH] 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(): - dhw_consumption_results = pd.DataFrame(building.domestic_hot_water_consumption[cte.MONTH], - columns=[f'{building.name} domestic hot water consumption Wh']) + dhw_consumption_results = building.domestic_hot_water_consumption[cte.MONTH] 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(): - heating_peak_load_results = pd.DataFrame(building.heating_peak_load[cte.MONTH], - columns=[f'{building.name} heating peak load W']) + heating_peak_load_results = building.heating_peak_load[cte.MONTH] 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(): - cooling_peak_load_results = pd.DataFrame(building.cooling_peak_load[cte.MONTH], - columns=[f'{building.name} cooling peak load W']) + cooling_peak_load_results = building.cooling_peak_load[cte.MONTH] 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(): - 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']) - + cooling_peak_load_results = [None] * 12 heating = 0 cooling = 0 for system in building.energy_systems: @@ -82,17 +64,17 @@ class Results: 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 + thermal_zone = building.thermal_zones_from_internal_zones[0] + 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 = [] @@ -103,170 +85,36 @@ class Results: 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']) + electricity_peak_load_results = monthly_electricity_peak 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.onsite_electrical_production.keys(): + monthly_onsite_electrical_production = building.onsite_electrical_production[cte.MONTH] + onsite_electrical_production = monthly_onsite_electrical_production + else: + onsite_electrical_production = [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']) + extra_electrical_consumption = building.distribution_systems_electrical_consumption[cte.MONTH] else: - extra_electrical_consumption = pd.DataFrame(array, - columns=[ - f'{building.name} electrical consumption for distribution Wh']) + extra_electrical_consumption = [None] * 12 - 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(): - 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 - 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(): - 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, + columns_names = [f'{building.name} heating demand J', + f'{building.name} cooling demand J', + f'{building.name} lighting demand J', + f'{building.name} appliances demand J', + 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, lighting_results, appliances_results, @@ -278,20 +126,21 @@ class 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' + extra_electrical_consumption]).T + print_results.columns = columns_names + 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() + full_path_results = Path(self._path / f'demand_{building.name}.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) + full_path_metadata = Path(self._path / 'metadata.csv').resolve() + with open(full_path_metadata, 'w') as metadata_file: + metadata_file.write(file) diff --git a/sra_engine.py b/sra_engine.py index bd3bc6e..fef9342 100644 --- a/sra_engine.py +++ b/sra_engine.py @@ -7,14 +7,13 @@ from hub.imports.results_factory import ResultFactory class SraEngine: - def __init__(self, city, file_path, output_file_path): + def __init__(self, city, output_file_path): """ SRA class - :param file_path: _sra.xml file path + :param city: City :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 if platform.system() == 'Linux': self._executable = 'sra' @@ -29,6 +28,8 @@ class SraEngine: Calls the software """ 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: raise Exception(error)