Beispiel #1
0
def main_analyse(in_stream, out_stream):
    group = []
    pfail = []

    current_scenario = None

    def output_group_stats(grp):
        group_size = sum(c for c, s in grp)
        failures = float(sum(c for c, s in grp if s.result is False))
        pfail.append(failures / group_size)
        out_stream.write(as_csv([failures, group_size, failures / group_size], ",") + ",")
        out_stream.write(str(count) + "," + str(current_scenario) + "\n")

    for count, scenario in stream_scenario_generator(in_stream):
        if scenario.scenario_type == "outage" or scenario.scenario_type == "base":
            if len(group) != 0:
                output_group_stats(group)
                group = []

            # output base stats of new group
            current_scenario = scenario
        else:
            group.append((count, scenario))

    if len(group) != 0:
        output_group_stats(group)
        group = []

    out_stream.write("\n")
    out_stream.write("min , " + str(min(pfail)) + "\n")
    out_stream.write("max , " + str(max(pfail)) + "\n")
    out_stream.write("avg , " + str(sum(pfail) / len(pfail)) + "\n")
Beispiel #2
0
def main_analyse(in_stream, out_stream):
    group = []
    pfail = []

    current_scenario = None

    def output_group_stats(grp):
        group_size = sum(c for c, s in grp)
        failures = float(sum(c for c, s in grp if s.result is False))
        pfail.append(failures / group_size)
        out_stream.write(as_csv([failures, group_size, failures / group_size], ",") + ",")
        out_stream.write(str(count) + "," + str(current_scenario) + "\n")

    for count, scenario in stream_scenario_generator(in_stream):
        if scenario.scenario_type == "outage" or scenario.scenario_type == "base":
            if len(group) != 0:
                output_group_stats(group)
                group = []

            # output base stats of new group
            current_scenario = scenario
        else:
            group.append((count, scenario))

    if len(group) != 0:
        output_group_stats(group)
        group = []

    out_stream.write("\n")
    out_stream.write("min , " + str(min(pfail)) + "\n")
    out_stream.write("max , " + str(max(pfail)) + "\n")
    out_stream.write("avg , " + str(sum(pfail) / len(pfail)) + "\n")
Beispiel #3
0
def main_failure(num, no_input, in_stream, out_stream):

    fail_batch = generate_n_unique(failure_scenario_generator(open("rts.net")), num)

    # for information print the unmodified base case
    # and the un-combined failures
    if not no_input:
        out_stream.write("0, base, None, , 1.0" + windstr(1) + "\n")
    output_scenario(fail_batch, out_stream)

    # if we didn't have a input file then we are done
    if no_input:
        return

    # otherwise read the input as a list of scenarios and their count
    # for each base combine it with all the failures
    # we ignore the count for the base (not sure what to do with it)
    # skip the failed base cases (if they are simulated at all)
    for base_count, base_scenario in stream_scenario_generator(in_stream):
        if base_scenario.result is not False:
            out_stream.write(str(base_count) + ", " + str(base_scenario) + "\n")

            for count, fail_scenario in fail_batch:
                new_scenario = combine_scenarios(base_scenario, fail_scenario)
                out_stream.write(str(count) + ", " + str(new_scenario) + "\n")
Beispiel #4
0
def main_failure(num, no_input, in_stream, out_stream):

    fail_batch = generate_n_unique(failure_scenario_generator(open("rts.net")), num)

    # for information print the unmodified base case
    # and the un-combined failures
    if not no_input:
        out_stream.write("0, base, None, , 1.0" + windstr(1) + "\n")
    output_scenario(fail_batch, out_stream)

    # if we didn't have a input file then we are done
    if no_input:
        return

    # otherwise read the input as a list of scenarios and their count
    # for each base combine it with all the failures
    # we ignore the count for the base (not sure what to do with it)
    # skip the failed base cases (if they are simulated at all)
    for base_count, base_scenario in stream_scenario_generator(in_stream):
        if base_scenario.result is not False:
            out_stream.write(str(base_count) + ", " + str(base_scenario) + "\n")

            for count, fail_scenario in fail_batch:
                new_scenario = combine_scenarios(base_scenario, fail_scenario)
                out_stream.write(str(count) + ", " + str(new_scenario) + "\n")
Beispiel #5
0
def main_simulate(in_stream, out_stream):
    limits = Limits(open("rts.lim"))
    loadflow = Loadflow(open("rts.lf"), limits)

    for count, scenario in stream_scenario_generator(in_stream):
        result, result_reason = loadflow.simulate(scenario)
        scenario.result = result
        scenario.result_reason = result_reason
        out_stream.write(str(count) + ", " + str(scenario) + "\n")
Beispiel #6
0
def main_simulate(in_stream, out_stream):
    limits = Limits(open("rts.lim"))
    loadflow = Loadflow(open("rts.lf"), limits)

    for count, scenario in stream_scenario_generator(in_stream):
        result, result_reason = loadflow.simulate(scenario)
        scenario.result = result
        scenario.result_reason = result_reason
        out_stream.write(str(count) + ", " + str(scenario) + "\n")
Beispiel #7
0
def main_test(out_stream):
    """print the results and the intermediate file for
       a number of interesting scenarios. So we can check
       by hand if the intermediate file generator and the
       simulator are doing the correct thing.
    """

    batch_string = ""
    batch_string += "1, base, None, , 1.0" + windstr(1) + "\n"  # base - as normal
    batch_string += "1, half, None, , 0.5" + windstr(1) + "\n"  # half load power
    batch_string += "1, tenth, None, , 0.1" + windstr(1) + "\n"  # tenth load power
    batch_string += "1, island, None, , 1.0" + windstr(1) + ", B11\n"  # island
    batch_string += "1, slack, None, , 1.0" + windstr(1) + ", G12\n"  # removed 1 slack bus
    batch_string += "1, slack-all, None, , 1.0" + windstr(1) + ", G12, G13, G14\n"  # removed all slack busses
    batch_string += "1, line, None, , 1.0" + windstr(1) + ", A2\n"  # remove 1 line
    batch_string += "1, gen, None, , 1.0" + windstr(1) + ", G24\n"  # remove 1 generator
    batch_string += "1, bus, None, , 1.0" + windstr(1) + ", 104\n"  # remove 1 bus without generators
    batch_string += "1, bus-gen, None, , 1.0" + windstr(1) + ", 101\n"  # remove 1 bus with generators attached
    batch_string += "1, bus-slack, None, , 1.0" + windstr(1) + ", 113\n"  # remove slack bus and all slack generators
    batch_string += "1, bus-island, None, , 1.0" + windstr(1) + ", 208\n"  # remove bus that causes island
    batch_string += "1, high-load, None, , 1.10" + windstr(1) + "\n"  # load power high
    batch_string += "1, over-max, None, , 1.15" + windstr(1) + "\n"  # load power above max gen power

    if windlevel.num_wind > 0:
        batch_string += "1, wind-50, None, , 1.0" + windstr(0.5) + "\n"  # base - wind @ 50%
        batch_string += "1, wind-10, None, , 1.0" + windstr(0.1) + "\n"  # base - wind @ 10%
        batch_string += "1, wind-200, None, , 1.0" + windstr(2.0) + "\n"  # base - wind @ 200%

    in_stream = StringIO(batch_string)

    limits = Limits(open("rts.lim"))
    loadflow = Loadflow(open("rts.lf"), limits)

    for count, scenario in stream_scenario_generator(in_stream):
        intermediate_file = open(scenario.scenario_type + ".csv", "w")

        try:
            loadflow.lfgenerator(intermediate_file, scenario)
            result, result_reason = loadflow.simulate(scenario)
        except Exception, e:
            # remove `,` from message
            result, result_reason = (False, "".join(c for c in str(e) if c not in ","))

        intermediate_file.close()
        scenario.result = result
        scenario.result_reason = result_reason
        out_stream.write(str(count) + ", " + str(scenario) + "\n")
Beispiel #8
0
def main_test(out_stream):
    """print the results and the intermediate file for
       a number of interesting scenarios. So we can check
       by hand if the intermediate file generator and the
       simulator are doing the correct thing.
    """

    batch_string = ""
    batch_string += "1, base, None, , 1.0" + windstr(1) + "\n"             # base - as normal
    batch_string += "1, half, None, , 0.5" + windstr(1) + "\n"             # half load power
    batch_string += "1, tenth, None, , 0.1" + windstr(1) + "\n"            # tenth load power
    batch_string += "1, island, None, , 1.0" + windstr(1) + ", B11\n"      # island
    batch_string += "1, slack, None, , 1.0" + windstr(1) + ", G12\n"       # removed 1 slack bus
    batch_string += "1, slack-all, None, , 1.0" + windstr(1) + ", G12, G13, G14\n"  # removed all slack busses
    batch_string += "1, line, None, , 1.0" + windstr(1) + ", A2\n"         # remove 1 line
    batch_string += "1, gen, None, , 1.0" + windstr(1) + ", G24\n"         # remove 1 generator
    batch_string += "1, bus, None, , 1.0" + windstr(1) + ", 104\n"         # remove 1 bus without generators
    batch_string += "1, bus-gen, None, , 1.0" + windstr(1) + ", 101\n"     # remove 1 bus with generators attached
    batch_string += "1, bus-slack, None, , 1.0" + windstr(1) + ", 113\n"   # remove slack bus and all slack generators
    batch_string += "1, bus-island, None, , 1.0" + windstr(1) + ", 208\n"  # remove bus that causes island
    batch_string += "1, high-load, None, , 1.10" + windstr(1) + "\n"       # load power high
    batch_string += "1, over-max, None, , 1.15" + windstr(1) + "\n"        # load power above max gen power

    if windlevel.num_wind > 0:
        batch_string += "1, wind-50, None, , 1.0" + windstr(0.5) + "\n"             # base - wind @ 50%
        batch_string += "1, wind-10, None, , 1.0" + windstr(0.1) + "\n"             # base - wind @ 10%
        batch_string += "1, wind-200, None, , 1.0" + windstr(2.0) + "\n"             # base - wind @ 200%

    in_stream = StringIO(batch_string)

    limits = Limits(open("rts.lim"))
    loadflow = Loadflow(open("rts.lf"), limits)

    for count, scenario in stream_scenario_generator(in_stream):
        intermediate_file = open(scenario.scenario_type + ".csv", "w")

        try:
            loadflow.lfgenerator(intermediate_file, scenario)
            result, result_reason = loadflow.simulate(scenario)
        except Exception, e:
            # remove `,` from message
            result, result_reason = (False, ''.join(c for c in str(e) if c not in ','))

        intermediate_file.close()
        scenario.result = result
        scenario.result_reason = result_reason
        out_stream.write(str(count) + ", " + str(scenario) + "\n")