Ask Your Question
0

Y Matrix Python

asked 2022-07-15 06:02:34 -0500

vnedelea gravatar image

Someone has a code to build the Y matrix with python considering what provides outputymatrix funtion from the PSSE API?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2022-08-05 04:04:51 -0500

vnedelea gravatar image

updated 2022-08-05 08:00:00 -0500

jconto gravatar image

I have created a code to build the Y matrix. The problem is that I've noticed that the funtion outputYmatrix does not calculate the Y in all nodes in my case... someone knows why?

import numpy as np
import pandas as pd
import sqlite3
import re
import psse35
import psspy
import pssarrays

psspy.psseinit()

_i = psspy.getdefaultint()

_f = psspy.getdefaultreal()

_s = psspy.getdefaultchar()

psspy.case(r'CASE.sav')

psspy.output_y_matrix(_i,_i,_i,0,r'outYmatrix.txt')

f = open(r'outYmatrix.txt')

listaY = []

for lines in f:

    if lines.startswith(' ZERO') or not lines.strip(): break

    else:

        listaY.append(re.split('[,\n]',lines))


conn = sqlite3.connect(':memory:')

cursor = conn.cursor()

cursor.execute('CREATE TABLE YMATRIX (IBUS INT, JBUS INT, Yreal real, Yimag real)')

conn.commit()

[cursor.execute(f'INSERT INTO YMATRIX VALUES ({item[0]},{item[1]},{item[2]},{item[3]})')for item in listaY]

df = pd.read_sql('SELECT * FROM YMATRIX ORDER BY IBUS, JBUS',conn).set_index('IBUS')

df['Y'] = df.Yreal + 1j*df.Yimag

df = df.astype({'Y':str})

df2 = df.reset_index().groupby([df.index, 'JBUS'])['Y'].aggregate('first').unstack().fillna('(0+0j)')

Ymatrix=df2.to_numpy(complex)

print(Ymatrix.shape)

print(Ymatrix)
edit flag offensive delete link more

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-07-15 06:02:34 -0500

Seen: 475 times

Last updated: Aug 05 '22