Beispiel #1
0
def run_savnw_simulation(datapath, outfile1, outfile2, outfile3, prgfile):

    import psspy
    psspy.psseinit()

    savfile = 'Converted_NETS-NYPS 68 Bus System_C.sav'
    snpfile = 'NETS-NYPS 68 Bus System.snp'

    if datapath:
        savfile = os.path.join(datapath, savfile)
        snpfile = os.path.join(datapath,
                               snpfile)  #why produce these two kinds of files?

    psspy.lines_per_page_one_device(1, 90)
    psspy.progress_output(2, prgfile, [0, 0])

    ierr = psspy.case(savfile)
    if ierr:
        psspy.progress_output(1, "", [0, 0])
        print(" psspy.case Error")
        return
    ierr = psspy.rstr(snpfile)
    if ierr:
        psspy.progress_output(1, "", [0, 0])
        print(" psspy.rstr Error")
        return

# fault + line trip
    psspy.strt(0, outfile1)
    psspy.run(0, 1.0, 1000, 1, 0)
    psspy.dist_bus_fault(52, 1, 138.0, [0.0, -0.2E+10])
    psspy.run(0, 1.1, 1000, 1, 0)
    psspy.dist_clear_fault(1)
    psspy.dist_branch_trip(52, 55, '1')
    psspy.run(0, 1.2, 1000, 1, 0)
    psspy.dist_machine_trip(1, '1')
    psspy.run(0, 5.0, 1000, 1, 0)

    # line trip (with faults) + generator trip
    psspy.case(savfile)
    psspy.rstr(snpfile)
    psspy.strt(0, outfile2)
    psspy.run(0, 1.0, 1000, 1, 0)
    psspy.dist_bus_fault(52, 1, 138.0, [0.0, -0.2E+10])
    psspy.run(0, 1.1, 1000, 1, 0)
    psspy.dist_clear_fault(1)
    psspy.run(0, 1.2, 1000, 1, 0)
    psspy.dist_machine_trip(8, '1')
    psspy.run(0, 5.0, 1000, 1, 0)

    psspy.case(savfile)
    psspy.rstr(snpfile)
    psspy.strt(0, outfile3)
    psspy.run(0, 1.0, 1000, 1, 0)
    psspy.dist_branch_trip(32, 33, '1')
    psspy.run(0, 5.0, 1000, 1, 0)

    psspy.lines_per_page_one_device(2, 10000000)
    psspy.progress_output(1, "", [0, 0])
def run_savnw_simulation(datapath, outfile1, outfile2, outfile3, prgfile):

    import psspy
    psspy.psseinit()

    savfile = 'savcnv.sav'
    snpfile = 'savnw.snp'

    if datapath:
        savfile = os.path.join(datapath, savfile)
        snpfile = os.path.join(datapath, snpfile)

    psspy.lines_per_page_one_device(1, 90)
    psspy.progress_output(2, prgfile, [0, 0])

    ierr = psspy.case(savfile)
    if ierr:
        psspy.progress_output(1, "", [0, 0])
        print(" psspy.case Error")
        return
    ierr = psspy.rstr(snpfile)
    if ierr:
        psspy.progress_output(1, "", [0, 0])
        print(" psspy.rstr Error")
        return

    psspy.strt(0, outfile1)
    psspy.run(0, 1.0, 1000, 1, 0)
    psspy.dist_bus_fault(154, 1, 230.0, [0.0, -0.2E+10])
    psspy.run(0, 1.05, 1000, 1, 0)
    psspy.dist_clear_fault(1)
    psspy.run(0, 5.0, 1000, 1, 0)

    psspy.case(savfile)
    psspy.rstr(snpfile)
    psspy.strt(0, outfile2)
    psspy.run(0, 1.0, 1000, 1, 0)
    psspy.dist_machine_trip(3018, '1')
    psspy.run(0, 5.0, 1000, 1, 0)

    psspy.case(savfile)
    psspy.rstr(snpfile)
    psspy.strt(0, outfile3)
    psspy.run(0, 1.0, 1000, 1, 0)
    psspy.dist_branch_trip(3005, 3007, '1')
    psspy.run(0, 5.0, 1000, 1, 0)

    psspy.lines_per_page_one_device(2, 10000000)
    psspy.progress_output(1, "", [0, 0])
def run_savnw_simulation(datapath, outfile, prgfile):

    import psspy
    psspy.psseinit()

    savfile = 'Converted_NETS-NYPS 68 Bus System_C.sav'
    snpfile = 'NETS-NYPS 68 Bus System.snp'

    if datapath:
        savfile = os.path.join(datapath, savfile)
        snpfile = os.path.join(datapath, snpfile)

    psspy.lines_per_page_one_device(1, 90)
    psspy.progress_output(2, prgfile, [0, 0])  # directly output to file
    #psspy.chsb(0,1,[-1,-1,-1,1,13,0])

    ierr = psspy.case(savfile)
    if ierr:
        psspy.progress_output(1, "", [0, 0])
        print(" psspy.case Error")
        return
    ierr = psspy.rstr(snpfile)
    if ierr:
        psspy.progress_output(1, "", [0, 0])
        print(" psspy.rstr Error")
        return

    # run generator trip automatically
    for i in range(16):
        psspy.case(savfile)
        psspy.rstr(snpfile)
        psspy.strt(0, outfile[i])
        #psspy.chsb(0,1,[-1,-1,-1,1,13,0])
        psspy.run(0, 1.0, 1000, 1, 0)
        psspy.dist_machine_trip(i + 1, '1')
        psspy.run(0, 5.0, 1000, 1, 0)

    psspy.lines_per_page_one_device(
        2, 10000000
    )  #Integer DEVICE Indicates which of the four output devices is to be processed (input;
    #1 for disk files.
    #2 for the report window.
    #3 for the first primary hard copy output device.
    #4 for the second primary hard copy output device.
    psspy.progress_output(1, "", [0, 0])
    return outfile, prgfile
def run_savnw_simulation(datapath, outfile, prgfile):

    import psspy
    psspy.psseinit()

    savfile = 'Converted_NETS-NYPS 68 Bus System_C.sav'
    snpfile = 'NETS-NYPS 68 Bus System.snp'

    if datapath:
        savfile = os.path.join(datapath, savfile)
        snpfile = os.path.join(datapath, snpfile)

    psspy.lines_per_page_one_device(1,90)
    psspy.progress_output(2,prgfile,[0,0]) # directly output to file 
    

    ierr = psspy.case(savfile)
    if ierr:
        psspy.progress_output(1,"",[0,0])
        print(" psspy.case Error")
        return
    ierr = psspy.rstr(snpfile)
    if ierr:
        psspy.progress_output(1,"",[0,0])
        print(" psspy.rstr Error")
        return

    # branches
    ibus,jbus,id=read_rawdata.branch_bus()
    for i,gener in enumerate(all_gener):
        psspy.case(savfile)
        psspy.rstr(snpfile)
        psspy.strt(0,outfile[i]) 
        psspy.run(0, 1.0,1000,1,0)
        dist_branch_fault(ibus[i], jbus[i], id[i])
        psspy.run(0, 1.2,1000,1,0)
        psspy.dist_clear_fault(1)
        psspy.run(0, 5.0,1000,1,0)

    psspy.lines_per_page_one_device(2,10000000)#Integer DEVICE Indicates which of the four output devices is to be processed (input;
    #1 for disk files.
    #2 for the report window.
    #3 for the first primary hard copy output device.
    #4 for the second primary hard copy output device.
    psspy.progress_output(1,"",[0,0])
    return outfile,prgfile
Beispiel #5
0
#add the the above line 


#Here is the macro script
import psspy
import redirect
_i=psspy.getdefaultint()
_f=psspy.getdefaultreal()
_s=psspy.getdefaultchar()
redirect.psse2py()
import pssdb
psspy.psseinit(80000)
psspy.case(r"""psse.sav""")
psspy.resq(r""" psse.seq""")
psspy.lines_per_page_one_device(1,60)
psspy.report_output(2,r"""report.txt""",[0,0])
psspy.flat([1,1,1,0],[0.0,0.0])
psspy.seqd([0,0])
psspy.sequence_network_setup(0)
psspy.scmu(1,[0,0,0,0,0,0,0],[0.0,0.0,0.0,0.0,0.0],"")
psspy.scmu(2,[7,1082,0,0,0,0,0],[0.0,0.0,0.0,0.0,0.0],"")
psspy.scmu(3,[7,1082,0,0,0,0,0],[0.0,0.0,0.0,0.0,0.0],"")
psspy.sequence_network_setup(0)
#end of script

# add below line to show the report
f=open("report.txt",'r')
for line in f.readlines():
	print line
Beispiel #6
0
execution_sequence = [0, 0, 0, 0]

for i in range(len(execution_sequence)):

    if skip_ref_accc and i == 0:
        execution_sequence[i] = 0
    else:
        execution_sequence[i] = 1

    run_accc_ref_case = execution_sequence[0]
    generate_sav_files = execution_sequence[1]
    run_accc = execution_sequence[2]
    results_comparison = execution_sequence[3]

    if record_output == 1:
        psspy.lines_per_page_one_device(1, 1000000)
        psspy.progress_output(2, r"""output_record.txt""", [0, 0])

    print(results_comparison + run_accc + generate_sav_files +
          run_accc_ref_case)

    if (results_comparison + run_accc + generate_sav_files +
            run_accc_ref_case) <= 1:
        if generate_sav_files and skip_project_case_generation == 0:
            for i in range(len(injection_levels)):

                PSSE_functions.load_case(path_to_case,
                                         case_name_without_project)
                PSSE_functions.run_power_flow()

                if disconnect_gen_list:
def run_savnw_simulation(datapath, outfile1, outfile2, outfile3, prgfile):

    import psspy
    psspy.psseinit()

    savfile = 'savcnv.sav'
    snpfile = 'savnw.snp'

    if datapath:
        savfile = os.path.join(datapath, savfile)
        snpfile = os.path.join(datapath, snpfile)

    psspy.lines_per_page_one_device(1,90)
    psspy.progress_output(2,prgfile,[0,0]) # directly output to file
    

    ierr = psspy.case(savfile)
    if ierr:
        psspy.progress_output(1,"",[0,0])
        print(" psspy.case Error")
        return
    ierr = psspy.rstr(snpfile)
    if ierr:
        psspy.progress_output(1,"",[0,0])
        print(" psspy.rstr Error")
        return
    
# fault + line trip
    psspy.strt(0,outfile1)
    psspy.chsb(0,1, [-1,-1,-1,1,13,0])
    psspy.run(0, 1.0,1000,1,0)# start from 1 second, 1000 steps, and 1 writing for 1 output step
    psspy.dist_bus_fault(154,1, 230.0,[0.0,-0.2E+10]) # ibus, units, voltage kv
    psspy.run(0, 1.1,1000,1,0)# start from 1.1 second, 1000 steps, and 1 writing for 1 output step
    psspy.dist_clear_fault(1) 
    psspy.dist_branch_trip(3005,3007,'1')
    psspy.run(0,1.2,1000,1,0)
    psspy.dist_machine_trip(3018,'1')
    psspy.run(0, 5.0,1000,1,0)

# line trip (with faults) + generator trip   
    psspy.case(savfile)
    psspy.rstr(snpfile)
    psspy.strt(0,outfile2)
    psspy.chsb(0,1, [-1,-1,-1,1,13,0])
    psspy.run(0, 1.0,1000,1,0)
    psspy.dist_bus_fault(3005,1,230.0,[0.0,-0.2E+10])
    psspy.run(0,1.1,1000,1,0)
    psspy.dist_clear_fault(1)
    psspy.run(0,1.2,1000,1,0)
    psspy.dist_machine_trip(3018,'1')
    psspy.run(0, 5.0,1000,1,0)

    psspy.case(savfile)
    psspy.rstr(snpfile)
    psspy.strt(0,outfile3)
    psspy.chsb(0,1, [-1,-1,-1,1,13,0])
    psspy.run(0, 1.0,1000,1,0)
    psspy.dist_branch_trip(3005,3007,'1')
    psspy.run(0, 5.0,1000,1,0)

    psspy.lines_per_page_one_device(2,10000000)
    psspy.progress_output(1,"",[0,0])
Beispiel #8
0
def run_savnw_simulation(datapath, outfile1, outfile2, outfile3, prgfile):
    _F1_start=100
    _F1_end=100+70*1/60.0;

    _F2_start = 300
    _F2_end = 400;

    _runto=300;
    import psspy
    psspy.psseinit()

    savfile = 'IEEE 9 Bus_modifiedj4ab.sav'
    snpfile = 'IEEE 9 Bus_modifiedj4ab.snp'
    _i = psspy.getdefaultint()
    _f = psspy.getdefaultreal()
    _s = psspy.getdefaultchar()
    INTGAR = [_i] * 7
    REALAR = [_f] * 8

    if datapath:
        savfile = os.path.join(datapath, savfile)
        snpfile = os.path.join(datapath, snpfile)

    psspy.lines_per_page_one_device(1,90)
    psspy.progress_output(2,prgfile,[0,0])  #Use this API to specify the progress output device.

    ierr = psspy.case(savfile)   #Use this API to open a PSSE Saved Case file and transfers its data into the PSSE working case
    if ierr:
        psspy.progress_output(1,"",[0,0])
        print(" psspy.case Error")
        return
    ierr = psspy.rstr(snpfile)#Use this API to read a dynamics Snapshot File into PSSE working memory (activity RSTR).
    if ierr:
        psspy.progress_output(1,"",[0,0])
        print(" psspy.rstr Error")
        return

    psspy.strt(0,outfile1)  #strt(option, outfile)   #Use this API to initialize a PSSE dynamic simulation for state-space simulations (i.e., in preparation for activity RUN) and to specify the Channel Output File into which the output channel values are to be recorded during the dynamic simulation (activity STRT).
    psspy.run(0, _F1_start,5000,1,0) #Use this API to calculate PSSE state-space dynamic simulations (activity RUN).
    #psspy.dist_bus_fault(8,1, 230.0,[0.0,-0.2E+10]) #Use this API routine to apply a fault at a bus during dynamic simulations. (Note: use DIST_BUS_FAULT_2 if phase voltages are to be calculated during the simulation.)


    businfo = subsystem_info('bus', ['NUMBER', 'NAME', 'PU'], sid=-1)
    print businfo
    psspy.dist_branch_fault(8,9, '1',3,0.0,[0.0,0.000001])
    ##psspy.dist_branch_trip(8, 7, '1')
    ##psspy.load_chng_5(11, r"""1""", [0, _i, _i, _i, _i, _i, _i], [_f, _f, _f, _f, _f, _f, _f, _f])
    businfo = subsystem_info('bus', ['NUMBER', 'NAME', 'PU'], sid=-1)
    print businfo

    psspy.run(0, _F1_end+1.5*1/60,5000,1,0)
    businfo = subsystem_info('bus', ['NUMBER', 'NAME', 'PU'], sid=-1)
    print businfo



    #psspy.dist_branch_close(8,7,'1')
   ## psspy.load_chng_5(11, r"""1""", [1, _i, _i, _i, _i, _i, _i], [_f, _f, _f, _f, _f, _f, _f, _f])
    psspy.dist_clear_fault(1)
    psspy.run(0, _F1_end+2.0, 5000, 1, 0)
    businfo = subsystem_info('bus', ['NUMBER', 'NAME', 'PU'], sid=-1)
    print businfo

    #psspy.dist_clear_fault(1)  #Use this API to clear a fault during dynamic simulations. The fault must have previously been applied using one of the following APIs:
    psspy.run(0, _runto,5000,1,0)
#trigger machine
#    psspy.case(savfile)    #Use this API to open a PSSE Saved Case file and transfers its data into the PSSE working case
#    psspy.rstr(snpfile)     #Use this API to read a dynamics Snapshot File into PSSE working memory (activity RSTR).
#    psspy.strt(0,outfile2)
#    psspy.run(0, 1.0,1000,1,0)
#    psspy.dist_machine_trip(2,'1')
#    psspy.run(0, 10.0,1000,1,0)
#trigger line
#    psspy.case(savfile)
#    psspy.rstr(snpfile)
#    psspy.strt(0,outfile3)
#    psspy.run(0, 1.0,1000,1,0)
#    psspy.dist_branch_trip(7,8,'1')
#    psspy.run(0, 10.0,1000,1,0)

    psspy.lines_per_page_one_device(2,10000000)
    psspy.progress_output(1,"",[0,0])
def main():
    startTime = time.time()
    totalRealPowerLeftUniform = []
    totalImagPowerLeftUniform = []
    totalRealPowerLeftRollout = []
    totalImagPowerLeftRollout = []
    totalRealPowerLeftRollout1 = []
    totalImagPowerLeftRollout1 = []
    totalRealPowerLeftSelective = []
    totalImagPowerLeftSelective = []
    rewardUniform = [] 
    rewardRollout0 = [] 
    rewardRollout1 = [] 
    rewardSelective = [] 	
    worstUniform = []
    worstRollout = []
    worstRollout1 = []
    worstSelective = []	
    fileName = 'realPowerComparison.csv'
    fileName2 = 'imagPowerComparison.csv'
    
    for i in range(0,50):
        
        psspy.lines_per_page_one_device(1,10000)   
        psspy.progress_output(2,r"""output""",[0,0])
        case_file = 'caseNumber_' + str(i) + '.sav'
        my_r = generate_reward_list(19, case_file)
        print my_r
        
        load_un, rarray_un, max_loads, bus_ids = begin_uniform_loadshed(case_file)
        percentOfLoadsSurviving(max_loads, load_un, totalImagPowerLeftUniform, totalRealPowerLeftUniform, rarray_un[0], worstUniform)
        load_single, rarray_single, max_loads, bus_ids = begin_policy_rollout(case_file, 0, my_r)
        percentOfLoadsSurviving(max_loads, load_single, totalImagPowerLeftRollout, totalRealPowerLeftRollout, rarray_single[0], worstRollout)
        #load_single1, rarray_single1, max_loads1, bus_ids1 = begin_policy_rollout(case_file, 1, my_r)
       # percentOfLoadsSurviving(max_loads1, load_single1, totalImagPowerLeftRollout1, totalRealPowerLeftRollout1, rarray_single1[0], worstRollout1)
        load_sel, rarray_sel, max_loads, bus_ids = begin_selective_loadshed(case_file)
        percentOfLoadsSurviving(max_loads, load_sel, totalImagPowerLeftSelective, totalRealPowerLeftSelective, rarray_sel[0], worstSelective)
        print("TIME")	       
        print(time.time() - startTime)
        print my_r
        rewardUniform.append(reward(rarray_un, load_un, max_loads, bus_ids, my_r))
        rewardRollout0.append(reward(rarray_single, load_single, max_loads, bus_ids, my_r))
        rewardSelective.append(reward(rarray_sel, load_sel, max_loads, bus_ids, my_r))
        #rewardRollout1.append(reward(rarray_single1, load_single1, max_loads, bus_ids, my_r))
        print(load_single)
        print(max_loads)
        print(reward(rarray_single, load_single, max_loads, bus_ids, my_r))
        
        #print(rarray_un), sum(map(float, load_un))/sum(map(float, max_loads))
        #load_single, rarray_single, max_loads, bus_ids = begin_policy_rollout(case_file, 1)
        '''
        load_roll, rarray_roll, max_loads, bus_ids = begin_policy_rollout(case_file, 0)
        load_sel, rarray_sel, max_loads, bus_ids = begin_selective_loadshed(case_file)
        print(reward(rarray_un, load_un, max_loads, bus_ids, [1.0 for x in range(len(load_un[0]))]))
        print(reward(rarray_roll, load_roll, max_loads, bus_ids, [1.0 for x in range(len(load_un[0]))]))
        print(reward(rarray_sel, load_sel, max_loads, bus_ids, [1.0 for x in range(len(load_un[0]))]))
        print(load_sel)
        
	#steadyStateChangeInitSolution() #Basic case to solve the case with no dynamcis
    print totalImagPowerLeftUniform
    print totalRealPowerLeftUniform
    print worstUniform, worstRollout
    #print min(worstUniform), min(worstRollout), min(worstRollout1), min(worstSelective)
    '''
    with open(fileName, "a") as fp:
        wr = csv.writer(fp, dialect='excel')
        wr.writerow('Uniform')
        wr.writerow(totalRealPowerLeftUniform)
        wr.writerow('Rollout0')
        wr.writerow(totalRealPowerLeftRollout)
        #wr.writerow('Rollout1')
        #wr.writerow(totalRealPowerLeftRollout1)
        wr.writerow('Selective')
        wr.writerow(totalRealPowerLeftSelective)	
        wr.writerow('Rewards:')
        wr.writerow(rewardUniform)
        wr.writerow(rewardRollout0)
        #wr.writerow(rewardRollout1)
        wr.writerow(rewardSelective)
    with open(fileName2, "a") as fp:
        wr = csv.writer(fp, dialect='excel')
        wr.writerow('Uniform')
        wr.writerow(totalImagPowerLeftUniform)
        wr.writerow('Rollout0')
        wr.writerow(totalImagPowerLeftRollout)
        #wr.writerow('Rollout1')
        #wr.writerow(totalImagPowerLeftRollout1)
        wr.writerow('Selective')
        wr.writerow(totalImagPowerLeftSelective)