Spaces:
Sleeping
Sleeping
File size: 2,818 Bytes
ab77975 1211d07 ab77975 1211d07 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import streamlit as st
# Define the calculation function
def calculate_relay_curve(tr_kva, tr_volt, ct_pr, ct_sec, fac, tms, i_f_fac, curve):
tr_curr = round(tr_kva / (tr_volt * np.sqrt(3)), 3)
pick = round(fac * tr_curr / ct_pr, 3)
i_f = round(i_f_fac * tr_curr * fac, 3)
if curve == 'IEC Normal Inverse':
b_ = 0.14
a_ = 0.02
elif curve == 'IEC Very Inverse':
b_ = 13.5
a_ = 1
elif curve == 'IEC Extremely Inverse':
b_ = 80
a_ = 2.0
elif curve == 'IEC Long Time Inverse':
b_ = 120
a_ = 1.0
else:
st.error("Invalid Curve Selected.")
return
trip_t = b_ * tms / (((i_f * (ct_sec / ct_pr) / (pick * ct_sec)) ** a_) - 1)
x_curr = np.linspace(pick * ct_pr + 0.1 * pick * ct_pr, pick * ct_pr * 5, 100)
y_time = b_ * tms / (((x_curr * (ct_sec / ct_pr) / (pick * ct_sec)) ** a_) - 1)
fault_time = b_ * tms / (((i_f * (ct_sec / ct_pr) / (pick * ct_sec)) ** a_) - 1)
st.write('### Results:')
st.write('**Rated Current:**', tr_curr, 'A')
st.write('**Pickup:**', pick, 'x In')
st.write('**Fault Current:**', round(i_f, 3), 'A')
st.write('**Trip Time:**', round(fault_time, 3), 'sec')
# Plot the relay curve
fig, ax = plt.subplots()
ax.plot(x_curr, y_time)
ax.plot(i_f, b_ * tms / (((i_f * (ct_sec / ct_pr) / (pick * ct_sec)) ** a_) - 1), 'o')
ax.xlabel('Current (Amp)')
ax.ylabel('Time (sec)')
ax.title(f"Relay Curve: {curve}")
ax.set_xlabel('Current (Amp)')
ax.set_ylabel('Time (sec)')
ax.set_title(f"Relay Curve: {curve}")
ax.legend()
st.pyplot(fig)
# Streamlit app layout
st.title("Relay Curve Calculator")
st.sidebar.header("Input Parameters")
# Input fields
tr_kva = st.sidebar.number_input("Transformer Rating (kVA)", min_value=1.0, value=1000.0, step=1.0)
tr_volt = st.sidebar.number_input("Transformer Voltage (V)", min_value=1.0, value=11000.0, step=1.0)
ct_pr = st.sidebar.number_input("CT Primary (Amp)", min_value=1.0, value=200.0, step=1.0)
ct_sec = st.sidebar.number_input("CT Secondary (Amp)", min_value=1.0, value=5.0, step=1.0)
fac = st.sidebar.number_input("Fault Anticipation Factor", min_value=1.0, value=1.2, step=0.1)
tms = st.sidebar.number_input("Time Multiplier Setting (TMS)", min_value=0.01, value=0.1, step=0.01)
i_f_fac = st.sidebar.number_input("Fault Current Multiplier", min_value=1.0, value=10.0, step=0.1)
curve = st.sidebar.selectbox("Relay Curve Type", ['IEC Normal Inverse', 'IEC Very Inverse', 'IEC Extremely Inverse', 'IEC Long Time Inverse'])
# Run the calculation when the button is clicked
if st.sidebar.button("Calculate"):
calculate_relay_curve(tr_kva, tr_volt, ct_pr, ct_sec, fac, tms, i_f_fac, curve)
|