import streamlit as st import numpy as np from sklearn.linear_model import LinearRegression import pandas as pd # Title of the app st.title("132/11 kV Transformer Tap Changer Optimization App") # Nominal secondary voltage (11.5 kV) nominal_secondary_voltage = 11.5 # Input fields for voltage and load voltage_in = st.number_input("Enter the Input Voltage (132 kV)", min_value=100, max_value=150, value=132) voltage_out = st.number_input("Enter the Output Voltage (11 kV)", min_value=10.0, max_value=15.0, value=11.0) load = st.number_input("Enter the Current Load (MW)", min_value=50, max_value=500, value=250) # Convert secondary voltage to primary voltage using transformer ratio (132 kV / 11 kV) # This is the nominal transformer voltage ratio transformer_ratio = 132 / 11 # Calculate the optimal tap position based on output voltage def calculate_optimal_tap(voltage_in, voltage_out, load): # Desired output voltage should be 11.5 kV (nominal secondary voltage) target_voltage_out = nominal_secondary_voltage # Calculate the required primary voltage to achieve desired secondary voltage (11.5 kV) required_primary_voltage = target_voltage_out * transformer_ratio # Calculate the voltage deviation from nominal (in primary) voltage_deviation = voltage_in - required_primary_voltage # Optimizing tap changer setting based on voltage deviation # Assuming tap positions range from -13 (decreasing voltage) to +13 (increasing voltage) # Tap range can be calculated based on the voltage deviation and transformer ratio tap_position = round(voltage_deviation / (voltage_in / 27)) # 27 is the number of taps # Ensure that the tap position is within the range of the 27-tap MR tap changer if tap_position > 13: tap_position = 13 elif tap_position < -13: tap_position = -13 # Return the tap position recommendation return tap_position # Button to get the recommended tap position if st.button('Get Tap Position'): # Calculate the optimal tap position optimal_tap = calculate_optimal_tap(voltage_in, voltage_out, load) # Show the recommended tap position st.write(f"**Recommended Tap Position**: Tap {optimal_tap} (Adjust to maintain 11.5 kV output)") # Display additional results st.write(f"**Nominal Secondary Voltage**: {nominal_secondary_voltage} kV") st.write(f"**Input Voltage**: {voltage_in} kV") st.write(f"**Output Voltage**: {voltage_out} kV") st.write(f"**Current Load**: {load} MW")