简体   繁体   English

PSSE / Python导入excel值并从PSSE导出总线电压

[英]PSSE/Python import excel values and export bus voltages from PSSE

Could someone please help me with Python. 有人可以帮助我使用Python。 I am trying to run 168 newton raphson load flow studies for different values for loads and gens. 我正在尝试运行168牛顿拉夫逊潮流研究,以获取不同的载荷和发电量值。 I have these values set out in an excel spreadsheet and would like to automatically upload these values into PSSE, run the simulation then export the bus voltage results to another spreadsheet for all 168 sims in separate columns. 我在excel电子表格中列出了这些值,并希望将这些值自动上传到PSSE,运行仿真,然后将总线电压结果导出到另一电子表格中,用于所有168个sims的单独列中。

I have the following code but it is showing an error with line 47: def runstudy(hour, values) SyntaxError: invalid syntax 我有以下代码,但在第47行显示了错误:def runtimetudy(hour,values)SyntaxError:无效的语法

I am not sure how to rectify this. 我不确定该如何纠正。

Any help would be greatly appreciated 任何帮助将不胜感激

from __future__ import with_statement
from collections import defaultdict
import csv

import psspy


CSV_PQ_FILENAME = 'c:/Users\14088757\Desktop\EP401_Simulation Values_1.1.csv'
OUTPUT_CSV_FILENAME = 'c:/Users\14088757\Desktop\EP401_Simulation Values_1.1.csv'
STUDY_BASECASE = 'c:/Users\14088757\Desktop\EP401_PSSE_URA_20120716_6626.01.sav'


with open(CSV_PQ_FILENAME) as csvfile:
    reader = csv.reader(csvfile)
    headers = reader.next()
    data = list(reader)

# now all the data from that sheet is in 'data'
# the columns are:

# load?, bus num, id, p or q, 6625, 6626, .... 

hourly_data = defaultdict(list)

hour_headings = headers[4:]

for row in data:
    isload, busnum, _id, porq = row[:4]
    hour_values = row[4:]

    # group all of the hourly data together in one list.
    for hour, value in zip(hour_headings, hour_values):
        hourly_data[hour].append(
            (int(isload), int(busnum), _id, porq, float(value))

# hourly_data now looks like this:
# { '6626': [
#             (1, 104, '1', 'P', 0.33243)
#             ...
#            ],
#   '6627': [ ... ]
#   '6628': [ ... ]
#}

# lets run some simulations.

def runstudy(hour, values)

    # reload the base case.
    psspy.case(STUDY_BASECASE)

    # assume CSV has columns as described in the doc string
    for isload, bus, _id, porq, value in values:

        if isload:
            if porq.lower() == 'p':
                psspy.load_data_3(bus, _id, realar1=value)
            elif porq.lower() == 'q':
                psspy.load_data_3(bus, _id, realar2=value)
        else:
            psspy.machine_data_2(bus, _id, realar1=value)

    # solve case after adding all loads / machines.
    psspy.fnsl()

    # return the bus voltages.
    # now to write the new bus voltages to a file.
    ierr, (voltages,) = psspy.abusreal(sid=-1, string=["PU"])
    ierr, (buses,) = psspy.abusint(sid=-1, string=["NUMBER"])

    return buses, voltages


# here we assume the buses will always be the same, no need
# keep storing them. I'll only store the voltages.
all_results = {}
for hour, values in hourly_data.items():
    buses, voltages = runstudy(hour, values)
    all_results[hour] = voltages

# now write all the results to a csv file
# CSV will have these columns:


# bus number, voltage (pu) 2265, 2267, ...
spreadsheet_results = [['buses'] + buses]
for hour, voltages in all_results.items():
    spreadsheet_results.append([hour + ' pu'] + voltages)

# spreadsheet_results now looks like the one we want to write to the CSV.
with open(OUTPUT_CSV_FILENAME, 'wb') as output:
    output.writerows(spreadsheet_results)

Jim, 吉姆

There is a simple syntax error. 有一个简单的语法错误。 I am sure you have noticed it by now. 我相信您现在已经注意到了。 Do this - 做这个 -

def runstudy(hours, values):

I cannot say much about the rest of the code unless your share your .sav and .csv files. 除非您共享.sav和.csv文件,否则我不会对其余的代码说太多。 I would be like to know how it went especially because I am interested in PSSE. 我想知道进展如何,特别是因为我对PSSE感兴趣。 Mail me the files if you need further help. 如果需要进一步的帮助,请将文件邮寄给我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM