Save and Load Networks

Advantage

Disadvantage

Example: saving
case9241pegase

pickle

Allows storing of objects
- large filesize
- Stored objects might become
incompatible when loading
with different versions
- Savetime: 1.2s
- Loadtime: 0.65s
- Filesize: 18.4 MB

Excel

Human readable
- Long time to save and load
- Needs libraries that are not part of
standard python distribution
- Savetime: 23.9s
- Loadtime: 10.9s
- Filesize: 4.9 MB

SQL

- Savetime: 1.32s
- Loadtime: 0.6s
- Filesize: 5.1 MB

json

can be interpreted in
other languages
potential insecurity with additional
translation in json notation
-Savetime: 0.19s
-Loadtime: 0.79s
- Filesize: 5.3 MB

pickle

pandapower.to_pickle(net, filename)

Saves a pandapower Network with the pickle library.

INPUT:

net (dict) - The pandapower format network

filename (string) - The absolute or relative path to the output file or an writable file-like objectxs

EXAMPLE:

>>> pp.to_pickle(net, os.path.join("C:", "example_folder", "example1.p"))  # absolute path
>>> pp.to_pickle(net, "example2.p")  # relative path
pandapower.from_pickle(filename, convert=True)

Load a pandapower format Network from pickle file

INPUT:

filename (string or file) - The absolute or relative path to the input file or file-like object

convert (bool, True) - If True, converts the format of the net loaded from pickle from the older

version of pandapower to the newer version format

OUTPUT:

net (dict) - The pandapower format network

EXAMPLE:

>>> net1 = pp.from_pickle(os.path.join("C:", "example_folder", "example1.p")) #absolute path
>>> net2 = pp.from_pickle("example2.p") #relative path

Excel

pandapower.to_excel(net, filename, include_empty_tables=False, include_results=True)

Saves a pandapower Network to an excel file.

INPUT:

net (dict) - The pandapower format network

filename (string) - The absolute or relative path to the output file

OPTIONAL:

include_empty_tables (bool, False) - empty element tables are saved as excel sheet

include_results (bool, True) - results are included in the excel sheet

EXAMPLE:

>>> pp.to_excel(net, os.path.join("C:", "example_folder", "example1.xlsx"))  # absolute path
>>> pp.to_excel(net, "example2.xlsx")  # relative path
pandapower.from_excel(filename, convert=True)

Load a pandapower network from an excel file

INPUT:

filename (string) - The absolute or relative path to the input file.

convert (bool, True) - If True, converts the format of the net loaded from excel from

the older version of pandapower to the newer version format

OUTPUT:

net (dict) - The pandapower format network

EXAMPLE:

>>> net1 = pp.from_excel(os.path.join("C:", "example_folder", "example1.xlsx")) #absolute path
>>> net2 = pp.from_excel("example2.xlsx") #relative path

Json

pandapower.to_json(net, filename=None, encryption_key=None)

Saves a pandapower Network in JSON format. The index columns of all pandas DataFrames will be saved in ascending order. net elements which name begins with “_” (internal elements) will not be saved. Std types will also not be saved.

INPUT:

net (dict) - The pandapower format network

filename (string or file, None) - The absolute or relative path to the output file

or a file-like object, if ‘None’ the function returns a json string

encrytion_key (string, None) - If given, the pandapower network is stored as an

encrypted json string

EXAMPLE:

>>> pp.to_json(net, "example.json")
pandapower.from_json(filename, convert=True, encryption_key=None, elements_to_deserialize=None, keep_serialized_elements=True)

Load a pandapower network from a JSON file. The index of the returned network is not necessarily in the same order as the original network. Index columns of all pandas DataFrames are sorted in ascending order.

INPUT:

filename (string or file) - The absolute or relative path to the input file or file-like object

convert (bool, True) - If True, converts the format of the net loaded from json from the older

version of pandapower to the newer version format

encrytion_key (string, “”) - If given, key to decrypt an encrypted pandapower network

elements_to_deserialize (list, None) - Deserialize only certain pandapower elements. If None all elements are deserialized.

keep_serialized_elements (bool, True) - Keep serialized elements if given. Default: Serialized elements are kept.

OUTPUT:

net (dict) - The pandapower format network

EXAMPLE:

>>> net = pp.from_json("example.json")

SQL

pandapower.to_sqlite(net, filename, include_results=True)
pandapower.from_sqlite(filename, netname='')