wiqasali commited on
Commit
a3a916a
·
verified ·
1 Parent(s): d274150

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -40
app.py CHANGED
@@ -1,50 +1,59 @@
1
-
2
  import streamlit as st
3
  import numpy as np
4
  from sklearn.linear_model import LinearRegression
5
  import pandas as pd
6
 
7
- # Create the Streamlit app
8
- st.title("Transformer Tap Changer Optimization App")
 
 
 
9
 
10
  # Input fields for voltage and load
11
- voltage_in = st.number_input("Enter the Input Voltage (kV)", min_value=90, max_value=150, value=115)
12
- voltage_out = st.number_input("Enter the Output Voltage (kV)", min_value=80, max_value=130, value=100)
13
  load = st.number_input("Enter the Current Load (MW)", min_value=50, max_value=500, value=250)
14
 
15
- # Simple logic to determine the tap position based on voltage_out
16
- def optimize_tap_change(voltage_in, voltage_out, load):
17
- # Example logic to decide when to change tap position
18
- if voltage_out < 95:
19
- return "Tap 1 (Increase voltage)"
20
- elif voltage_out > 105:
21
- return "Tap 5 (Decrease voltage)"
22
- else:
23
- return "Tap 3 (Optimal position)"
24
-
25
- # Display the recommended tap position
26
- recommended_tap = optimize_tap_change(voltage_in, voltage_out, load)
27
-
28
- st.write(f"**Recommended Tap Position**: {recommended_tap}")
29
-
30
- # Create a simple dataset for machine learning model training
31
- # Example data (features: voltage_in, load, previous_tap_change)
32
- data = {
33
- 'voltage_in': [110, 115, 120, 125],
34
- 'load': [250, 300, 350, 400],
35
- 'tap_position': [3, 4, 2, 5] # Target variable: tap position
36
- }
37
- df = pd.DataFrame(data)
38
-
39
- X = df[['voltage_in', 'load']] # Features
40
- y = df['tap_position'] # Target variable
41
-
42
- # Train the Linear Regression model
43
- model = LinearRegression()
44
- model.fit(X, y)
45
-
46
- # Predict optimal tap position based on current input
47
- predicted_tap = model.predict([[voltage_in, load]])
48
-
49
- st.write(f"**Predicted Tap Position using Machine Learning**: Tap {int(predicted_tap[0])}")
 
 
 
 
 
 
 
50
 
 
 
1
  import streamlit as st
2
  import numpy as np
3
  from sklearn.linear_model import LinearRegression
4
  import pandas as pd
5
 
6
+ # Title of the app
7
+ st.title("132/11 kV Transformer Tap Changer Optimization App")
8
+
9
+ # Nominal secondary voltage (11.5 kV)
10
+ nominal_secondary_voltage = 11.5
11
 
12
  # Input fields for voltage and load
13
+ voltage_in = st.number_input("Enter the Input Voltage (132 kV)", min_value=100, max_value=150, value=132)
14
+ voltage_out = st.number_input("Enter the Output Voltage (11 kV)", min_value=10.0, max_value=15.0, value=11.0)
15
  load = st.number_input("Enter the Current Load (MW)", min_value=50, max_value=500, value=250)
16
 
17
+ # Convert secondary voltage to primary voltage using transformer ratio (132 kV / 11 kV)
18
+ # This is the nominal transformer voltage ratio
19
+ transformer_ratio = 132 / 11
20
+
21
+ # Calculate the optimal tap position based on output voltage
22
+ def calculate_optimal_tap(voltage_in, voltage_out, load):
23
+ # Desired output voltage should be 11.5 kV (nominal secondary voltage)
24
+ target_voltage_out = nominal_secondary_voltage
25
+
26
+ # Calculate the required primary voltage to achieve desired secondary voltage (11.5 kV)
27
+ required_primary_voltage = target_voltage_out * transformer_ratio
28
+
29
+ # Calculate the voltage deviation from nominal (in primary)
30
+ voltage_deviation = voltage_in - required_primary_voltage
31
+
32
+ # Optimizing tap changer setting based on voltage deviation
33
+ # Assuming tap positions range from -13 (decreasing voltage) to +13 (increasing voltage)
34
+ # Tap range can be calculated based on the voltage deviation and transformer ratio
35
+ tap_position = round(voltage_deviation / (voltage_in / 27)) # 27 is the number of taps
36
+
37
+ # Ensure that the tap position is within the range of the 27-tap MR tap changer
38
+ if tap_position > 13:
39
+ tap_position = 13
40
+ elif tap_position < -13:
41
+ tap_position = -13
42
+
43
+ # Return the tap position recommendation
44
+ return tap_position
45
+
46
+ # Button to get the recommended tap position
47
+ if st.button('Get Tap Position'):
48
+ # Calculate the optimal tap position
49
+ optimal_tap = calculate_optimal_tap(voltage_in, voltage_out, load)
50
+
51
+ # Show the recommended tap position
52
+ st.write(f"**Recommended Tap Position**: Tap {optimal_tap} (Adjust to maintain 11.5 kV output)")
53
+
54
+ # Display additional results
55
+ st.write(f"**Nominal Secondary Voltage**: {nominal_secondary_voltage} kV")
56
+ st.write(f"**Input Voltage**: {voltage_in} kV")
57
+ st.write(f"**Output Voltage**: {voltage_out} kV")
58
+ st.write(f"**Current Load**: {load} MW")
59