### Setup for Distributed Slack Example Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/distributed_slack.ipynb Imports necessary libraries and sets up a pandapower network for plotting and load flow calculations. Configures matplotlib for notebook display. ```python import matplotlib import matplotlib.pyplot as plt %matplotlib notebook from copy import deepcopy from pandapower.plotting.simple_plot import simple_plot from pandapower.networks.power_system_test_cases import case9 from pandapower.run import runpp from IPython.display import display, Markdown heading_dist_slack = Markdown("#### With distributed slack") heading_no_dist_slack = Markdown("#### Without distributed slack") net = case9() fig = plt.figure(figsize=(4,4)) ax = fig.add_subplot() simple_plot(net, plot_loads=True, plot_gens=True, load_size=2.5, gen_size=0.1, ax=ax); fig.tight_layout(pad=0) ``` -------------------------------- ### Import pandapower and example network Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/data_analysis.ipynb Imports necessary pandapower modules and loads an example network. Ensure pandapower and its dependencies are installed. ```python from pandapower.networks import mv_oberrhein from pandapower.run import runpp import pandas as pd #Import an example network: net = mv_oberrhein() ``` -------------------------------- ### Initialize DERController with CosphiP and PQVArea Source: https://github.com/e2niee/pandapower/blob/develop/doc/control/controller.md Example of initializing a DERController with a specific Q model (CosphiP) and a PQV area constraint (PQVArea4120V2). This setup is used before running the power flow calculation with control enabled. ```python from pandapower.networks.cigre_networks import create_cigre_network_mv from pandapower.control.controller.DERController import DERController, QModelCosphiP, PQVArea4120V2 from pandapower.run import runpp net = create_cigre_network_mv(with_der=True) controlled_sgens = DERController( net, net.sgen.index, q_model=QModelCosphiP(cosphi=-0.95), pqv_area=PQVArea4120V2() ) runpp(net, run_control=True) ``` -------------------------------- ### Load Example Network and Import Functions Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/powerflow.ipynb Imports necessary functions and loads a simple example network for power flow analysis. ```python from pandapower.networks import example_simple from pandapower.run import runpp, set_user_pf_options ``` ```python net = example_simple() net ``` -------------------------------- ### Example: Delete PostgreSQL Network Source: https://github.com/e2niee/pandapower/blob/develop/doc/file_io.md Demonstrates how to call the delete_postgresql_net function with example parameters. ```python delete_postgresql_net(0, "postgresql://user:password@host:port/database", "test_schema", "grid_id", "grid_catalogue") ``` -------------------------------- ### Install Numba for performance enhancement Source: https://github.com/e2niee/pandapower/blob/develop/doc/converter/cgmes.md Install the Numba library to potentially speed up the conversion process. ```default pip install numba ``` -------------------------------- ### Create and print a simple example network Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/internal_datastructure.ipynb Initializes a simple pandapower network and prints its structure. ```python net = example_simple() print(net) ``` -------------------------------- ### Run State Estimation with Flat Start Source: https://github.com/e2niee/pandapower/blob/develop/doc/estimation.md Initialize and run the state estimation using the 'flat' start condition. The success status and estimated voltage values are returned. ```python success = estimate(net, init="flat") V, delta = net.res_bus_est.vm_pu, net.res_bus_est.va_degree ``` -------------------------------- ### Prepare Network for Power-Grid-Model Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/power-grid-model_powerflow.ipynb Initializes an example network and removes the 'gen' (generator) table as it is not yet supported by power-grid-model. ```python net = example_simple() # Remove Generator since its not supported yet net["gen"] = net["gen"].iloc[:0] ``` -------------------------------- ### Install Additional Julia Packages for TNEP/OTS Source: https://github.com/e2niee/pandapower/blob/develop/doc/opf/pandamodels.md Install JSON, JuMP, Cbc, and Juniper for advanced features like TNEP and OTS. ```julia julia -e 'import Pkg; Pkg.add("JSON"); Pkg.add("JuMP");' ``` ```julia julia -e ‘import Pkg; Pkg.add(“Cbc”); Pkg.add(“Juniper”) ``` -------------------------------- ### Create Example Network with pandapower Source: https://github.com/e2niee/pandapower/blob/develop/doc/gridequivalent/gridequivalent_example.md Initializes a pandapower network using a predefined case and runs a power flow calculation. ```python from pandapower import runpp from pandapower.networks import case9 net = case9() # getting power flow results runpp(net) ``` -------------------------------- ### Load the example network Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/hosting_capacity.ipynb Loads the MV Oberrhein network from the pandapower networks package in 'generation' scenario. ```python def load_network(): return mv_oberrhein(scenario="generation") ``` -------------------------------- ### Install pandapower with converter support Source: https://github.com/e2niee/pandapower/blob/develop/doc/converter/cgmes.md Install pandapower along with the necessary converter dependencies using pip. ```default pip install pandapower[converter] ``` -------------------------------- ### Create Example Grid Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/vm_set_tap.ipynb Creates an example pandapower network including buses, lines, an external grid, a transformer, a load, and a static generator. ```python net = create_empty_network() for i in range(4): if i < 2: vn=110 else: vn=20 create_bus(net, name='Bus %s' % i, vn_kv=vn, type="n") create_line(net, 0, 1, length_km=10, std_type="149-AL1/24-ST1A 110.0",name="Line 1") create_line(net, 2, 3, length_km=10, std_type="184-AL1/30-ST1A 20.0",name="Line 2") create_ext_grid(net, 0, vm_pu=1.02, va_degree=50) trafo = create_transformer(net, 1, 2, name="110kV/20kV transformer", std_type="25 MVA 110/20 kV") create_load(net, 3, p_mw=35, q_mvar=4, scaling=1, name="load") create_sgen(net, 3, p_mw=10, q_mvar=3, name="generator") net.bus ``` -------------------------------- ### Create Example Network for Short-Circuit Calculation Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/shortcircuit/shortcircuit_renewables.ipynb Defines an example network including buses, an external grid connection, lines, and static generators representing renewable energy sources. Ensure all necessary pandapower modules are imported. ```python from pandapower.create import ( create_empty_network, create_bus, create_ext_grid, create_line, create_sgen ) from pandapower.shortcircuit import calc_sc from pandapower.std_types import create_std_type import numpy as np net = create_empty_network() for i in range(4): create_bus(net, vn_kv=110., index=i+1) create_ext_grid(net, 1, s_sc_max_mva=20*110*np.sqrt(3), rx_max=0.1) create_std_type(net, {"r_ohm_per_km": 0.120, "x_ohm_per_km": 0.393, "c_nf_per_km": 0.19, "max_i_ka": 0.6}, "example_type") for fb, tb, length in [(1, 2, 100), (1, 3, 50), (2, 3, 50), (3, 4, 25)]: create_line(net, from_bus=fb, to_bus=tb, length_km=length, std_type="example_type") for b, p in [(2, 100), (3, 50), (4, 50)]: create_sgen(net, b, p_mw=p, sn_mva=p, k=1.2) ``` -------------------------------- ### Create Example Network Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/opf_dcline.ipynb Initializes an empty pandapower network and creates buses, lines, a DC line, external grids, and a load. ```python net = create_empty_network() b1 = create_bus(net, 380) b2 = create_bus(net, 380) b3 = create_bus(net, 380) b4 = create_bus(net, 380) b5 = create_bus(net, 380) l1, l2, l3 = create_lines(net, [b1, b3, b4], [b2, b4, b5], [30, 20, 20], "490-AL1/64-ST1A 380.0") dcl1 = create_dcline(net, name="dc line", from_bus=b2, to_bus=b3, p_mw=200, loss_percent=1.0, loss_mw=0.5, vm_from_pu=1.01, vm_to_pu=1.012, max_p_mw=1000, in_service=True) eg1 = create_ext_grid(net, b1, 1.02, min_p_mw=0.) eg2 = create_ext_grid(net, b5, 1.02, min_p_mw=0.) l1 = create_load(net, bus=b4, p_mw=800, controllable = False) ``` -------------------------------- ### Install and Build Gurobi Julia Interface Source: https://github.com/e2niee/pandapower/blob/develop/doc/opf/pandamodels.md Install the Gurobi Julia interface using Pkg.add and then build it to ensure proper compilation. This is a prerequisite for using Gurobi with Julia-based power flow solvers. ```julia julia -e 'import Pkg; Pkg.add("Gurobi");' ``` ```julia add Gurobi ``` ```julia import Pkg; Pkg.build("Gurobi") ``` -------------------------------- ### Import Libraries and Initialize Network Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/power-grid-model_powerflow.ipynb Imports necessary functions and initializes a simple example network. Includes a warning filter for future warnings. ```python from pandapower.run import runpp_pgm from pandapower.networks import example_simple import warnings warnings.simplefilter(action='ignore', category=FutureWarning) ``` -------------------------------- ### Run Power Flow Initialization Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/FACTS.ipynb Initializes the power flow calculation for the network. Use 'flat' for a flat start initialization. ```python runpp(net, init='flat') ``` -------------------------------- ### Create a Basic Example Network in Python Source: https://github.com/e2niee/pandapower/blob/develop/doc/topology/examples.md Demonstrates how to create an empty network and populate it with buses, external grids, lines, transformers, loads, and switches. ```python from pandapower.create import create_empty_network, create_bus, create_ext_grid, create_line, \ create_transformer_from_parameters, create_load, create_switch net = create_empty_network() create_bus(net, name = "110 kV bar", vn_kv = 110, type = 'b') create_bus(net, name = "20 kV bar", vn_kv = 20, type = 'b') create_bus(net, name = "bus 2", vn_kv = 20, type = 'b') create_bus(net, name = "bus 3", vn_kv = 20, type = 'b') create_bus(net, name = "bus 4", vn_kv = 20, type = 'b') create_bus(net, name = "bus 5", vn_kv = 20, type = 'b') create_bus(net, name = "bus 6", vn_kv = 20, type = 'b') create_ext_grid(net, 0, vm_pu = 1) create_line(net, name = "line 0", from_bus = 1, to_bus = 2, length_km = 1, std_type = "NAYY 4x150 SE") create_line(net, name = "line 1", from_bus = 2, to_bus = 3, length_km = 1, std_type = "NAYY 4x150 SE") create_line(net, name = "line 2", from_bus = 3, to_bus = 4, length_km = 1, std_type = "NAYY 4x150 SE") create_line(net, name = "line 3", from_bus = 4, to_bus = 5, length_km = 1, std_type = "NAYY 4x150 SE") create_line(net, name = "line 4", from_bus = 5, to_bus = 6, length_km = 1, std_type = "NAYY 4x150 SE") create_line(net, name = "line 5", from_bus = 6, to_bus = 1, length_km = 1, std_type = "NAYY 4x150 SE") create_transformer_from_parameters(net, hv_bus=0, lv_bus=1, i0_percent=0.038, pfe_kw=11.6, vkr_percent=0.322, sn_mva=40, vn_lv_kv=22.0, vn_hv_kv=110.0, vk_percent=17.8) create_load(net, 2, p_mw = 1, q_mvar = 0.2, name = "load 0") create_load(net, 3, p_mw = 1, q_mvar = 0.2, name = "load 1") create_load(net, 4, p_mw = 1, q_mvar = 0.2, name = "load 2") create_load(net, 5, p_mw = 1, q_mvar = 0.2, name = "load 3") create_load(net, 6, p_mw = 1, q_mvar = 0.2, name = "load 4") create_switch(net, bus = 1, element = 0, et = 'l') create_switch(net, bus = 2, element = 0, et = 'l') create_switch(net, bus = 2, element = 1, et = 'l') create_switch(net, bus = 3, element = 1, et = 'l') create_switch(net, bus = 3, element = 2, et = 'l') create_switch(net, bus = 4, element = 2, et = 'l') create_switch(net, bus = 4, element = 3, et = 'l', closed = 0) create_switch(net, bus = 5, element = 3, et = 'l') create_switch(net, bus = 5, element = 4, et = 'l') create_switch(net, bus = 6, element = 4, et = 'l') create_switch(net, bus = 6, element = 5, et = 'l') create_switch(net, bus = 1, element = 5, et = 'l') ``` -------------------------------- ### Create an example network Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/state_estimation.ipynb Initializes an empty network and creates buses, an external grid connection (slack bus), and lines based on specified parameters. ```python net = create_empty_network() b1 = create_bus(net, name="bus 1", vn_kv=1., index=1) b2 = create_bus(net, name="bus 2", vn_kv=1., index=2) b3 = create_bus(net, name="bus 3", vn_kv=1., index=3) create_ext_grid(net, 1) # set the slack bus to bus 1 l1 = create_line_from_parameters(net, 1, 2, 1, r_ohm_per_km=.01, x_ohm_per_km=.03, c_nf_per_km=0., max_i_ka=1) l2 = create_line_from_parameters(net, 1, 3, 1, r_ohm_per_km=.02, x_ohm_per_km=.05, c_nf_per_km=0., max_i_ka=1) l3 = create_line_from_parameters(net, 2, 3, 1, r_ohm_per_km=.03, x_ohm_per_km=.08, c_nf_per_km=0., max_i_ka=1) net ``` -------------------------------- ### Execute Time Series Simulation Setup and Run Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/time_series_multiple_loads_generators.ipynb Sets up the simulation environment, loads a network case, creates data sources and controllers, and runs the main time series simulation function. Ensure the output directory exists before running. ```python output_dir = os.path.join(tempfile.gettempdir(), "time_series_example") print("Results can be found in your local temp folder: {}".format(output_dir)) if not os.path.exists(output_dir): os.mkdir(output_dir) # load ieee 14 bus system net = case14() # run load flow and save results runpp(net) n_timesteps = int(24*60/5) # number of timesteps to be calculated (5 minutes resolution for 24 hours) scale = 0.5 # scaling factor for the load and generation profiles profiles, ds = create_data_source(net, scale, n_timesteps) # create profiles and data source # 3. create controllers (to control P values of the load and the sgen) create_controllers(net, ds) # time steps to be calculated. Could also be a list with non-consecutive time steps time_steps = range(0, n_timesteps) # 4. the output writer with the desired results to be stored to files. ow = create_output_writer(net, time_steps, output_dir=output_dir) # 5. the main time series function run_timeseries(net, time_steps) # the main time series function ``` -------------------------------- ### Create an Overload Example Network Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/diagnostic.ipynb This function creates a pandapower network with components designed to exhibit overload conditions. It includes buses, lines, transformers, loads, and switches. This setup is useful for testing diagnostic functions. ```python def overload_example_network(): net = create_empty_network() create_bus(net, name = "110 kV bar", vn_kv = 110, type = 'b') create_bus(net, name = "20 kV bar", vn_kv = 20, type = 'b') create_bus(net, name = "bus 2", vn_kv = 20, type = 'b') create_bus(net, name = "bus 3", vn_kv = 20, type = 'b') create_bus(net, name = "bus 4", vn_kv = 20, type = 'b') create_bus(net, name = "bus 5", vn_kv = 20, type = 'b') create_bus(net, name = "bus 6", vn_kv = 20, type = 'b') create_ext_grid(net, 0, vm_pu = 1) create_line(net, name = "line 0", from_bus = 1, to_bus = 2, length_km = 1, std_type = NAYY_STD_TYPE) create_line(net, name = "line 1", from_bus = 2, to_bus = 3, length_km = 1, std_type = NAYY_STD_TYPE) create_line(net, name = "line 2", from_bus = 3, to_bus = 4, length_km = 1, std_type = NAYY_STD_TYPE) create_line(net, name = "line 3", from_bus = 4, to_bus = 5, length_km = 1, std_type = NAYY_STD_TYPE) create_line(net, name = "line 4", from_bus = 5, to_bus = 6, length_km = 1, std_type = NAYY_STD_TYPE) create_line(net, name = "line 5", from_bus = 6, to_bus = 1, length_km = 1, std_type = NAYY_STD_TYPE) create_transformer_from_parameters(net, hv_bus = 0, lv_bus = 1, i0_percent= 0.038, pfe_kw = 11.6, vkr_percent = 0.322, sn_mva = 40.0, vn_lv_kv = 22.0, vn_hv_kv = 110.0, vk_percent = 17.8) create_load(net, 2, p_mw = 100, q_mvar = 0.2, name = "load 0") create_load(net, 3, p_mw = 100, q_mvar = 0.2, name = "load 1") create_load(net, 4, p_mw = 100, q_mvar = 0.2, name = "load 2") create_load(net, 5, p_mw = 100, q_mvar = 0.2, name = "load 3") create_load(net, 6, p_mw = 100, q_mvar = 0.2, name = "load 4") create_switch(net, bus = 1, element = 0, et = 'l') create_switch(net, bus = 2, element = 0, et = 'l') create_switch(net, bus = 2, element = 1, et = 'l') create_switch(net, bus = 3, element = 1, et = 'l') create_switch(net, bus = 3, element = 2, et = 'l') create_switch(net, bus = 4, element = 2, et = 'l') create_switch(net, bus = 4, element = 3, et = 'l', closed = False) create_switch(net, bus = 5, element = 3, et = 'l') create_switch(net, bus = 5, element = 4, et = 'l') create_switch(net, bus = 6, element = 4, et = 'l') create_switch(net, bus = 6, element = 5, et = 'l') create_switch(net, bus = 1, element = 5, et = 'l') return net ``` -------------------------------- ### Test PowerModels Installation Source: https://github.com/e2niee/pandapower/blob/develop/doc/opf/pandamodels.md Verify the PowerModels.jl installation by running its test suite. ```julia test PowerModels ``` -------------------------------- ### Gurobi Environment Setup (Linux) Source: https://github.com/e2niee/pandapower/blob/develop/doc/opf/pandamodels.md Set the GUROBI_HOME environment variable and add Gurobi binaries to the PATH and LD_LIBRARY_PATH. Ensure the Gurobi license file is correctly pointed to. ```bash export GUROBI_HOME="/opt/gurobi_VERSION/linux64" export PATH="${PATH}:${GUROBI_HOME}/bin" export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${GUROBI_HOME}/lib" export GRB_LICENSE_FILE="/PATH_TO_YOUR_LICENSE_DIR/gurobi.lic" ``` -------------------------------- ### pandapower.toolbox.create_continuous_bus_index Source: https://github.com/e2niee/pandapower/blob/develop/doc/toolbox.md Creates a continuous bus index starting at ‘start’ and replaces all references of old indices by the new ones. ```APIDOC ## pandapower.toolbox.create_continuous_bus_index(net, start=0, store_old_index=False) ### Description Creates a continuous bus index starting at ‘start’ and replaces all references of old indices by the new ones. ### Parameters * **net** – pandapower network * **start** – index begins with “start” * **store_old_index** – if True, stores the old index in net.bus[“old_index”] * **Returns:** mapping of old to new index ``` -------------------------------- ### Initialize OutputWriter and Log Variables Source: https://github.com/e2niee/pandapower/blob/develop/doc/timeseries/output_writer.md Demonstrates how to create an OutputWriter instance and add variables for logging during a time series simulation. Includes logging bus voltage magnitudes and line loading percentages, as well as a custom function for logging cost function slope values. ```python from pandapower.timeseries.output_writer import OutputWriter from pandapower.networks import simple_four_bus_system net = 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 # Getting the cost function slope for each time step: def cost_logging(result, n_columns=2): return array([result[i][0][2] for i in range(len(result))]) ow.log_variable("pwl_cost", "points", eval_function=cost_logging) ``` -------------------------------- ### Example Function to Double Rated Power Source: https://github.com/e2niee/pandapower/blob/develop/CONTRIBUTING.md A simple Python function that modifies the network's rated power. This serves as an example for adding new functionality. ```python def double_rated_power(net): net.sn_mva *= 2 ``` -------------------------------- ### Generate Hello Message Function with Docstring Source: https://github.com/e2niee/pandapower/blob/develop/CONTRIBUTING.md Example of a Python function with a Google Style docstring. This includes parameters, return types, raised exceptions, and an example usage. ```python def generate_hello_message(name: str) -> str: """ A function to generate a hello message Parameters: name: the name to use for the message Returns: A message Raises: AttributeError: if name is empty or None Example: >>> msg = generate_hello_message("panda") """ if name is None or name == "": raise AttributeError("no name was provided") return f"Welcome to pandapower, {name}!" ``` -------------------------------- ### Create network elements for a 3-bus system Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/three_phase_loadflow_tutorial_simple.ipynb Sets up a new network with three buses and an external grid connection. This example initializes the network for a more complex scenario involving a transformer. ```python net = create_empty_network(sn_mva=100) bus_eg = create_bus(net, 10) bus_lv = create_bus(net, 0.4) bus_load = create_bus(net, 0.4 ) create_ext_grid(net, bus_eg, s_sc_max_mva=10000, rx_max=0.1) net.ext_grid["r0x0_max"] = 0.1 net.ext_grid["x0x_max"] = 1.0 print(net.trafo) print('-----------------------------------') ``` -------------------------------- ### Create Network from IEC 60909 Example Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/shortcircuit/sc_power_station_unit.ipynb Initializes a pandapower network based on the IEC 60909:4-2021 Figure 5 example. This sets up the base network for subsequent short-circuit calculations. ```python import numpy as np from pandapower.plotting import simple_plot from pandapower.test.shortcircuit.test_1ph import vde_232 net = vde_232() vn_trafo_hv = net.trafo.vn_hv_kv vn_trafo_lv = net.trafo.vn_lv_kv sn_mva = net.trafo.sn_mva vk0_percent = net.trafo.vk0_percent vkr0_percent = net.trafo.vkr0_percent ``` -------------------------------- ### Evaluate hosting capacity iteratively Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/hosting_capacity.ipynb This loop simulates adding PV plants incrementally until a constraint violation occurs. It records the total installed capacity and the type of violation for each iteration. ```python iterations = 50 results = pd.DataFrame(columns=["installed", "violation"]) for i in range(iterations): net = load_network() installed_mw = 0 while 1: violated, violation_type = violations(net) if violated: results.loc[i] = [installed_mw, violation_type] break else: plant_size = get_plant_size_mw() create_sgen(net, chose_bus(net), p_mw=plant_size, q_mvar=0) installed_mw += plant_size ``` -------------------------------- ### Chained Estimation with Warm Start for SciPy Optimization Source: https://github.com/e2niee/pandapower/blob/develop/doc/estimation.md Initialize Pandapower and EPPcI for chained estimation. Set up WLS and Opt algorithms for a warm start, which can improve convergence for the SciPy Optimization Tool. ```python # Initialize eppci for the algorithm which contains pypower-grid, # measurements and estimated grid state (initial value) net, ppc, eppci = pp2eppci(net) # Initialize algorithm estimation_wls = WLSAlgorithm(1e-3, 5) estimation_opt = OptAlgorithm(1e-6, 1000) ``` -------------------------------- ### Pandapower Diagnostic Function Report Example Source: https://github.com/e2niee/pandapower/blob/develop/doc/powerflow/diagnostic.md This example demonstrates how to handle errors and results within a custom diagnostic function's report method. It includes checks for errors and successful completion, along with placeholders for message formatting. ```python # error and success checks if error is not None: self.out.warning("Check for < > failed due to the following error:") self.out.warning(error) return if results is None: self.out.info("PASSED: < > successful.") return # message header ... # message body ... # message summary ... ``` -------------------------------- ### Display overviews and first 100 generators Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/ltds2pp_without_ssh.ipynb Prints statistical overviews and the first 100 entries for both PQ (static) and PV (dynamic) generators in the network. ```python print(f"Overview over the PQ generators: {net.sgen.describe()}") print(f"The PQ generators: {net.sgen.loc[:100]}") print(f"Overview over the PV generators: {net.gen.describe()}") print(f"The PV generators: {net.gen.loc[:100]}") ``` -------------------------------- ### pandapower.toolbox.get_connecting_branches Source: https://github.com/e2niee/pandapower/blob/develop/doc/toolbox.md Gets branches that connect any bus from buses1 with any bus from buses2. ```APIDOC ## pandapower.toolbox.get_connecting_branches(net, buses1, buses2, branch_elements=None) ### Description Gets branches that connect any bus of buses1 with any bus of buses2. ### Parameters * **net** (*pandapowerNet*) – The pandapower network. * **buses1** (*int* or *iterable of ints*) – The first set of buses. * **buses2** (*int* or *iterable of ints*) – The second set of buses. * **branch_elements** (*list*, optional) – A list of branch element types to consider. If None, all branch types are considered. ``` -------------------------------- ### Gurobi Environment Setup (MacOS) Source: https://github.com/e2niee/pandapower/blob/develop/doc/opf/pandamodels.md Set the GUROBI_HOME environment variable and add Gurobi binaries to the PATH and LD_LIBRARY_PATH. Ensure the Gurobi license file is correctly pointed to. ```bash # MacOS # gurobi export GUROBI_HOME="/Library/gurobiVERSION/mac64" export PATH="$PATH:$GUROBI_HOME/bin" export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$GUROBI_HOME/lib" export GRB_LICENSE_FILE="/PATH_TO_YOUR_LICENSE_DIR/gurobi.lic" ``` -------------------------------- ### Install PandaModels.jl Source: https://github.com/e2niee/pandapower/blob/develop/doc/opf/pandamodels.md Add the PandaModels.jl interface package using the Julia package manager. ```julia add PandaModels ``` -------------------------------- ### Create a pandapower network for Q capability testing Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/q_reactive_power_capability.ipynb Sets up a pandapower network with buses, external grid, lines, loads, transformers, and a generator. Optionally includes reactive power capability curve data. ```python #Create network def test_net_for_q_capability_curve(characteristics_data=False): net = create_empty_network() bus1 = create_bus(net, name="bus1", vn_kv=20., type="b", min_vm_pu=0., max_vm_pu=1.05) bus2 = create_bus(net, name="bus2", vn_kv=110., type="b", min_vm_pu=0., max_vm_pu=1.05) bus3 = create_bus(net, name="bus3", vn_kv=110., type="b", min_vm_pu=0., max_vm_pu=1.05) create_ext_grid(net, bus3, name="External Grid", vm_pu=1.0, va_degree=0.0,max_p_mw=100000, min_p_mw=0, min_q_mvar=-300, max_q_mvar=300, s_sc_max_mva=10000, s_sc_min_mva=8000, rx_max=0.1, rx_min=0.1) # create lines create_line_from_parameters(net, bus2, bus3, length_km=10,df=1,max_loading_percent=100,vn_kv=110,max_i_ka=0.74,type="ol", r_ohm_per_km=0.0949, x_ohm_per_km =0.38, c_nf_per_km=0.0092, name="Line") # create load create_load(net, bus3, p_mw=200, q_mvar=180, name="Load", vm_pu=1.0 ) # create transformer create_transformer_from_parameters(net, bus2, bus1, name="110kV/20kV transformer", parallel=1,max_loading_percent=100,sn_mva=210, vn_hv_kv=110, vn_lv_kv=20, vk_percent=12.5, vkr_percent=0.01904762, vk0_percent=10, vkr0_percent=0, shift_degree=330, vector_group="YNd11", i0_percent= 0.26, pfe_kw=0,si0_hv_partial=0.5) create_gen(net, bus1, p_mw=100, sn_mva=255.0, scaling=1.0, type="Hydro", cos_phi=0.8, pg_percent=0.0, vn_kv=19.0, vm_pu=1.0) if characteristics_data: net["q_capability_curve_table"] = pd.DataFrame( {'id_q_capability_curve': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'p_mw': [-331.01001, -298.0, -198.0, -66.2000, -0.1, 0, 0.1, 66.200, 100, 198.00, 298.00, 331.01001], 'q_min_mvar':[-0.0100, -134.0099, -265.01001, -323.01001, -323.01001, -323.01001, -323.01001, -323.01001, 0, -265.01001, -134.00999, -0.01000 ], 'q_max_mvar':[0.01000, 134.00999, 228.00999, 257.01001, 261.01001, 261.01001, 261.01001, 257.01001, 30, 40, 134.0099, 0.01]}) net.gen.loc[0,"id_q_capability_characteristic"] = 0 net.gen['curve_style'] = "straightLineYValues" return net ``` -------------------------------- ### Compare Vm and P/Q for different control strategies Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/DER_control_tutorial.ipynb Compares voltage and active/reactive power values between a fixed reactive power strategy and a cosphi(P) strategy. Use this to analyze the impact of different control methods on grid behavior. ```python greater_0_5 = net.sgen.index[net.sgen.p_mw > 0.5] df_compare = pd.DataFrame({ "Vm_qfix": net.res_bus.vm_pu.loc[net.sgen.bus.loc[greater_0_5]].values, "Vm_cosphiP": net_cosphiP.res_bus.vm_pu.loc[net_cosphiP.sgen.bus.loc[greater_0_5]].values, "P_qfix": net.res_sgen.p_mw.loc[greater_0_5], "P_cosphiP": net_cosphiP.res_sgen.p_mw.loc[greater_0_5], "Q_qfix": net.res_sgen.q_mvar.loc[greater_0_5], "Q_cosphiP": net_cosphiP.res_sgen.q_mvar.loc[greater_0_5], }) print(df_compare) ``` -------------------------------- ### Test PowerModels Installation (Alternative) Source: https://github.com/e2niee/pandapower/blob/develop/doc/opf/pandamodels.md An alternative method to test PowerModels.jl using the Pkg module. ```julia using Pkg Pkg.test("PowerModels") ``` -------------------------------- ### Execute Time Series Simulation and Set Up Output Directory Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/ieee_european_lv_time_series.ipynb Configures the output directory for time series simulation results and initiates the simulation. Results are stored in the system's temporary directory. ```python output_dir = os.path.join(tempfile.gettempdir(), "time_series_example") print("Results can be found in your local temp folder: {}".format(output_dir)) if not os.path.exists(output_dir): os.mkdir(output_dir) timeseries_example(output_dir) ``` -------------------------------- ### Get in-service generator buses Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/internal_datastructure.ipynb Retrieves the pandapower bus indices for all generators that are currently in service. ```python gen_buses = net.gen.loc[net.gen.in_service.values, "bus"].values print(f"pandapower gen bus: {gen_buses}") ``` -------------------------------- ### Get HV nodes Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/ltds2pp.ipynb Filter and display bus elements with a nominal voltage between 100kV and 150kV. ```python print("the HV nodes first") print(net.bus.loc[(net.bus.vn_kv > 100) & (net.bus.vn_kv < 150)]) ``` -------------------------------- ### Initialize DiscreteTapControl from Tap Step Percent Source: https://github.com/e2niee/pandapower/blob/develop/doc/control/controller.md Alternative initialization for DiscreteTapControl using a voltage setpoint and the tap_step_percent parameter to calculate voltage limits. Use this when vm_lower_pu and vm_upper_pu are not directly provided. ```python c = DiscreteTapControl.from_tap_step_percent(net, element_index, vm_set_pu) ``` -------------------------------- ### Create a pandapower network with buses and components Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/pandamodels_opf.ipynb Initialize an empty network and define buses with voltage constraints. Then, add a 3-Winding transformer, 110kV lines, loads, and generators with associated costs. This sets up the grid topology and operational parameters for OPF. ```python net = create_empty_network() min_vm_pu = 0.95 max_vm_pu = 1.05 #create buses bus1 = create_bus(net, vn_kv=220., geodata=(5,9), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu) bus2 = create_bus(net, vn_kv=110., geodata=(6,10), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu) bus3 = create_bus(net, vn_kv=110., geodata=(10,9), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu) bus4 = create_bus(net, vn_kv=110., geodata=(8,8), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu) bus5 = create_bus(net, vn_kv=110., geodata=(6,8), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu) #create 220/110/110 kV 3W-transformer create_transformer3w_from_parameters(net, bus1, bus2, bus5, vn_hv_kv=220, vn_mv_kv=110, vn_lv_kv=110, vk_hv_percent=10., vk_mv_percent=10., vk_lv_percent=10., vkr_hv_percent=0.5, vkr_mv_percent=0.5, vkr_lv_percent=0.5, pfe_kw=10, i0_percent=0.1, shift_mv_degree=0, shift_lv_degree=0, sn_hv_mva=100, sn_mv_mva=50, sn_lv_mva=50) #create 110 kV lines l1 = create_line(net, bus2, bus3, length_km=70., std_type='149-AL1/24-ST1A 110.0') l2 = create_line(net, bus3, bus4, length_km=50., std_type='149-AL1/24-ST1A 110.0') l3 = create_line(net, bus4, bus2, length_km=40., std_type='149-AL1/24-ST1A 110.0') l4 = create_line(net, bus4, bus5, length_km=30., std_type='149-AL1/24-ST1A 110.0') #create loads create_load(net, bus2, p_mw=60) create_load(net, bus3, p_mw=70) create_load(net, bus4, p_mw=10) #create generators g1 = create_gen(net, bus1, p_mw=40, min_p_mw=0, max_p_mw=200, vm_pu=1.01, slack=True) create_poly_cost(net, g1, 'gen', cp1_eur_per_mw=1) g2 = create_gen(net, bus3, p_mw=40, min_p_mw=0, max_p_mw=200, vm_pu=1.01) create_poly_cost(net, g2, 'gen', cp1_eur_per_mw=3) g3 = create_gen(net, bus4, p_mw=50, min_p_mw=0, max_p_mw=200, vm_pu=1.01) create_poly_cost(net, g3, 'gen', cp1_eur_per_mw=3) net ``` -------------------------------- ### Compare Power Loss and Loading Results Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/pandamodels_reactive power optimization.ipynb Print and compare the total power loss and line loading percentages before and after running the respective optimization functions. This helps to quantify the effectiveness of the optimization. ```python print("loss without optimization:", net.res_line.pl_mw.values.sum()) print("loss with optimization:", net_loss.res_line.pl_mw.values.sum()) print("++++++++++++++++++++++++++++++++++++++++++++++") print("loading without optimization:", net.res_line.loading_percent.values.sum()) print("loading with optimization:", net_loading.res_line.loading_percent.values.sum()) ``` -------------------------------- ### Initialize Empty Pandapower Network Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/create_advanced.ipynb Creates an empty pandapower network object to start building the grid. ```python #create an empty network net = create_empty_network() ``` -------------------------------- ### Get ks Value Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/shortcircuit/sc_power_station_unit.ipynb Retrieves the calculated value of the short-circuit current factor (ks) for the first element. ```python ks.at[0] ``` -------------------------------- ### Create and Apply Standard Line Types Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/std_types.ipynb Demonstrates creating a network, defining standard line types in a dictionary, and adding them to the network using `create_std_types`. It also shows how to list available standard types. ```python net = create_empty_network() linetypes = {"typ1": {"r_ohm_per_km": 0.01, "x_ohm_per_km": 0.02, "c_nf_per_km": 10, "max_i_ka": 0.4, "type": "cs"}, "typ2": {"r_ohm_per_km": 0.015, "x_ohm_per_km": 0.01, "c_nf_per_km": 30, "max_i_ka": 0.3, "type": "cs"}} create_std_types(net, data=linetypes, element="line") available_std_types(net) ``` -------------------------------- ### Get Jacobian matrix shape Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/internal_datastructure.ipynb Prints the shape of the Jacobian matrix, which is used in power flow calculations. ```python J = net._ppc["internal"]["J"] print(f"Jacobian shape: {J.shape}") ``` -------------------------------- ### Initialize Network and Controller Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/building_a_controller.ipynb Loads a pandapower network, creates a time series data source, adds a storage unit to the grid, and instantiates the custom Storage controller. ```python # importing a grid from the library from pandapower.networks import mv_oberrhein # loading the network with the usecase 'generation' net = mv_oberrhein() runpp(net) # creating a simple time series framedata = pd.DataFrame([0.1, .05, 0.1, .005, -0.2, 0], columns=['P']) datasource = ts.DFData(framedata) # creating storage unit in the grid, which will be controlled by our controller store_el = create_storage(net, 30, p_mw = .1, q_mvar = 0, max_e_mwh = 0.1, ) # creating an Object of our new build storage controller, controlling the storage unit ctrl = Storage(net=net, element_index=store_el, data_source=datasource,p_profile='P') ``` -------------------------------- ### Get Connecting Branches Source: https://github.com/e2niee/pandapower/blob/develop/doc/toolbox.md Finds branches that link any bus from the first set to any bus from the second set. ```python pandapower.toolbox.get_connecting_branches(net, buses1, buses2, branch_elements=None) ``` -------------------------------- ### Import necessary pandapower modules Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/plotting_basic.ipynb Imports required for plotting and network operations. Ensure all listed packages are installed. ```python import numpy as np import geojson from pandapower.networks import mv_oberrhein from pandapower.topology.create_graph import create_nxgraph from pandapower.topology.graph_searches import calc_distance_to_bus, connected_components from pandapower.plotting.simple_plot import simple_plot from pandapower.run import runpp from pandapower.plotting.plotting_toolbox import get_collection_sizes from pandapower.plotting import create_line_collection, create_bus_collection, draw_collections, create_annotation_collection ``` -------------------------------- ### Setup for time-series analysis with DER controller Source: https://github.com/e2niee/pandapower/blob/develop/tutorials/DER_control_tutorial.ipynb Initializes a simplified network and an OutputWriter for time-series simulations, logging active and reactive power of sgens. This is a prerequisite for analyzing DER behavior over time. ```python def simple_test_net_for_timeseries(): # this is basically the same grid as simple_test_net() but with only one line to one bus # with one sgen net = create_empty_network() create_buses(net, 2, vn_kv=20) create_ext_grid(net, 0) create_sgen(net, 1, p_mw=5., sn_mva=5.) create_line(net, 0, 1, length_km=5.0, std_type="NAYY 4x50 SE") # create outputwriter and define variables to log ow = OutputWriter(net) ow.log_variable("res_sgen", "p_mw") ow.log_variable("res_sgen", "q_mvar") return net, ow ts_data = pd.DataFrame({"p_0": -p_vals_5}) data = DFData(ts_data) ``` -------------------------------- ### Install Julia Packages Source: https://github.com/e2niee/pandapower/blob/develop/doc/opf/pandamodels.md Add necessary Julia packages for optimization and Python interoperability using the package manager. ```julia add Ipopt PowerModels PyCall ```