The script below is used to determine relay operating times, as defined in the standard IEC 60255. The equation and relevant information can be found here.
curve_equation
takes three input values, and outputs a list of values representing the trip times for currents in the fixed range np.logspace(np.log10(Is), 5, 1e2)
.
The part in the bottom plots the trip times for the different curves. The function curve_equation
will be used to much more than that, so I'm mostly interested in improvements to that one.
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 13:28:26 2018
@author: Stewie
"""
import numpy as np
import matplotlib.pyplot as plt
def curve_equation(curve_name, T, Is):
"""
This function calculates and returns the inverse curves for
the selected curve type.
Input:
curve_name: one of the strings: "SIT", "VIT", "LTI", "EIT", "UIT"
T: The time dial setting. Typically in the range 0.1 ... 1
Is: The current setting. Typically in the range 100-10000
The appropriate k, alpha and theta values are selected based on the
curve type.
"""
# Define constants to be used in the curve equation
k = (0.14, 13.5, 120, 80, 315.2)
alpha = (0.02, 1, 2, 2, 2.5)
beta = (2.97, 1.5, 13.33, 0.808, 1)
curve_types = ("SIT", "VIT", "LTI", "EIT", "UIT")
# idx is the index of the values we want
try:
idx = curve_types.index(curve_name)
except:
print("Non-existing curve-type")
return
I = np.logspace(np.log10(Is), 5, 1e2)
def td_equation():
td = k[idx]/((I/Is)**alpha[idx]-1) * (T / beta[idx])
return(td)
return(td_equation())
# For testing / plotting purposes:
curve_types = ("SIT", "VIT", "LTI", "EIT", "UIT")
I = np.logspace(1, 5, 1e2)
for curve_type in curve_types:
plt.loglog(I, curve_equation(curve_type, 1, 1e2), label=curve_type)
plt.xlabel("Current [A]")
plt.ylabel("Time [s]")
plt.title("IEC Time/current curves")
plt.grid()
plt.legend()
NameError: name 'I' is not defined
error on theplt.loglog(I, …)
line. \$\endgroup\$I
was already stored as a variable outside the function so I didn't get an error message when I removed it. \$\endgroup\$