def test_unsupplied_buses_with_in_service(): # IS ext_grid --- open switch --- OOS bus --- open switch --- IS bus net = pp.create_empty_network() bus_sl = pp.create_bus(net, 0.4) pp.create_ext_grid(net, bus_sl) bus0 = pp.create_bus(net, 0.4, in_service=False) pp.create_switch(net, bus_sl, bus0, 'b', False) bus1 = pp.create_bus(net, 0.4, in_service=True) pp.create_switch(net, bus0, bus1, 'b', False) ub = top.unsupplied_buses(net) assert ub == {2} # OOS ext_grid --- closed switch --- IS bus net = pp.create_empty_network() bus_sl = pp.create_bus(net, 0.4) pp.create_ext_grid(net, bus_sl, in_service=False) bus0 = pp.create_bus(net, 0.4, in_service=True) pp.create_switch(net, bus_sl, bus0, 'b', True) ub = top.unsupplied_buses(net) assert ub == {0, 1}
def check_energized(self): """ Check the island bus """ num_de_energized = len(pt.unsupplied_buses(self.net)) list_de_energized = list(pt.unsupplied_buses(self.net)) return num_de_energized, list_de_energized
def test_unsupplied_buses_with_switches(): net = pp.create_empty_network() pp.create_buses(net, 8, 20) pp.create_buses(net, 5, 0.4) pp.create_ext_grid(net, 0) pp.create_line(net, 0, 1, 1.2, "NA2XS2Y 1x185 RM/25 12/20 kV") pp.create_switch(net, 0, 0, "l", closed=True) pp.create_switch(net, 1, 0, "l", closed=False) pp.create_line(net, 0, 2, 1.2, "NA2XS2Y 1x185 RM/25 12/20 kV") pp.create_switch(net, 0, 1, "l", closed=False) pp.create_switch(net, 2, 1, "l", closed=True) pp.create_line(net, 0, 3, 1.2, "NA2XS2Y 1x185 RM/25 12/20 kV") pp.create_switch(net, 0, 2, "l", closed=False) pp.create_switch(net, 3, 2, "l", closed=False) pp.create_line(net, 0, 4, 1.2, "NA2XS2Y 1x185 RM/25 12/20 kV") pp.create_switch(net, 0, 3, "l", closed=True) pp.create_switch(net, 4, 3, "l", closed=True) pp.create_line(net, 0, 5, 1.2, "NA2XS2Y 1x185 RM/25 12/20 kV") pp.create_switch(net, 0, 6, "b", closed=True) pp.create_switch(net, 0, 7, "b", closed=False) pp.create_transformer(net, 0, 8, "0.63 MVA 20/0.4 kV") pp.create_switch(net, 0, 0, "t", closed=True) pp.create_switch(net, 8, 0, "t", closed=False) pp.create_transformer(net, 0, 9, "0.63 MVA 20/0.4 kV") pp.create_switch(net, 0, 1, "t", closed=False) pp.create_switch(net, 9, 1, "t", closed=True) pp.create_transformer(net, 0, 10, "0.63 MVA 20/0.4 kV") pp.create_switch(net, 0, 2, "t", closed=False) pp.create_switch(net, 10, 2, "t", closed=False) pp.create_transformer(net, 0, 11, "0.63 MVA 20/0.4 kV") pp.create_switch(net, 0, 3, "t", closed=True) pp.create_switch(net, 11, 3, "t", closed=True) pp.create_transformer(net, 0, 12, "0.63 MVA 20/0.4 kV") pp.create_buses(net, 2, 20) pp.create_impedance(net, 0, 13, 1, 1, 10) pp.create_impedance(net, 0, 14, 1, 1, 10, in_service=False) ub = top.unsupplied_buses(net) assert ub == {1, 2, 3, 7, 8, 9, 10, 14} ub = top.unsupplied_buses(net, respect_switches=False) assert ub == {14}
def _test_net_validity(net, sb_code_params, shortened, input_path=None): """ This function is to test validity of a simbench net. """ # --- deduce values from sb_code_params to test extracted csv data # lv_net_extent: 0-no lv_net 1-one lv_net 2-all lv_nets lv_net_extent = int(bool(len(sb_code_params[2]))) if bool(lv_net_extent) and sb_code_params[4] == "all": lv_net_extent += 1 # net_factor: how many lower voltage grids are expected to be connected if shortened: net_factor = 8 else: if sb_code_params[1] == "HV": net_factor = 10 else: net_factor = 50 # --- test data existence # buses expected_buses = {0: 12, 1: 80, 2: net_factor*12}[lv_net_extent] if sb_code_params[1] != "EHV" \ else {0: 6, 1: 65, 2: 125}[lv_net_extent] assert net.bus.shape[0] > expected_buses # ext_grid assert bool(net.ext_grid.shape[0]) # switches if sb_code_params[6]: if int(sb_code_params[5]) > 0: if net.switch.shape[0] <= net.line.shape[0] * 2 - 2: logger.info( "There are %i switches, but %i " % (net.switch.shape[0], net.line.shape[0]) + "lines -> some lines are not surrounded by switches.") else: assert net.switch.shape[0] > net.line.shape[0] * 2 - 2 else: assert not net.switch.closed.any() assert (net.switch.et != "b").all() # all buses supplied if sb_code_params[1] != "complete_data": unsup_buses = unsupplied_buses(net, respect_switches=False) if len(unsup_buses): logger.error("There are %i unsupplied buses." % len(unsup_buses)) if len(unsup_buses) < 10: logger.error("These are: " + str(net.bus.name.loc[unsup_buses])) assert not len(unsup_buses) # lines assert net.line.shape[0] >= net.bus.shape[0]-net.trafo.shape[0]-(net.switch.et == "b").sum() - \ 2*net.trafo3w.shape[0]-net.impedance.shape[0]-net.dcline.shape[0]-net.ext_grid.shape[0] # trafos if sb_code_params[1] == "EHV": expected_trafos = {0: 0, 1: 2, 2: 8}[lv_net_extent] elif sb_code_params[1] == "HV": expected_trafos = {0: 2, 1: 4, 2: net_factor * 2}[lv_net_extent] elif sb_code_params[1] == "MV": expected_trafos = {0: 2, 1: 3, 2: net_factor * 1}[lv_net_extent] elif sb_code_params[1] == "LV": expected_trafos = {0: 1}[lv_net_extent] elif sb_code_params[1] == "complete_data": expected_trafos = 200 assert net.trafo.shape[0] >= expected_trafos # load expected_loads = {0: 10, 1: net_factor, 2: net_factor*10}[lv_net_extent] if \ sb_code_params[1] != "EHV" else {0: 3, 1: 53, 2: 113}[lv_net_extent] assert net.load.shape[0] > expected_loads # sgen if sb_code_params[1] == "LV": expected_sgen = {0: 0}[lv_net_extent] elif sb_code_params[2] == "LV": expected_sgen = {1: 50, 2: 50 + net_factor * 1}[lv_net_extent] else: expected_sgen = expected_loads assert net.sgen.shape[0] > expected_sgen # measurement if pd.Series(["HV", "MV"]).isin([sb_code_params[1], sb_code_params[2]]).any(): assert net.measurement.shape[0] > 1 # bus_geodata assert net.bus.shape[0] == net.bus_geodata.shape[0] # check_that_all_buses_connected_by_switches_have_same_geodata for bus_group in bus_groups_connected_by_switches(net): first_bus = list(bus_group)[0] assert all( np.isclose(net.bus_geodata.x.loc[bus_group], net.bus_geodata.x.loc[first_bus]) & np.isclose(net.bus_geodata.y.loc[bus_group], net.bus_geodata.y.loc[first_bus])) # --- test data content # substation for elm in ["bus", "trafo", "trafo3w", "switch"]: mentioned_substations = pd.Series( net[elm].substation.unique()).dropna() if not mentioned_substations.isin(net.substation.name.values).all(): raise AssertionError( str( list(mentioned_substations. loc[~mentioned_substations.isin(net.substation.name. values)].values)) + " from element '%s' misses in net.substation" % elm) # check subnet input_path = input_path if input_path is not None else sb.complete_data_path( sb_code_params[5]) hv_subnet, lv_subnets = sb.get_relevant_subnets(sb_code_params, input_path=input_path) allowed_elms_missing_subnet = [ "gen", "dcline", "trafo3w", "impedance", "measurement", "shunt", "storage", "ward", "xward" ] if not sb_code_params[6]: allowed_elms_missing_subnet += ["switch"] if sb_code_params[1] != "complete_data": hv_subnets = sb.ensure_iterability(hv_subnet) for elm in pp.pp_elements(): if "subnet" not in net[elm].columns or not bool(net[elm].shape[0]): assert elm in allowed_elms_missing_subnet else: # subnet is in net[elm].columns and there are one or more elements subnet_split = net[elm].subnet.str.split("_", expand=True) subnet_ok = set() subnet_ok |= set( subnet_split.index[subnet_split[0].isin(hv_subnets + lv_subnets)]) if elm in ["bus", "measurement", "switch"]: if 1 in subnet_split.columns: subnet_ok |= set(subnet_split.index[ subnet_split[1].isin(hv_subnets)]) assert len(subnet_ok) == net[elm].shape[0] # check profile existing assert not sb.profiles_are_missing(net) # --- check profiles and loadflow check_loadflow = sb_code_params[1] != "complete_data" check_loadflow &= sb_code_params[2] != "HVMVLV" if check_loadflow: try: pp.runpp(net) converged = net.converged except: sb_code = sb.get_simbench_code_from_parameters(sb_code_params) logger.error("Loadflow not converged with %s" % sb_code) converged = False assert converged
def make_fault(self, mode="N-1", island_allow=False, island_bus=False, loop=100): """ make fault sense of lines, buses ... # searching loop is set to 100 as defult - mode = "N-1" ; "N-2" ; "LPHI" * "LPHI" mode is an interface for meteorological disasters * - island_allow = False : line[0]=(1,2) cant be distoried island_allow = True : the system could be operation in island mode as microgrid - island_bus = False : all buses could be re-energized by reconfiguration island_bus = True : some buses cannot be recovered by reconfiguration #TODO : Current function = mode = "N-1" & "N-2" ; island_allow = False ; island_bus = False """ # reset net self.reflash_net() res_sense = np.zeros((loop, 37), dtype=int) if mode == "N-1": s = 0 for i in range(loop): self.reflash_net() faultlist = random.randint(1, 36) if island_allow == False: if island_bus == False: self.prim_net.line["in_service"][faultlist] = False if len(pt.unsupplied_buses(self.prim_net)) == 0: res_sense[s, faultlist] = 1 s += 1 pass pass pass pass # remove duplicate lines res_sense = np.unique(res_sense, axis=0) res_sense = np.delete(res_sense, [-1], axis=0) np.savetxt("./out/res_faultmaker/result.csv", res_sense, fmt="%i", delimiter=",") pass if mode == "N-2": s = 0 for i in range(loop): self.reflash_net() faultlist = [] while (len(faultlist) < 2): x = random.randint(1, 36) if x not in faultlist: faultlist.append(x) pass pass if island_allow == False: if island_bus == False: self.prim_net.line["in_service"][faultlist[0]] = False self.prim_net.line["in_service"][faultlist[1]] = False if len(pt.unsupplied_buses(self.prim_net)) == 0: res_sense[s, faultlist] = 1 s += 1 pass pass pass pass # remove duplicate lines res_sense = np.unique(res_sense, axis=0) res_sense = np.delete(res_sense, [-1], axis=0) np.savetxt("./out/res_faultmaker/result.csv", res_sense, fmt="%i", delimiter=",") pass pass
print('\t\tCreating base grid') net = create_pp_grid(nodes, lines, tech, lv, n0=0, hv=True, ntrafos_hv=2, vn_kv=20, tanphi=0.3, hv_trafo_controller=True, verbose=True) # Check connectedness # Check unsupplied buses from External grid ub = ppt.unsupplied_buses(net) if len(ub) == 0: print('Connectedness ok') else: print('There are Non supplied buses!') print('Running') t = time() pp.runpp(net, run_control=True) print('Run! dt={:.2f}'.format(time() - t)) plot_v_profile(net) plt.title('Voltage profile') # TODO: Find out why time series of Pandapower doesnt work