def analyze_jsonout(space,
                    minAttack,
                    maxAttack,
                    interval,
                    fname,
                    iterations=200):
    print("Beginning system size analysis...")

    results = dict()

    print('  running 30 bus test case... ', end='', flush=True)
    c30 = pp.case30()
    n_b = len(c30['branch'])
    results['30bus'] = equal_freespace(c30,
                                       space,
                                       int(n_b * minAttack),
                                       int(n_b * maxAttack),
                                       interval,
                                       iterations=iterations)
    print('finished!')

    print('  running 57 bus test case... ', end='', flush=True)
    c57 = pp.case57()
    n_b = len(c57['branch'])
    results['57bus'] = equal_freespace(c57,
                                       space,
                                       int(n_b * minAttack),
                                       int(n_b * maxAttack),
                                       interval,
                                       iterations=iterations)
    print('finished!')

    print('  running 118 bus test case... ', end='', flush=True)
    c118 = pp.case118()
    n_b = len(c118['branch'])
    results['118bus'] = equal_freespace(c118,
                                        space,
                                        int(n_b * minAttack),
                                        int(n_b * maxAttack),
                                        interval,
                                        iterations=iterations)
    print('finished!')

    print('  running 300 bus test case... ', end='', flush=True)
    c300 = pp.case300()
    n_b = len(c300['branch'])
    results['300bus'] = equal_freespace(c300,
                                        space,
                                        int(n_b * minAttack),
                                        int(n_b * maxAttack),
                                        interval,
                                        iterations=iterations)
    print('finished!')

    with open(fname, 'w') as outfile:
        json.dump(results, outfile)

    print("Full system size analysis complete!")
def test_buses_to_ppc_subgrid(iterations=2000):
    # out of date
    for i in range(iterations):
        grid1 = pp.case118()
        buses_array_idx = sorted(
            random.sample(range(118), random.randint(1, 118)))
        buses = grid1['bus'][buses_array_idx]
        bus_ids = buses[:, idx_bus.BUS_I].astype(int)
        grid1['bus'] = buses

        del_gens = []
        for i, gen in enumerate(grid1['gen']):
            if int(gen[idx_gen.GEN_BUS]) not in bus_ids:
                del_gens.append(i)
        grid1['gen'] = np.delete(grid1['gen'], del_gens, 0)

        del_branches = []
        for i, branch in enumerate(grid1['branch']):
            if int(branch[idx_brch.F_BUS]) not in bus_ids or int(
                    branch[idx_brch.T_BUS]) not in bus_ids:
                del_branches.append(i)
        grid1['branch'] = np.delete(grid1['branch'], del_branches, 0)

        grid2 = pp.case118()
        grid2 = buses_to_ppc_subgrid(set(bus_ids), grid2)

        assert (np.array_equal(grid1['bus'][:, idx_bus.BUS_I],
                               grid2['bus'][:, idx_bus.BUS_I]))
        try:
            assert (np.array_equal(grid1['gen'][:, idx_gen.GEN_BUS],
                                   grid2['gen'][:, idx_gen.GEN_BUS]))
        except:
            # no generators in the component
            assert (len(grid1['gen']) == 0)
            assert (grid2['gen'][0, idx_gen.GEN_BUS]
                    not in pp.case118()['gen'][:, idx_gen.GEN_BUS])
        try:
            assert (np.array_equal(grid1['branch'][:, idx_brch.F_BUS],
                                   grid2['branch'][:, idx_brch.F_BUS]))
            assert (np.array_equal(grid1['branch'][:, idx_brch.T_BUS],
                                   grid2['branch'][:, idx_brch.T_BUS]))
        except:
            assert (len(grid1['branch']) == 0 and len(grid2['branch']) == 0)
def test_ppc_to_nx(iterations=2000):
    for i in range(iterations):
        grid = pp.case118()
        all_branches = grid['branch'][:, 0:2]
        branches = sorted(random.sample(range(1, 187), random.randint(0, 186)))
        del_branches = sorted(list(set(range(1, 187)) - set(branches)))
        branches = [1, 2, 3]
        del_branches = list(range(4, 187))
        grid['branch'][np.array(del_branches, dtype=int) - 1,
                       idx_brch.BR_X] = np.inf

        graph = nx.Graph()
        graph.add_nodes_from(range(1, 119))
        graph.add_edges_from(all_branches[np.array(branches) - 1].astype(int))
        assert (nx.could_be_isomorphic(ppc_to_nx(grid), graph))
Exemplo n.º 4
0
######################   Entereing Execution Mode  ##########################################################
    status = h.helicsFederateEnterInitializingMode(fed)
    status = h.helicsFederateEnterExecutingMode(fed)

    #Pypower Processing (inputs)
    hours = 24
    total_inteval = int(60 * 60 * hours)
    grantedtime = -1
    pf_interval = 5 * 60  # in seconds (minimim_resolution)
    acopf_interval = 15 * 60  # in seconds (minimim_resolution)
    random.seed(0)

    peak_demand = []
    ppc = []
    case_format = case118()
    peak_demand = case_format['bus'][:, 2][:].copy()
    ppc = case_format.copy()

    ######################   creating fixed load profiles for each bus based on PF interval #############################

    # load profiles (inputs)
    profiles = spio.loadmat('normalized_load_data_1min_ORIGINAL.mat',
                            squeeze_me=True,
                            struct_as_record=False)
    load_profiles_1min = profiles['my_data']
    resolution_load = numpy.floor(total_inteval / pf_interval)
    points = numpy.floor(
        numpy.linspace(0,
                       len(load_profiles_1min) - 1, resolution_load + 1))
    time_pf = numpy.linspace(0, total_inteval, resolution_load + 1)
def analyze_csvout(factor,
                   minAttack,
                   maxAttack,
                   interval,
                   fname,
                   iterations=200):
    print('Beginning system size analysis...')

    with open(fname, 'w', newline='') as csvfile:
        writer = csv.writer(csvfile)

        #space = lambda case : avg_line_flow(case) * factor
        space = lambda case: 100

        print('  running 30 bus test case... ')
        writer.writerow(['IEEE 30 bus test case'])
        #c30 = equalize_generation(pp.case30())
        c30 = pp.case30()
        out30 = equal_freespace(c30,
                                space(c30),
                                0,
                                len(c30['branch']),
                                interval,
                                iterations=iterations,
                                printProgress=True)
        print('    finished!')
        for key in sorted(out30['average'].keys()):
            writer.writerow([key, out30[key]])

        print('  running 57 bus test case... ')
        writer.writerow([])
        writer.writerow(['IEEE 57 bus test case'])
        #c57 = equalize_generation(pp.case57())
        c57 = pp.case57()
        out57 = equal_freespace(c57,
                                space(c57),
                                0,
                                len(c57['branch']),
                                interval,
                                iterations=iterations,
                                printProgress=True)
        print('    finished!')
        for key in sorted(out57['average'].keys()):
            writer.writerow([key, out57[key]])

        print('  running 118 bus test case... ')
        writer.writerow([])
        writer.writerow(['IEEE 118 bus test case'])
        #c118 = equalize_generation(pp.case118())
        c118 = pp.case118()
        out118 = equal_freespace(c118,
                                 space(c118),
                                 0,
                                 len(c118['branch']),
                                 interval,
                                 iterations=iterations,
                                 printProgress=True)
        print('    finished!')
        for key in sorted(out118.keys()):
            writer.writerow([key, out118['average'][key]])

        print('  running 300 bus test case... ')
        writer.writerow([])
        writer.writerow(['IEEE 300 bus test case'])
        #c300 = equalize_generation(pp.case300())
        c300 = pp.case300()
        out300 = equal_freespace(c300,
                                 space(c300),
                                 0,
                                 len(c300['branch']),
                                 interval,
                                 iterations=iterations,
                                 printProgress=True)
        print('    finished!')
        for key in sorted(out300.keys()):
            writer.writerow([key, out300['average'][key]])

    print('System size analysis complete!')