Ask Your Question
1

Import load (MW/Mvar) and Generation (MW) from CSV file to PSS/E case

asked 2022-03-11 00:58:05 -0500

psse_user_88 gravatar image

updated 2022-03-17 03:04:19 -0500

Hello, I am trying to make a script in python that reads from CSV files the load and generation values and updates the values in the PSS/E sav case for one timestamp. csv file structure for load looks like this:

node number, load MW, load Mvar 10004, 5, 5 10006, 5, 5 . . .

The status of the script is as follows:

import os
import sys

PSSE_LOCATION = r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN"
sys.path.append(PSSE_LOCATION)
os.environ['PATH'] = os.environ['PATH'] + ';' + PSSE_LOCATION

import psspy
_i = psspy.getdefaultint()
_f = psspy.getdefaultreal()
_s = psspy.getdefaultchar()
psspy.psseinit(100000)
psspy.throwPsseExceptions = True

STUDY_CASE = 'C:\\path\\20220301_0030_FO1.sav'

psspy.case(STUDY_CASE)
#My updated code is below, changed identation
with open("1.csv", 'r') as file:
    reader = csv.reader(file)
    for row in reader:
        loadbus = int(row[0])
        loadid = '1'  # or loaddatalst [x], x is position of load id in row
        loadp = float(row[1])
        loadq = float(row[2])
        psspy.load_data_4(loadbus, loadid, [_i, _i, _i, _i, _i, _i], [loadp, loadq, 0, 0, 0, 0])


psspy.fnsl([0, 0, 0, 0, 0, 0, 99, 0])
psspy.area_2(0, 1, 1)
psspy.save(STUDY_CASE)
psspy.rawd_2(0, 1, [1, 1, 1, 0, 0, 0, 0], 0, r"""20220301_0030_FO1.raw""")

The part I am struggling with is defining some way of importing the CSV list in python and applying the load (MW/Mvar) in each load node.

Thank you.

to follow up after JConto answer, my code for updating load and generation in PSSE case looks like this:

#read load p and q
with open('load.csv', 'r') as file:
reader = csv.reader(file)
for row in reader:
   loadbus = int(row[0])
   loadid = '1'  # or loaddatalst [x], x is position of load id in row
   loadp = float(row[1])
   loadq = float(row[2])
   psspy.load_data_4(loadbus, loadid, [_i, _i, _i, _i, _i, _i], [loadp, loadq, 0, 0, 0, 0])

#read generators
with open('gen.csv', 'r') as file:
reader = csv.reader(file)
for row in reader:
    genbus = int(row[0])
    genid = str(row[1])  # or loaddatalst [x], x is position of load id in row
    status = int(row[2])
    genp = float(row[3])
    genq = float(row[4])
    psspy.machine_chng_2(genbus, genid, [status, _i, _i, _i, _i, _i],[genp, genq, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f])
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2022-03-11 08:17:05 -0500

jconto gravatar image

updated 2022-03-16 12:22:02 -0500

Load data in a CSV file can be read as follow:

import csv
with open('loaddata.csv', 'r') as file:
     reader = csv.reader(file)
for row in reader:
    #format=node number, load MW, load Mvar
    #             10004,       5,         5
    #loaddatalst = row.split(',')
    loadbus = int(loaddatalst[0])
    loadid = '1'             #or loaddatalst [x], x is position of load id in row
    loadp = float(loaddatalst[1])
    loadq = float(loaddatalst[2])
    psspy.load_data_4(loadbus, loadid,[_i,_i,_i,_i,_i,_i],[loadp, loadq, 0, 0, 0, 0])

With a second "CSV read block" the data for generators can be updated. Search the internet for "python CSV read", converting data types and the PSSe API for fuctions and data types needed as parameters.

edit flag offensive delete link more

Comments

Thank you JConto, I am getting this error: Traceback (most recent call last): File "C:/path/lexon.py", line 28, in <module> for row in reader: ValueError: I/O operation on closed file Is it indentation issue?

psse_user_88 gravatar imagepsse_user_88 ( 2022-03-13 08:45:23 -0500 )edit

please see updated code. I am getting: loaddatalst = row.split(",") AttributeError: 'list' object has no attribute 'split'

psse_user_88 gravatar imagepsse_user_88 ( 2022-03-13 09:20:33 -0500 )edit

I was able to solve by removing loaddatalst. The for row loop had done the splitting already. Thank you JConto

psse_user_88 gravatar imagepsse_user_88 ( 2022-03-14 08:32:34 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: 2022-03-11 00:58:05 -0500

Seen: 445 times

Last updated: Mar 17 '22