Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,88 +0,0 @@
|
|
1 |
-
import numpy as np
|
2 |
-
import matplotlib.pyplot as plt
|
3 |
-
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 |
-
# 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
|
16 |
-
elif curve == 'IEC Very Inverse':
|
17 |
-
b_ = 13.5
|
18 |
-
a_ = 1
|
19 |
-
elif curve == 'IEC Extremely Inverse':
|
20 |
-
b_ = 80
|
21 |
-
a_ = 2.0
|
22 |
-
elif curve == 'IEC Long Time Inverse':
|
23 |
-
b_ = 120
|
24 |
-
a_ = 1.0
|
25 |
-
else:
|
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 (current vs time)
|
37 |
-
x_curr = np.linspace(pick * ct_pr * 1.1, pick * ct_pr * 5, 500)
|
38 |
-
y_time = []
|
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(figsize=(10, 6))
|
55 |
-
ax.plot(x_curr, y_time, label="Relay Curve", color='blue')
|
56 |
-
|
57 |
-
# Mark the fault current and trip time on the graph
|
58 |
-
ax.axvline(x=i_f, color='red', linestyle='--', label=f"Fault Current: {i_f} A")
|
59 |
-
ax.axhline(y=fault_time, color='green', linestyle='--', label=f"Trip Time: {round(fault_time, 3)} sec")
|
60 |
-
|
61 |
-
# Adding labels and title
|
62 |
-
ax.set_xlabel('Current (Amp)')
|
63 |
-
ax.set_ylabel('Time (sec)')
|
64 |
-
ax.set_title(f"Relay Curve: {curve}")
|
65 |
-
|
66 |
-
# Adding a legend
|
67 |
-
ax.legend()
|
68 |
-
|
69 |
-
# Show the plot
|
70 |
-
st.pyplot(fig)
|
71 |
-
|
72 |
-
# Streamlit app layout
|
73 |
-
st.title("Relay Curve Calculator")
|
74 |
-
st.sidebar.header("Input Parameters")
|
75 |
-
|
76 |
-
# Input fields
|
77 |
-
tr_kva = st.sidebar.number_input("Transformer Rating (kVA)", min_value=1.0, value=1000.0, step=1.0)
|
78 |
-
tr_volt = st.sidebar.number_input("Transformer Voltage (V)", min_value=1.0, value=11000.0, step=1.0)
|
79 |
-
ct_pr = st.sidebar.number_input("CT Primary (Amp)", min_value=1.0, value=200.0, step=1.0)
|
80 |
-
ct_sec = st.sidebar.number_input("CT Secondary (Amp)", min_value=1.0, value=5.0, step=1.0)
|
81 |
-
fac = st.sidebar.number_input("Fault Anticipation Factor", min_value=1.0, value=1.2, step=0.1)
|
82 |
-
tms = st.sidebar.number_input("Time Multiplier Setting (TMS)", min_value=0.01, value=0.1, step=0.01)
|
83 |
-
i_f_fac = st.sidebar.number_input("Fault Current Multiplier", min_value=1.0, value=10.0, step=0.1)
|
84 |
-
curve = st.sidebar.selectbox("Relay Curve Type", ['IEC Normal Inverse', 'IEC Very Inverse', 'IEC Extremely Inverse', 'IEC Long Time Inverse'])
|
85 |
-
|
86 |
-
# Run the calculation when the button is clicked
|
87 |
-
if st.sidebar.button("Calculate"):
|
88 |
-
calculate_relay_curve(tr_kva, tr_volt, ct_pr, ct_sec, fac, tms, i_f_fac, curve)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|