Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# create generator
pp.create_gen(net, bus6, p_kw=-6000, vm_pu=1.05)
# create static generator
pp.create_sgen(net, bus7, p_kw=-2000)
# Last mit 20MV bei scaling 0.6 ~ 12MV -> Industrie / Verbaucher am MS Netz
# create load
pp.create_load(net, bus8, p_kw=20000, q_kvar=4000, scaling=0.6)
# create shunt
pp.create_shunt(net, bus3, p_kw=0, q_kvar=-960, name='Shunt')
# run power flow and generate result tables
pp.runpp(net)
return net
"'ppc_net['success'] != 1'")
if (ppc_net['branch'].shape[1] < 17):
ppc_success = False
logger.error("The shape of given ppc data indicates missing pypower powerflow results.")
# --- try to run a pandapower powerflow
if run[1]:
if pf_type == "runpp":
try:
pp.runpp(net, init="dc", calculate_voltage_angles=True, trafo_model="pi")
except pp.LoadflowNotConverged:
try:
pp.runpp(net, calculate_voltage_angles=True, init="flat", trafo_model="pi")
except pp.LoadflowNotConverged:
try:
pp.runpp(net, trafo_model="pi", calculate_voltage_angles=False)
if "bus_va_degree" in max_diff_values.keys():
max_diff_values["bus_va_degree"] = 1e2 if max_diff_values[
"bus_va_degree"] < 1e2 else max_diff_values["bus_va_degree"]
logger.info("voltage_angles could be calculated.")
except pp.LoadflowNotConverged:
logger.error('The pandapower powerflow does not converge.')
elif pf_type == "rundcpp":
try:
pp.rundcpp(net, trafo_model="pi")
except pp.LoadflowNotConverged:
logger.error('The pandapower dc powerflow does not converge.')
elif pf_type == "runopp":
try:
pp.runopp(net, init="flat", calculate_voltage_angles=True)
except pp.OPFNotConverged:
try:
#tid = pp.create_transformer_from_parameters(net,
# hv_bus=b1,
# lv_bus=b2,
# sn_kva=400.,
# vn_hv_kv=20.,
# vn_lv_kv=0.4,
# vsc_percent=6.,
# vscr_percent=1.425,
# i0_percent=0.3375,
# pfe_kw=1.35)
#create line by standard type
lid = pp.create_line(net, from_bus=b2, to_bus=b3, length_km=0.1,
std_type="NAYY 4x50 SE", name="Line")
#run loadflow
pp.runpp(net)
#print element tables
print("-------------------")
print(" ELEMENT TABLES ")
print("-------------------")
print("net.bus")
print(net.bus)
print("\n net.trafo")
print(net.trafo)
print("\n net.line")
print(net.line)
def add_virtual_meas_for_unobserved_bus(net, zero_injection='auto', fuse_buses_with_bb_switch='all'):
pp_p_unobserved_bus, pp_q_unobserved_bus = find_unobserved_bus(net, zero_injection, fuse_buses_with_bb_switch)
pp.runpp(net)
net.measurement = net.measurement.reset_index(drop=True)
for bus_ix in pp_p_unobserved_bus.index:
pp.create_measurement(net, "p", "bus", value= -net.res_bus.at[bus_ix, "p_mw"], std_dev=0.5, element=bus_ix)
for bus_ix in pp_q_unobserved_bus.index:
pp.create_measurement(net, "q", "bus", value= -net.res_bus.at[bus_ix, "q_mvar"], std_dev=0.5, element=bus_ix)
net.load.q_mvar = np.tan(np.arccos(cosphi_load)) * net.load.p_mw
net.sgen.q_mvar = np.tan(np.arccos(cosphi_pv)) * net.sgen.p_mw
hv_trafos = net.trafo[net.trafo.sn_mva > 1].index
if scenario == "load":
net.load.scaling = 0.6
net.sgen.scaling = 0.0
net.trafo.tap_pos.loc[hv_trafos] = [-2, -3]
elif scenario == "generation":
net.load.scaling = 0.1
net.sgen.scaling = 0.8
net.trafo.tap_pos.loc[hv_trafos] = [0, 0]
else:
raise ValueError("Unknown scenario %s - chose 'load' or 'generation'" % scenario)
pp.runpp(net)
return net
if ppc_net['success'] != 1:
ppc_success = False
logger.error("The given ppc data indicates an unsuccessful pypower powerflow: " +
"'ppc_net['success'] != 1'")
if (ppc_net['branch'].shape[1] < 17):
ppc_success = False
logger.error("The shape of given ppc data indicates missing pypower powerflow results.")
# --- try to run a pandapower powerflow
if run[1]:
if pf_type == "runpp":
try:
pp.runpp(net, init="dc", calculate_voltage_angles=True, trafo_model="pi")
except pp.LoadflowNotConverged:
try:
pp.runpp(net, calculate_voltage_angles=True, init="flat", trafo_model="pi")
except pp.LoadflowNotConverged:
try:
pp.runpp(net, trafo_model="pi", calculate_voltage_angles=False)
if "bus_va_degree" in max_diff_values.keys():
max_diff_values["bus_va_degree"] = 1e2 if max_diff_values[
"bus_va_degree"] < 1e2 else max_diff_values["bus_va_degree"]
logger.info("voltage_angles could be calculated.")
except pp.LoadflowNotConverged:
logger.error('The pandapower powerflow does not converge.')
elif pf_type == "rundcpp":
try:
pp.rundcpp(net, trafo_model="pi")
except pp.LoadflowNotConverged:
logger.error('The pandapower dc powerflow does not converge.')
elif pf_type == "runopp":
try:
def runpp(self):
try:
pp.runpp(self.net, **self.net._runpp_options)
self.mainPrintMessage(str(self.net))
except pp.LoadflowNotConverged:
self.mainPrintMessage("Power Flow did not Converge!")
except:
self.mainPrintMessage("Error occured - empty network?")
import pandapower.networks as pn
net = pn.networks.setup_grid(5, p=0.3, num_loads=7)
"""
if not num_loads and not deviation:
raise UserWarning("specify either num_loads or deviation!")
random.seed(seed)
net = random_empty_grid(num_buses, p)
if num_loads:
for _ in range(num_loads):
pp.create_load(net, random.randrange(1, num_buses), p_kw=200)
return net
else:
pp.runpp(net)
while net.res_bus.vm_pu.min() > 0.985 - deviation:
pp.create_load(net, random.randrange(1, num_buses), p_kw=200)
pp.runpp(net)
return net