Beispiel #1
0
def test008():
    clean = False
    
    def copy_psat(in_filename, out_filename):
        psat = read_psat(in_filename + ".m")
        with open(out_filename + ".m", "w") as psat_stream:
            psat.write(psat_stream)
            
    def sim(psat, scenario_text):
        scenario = text_to_scenario(scenario_text)
        return simulate_scenario(psat, scenario, clean)
        
    data = """
           [base] opf
               set all demand 0.6
           """

    copy_psat("rts", "psat_base")
    psat = read_psat("psat_base.m")
    report = sim(psat, data)
    print "base result = '" + str(report_in_limits(report)) + "'"
    opf_psat = report_to_psat(report, psat)
    opf_report = single_simulate(opf_psat, "pf", "one", clean)
    print "opf result = '" + str(report_in_limits(opf_report)) + "'"
    
    opf_psat_2 = report_to_psat(opf_report, opf_psat)
    opf_report_2 = single_simulate(opf_psat_2, "pf", "two", clean)
    print "opf result 2 = '" + str(report_in_limits(opf_report_2)) + "'"
Beispiel #2
0
def test_case(both=False, clean=False):
    """one specified scenario, simulated"""

    clean_files()
    
    data = """
           [test_case] opf
           """
         
            # remove generator g4
            # remove generator g23
            # set all demand 0.7

    data_2 = """
             [test_case_2] pf
             """
           
    scenario = text_to_scenario(data)
    psat = read_psat("rtskillmod.m")
    report = simulate_scenario(psat, scenario, clean)
    print "result = '" + str(report_in_limits(report)) + "'"

    if both:
        # clean_files()
        
        scenario_2 = text_to_scenario(data_2)
        psat_2 = report_to_psat(report, psat)
        report_2 = simulate_scenario(psat_2, scenario_2, clean)
        print "result 2 = '" + str(report_in_limits(report_2)) + "'"
Beispiel #3
0
def test_case(both=False, clean=False):
    """one specified scenario, simulated"""

    clean_files()

    data = """
           [test_case] opf
           """

    # remove generator g4
    # remove generator g23
    # set all demand 0.7

    data_2 = """
             [test_case_2] pf
             """

    scenario = text_to_scenario(data)
    psat = read_psat("rtskillmod.m")
    report = simulate_scenario(psat, scenario, clean)
    print "result = '" + str(report_in_limits(report)) + "'"

    if both:
        # clean_files()

        scenario_2 = text_to_scenario(data_2)
        psat_2 = report_to_psat(report, psat)
        report_2 = simulate_scenario(psat_2, scenario_2, clean)
        print "result 2 = '" + str(report_in_limits(report_2)) + "'"
Beispiel #4
0
def upec(n_failures=100):
    """if we happen to have a stage one that kills the shunt bus then most bugs 
    go away. use this to get some data."""

    clean_files()
    clean = True

    data = """
           [upec] opf
             # remove generator g33
             # set all demand 0.7686144
             # remove bus 6
           """

    scenario = text_to_scenario(data)
    psat = read_psat("rts2.m")

    tmp_psat = scenario_to_psat(scenario, psat)
    report = single_simulate(tmp_psat, scenario.simtype, scenario.title)
    new_psat = report_to_psat(report, tmp_psat)

    prob = read_probabilities("rts.net")
    failure_batch = make_failures(prob, n_failures)

    failure_batch.scenarios.insert(0, Scenario("basecase"))
    batch_simulate(failure_batch, new_psat, 100, clean)

    filename = scenario.title + ".bch2"
    with open(filename, "w") as result_file:
        failure_batch.csv_write(result_file)
Beispiel #5
0
def test003():
    """
    load flow a file then do it again; psat_report and psat_data should match
    """

    clean_files()

    simtype = "opf"

    def helper(title):
        matlab_filename = "matlab_" + title
        psat_filename = title + ".m"
        single_matlab_script(matlab_filename + ".m", psat_filename, simtype)
        res = simulate(matlab_filename)
        if res != [True]: raise Error("expected [True] got %s" % str(res))

    helper("rts")

    report = read_report("rts_01.txt")
    psat = read_psat("rts.m")

    new_psat = report_to_psat(report, psat)

    with open("test_d.m", "w") as new_psat_stream:
        new_psat.write(new_psat_stream)

    helper("test_d")
Beispiel #6
0
    def cycle(in_filename, out_psat_filename):
        report = read_report(in_filename + "_01.txt")
        psat = read_psat(in_filename + ".m")

        new_psat = report_to_psat(report, psat)
        new_psat.generators[39].v = "1.01401"
        new_psat.generators[40].v = "1.01401"
        new_psat.generators[41].v = "1.01401"
        new_psat.generators[42].v = "1.01401"
        new_psat.generators[43].v = "1.01401"

        with open(out_psat_filename + ".m", "w") as new_psat_stream:
            new_psat.write(new_psat_stream)
Beispiel #7
0
def simulate_cases(outage_batch, failure_batch, psat, summary_file,
                   mismatch_file):
    clean_files()

    print "[C] simulate %d unique states with %d unique contingencies" % (
        len(outage_batch), len(failure_batch))

    for n, scenario in enumerate(outage_batch):
        try:
            print "[C] simulating state", n + 1, "of", int(
                math.ceil(len(outage_batch)))
            report = simulate_scenario(psat, scenario, False)
            scenario_psat = report_to_psat(report, psat)
            clean_files()
            mismatch_file.write(
                as_csv("---- ---- ---- ---- ---- ----".split()) + "\n")
            mismatch_file.write(
                as_csv([scenario.title] + list(scenario_psat.get_stats())) +
                "\n")
            mismatch_file.write(
                as_csv("---- ---- ---- ---- ---- ----".split()) + "\n")
            print "[C] simulating state - prep done."

            for x in failure_batch:
                x.result = None

            batch_simulate(failure_batch, scenario_psat, 100, True,
                           mismatch_file)

            filename = scenario.title + ".txt"
            with open(filename, "w") as result_file:
                failure_batch.csv_write(result_file)

            print "-" * 80
            print "---- Outage Case %d Stats ----" % n
            failure_batch.write_stats(sys.stdout)
            summary_file.write("Outage Case %d Stats\n" % n)
            summary_file.write("%s\n" % ("-" * 80))
            failure_batch.write_stats(summary_file)

            print "[C] simulating state", n + 1, "done"
        except Exception as exce:
            print "[E] Error Caught at main.simulate_cases (%s)" % scenario.title
            print exce
            raise
Beispiel #8
0
def simulate_cases(outage_batch, failure_batch, psat, summary_file, mismatch_file):
    clean_files()

    print "[C] simulate %d unique states with %d unique contingencies" % (
                                                        len(outage_batch),
                                                        len(failure_batch))
    
    for n, scenario in enumerate(outage_batch):
        try:
            print "[C] simulating state", n + 1, "of", int(math.ceil(len(outage_batch)))
            report = simulate_scenario(psat, scenario, False)
            scenario_psat = report_to_psat(report, psat)
            clean_files()
            mismatch_file.write(as_csv("---- ---- ---- ---- ---- ----".split()) + "\n")
            mismatch_file.write(as_csv([scenario.title] + list(scenario_psat.get_stats())) + "\n")
            mismatch_file.write(as_csv("---- ---- ---- ---- ---- ----".split()) + "\n")
            print "[C] simulating state - prep done."

            for x in failure_batch:
                x.result = None

            batch_simulate(failure_batch, scenario_psat, 100, True, mismatch_file)
            
            filename = scenario.title + ".txt"
            with open(filename, "w") as result_file:
                failure_batch.csv_write(result_file)
            
            print "-" * 80
            print "---- Outage Case %d Stats ----" % n
            failure_batch.write_stats(sys.stdout)
            summary_file.write("Outage Case %d Stats\n" % n)
            summary_file.write("%s\n" % ("-"*80))
            failure_batch.write_stats(summary_file)
            
            print "[C] simulating state", n + 1, "done"
        except Exception as exce:
            print "[E] Error Caught at main.simulate_cases (%s)" % scenario.title
            print exce
            raise