psspy.prompt_output(2,psse_log,[0,0]) #ignored """ ##### Load Raw Datafile and do power flow print "\n Reading raw file:", settings['filename'] # " Reading raw file: {0:s}".format('text') ierr = psspy.read(0, settings['filename']) #This is for the power flow. I'll use the solved case instead ierr = psspy.fnsl(settings['pf_options']) ##### Prepare case for dynamic simulation # Load conversion (multiple-step) psspy.conl(_i, _i, 1, [0, _i], [_f, _f, _f, _f]) # all constant power load to constant current, constant reactive power load to constant admittance # standard practice for dynamic simulations, constant MVA load is not acceptable psspy.conl(1, 1, 2, [_i, _i], [100.0, 0.0, 0.0, 100.0]) psspy.conl(_i, _i, 3, [_i, _i], [_f, _f, _f, _f]) ierr = psspy.cong(0) #converting generators ierr = psspy.ordr(0) #order the network nodes to maintain sparsity ierr = psspy.fact() #factorise the network admittance matrix ierr = psspy.tysl(0) #solving the converted case ierr = psspy.dynamicsmode(0) #enter dynamics mode print "\n Reading dyr file:", settings['dyr_file'] ierr = psspy.dyre_new([1, 1, 1, 1], settings['dyr_file'])
psspy.two_winding_data_3(bus_flt, bus_IDTRF, r"""1""", [1, bus_flt, 1, 0, 0, 0, 33, 0, bus_flt, 0, 1, 0, 1, 1, 1], [0.0, 0.0001, 100.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.1, 0.9, 1.1, 0.9, 0.0, 0.0, 0.0], r"""IDTRF""") OutputFilePath = FigurePath + '07. Grid Voltage Step Test' + "\\" + 'Test' + str( test+42) + '_' + FileName + '_sFac' + str(acceleration) + '_dT' + str( integration_step) + '_Grid Voltage Step Test.out' # ! Setup Dynamic Simulation parameters psspy.dynamics_solution_param_2([n_iteration, _i, _i, _i, _i, _i, _i, _i], [acceleration, tolerance, integration_step, _f, _f, _f, _f, _f]) psspy.fdns([0, 0, 1, 1, 0, 0, 99, 0]) # convert load , do not change psspy.cong(0) psspy.conl(0, 1, 1, [0, 0], [100.0, 0.0, 0.0, 100.0]) psspy.conl(0, 1, 2, [0, 0], [100.0, 0.0, 0.0, 100.0]) psspy.conl(0, 1, 3, [0, 0], [100.0, 0.0, 0.0, 100.0]) psspy.ordr(0) # ! Order the matrix: ORDR psspy.fact() # ! Factorize the matrix: FACT psspy.tysl(0) # ! TYSL psspy.bus_frequency_channel([1, 969], r"""System frequency""") psspy.voltage_channel([2, -1, -1, 969], r"""IB_Voltage""") psspy.voltage_channel([3, -1, -1, 100], r"""UUT_Voltage""") psspy.voltage_channel([4, -1, -1, 106], r"""POC_Voltage""") psspy.machine_array_channel([5, 2, 100], r"""1""", r"""UUT_Pelec""") psspy.machine_array_channel([6, 3, 100], r"""1""", r"""UUT_Qelec""") psspy.branch_p_and_q_channel([7, -1, -1, 105, 106], r"""1""", [r"""POC_Flow""", ""]) psspy.machine_array_channel([9, 9, 100], r"""1""", r"""UUT_IDcmd""") psspy.machine_array_channel([10, 12, 100], r"""1""", r"""UUT_IQcmd""")
[r"""P Injection""", r"""Q Injection"""]) ierr = psspy.machine_array_channel([7, 2, 101], r"""1""", r"""Pelec 100""") ierr = psspy.machine_array_channel([8, 3, 101], r"""1""", r"""Qelec 100""") [ierr, var_ppc_conp] = psspy.mdlind(101, '1', 'EXC', 'CON') [ierr, var_ppc_setp] = psspy.mdlind(101, '1', 'EXC', 'VAR') [ierr, var_ppc_mode] = psspy.mdlind(101, '1', 'EXC', 'ICON') [ierr, var_inv_con] = psspy.mdlind(101, '1', 'GEN', 'CON') [ierr, var_inv_var] = psspy.mdlind(101, '1', 'GEN', 'VAR') # convert load , do not change psspy.cong(0) psspy.bsys(0, 0, [0.0, 500.], 1, [7], 0, [], 0, [], 0, []) psspy.bsys(0, 0, [0.0, 500.], 1, [7], 0, [], 0, [], 0, []) psspy.conl(0, 0, 1, [0, 0], [91.27, 19.36, -126.88, 188.43]) psspy.conl(0, 0, 2, [0, 0], [91.27, 19.36, -126.88, 188.43]) psspy.bsys(1, 0, [0.0, 0.0], 0, [], 6, [37600, 37601, 37602, 37580, 37584, 38588], 0, [], 0, []) psspy.conl(1, 0, 2, [0, 0], [52.75, 58.13, 5.97, 95.52]) psspy.bsys(1, 0, [0.0, 0.0], 0, [], 1, [21790], 0, [], 0, []) psspy.conl(1, 0, 2, [0, 0], [86.63, 25.19, -378.97, 347.97]) psspy.bsys(1, 0, [0.0, 0.0], 0, [], 1, [45082], 0, [], 0, []) psspy.conl(1, 0, 2, [0, 0], [51.36, 59.32, -228.04, 254.01]) psspy.bsys( 1, 0, [0.0, 0.0], 0, [], 9, [40320, 40340, 40350, 40970, 40980, 40990, 41050, 41071, 41120], 0, [], 0, []) psspy.conl(1, 0, 2, [0, 0], [100.0, 0.0, 0.0, 100.0]) psspy.conl(0, 1, 2, [0, 0], [100.0, 0.0, -306.02, 303.0]) psspy.conl(0, 1, 3, [0, 0], [100.0, 0.0, -306.02, 303.0])
[ierr, var_ppc_conp] = psspy.mdlind(101, '1', 'EXC', 'CON') [ierr, var_ppc_setp] = psspy.mdlind(101, '1', 'EXC', 'VAR') [ierr, var_ppc_mode] = psspy.mdlind(101, '1', 'EXC', 'ICON') [ierr, var_inv_con] = psspy.mdlind(101, '1', 'GEN', 'CON') [ierr, var_inv_var] = psspy.mdlind(101, '1', 'GEN', 'VAR') [ierr, var_inv_stt] = psspy.mdlind(101, '1', 'GEN', 'STATE') psspy.bus_frequency_channel([1, 400], r"""System frequency""") #psspy.voltage_channel([2, -1, -1, 101], r"""Inverter Voltage Mag.""") psspy.machine_array_channel([2, 4, 101],r"""1""", r"""Inverter Voltage Mag.""") psspy.voltage_channel([3, -1, -1, 400], r"""WD SF POC Voltage Mag.""") psspy.branch_p_and_q_channel([4, -1, -1, 400, 46660], r"""1""", [r"""P Injection""", r"""Q Injection"""]) ierr = psspy.machine_array_channel([7, 2, 101], r"""1""", r"""Pelec 101""") ierr = psspy.machine_array_channel([8, 3, 101], r"""1""", r"""Qelec 101""") psspy.cong(0) psspy.conl(0, 1, 1, [0, 0], [0.0, 0.0, 0.1, 0.0]) psspy.conl(0, 1, 2, [0, 0], [0.0, 0.0, 0.1, 0.0]) psspy.conl(0, 1, 3, [0, 0], [0.0, 0.0, 0.1, 0.0]) psspy.ordr(1) psspy.fact() psspy.tysl(1) psspy.change_plmod_con(600, r"""1""", r"""GENCLS""", 1, 8) #psspy.change_plmod_icon(101,r"""1""",r"""GPMPPC""",4,0) # start simulation psspy.strt_2([0, 0], OutputFilePath) psspy.run(0, 1, 1000, 1, 0) psspy.run(0, 5, 1000, 1, 0) psspy.two_winding_chng_5(500,46660,r"""1""",[_i,_i,_i,_i,_i,_i,_i,_i,500,_i,_i,0,_i,_i,_i],[_f,_f,_f,_f,_f,_f, vref,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f],"","") psspy.run(0, 5.9, 1000, 1, 0) psspy.two_winding_chng_5(500,46660,r"""1""",[_i,_i,_i,_i,_i,_i,_i,_i,500,_i,_i,0,_i,_i,_i],[_f,_f,_f,_f,_f,_f, 1,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f],"","") psspy.run(0, 15, 1000, 1, 0)
if iVal == 0: print "Met convergence tolerance" elif iVal == 1: print "The iteration limit exceeded" elif iVal > 1: print "Blown up or others" # ------------------------------------------------- # # Dynamic Simulation # Convert gen & load # convert generators ierr = psspy.cong(0) # convert load for i in [1, 2, 3]: ierr = psspy.conl(0, 1, i, [0, 0], [100, 0, 0, 100])[0] # save converted case psspy.save(r'{0}\savnw_C.sav'.format(example_path)) # Load dynamics ierr = psspy.dyre_new([_i, _i, _i, _i], dyr_case, _s, _s, _s) # Set output channels psspy.chsb(sid=0, all=1, status=[-1, -1, -1, 1, 12, 0]) # # Save snapshot psspy.snap(sfile=r'{0}\PythonDynTest.snp'.format(example_path)) # Initialize and run the dynamic scenario
def convertPEVs(aev_representation=[0.0, 0.0, 0.0, 0.0]): psspy.bsys(1, 0, [345., 345.], 3, [1, 2, 3], 0, [], 1, [2], 0, []) psspy.conl(1, 0, 1, [0, 0], [0.0, 0.0, 0.0, 0.0]) psspy.conl(1, 0, 2, [0, 0], [0.0, 0.0, 0.0, 0.0]) psspy.conl(1, 0, 3, [0, 0], [0.0, 0.0, 0.0, 0.0])
def do_simulation(): global num_sample_id # set Samples Path sample_path = r'./Sample_9bus_' + input('请输入样本集编号:') if os.path.exists(sample_path): print('该样本集已存在,请重新输入...\n') sample_path = r'./Sample_9bus_' + input('请重新输入样本集编号:') else: os.makedirs(sample_path) # # 1 母线故障——样本编号:1~12*num_bus -> [1, 108] # for i in range(num_bus): # # for i in range(1): # for j in range(len(clear_time)): # # init # psspy.psseinit(50) # psspy.case(r""".\Models\9Bus-test\ieee9bus_v32.sav""") # psspy.fnsl([0, 0, 0, 1, 1, 0, 99, 0]) # psspy.cong(0) # psspy.conl(0, 1, 1, [0, 0], [100.0, 0.0, 0.0, 100.0]) # psspy.conl(0, 1, 2, [0, 0], [100.0, 0.0, 0.0, 100.0]) # psspy.conl(0, 1, 3, [0, 0], [100.0, 0.0, 0.0, 100.0]) # psspy.fact() # psspy.tysl(0) # psspy.dyre_new([1, 1, 1, 1], r""".\Models\9Bus-test\ieee9bus.dyr""", "", "", "") # # # perform Dynamic Simulation # # 1) set "Channal Setup Wizard" # psspy.chsb(0, 1, [-1, -1, -1, 1, 1, 0]) # Angle # psspy.chsb(0, 1, [-1, -1, -1, 1, 7, 0]) # # psspy.chsb(0, 1, [-1, -1, -1, 1, 13, 0]) # # # # 2) name output file # psspy.set_chnfil_type(0) # 1 for OUTX format, 0 for (old) OUT format # psspy.strt_2([0, 1], sample_path + '\\t9Bus-PY-00' + str(num_sample_id) + '.out') # num_sample_id += 1 # # # 3) in normal stat, run network to 1 seconds # psspy.run(0, 1.0, 0, 1, 1) # # # 4) set Balanced_bus_fault with R,X -> [0, 0] # psspy.dist_bus_fault(bus_id[i], 1, bus_kv[i], [0.0, -2E+2]) # -------- ! important # # # 5) set fault run time # psspy.run(0, 1 + clear_time[j], 0, 1, 1) # # # 6) clear fault, and run net to 10 seconds # psspy.dist_clear_fault(1) # psspy.run(0, 10.0, 0, 1, 1) # # # 7) 关闭本次仿真相关的文件, importaant !!!!!!!!!!!!!!!!!!!!!! # psspy.pssehalt_2() # 2 非变压器支路故障——样本编号: [108+1, 108+360] for i in range(num_notrans_brch): # for i in range(1): for k in range(len(fault_position)): # for k in range(1): for j in range(len(clear_time)): print('\n\n\n\n----------------我是分割线--------------\n') print('已仿真第 ' + str(num_sample_id) + ' 条样本\n\n\n\n') # init psspy.psseinit(50) psspy.case(r""".\Models\9Bus-test\ieee9bus_v32.sav""") psspy.fnsl([0, 0, 0, 1, 1, 0, 99, 0]) psspy.cong(0) psspy.conl(0, 1, 1, [0, 0], [100.0, 0.0, 0.0, 100.0]) psspy.conl(0, 1, 2, [0, 0], [100.0, 0.0, 0.0, 100.0]) psspy.conl(0, 1, 3, [0, 0], [100.0, 0.0, 0.0, 100.0]) psspy.fact() psspy.tysl(0) psspy.dyre_new([1, 1, 1, 1], r""".\Models\9Bus-test\ieee9bus.dyr""", "", "", "") # perform Dynamic Simulation # 1) set "Channal Setup Wizard" psspy.chsb(0, 1, [-1, -1, -1, 1, 1, 0]) # Angle psspy.chsb(0, 1, [-1, -1, -1, 1, 7, 0]) # psspy.chsb(0, 1, [-1, -1, -1, 1, 13, 0]) # # 1.1) set Relative Machine Angle psspy.set_relang(1, 1, r"""1""") # 2) name output file psspy.set_chnfil_type( 0) # 1 for OUTX format, 0 for (old) OUT format psspy.strt_2([0, 1], sample_path + '//t9Bus-PY-00' + str(num_sample_id) + '.out') num_sample_id += 1 # 3) in normal stat, run network to 1 seconds psspy.run(0, 1.0, 0, 1, 1) # 4) set unbalanced_Branch_fault -- 3 Phase -- with R,X -> [0, 0] psspy.dist_spcb_fault_2( notrans_brch[i][0], notrans_brch[i][1], r"""1""", [3, 0, 3, 1, 0, 0, 1], [fault_position[k], 0.0, 0.0, 0.0, 0.0 ]) # -------- ! important # 5) set fault run time psspy.run(0, 1 + clear_time[j], 0, 1, 1) # 6) clear fault, and run net to 10 seconds psspy.dist_clear_fault(1) psspy.run(0, 10.0, 0, 1, 1) # 7) 关闭本次仿真相关的文件, importaant !!!!!!!!!!!!!!!!!!!!!! psspy.pssehalt_2()
def do_simulation(sav_path, dyr_path): global num_sample_id # set Samples Path sample_path = r'./Sample_14bus_' + input('请输入样本集编号:') if os.path.exists(sample_path): print('该样本集已存在,请重新输入...\n') sample_path = r'./Sample_14bus_' + input('请重新输入样本集编号:') else: os.makedirs(sample_path) # # 1 母线故障——样本编号:1~12*num_bus -> [1, 168] # for i in range(num_bus): # # for i in range(1): # for j in range(len(clear_time)): # # init # psspy.psseinit(50) # psspy.case(sav_path) # psspy.fnsl([0, 0, 0, 1, 1, 0, 99, 0]) # psspy.cong(0) # psspy.conl(0, 1, 1, [0, 0], [100.0, 0.0, 0.0, 100.0]) # psspy.conl(0, 1, 2, [0, 0], [100.0, 0.0, 0.0, 100.0]) # psspy.conl(0, 1, 3, [0, 0], [100.0, 0.0, 0.0, 100.0]) # psspy.fact() # psspy.tysl(0) # psspy.dyre_new([1, 1, 1, 1], dyr_path, "", "", "") # # # perform Dynamic Simulation # # 1) set "Channal Setup Wizard" # psspy.chsb(0, 1, [-1, -1, -1, 1, 1, 0]) # Angle -> 发电机功角 # psspy.chsb(0, 1, [-1, -1, -1, 1, 14, 0]) # Volt & Angle -> 电压&相角 # psspy.chsb(0, 1, [-1, -1, -1, 1, 16, 0]) # Flow (P & Q) -> 潮流 # # # 2) name output file # psspy.set_chnfil_type(0) # 1 for OUTX format, 0 for (old) OUT format # psspy.strt_2([0, 1], sample_path + '\\t14Bus-PY-00' + str(num_sample_id) + '.out') # num_sample_id += 1 # # # 3) in normal stat, run network to 1 seconds # psspy.run(0, 1.0, 0, 1, 1) # # # 4) set Balanced_bus_fault; Default with R,X -> [0, -2e+009] # psspy.dist_bus_fault(bus_id[i], 1, bus_kv[i], [0.0, -2E9]) # -------- ! important # # # bus5 unbalanced fault with [R-LL, X-LL, R-LG, X-LG], 是单相故障 !!!!!!! # # 事实证明设置LL的RX对稳定毫无影响!! # # psspy.dist_scmu_fault_2([0, 0, 2, bus_id[i], ], [2E5, 3E5, 0, 0]) # # # 5) set fault run time # psspy.run(0, 1 + clear_time[j], 0, 1, 1) # # # 5) clear fault, and run net to 10 seconds # psspy.dist_clear_fault(1) # psspy.run(0, 10.0, 0, 1, 1) # 2 非变压器支路故障——样本编号: [bus_id ,bus_id + 960] # 根据本循环写的嵌套次序,故障时间每12条仿真为一个循环 # for i in range(num_notrans_brch): for i in range(1): # for k in range(len(fault_position)): for k in range(3): # for j in range(len(clear_time)): for j in range(12): print('\n\n\n\n----------------我是分割线--------------\n\n\n\n\n') print('已仿真第 ' + str(num_sample_id) + ' 条样本') # init psspy.psseinit(10) psspy.case(sav_path) psspy.fnsl([0, 0, 0, 1, 1, 0, 99, 0]) psspy.cong(0) psspy.conl(0, 1, 1, [0, 0], [100.0, 0.0, 0.0, 100.0]) psspy.conl(0, 1, 2, [0, 0], [100.0, 0.0, 0.0, 100.0]) psspy.conl(0, 1, 3, [0, 0], [100.0, 0.0, 0.0, 100.0]) psspy.fact() psspy.tysl(0) psspy.dyre_new([1, 1, 1, 1], dyr_path, "", "", "") # perform Dynamic Simulation # 1) set "Channal Setup Wizard" psspy.chsb(0, 1, [-1, -1, -1, 1, 1, 0]) # Angle -> 发电机功角 psspy.chsb(0, 1, [-1, -1, -1, 1, 14, 0]) # Volt & Angle -> 电压&相角 psspy.chsb(0, 1, [-1, -1, -1, 1, 16, 0]) # Flow (P & Q) -> 潮流 # 2) name output file psspy.set_chnfil_type( 0) # 1 for OUTX format, 0 for (old) OUT format psspy.strt_2([0, 1], sample_path + '\\t14Bus-PY-00' + str(num_sample_id) + '.out') num_sample_id += 1 # 3) in normal stat, run network to 1 seconds psspy.run(0, 1.0, 0, 1, 1) # 4) set unbalanced_Branch_fault -- 3 Phase -- with R,X -> [0, 0] psspy.dist_spcb_fault_2( notrans_brch[i][0], notrans_brch[i][1], r"""1""", [3, 0, 3, 1, 0, 0, 1], [fault_position[k], 0.0, 0.0, 0.0, 0.0 ]) # -------- ! important # 5) set fault run time psspy.run(0, 1 + clear_time[j], 0, 1, 1) # 6) clear fault, and run net to 10 seconds psspy.dist_clear_fault(1) psspy.run(0, 10.0, 0, 1, 1) # 7) 关闭本次仿真相关的文件, importaant !!!!!!!!!!!!!!!!!!!!!! psspy.pssehalt_2()
def Run_SIM(x, dyr_file, out_file): #inputs are strings\ dyre = r"""C:\Users\psse\Desktop\Phylicia\Error and Accuracy Tracking Project Sp18\RTS96\%s""" % dyr_file out = r"""C:\Users\psse\Desktop\Phylicia\Error and Accuracy Tracking Project Sp18\RTS96\Channels\opt_%s.out""" % out_file print dyr_file ierr = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] #checking for errors output = StringIO.StringIO() with silence(output): ierr[0] = psspy.psseinit( 200000 ) #need to have this high, otherwise there are not enough output channels ierr[1] = psspy.case( r"""C:\Users\psse\Desktop\Phylicia\Error and Accuracy Tracking Project Sp18\RTS96\RTS96DYN.sav""" ) ierr[2] = psspy.fdns([0, 0, 0, 1, 1, 0, 99, 0]) ierr[3] = psspy.cong(0) ierr[4] = psspy.conl(0, 1, 1, [0, 0], [100.0, 0.0, 0.0, 100.0]) ierr[5] = psspy.conl(0, 1, 2, [0, 0], [100.0, 0.0, 0.0, 100.0]) ierr[6] = psspy.conl(0, 1, 3, [0, 0], [100.0, 0.0, 0.0, 100.0]) ierr[7] = psspy.ordr(0) ierr[8] = psspy.fact() ierr[9] = psspy.tysl(0) ierr[10] = psspy.dyre_new([1, 1, 1, 1], dyre, "", "", "") ierr[11] = psspy.chsb(0, 1, [-1, -1, -1, 1, 13, 0]) #record voltage ierr[12] = psspy.chsb(0, 1, [-1, -1, -1, 1, 12, 0]) #record frequency ierr[13] = psspy.chsb(0, 1, [-1, -1, -1, 1, 1, 0]) #angle ierr[14] = psspy.chsb(0, 1, [-1, -1, -1, 1, 16, 0]) #line P & Q ierr[15] = psspy.strt_2([0, 0], out) ierr[16] = psspy.run(0, 0.1, 1, 1, 0) #Line outage or line fault a = int(x[0]) b = int(x[1]) c = int(x[2]) ierr[17] = psspy.branch_chng_3( a, b, r"""1""", [0, _i, _i, _i, _i, _i], [_f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f], [_f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f], "") #Line Outage #ierr[17] = psspy.dist_branch_fault(a,b,r"""1""",1, c,[0.0,-0.2E+10]) #Line Fault, NaN (network no good) #generator outage #x = int(x) #ierr[17] = psspy.machine_chng_2(x,r"""1""",[0,_i,_i,_i,_i,_i],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f]) #Generator Outage #Bus Fault #ierr[17] = psspy.dist_bus_fault(211,1, 230.0,[0.0,-0.2E+10]) #bus Fault, NaN (network no good) ierr[18] = psspy.change_channel_out_file(out) ierr[19] = psspy.run(0, 0.5, 1, 1, 0) #this was 10 psspy.dist_clear_fault(1) psspy.change_channel_out_file(out) psspy.run(1, 10.0, 1, 1, 0) ierr[20] = psspy.delete_all_plot_channels() print "completed simulation" print ierr run_output = output.getvalue() current_error = 0 if "Network not converged" in run_output: print "Network not converged" #need to have something in if statement otherwise you get an indentation error result = 0 #this will go out to a if condition to rerun the program with a different selection of buses at this accuracy current_error = 1 #raise SystemExit #this will quit the program elif "NaN" in run_output: print "NaN, network is no good" result = 0 #this will go out to a if condition to rerun the program with a different selection of buses at this accuracy current_error = 1 #raise SystemExit #this will quit the program if current_error == 0 and "INITIAL CONDITIONS CHECK O.K." in run_output: print "continuing with study..." #Gather the data and output to excel data = dyntools.CHNF(out) #getting data from channel.out file d, e, z = data.get_data( ) #gathering data from data in dictionary format #Concatenate data so all data from one simulation is in one file c = 1 #must start at 1, not zero #Save Frequency and Voltage while c < 726: if c < 100: #Record Angle v = z[c] new_v = ", ".join( str(i) for i in v ) #this removes the brackets at the beginning and end of the list so can be processed in matlab a = np.matrix(new_v) #make it into a matrix if c == 1: ang_all = np.copy(a) else: ang_all = np.concatenate( (ang_all, a), axis=0 ) #changed to concatenate vertically to test them all individually if c > 99 and c < 173: #Record Frequency v = z[c] new_v = ", ".join( str(i) for i in v ) #this removes the brackets at the beginning and end of the list so can be processed in matlab f = np.matrix(new_v) #make it into a matrix if c == 100: f_all = np.copy(f) else: f_all = np.concatenate( (f_all, f), axis=0 ) #changed to concatenate vertically to test them all individually if c > 172 and c < 246: #Record voltage magnitude v = z[c] new_v = ", ".join( str(i) for i in v ) #this removes the brackets at the beginning and end of the list so can be processed in matlab f = np.matrix(new_v) #make it into a matrix if c == 173: all = np.copy(f) else: all = np.concatenate( (all, f), axis=0 ) #changed to concatenate vertically to test them all individually if c > 245 and c < 726: #Record P and Q if float(c / 2) == int(c / 2): #P , even numbers v = z[c] new_v = ", ".join( str(i) for i in v ) #this removes the brackets at the beginning and end of the list so can be processed in matlab f = np.matrix(new_v) #make it into a matrix if c == 246: P_all = np.copy(f) else: P_all = np.concatenate( (P_all, f), axis=0 ) #changed to concatenate vertically to test them all individually else: #Q, odd numbers v = z[c] new_v = ", ".join( str(i) for i in v ) #this removes the brackets at the beginning and end of the list so can be processed in matlab f = np.matrix(new_v) #make it into a matrix if c == 247: Q_all = np.copy(f) else: Q_all = np.concatenate( (Q_all, f), axis=0 ) #changed to concatenate vertically to test them all individually c = c + 1 result = [all, f_all, ang_all, P_all, Q_all] #0 is voltage, 1 is frequency return result