First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
0

Checking whether the voltage within the range

asked Aug 9 '3

Jimmy gravatar image

My Goal:Checking whether the voltage within the range of 0.9 to 1.05

**My_Code_1:**

ierr, volts = psspy.abusreal(1,1,string='PU')

x1.set_cell ((3, 'z'),'pass' if (0.9 < max(zip(*volts )) < 1.05  and  0.9 < min(zip(*volts ))

             < 1.05) else 'Not Pass')*


**My_Code_1_Result:**  

'Not Pass'

**My_Code_2:**

ierr, volts = psspy.abusreal(1,1,string='PU')

max_value = max(zip(*volts ))

min_value = min(zip(*volts ))

x1.set_cell ((3, 'z'),'pass' if (0.9 < max_value  < 1.05  and  0.9 < min_value< 1.05) else 

             'Not Pass')*


**My_Code_2_Result:**  

'Not Pass'

**My_Code_3:**

tolerance = 1e-6 

ierr, volts = psspy.abusreal(1,1,string='PU')

x1.set_cell ((3, 'z'),'pass' if (0.9+tolerance < max(zip(*volts )) < 1.05-tolerance and 0.9+tolerance < min(zip(*volts)<1.05-tolerance) else 'Not Pass')*


**My_Code_3_Result:**  

'Not Pass'

I checked all the value of max(zip(volts )) and min(zip(volts )).

They are all within 0.9~1.05. But why keep jumping into else shows 'Not Pass' ?

I did it wrong or can't do like this ?

Thank you for reading my question.

1 answer

Sort by » oldest newest most voted
1

answered Aug 9 '3

perolofl gravatar image

The problem is that max(zip(*volts)) returns a tuple, e.g. (1.0404236316680908,) and not a float, so the if-statement doesn't work.

Use max(volts[0]) instead.

A tip is to print the values to check if they have the expected format when the code is not working correctly.

link

Comments

Thank you for answering my questions. I see. Thank you.

Jimmy gravatar imageJimmy (Aug 10 '3)

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: Aug 9 '3

Seen: 191 times

Last updated: Aug 09 '23