How can I read data from a result file (ElmRes) via script?


There are several ways to read data from a result file:

  • Use ElmRes.GetValue(): The function reads a specific cell from a result file based on the row and column index. If the entire result file is to be red, a loop though each cell (columns and rows) is needed for a dense result file. In a sparse result file the functions GetFirstValidObject() and GetNextValidObject() can be used to minimize the instances of access. Additional function for the result file like FindColumn(), ect can be used to identify the relevant column.
  • Use ElmRes.GetColumnValues(): Reading the data of a specific column from a result file with the help of a vector object (IntVec). If all data from a column needs to be extracted, this method is faster compared to GetValue(). But an additional vector object is needed. It can be created (and deleted) on the fly in the code or an existing data vector can be used. The function is committing the results of a column to the data vector, from where it can be retrieved by accessing the attribute “V” of the data vector via GetAttribute().
  • Use the ComRes to export the data to csv and read the csv file (Python): The data in a result file can be exported very efficiently to a csv file via the ComRes. Python offers modules like pandas or csv to read data from csv files. In some applications, this can be more efficient compared to reading results files directly from PowerFactory. Especially, if the result evaluation is executed in a separate script. In this case the calculation no connection to PowerFactory needs to be established and the calculation can be handled seperatly. Also loading the result file is not required for the export via the ComRes. Exporting and reimporting results can also be done with DPL, but the csv handling is not as sophisticated as in Python and the direct approach via GetValue() or GetColumnValues() is recommended.


The options all have benefits and disadvantages and the most efficient way to read a result depends on the use case and the design of result file.  Result files can be dense (e.g. for RMS or QDS simulations) or sparse (e.g. for Contingency Analysis or Sensitivity Analysis). Also result files can vary strongly in number of rows and columns.  

The GetValue() function is great for accessing only selected information from the result file, but the performance of the other two options is generally better for reading entire and especially larger result files.

Data objects are not stored directly in result files and only the index of an object is retrieved by GetValue()/GetColumnValues(). Thus, data objects have to be retrieved with the GetObj() function based in this index.

The attached example showcases the different possibilities to read result files in Python (Same principles apply to DPL). The script “ReadData” in the project library contains embedded code and 3 different result files in the contents. The script reads the result files and writes the time for each method and each result file to the output window.