Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,11 +4,12 @@ import streamlit as st
|
|
4 |
|
5 |
# Define the calculation function
|
6 |
def calculate_relay_curve(tr_kva, tr_volt, ct_pr, ct_sec, fac, tms, i_f_fac, curve):
|
|
|
7 |
tr_curr = round(tr_kva / (tr_volt * np.sqrt(3)), 3)
|
8 |
-
pick = round(fac * tr_curr / ct_pr, 3)
|
9 |
-
i_f = round(i_f_fac * tr_curr * fac, 3)
|
10 |
|
11 |
-
#
|
12 |
if curve == 'IEC Normal Inverse':
|
13 |
b_ = 0.14
|
14 |
a_ = 0.02
|
@@ -25,11 +26,11 @@ def calculate_relay_curve(tr_kva, tr_volt, ct_pr, ct_sec, fac, tms, i_f_fac, cur
|
|
25 |
st.error("Invalid Curve Selected.")
|
26 |
return
|
27 |
|
28 |
-
# Calculate trip time
|
29 |
try:
|
30 |
-
|
31 |
except ZeroDivisionError:
|
32 |
-
st.error("Error in trip time calculation. Check input values.")
|
33 |
return
|
34 |
|
35 |
# Generate data for the relay curve
|
@@ -38,28 +39,22 @@ def calculate_relay_curve(tr_kva, tr_volt, ct_pr, ct_sec, fac, tms, i_f_fac, cur
|
|
38 |
for x in x_curr:
|
39 |
try:
|
40 |
time = b_ * tms / (((x * (ct_sec / ct_pr) / (pick * ct_sec)) ** a_) - 1)
|
41 |
-
y_time.append(time)
|
42 |
except ZeroDivisionError:
|
43 |
y_time.append(np.nan)
|
44 |
|
45 |
-
# Fault time calculation
|
46 |
-
try:
|
47 |
-
fault_time = b_ * tms / (((i_f * (ct_sec / ct_pr) / (pick * ct_sec)) ** a_) - 1)
|
48 |
-
except ZeroDivisionError:
|
49 |
-
fault_time = np.nan
|
50 |
-
|
51 |
# Display results
|
52 |
st.write('### Results:')
|
53 |
-
st.write('**Rated Current:**
|
54 |
-
st.write('**Pickup:**
|
55 |
-
st.write('**Fault Current:**
|
56 |
-
st.write('**Trip Time:**
|
57 |
|
58 |
# Plot the relay curve
|
59 |
fig, ax = plt.subplots()
|
60 |
-
ax.plot(x_curr, y_time, label="Relay Curve")
|
61 |
-
ax.axvline(x=i_f, color='red', linestyle='--', label="Fault Current")
|
62 |
-
ax.axhline(y=fault_time, color='
|
63 |
ax.set_xlabel('Current (Amp)')
|
64 |
ax.set_ylabel('Time (sec)')
|
65 |
ax.set_title(f"Relay Curve: {curve}")
|
|
|
4 |
|
5 |
# Define the calculation function
|
6 |
def calculate_relay_curve(tr_kva, tr_volt, ct_pr, ct_sec, fac, tms, i_f_fac, curve):
|
7 |
+
# Calculate transformer current
|
8 |
tr_curr = round(tr_kva / (tr_volt * np.sqrt(3)), 3)
|
9 |
+
pick = round(fac * tr_curr / ct_pr, 3) # Pickup value in multiples of In
|
10 |
+
i_f = round(i_f_fac * tr_curr * fac, 3) # Fault current in amps
|
11 |
|
12 |
+
# Select curve coefficients based on relay type
|
13 |
if curve == 'IEC Normal Inverse':
|
14 |
b_ = 0.14
|
15 |
a_ = 0.02
|
|
|
26 |
st.error("Invalid Curve Selected.")
|
27 |
return
|
28 |
|
29 |
+
# Calculate fault trip time
|
30 |
try:
|
31 |
+
fault_time = b_ * tms / (((i_f * (ct_sec / ct_pr) / (pick * ct_sec)) ** a_) - 1)
|
32 |
except ZeroDivisionError:
|
33 |
+
st.error("Error: Division by zero in fault trip time calculation. Check input values.")
|
34 |
return
|
35 |
|
36 |
# Generate data for the relay curve
|
|
|
39 |
for x in x_curr:
|
40 |
try:
|
41 |
time = b_ * tms / (((x * (ct_sec / ct_pr) / (pick * ct_sec)) ** a_) - 1)
|
42 |
+
y_time.append(time if time > 0 else np.nan) # Avoid negative/undefined times
|
43 |
except ZeroDivisionError:
|
44 |
y_time.append(np.nan)
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
# Display results
|
47 |
st.write('### Results:')
|
48 |
+
st.write(f'**Rated Current:** {tr_curr} A')
|
49 |
+
st.write(f'**Pickup:** {pick} x In')
|
50 |
+
st.write(f'**Fault Current:** {i_f} A')
|
51 |
+
st.write(f'**Trip Time:** {round(fault_time, 3)} sec')
|
52 |
|
53 |
# Plot the relay curve
|
54 |
fig, ax = plt.subplots()
|
55 |
+
ax.plot(x_curr, y_time, label="Relay Curve", color='blue')
|
56 |
+
ax.axvline(x=i_f, color='red', linestyle='--', label=f"Fault Current: {i_f} A")
|
57 |
+
ax.axhline(y=fault_time, color='green', linestyle='--', label=f"Trip Time: {round(fault_time, 3)} sec")
|
58 |
ax.set_xlabel('Current (Amp)')
|
59 |
ax.set_ylabel('Time (sec)')
|
60 |
ax.set_title(f"Relay Curve: {curve}")
|