def test_reindex_buses(): net_orig = nw.example_simple() net = nw.example_simple() to_add = 5 new_bus_idxs = np.array(list(net.bus.index)) + to_add bus_lookup = dict(zip(net["bus"].index.values, new_bus_idxs)) # a more complexe bus_lookup of course should also work, but this one is easy to check pp.reindex_buses(net, bus_lookup) for elm in net.keys(): if isinstance(net[elm], pd.DataFrame) and net[elm].shape[0]: cols = pd.Series(net[elm].columns) bus_cols = cols.loc[cols.str.contains("bus")] if len(bus_cols): for bus_col in bus_cols: assert all(net[elm][bus_col] == net_orig[elm][bus_col] + to_add) if elm == "bus": assert all(np.array(list(net[elm].index)) == np.array(list( net_orig[elm].index)) + to_add)
def get_net(): """ Get a pp network consistent with pypower dynamic nine bus case. """ net = nw.case9() # Make consistent with the case in pypower dynamics. net.sn_mva = 100.0 net.gen.vm_pu = 1.025 net.ext_grid.vm_pu = 1.04 pp.create_continuous_bus_index(net, 1) pp.reindex_buses(net, { 5: 6, 6: 9, 7: 8, 8: 7, 9: 5, }) net.bus = net.bus.sort_index() net.load = net.load.sort_values('bus').reset_index(drop=True) net.line = net.line.sort_values('from_bus').reset_index(drop=True) return net