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")) >>> net2 = pp.from_excel("example2.xlsx") #relative path
Json
- pandapower.to_json(net, filename=None, encryption_key=None, store_index_names=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, add_basic_std_types=False, replace_elements=None, empty_dict_like_object=None, ignore_unknown_objects=False)
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.
add_basic_std_types (bool, False) - Add missing standard-types from pandapower standard type library.
replace_elements (dict, None) - Keys are replaced by values found in json string. Both key and value are supposed to be strings.
empty_dict_like_object (dict/pandapower.pandapowerNet/…, None) - If None, the output of pandapower.create_empty_network() is used as an empty element to be filled by the data of the json string. Give another dict-like object to start filling that alternative object with the json data.
- ignore_unknown_objects (bool, False) - If set to True, ignore any objects that cannot be
deserialized instead of raising an error
- OUTPUT:
net (dict) - The pandapower format network
EXAMPLE:
>>> net = pp.from_json("example.json")
SQL
- pandapower.to_sqlite(net, filename, include_results=False)
Saves pandapowerNet an SQLite format
- Parameters:
- netgrid model
pandapowerNet
- filenamepath to a text file where the data will be stored
str
- include_resultswhether result tables should be included
bool
- pandapower.from_sqlite(filename)
Loads a grid model from SQLite format
- Parameters:
- filenamepath to the text file where the data are stored
- Returns:
- netthe grid model
pandapowerNet
PostgreSQL
- pandapower.to_postgresql(net, host, user, password, database, schema, include_results=False, grid_id=None, grid_id_column='grid_id', grid_catalogue_name='grid_catalogue', index_name=None)
Uploads a pandapowerNet to a PostgreSQL database. The database must exist, the element tables are created if they do not exist. JSON serialization (e.g. for controller objects) is not implemented yet.
- Parameters:
- netpandapowerNet
the grid model to be uploaded to the database
- hoststr
hostname for connecting to the database
- userstr
username for logging in
- passwordstr
- databasestr
name of the database
- schemastr
name of the database schema (e.g. ‘postgres’)
- include_resultsbool
specify whether the power flow results are included when the grid is uploaded, default=False
- grid_idint
unique grid_id that will be used to identify the data for the grid model, default None. If None, it will be set automatically by PostgreSQL
- grid_id_columnstr
name of the column for “grid_id” in the PosgreSQL tables, default=”grid_id”.
- grid_catalogue_namestr
name of the catalogue table that includes all grid_id values and the timestamp when the grid data were added
- index_namestr
name of the custom column to be used inplace of index in the element tables if it is not the standard DataFrame index
- Returns:
- grid_id: int
returns either the user-specified grid_id or the automatically generated grid_id of the grid model
- pandapower.from_postgresql(grid_id, host, user, password, database, schema, grid_id_column='grid_id', grid_catalogue_name='grid_catalogue', empty_dict_like_object=None, grid_tables=None)
Downloads an existing pandapowerNet from a PostgreSQL database.
- Parameters:
- grid_idint
unique grid_id that will be used to identify the data for the grid model
- hoststr
hostname for connecting to the database
- userstr
username for logging in
- passwordstr
- databasestr
name of the database
- schemastr
name of the database schema (e.g. ‘postgres’)
- grid_id_columnstr
name of the column for “grid_id” in the PosgreSQL tables, default=”grid_id”.
- grid_catalogue_namestr
name of the catalogue table that includes all grid_id values and the timestamp when the grid data were added
- empty_dict_like_objectdict-like
If None, the output of pandapower.create_empty_network() is used as an empty element to be filled by the grid data. Give another dict-like object to start filling that alternative object with the data.
- Returns:
- netpandapowerNet
- pandapower.delete_postgresql_net(grid_id, host, user, password, database, schema, grid_id_column='grid_id', grid_catalogue_name='grid_catalogue')
Removes a grid model from the PostgreSQL database.
- Parameters:
- grid_idint
unique grid_id that will be used to identify the data for the grid model
- hoststr
hostname for the DB, e.g. “localhost”
- userstr
- passwordstr
- databasestr
name of the database
- schemastr
name of the database schema (e.g. ‘postgres’)
- grid_id_columnstr
name of the column for “grid_id” in the PosgreSQL tables, default=”grid_id”.
- grid_catalogue_namestr
name of the catalogue table that includes all grid_id values and the timestamp when the grid data were added
- Returns: