Tutorial 4: Exporting ESDL parameters to Excel
This tutorial shows how to export ESDL parameters to an Excel file (in CSV format). For that purpose, the ESDL from Tutorial 3 is loaded, and energy asset parameters such as type, ID, name, power, and efficiency are written to an Excel file.
Start with importing the required libraries
from esdl import esdl
from esdl.esdl_handler import EnergySystemHandler
import pandas as pd
Define constants such as ESDL file name and the folder it is located in.
if __name__ == '__main__':
folder_name = "ESDLs"
file_name = "Tutorial3_pyESDL.esdl"
Create an EnergySystemHandler - a class that helps a developer to read and write ESDL-files
energy_system_handler = EnergySystemHandler()
Load the ESDL file whose energy asset parameters will be written to a CSV file.
energy_system: esdl.EnergySystem = energy_system_handler.load_file(folder_name + "/" + file_name)
Define lists where different asset parameters will be written to (this will later be added to a DataFrame which is converted to a CSV file.
asset_types_list = []
asset_names_list = []
asset_ids_list = []
asset_powers_list = []
asset_efficiencies_list = []
Define a DataFrame which will contain asset parameters, and which will be converted to a CSV file.
asset_parameters = pd.DataFrame()
Iterate through all ESDL elements
# get_all_instances_of_type
for esdl_element in energy_system.eAllContents():
Check if the element is an EnegyAsset
if isinstance(esdl_element, esdl.EnergyAsset):
If it is, write its type (using eClass.name), ID, and name to a corresponding list
asset_types_list.append(esdl_element.eClass.name)
asset_ids_list.append(esdl_element.id)
asset_names_list.append(esdl_element.name)
If an element is a Producer, a Consumer or a Conversion, write its power
if isinstance(esdl_element, esdl.Producer) or isinstance(esdl_element, esdl.Consumer) or isinstance(
esdl_element, esdl.Conversion):
asset_powers_list.append(esdl_element.power)
else:
asset_powers_list.append("")
If an element is a PowerPlant, write its efficiency
if isinstance(esdl_element, esdl.PowerPlant):
asset_efficiencies_list.append(esdl_element.efficiency)
else:
asset_efficiencies_list.append("")
Add the lists to the DataFrame
asset_parameters["Type"] = asset_types_list
asset_parameters["ID"] = asset_ids_list
asset_parameters["Name"] = asset_names_list
asset_parameters["Power"] = asset_powers_list
asset_parameters["Efficiency"] = asset_efficiencies_list
Define the name of the CSV, and convert the DataFrame to that CSV
filename = 'asset_parameters.csv'
asset_parameters.to_csv(filename,
index=False,
sep=';')