Ask Your Question
0

Data conversion/comparison python-PSSE-excel

asked 2016-06-09 18:15:24 -0600

LFrater gravatar image

I am having trouble when I compare PGen levels using by psspy.py reading from PSSE and data read from Excel using excelpy.

For example, I read PGen levels from a machine (using psspy.py psspy.amachreal) and store the data using excelpy in a spreadsheet. I then read the data back from excel using excelpy and compare this with the current machine PGen the number comparison in python "==" typically fails. In the code snippet below the IF statement is quite often false even though the excel and PSSE value look the same.

machPGens = psspy.amachreal(sid=-1, flag=4, string="PGEN")
machPGen = xlsfile.get_range((topRow, leftCol, bottomRow, rightCol),transpose=True)
#code here to find the matching machine idx2 and idx
if machPGen[idx2]==machPGens[idx]:

In this process there are a number of conversions of the data

Firstly from PSSE to python to excel

And from excel to python and the data comparison

The comparison is normally true when PGen is an integer. Another issue I notice is sometimes in PSSE a machine may have a PMax of 8.2 MW (as shown in PSSE), however when reading using psspy the machine PMax is 8.19963821. Even when the excel value is exactly 8.19963821 the comparison still fails.

I assume a simple fix to this is to check if the PGen is within some small range +/-0.001MW

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-08-08 06:28:26 -0600

Cao Huy gravatar image

Because in case Pgen is a float, you can't expect it remain the same after the conversion. Normaly, when doing float comparision, we compare difference with a small epsilon.

For more information, read:

float comparision

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: 2016-06-09 18:15:24 -0600

Seen: 564 times

Last updated: Aug 08 '16