Export functions of SAInt API

SAInt offers the ability to export network and scenario data through its application programming interface (API). The objective of this tutorial is to learn how to use SAInt API functions to streamline the process of exporting network and scenario related data.

Copy the network and scenario file used in this tutorial from the sub-folder .\Scripting\API Beginner\export of the folder Tutorials in the directory (C:\Users\...\Documents\encoord\SAInt-v3\Projects).

1. Export the electric network

Let’s get started by opening your preferred Python IDE and creating a new Python script. After creating the script, copy the network and scenario files from the tutorial’s directory to your Python script directory. Once the electric network file, ENET09_13.enet, has been loaded into the memory using the openENET functions, it can be exported to an Excel network import file. The network import file is a useful tool for making changes to the network efficiently. For example, you can add new objects to the network or modify the properties of existing objects. After making any necessary changes to the Excel network import file, it can be reimported into SAInt using the importENET function. Copy the code below into your new Python script and execute.

# Import ctypes package
from ctypes import *

# Path to the SAInt-API.dll file (located in the SAInt installation folder)
path = "C:\\Program Files\\encoord\\SAInt-v3\\SAInt-API.dll"
# Create a SAInt API DLL object
saint_dll = cdll.LoadLibrary(path)

# Load the electric network
saint_dll.openENET(
        "ENET09_13.enet"
        )

# Export the electric network
saint_dll.exportENET(
        "ENET09_13_Exported.xlsx"
        )

After the export process is finished, you will find that a file named ENET09_13_Exported.xlsx has been automatically generated and saved in your Python script directory. You are encouraged to take a moment to examine the contents of the exported file.

Example 1. Logs from the exportENET function

Network exported to import file C:\..\ENET09_13_Exported.xlsx successfully!

2. Export the electric scenario events

Now that the electric network is loaded into the memory, let’s export the events of the scenario PCM_DCUCOPF.esce to an Excel file, using the exportESCE function. This import file serves as an efficient tool for managing events within the scenario, allowing you to easily add, remove, or modify events as needed. The user can make the desired changes to the Excel events import file, and then re-import it into a new or existing scenario to apply those changes. Add the code below into your Python script and execute:

# Load the electric scenario
saint_dll.openESCE(
        "PCM_DCUCOPF_5.esce"
        )

# Export the electric scenario events
saint_dll.exportESCE(
        "PCM_DCUCOPF_5_Events.xlsx"
        )

After the export process is finished, you will notice that a file named PCM_DCUCOPF_5_Events.xlsx has been automatically generated into your Python script directory. This file contains the all the scenario events with their properties. You are encouraged to take a moment to review the contents of the exported file and familiarize yourself with its format and contents.

Example 2. Logs from the exportESCE function

Electric Scenario Events exported successfully to C:\..\PCM_DCUCOPF_5_Events.xlsx!

3. Export the electric scenario profiles

After loading the electric network and scenario into memory, you have the ability to export the profiles included in the scenario to a SAInt profile file, using the exportEPRF function. This file provides a convenient way to save and reuse the profiles in future scenarios, allowing you to easily transfer them between different projects and simulations. Add the code below into your Python script and execute:

# Export the electric scenario profiles
saint_dll.exportEPRF(
        "PCM_DCUCOPF_5_Profiles.prfl"
        )

After the export process is finished, you will find that a file named PCM_DCUCOPF_5_Profiles.prfl has been automatically generated into your Python script directory. This file contains the exported profiles from the scenario and can be used in other simulations.

Example 3. Logs from the exportEPRF function

10 Profiles exported successfully to PCM_DCUCOPF_5_Profiles.prfl!

4. Export results from the electric scenario

After successfully completing a simulation for an electric scenario, the SAInt API provides the option to export relevant results. In this tutorial, the focus is on the export functionalities of the SAInt API, rather than executing a simulation. However, the SAInt API offers the flexibility to load the solution file of a previously simulated scenario and export user-defined results. In this step, we will load the solution file PCM_DCUCOPF_5.esol of the scenario PCM_DCUCOPF_5.esce. Once the solution file is loaded using the openESOL function, the writeESOL function can be used to export scenario results. The writeESOL function takes two mandatory parameters:

  • The path to the results description file: This is a path to an Excel or text file that contains the SAInt object identifiers and the result property extensions. In this case, we will extract network level results. Create a new Excel file and copy the following object identifiers and property extensions into it:

    • ENET.PFGEN.[MW]

    • ENET.PXGEN.[MW]

    • ENET.PHGEN.[MW]

    • ENET.PWIND.[MW]

    • ENET.PPV.[MW]

Next, save the Excel file as Results_Description.xlsx into your Python script directory.

  • The path to the output results file: This is the preferred path to save the results output file. The results output file contains columns with time series results based on the SAInt object identifiers and result property extensions. Add the code below to your Python script and execute it to complete the results export process.

# Load the scenario solution file
saint_dll.openESOL(
        "PCM_DCUCOPF_5.esol"
        )

# Export results from the scenario
saint_dll.writeESOL(
        "Results_Description.xlsx",
        "Output_Results.xlsx"
        )