首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PSSE/Python从PSSE导入excel值和导出总线电压

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

Stack Overflow用户
提问于 2012-08-09 13:31:39
回答 1查看 3.6K关注 0票数 0

有没有人能帮我学下Python?我正在尝试运行168个牛顿·拉普森负荷流研究,以获得不同的负荷和gens值。我在excel电子表格中设置了这些值,并希望自动将这些值上传到PSSE中,运行仿真,然后将所有168个sims的母线电压结果导出到另一个电子表格中。

我有以下代码,但它在第47行显示错误: def runstudy(小时,值) SyntaxError:无效语法

我不确定如何纠正这一点。

任何帮助都将不胜感激

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2012-08-19 10:53:40

吉姆,

有一个简单的语法错误。我相信你现在已经注意到了。这样做-

代码语言:javascript
复制
def runstudy(hours, values):

除非你分享你的.sav和.csv文件,否则我不能说太多关于剩下的代码。我想知道它是如何进行的,特别是因为我对PSSE感兴趣。如果您需要进一步的帮助,请将文件发送给我。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11877310

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档