OutputWriter(net, time_steps=None, output_path=None, output_file_type='.p', write_time=None, log_variables=None, csv_separator=';')¶
The OutputWriter class is used to store and format specific outputs from a time series calculation.
It contains a python-dictionary output which is a container for result DataFrames or arbitrary information you would like to store. By default a pandas DataFrame is initialized for the key Parameters, which has the columns “time_step”, “controller_unstable”, “powerflow_failed”.
To simple log outputs during a time series simulation use ow.log_variable(table, column) where table is the name of the (result) table, e.g. “res_bus”, and column the name of the column, e.g. “vm_pu”.
More sophisticated outputs can be added as well since for each value to be stored a function is added to the output_list which is called at the end of each time step. The function reads the calculation results and returns the desired values to store. These values are then stored in the output DataFrame in a column named after the function you implemented. Such a function can be used to store only some information of the power flow results, like the highest values of the line loading in a time step or the mean values. Check the “advanced time series example” jupyter notebook for an example.
net - The pandapower format network
time_steps (list) - time_steps to calculate as a list (or range)
output_path (string, None) - Path to a folder where the output is written to.
csv_separator (string, “;”) - The separator used when writing to a csv file
write_time (int, None) - Time to save periodically to disk in minutes. Deactivated by default
log_variables (list, None) - list of tuples with (table, column) values to be logged by output writer. Defaults are: res_bus.vm_pu and res_line.loading_percent. Additional variables can be added later on with ow.log_variable or removed with ow.remove_log_variable
>>> from pandapower.timeseries.output_writer import OutputWriter >>> from pandapower.networks as nw >>> net = nw.simple_four_bus_system() >>> ow = OutputWriter(net) # create an OutputWriter >>> ow.log_variable('res_bus', 'vm_pu') # add logging for bus voltage magnitudes >>> ow.log_variable('res_line', 'loading_percent') # add logging for line loadings in percent
Save the output to separate files in output_path with the file_type output_file_type. This is called after the time series simulation by default.
append (bool, False) - Option for appending instead of overwriting the file
inits the log variables given to output writer. log_variables is a list with tuples of DataFrame columns to log. Example: [(“res_bus”, “vm_pu”), (“res_bus”, “va_degree”)]
If None are given the defaults are: res_bus.vm_pu res_line.loading_percent
log_variable(table, variable, index=None, eval_function=None, eval_name=None)¶
Adds a variable to log during simulation and appends it to output_list. INPUT:
table (str) - The DataFrame table where the variable is located as a string (e.g. “res_bus”)
variable (str) - variable that should be logged as string (e.g. “p_mw”)
index (iterable, None) - Can be either one index or a list of indices, or a numpy array of indices, or a pandas Index, or a pandas Series (e.g. net.load.bus) for which the variable will be logged. If no index is given, the variable will be logged for all elements in the table
eval_function (function, None) - A function to be applied on the table / variable / index combination. example: pd.min or pd.mean
- eval_name (str, None) - The name for an applied function. It must be unique.
If the name is None the name consists of the table, variable, index and eval function example: “max_load_p_mw_values”
>>> ow.log_variable('res_bus', 'vm_pu') # add logging for bus voltage magnitudes >>> ow.log_variable('res_line', 'loading_percent', index=[0, 2, 5]) # add logging for line loading of lines with indices 0, 2, 5 >>> ow.log_variable('res_line', 'loading_percent', eval_function=pd.max) # get the highest line loading only
removes a logged variable from outputs
INPUT: table (str) - name of the DataFrame table (example: “res_bus”)
OPTIONAL: variable (str, None) - column name of the DataFrame table (example: “vm_pu”). If None all are variables of table are removed