Import load (MW/Mvar) and Generation (MW) from CSV file to PSS/E case
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])