Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +91 -0
- requirements.txt +3 -0
- steam_density.csv +51 -0
app.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import io
|
5 |
+
|
6 |
+
# Load steam density CSV
|
7 |
+
@st.cache_data
|
8 |
+
def load_density_data():
|
9 |
+
return pd.read_csv("steam_density.csv").round()
|
10 |
+
|
11 |
+
density_df = load_density_data()
|
12 |
+
|
13 |
+
# List of commercially available pipe sizes
|
14 |
+
commercial_pipes = [15, 20, 25, 40, 50, 65, 80, 100, 125, 150]
|
15 |
+
|
16 |
+
def get_nearest_commercial_size(size):
|
17 |
+
"""Find the nearest upper commercially available pipe size."""
|
18 |
+
for pipe in commercial_pipes:
|
19 |
+
if size <= pipe:
|
20 |
+
return pipe
|
21 |
+
return "Not Available" # If size exceeds the largest available pipe
|
22 |
+
|
23 |
+
# Function to calculate new pipe size
|
24 |
+
def calculate_new_line_size(flow_kg_hr, pressure_bar, density_df):
|
25 |
+
pressure_bar_new = round(float(pressure_bar))
|
26 |
+
# Interpolate density from CSV data
|
27 |
+
density = np.interp(pressure_bar_new, density_df["Pressure (bar)"], density_df["Density Saturated (kg/m³)"])
|
28 |
+
|
29 |
+
# Convert flow to kg/s
|
30 |
+
flow_kg_s = flow_kg_hr / 3600
|
31 |
+
|
32 |
+
# Velocity range for saturated steam
|
33 |
+
velocity = 30 # Mid-range velocity in m/s
|
34 |
+
|
35 |
+
# Calculate required pipe diameter (m)
|
36 |
+
diameter_m = np.sqrt((4 * flow_kg_s) / (np.pi * velocity * density))
|
37 |
+
|
38 |
+
# Convert to mm
|
39 |
+
return round(diameter_m * 1000, 1)
|
40 |
+
|
41 |
+
# Streamlit UI
|
42 |
+
st.title("Steam Pipe Line Size Validator")
|
43 |
+
|
44 |
+
num_lines = st.number_input("Number of Lines to Validate", min_value=1, step=1)
|
45 |
+
|
46 |
+
data = []
|
47 |
+
if num_lines:
|
48 |
+
for i in range(num_lines):
|
49 |
+
st.subheader(f"Line {i+1}")
|
50 |
+
name = st.text_input(f"Line {i+1} Name", key=f"name_{i}")
|
51 |
+
flow = st.number_input(f"Flow (Kg/hr) for Line {i+1}", min_value=1.0, step=0.1, key=f"flow_{i}")
|
52 |
+
pressure = st.number_input(f"Pressure (bar) for Line {i+1}", min_value=1.0, step=0.1, key=f"pressure_{i}")
|
53 |
+
present_size = st.number_input(f"Present Line Size (mm) for Line {i+1}", min_value=1.0, step=0.1, key=f"size_{i}")
|
54 |
+
data.append([name, round(flow), round(pressure), round(present_size)])
|
55 |
+
|
56 |
+
if st.button("Validate All Lines"):
|
57 |
+
validated_data = []
|
58 |
+
for entry in data:
|
59 |
+
name, flow, pressure, present_size = entry
|
60 |
+
new_size = calculate_new_line_size(flow, pressure, density_df)
|
61 |
+
nearest_commercial_size = get_nearest_commercial_size(new_size)
|
62 |
+
|
63 |
+
# Allow minor tolerance
|
64 |
+
tolerance = 5 # ±5 mm
|
65 |
+
status = "Yes" if abs(new_size - present_size) <= tolerance else "No"
|
66 |
+
|
67 |
+
validated_data.append([name, flow, pressure, present_size, new_size, nearest_commercial_size, status])
|
68 |
+
|
69 |
+
df_result = pd.DataFrame(validated_data, columns=[
|
70 |
+
"Line Name", "Flow (Kg/hr)", "Pressure (bar)", "Present Size (mm)",
|
71 |
+
"New Size (mm)", "Commercial Size (mm)", "Valid"
|
72 |
+
])
|
73 |
+
|
74 |
+
# Apply styling
|
75 |
+
def highlight_status(val):
|
76 |
+
return 'background-color: green; color: white;' if val == "Yes" else 'background-color: red; color: white;'
|
77 |
+
|
78 |
+
st.dataframe(df_result.style.applymap(highlight_status, subset=["Valid"]))
|
79 |
+
|
80 |
+
# Convert DataFrame to Excel file in-memory
|
81 |
+
output = io.BytesIO()
|
82 |
+
with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
|
83 |
+
df_result.to_excel(writer, index=False, sheet_name="Validated Lines")
|
84 |
+
|
85 |
+
# Download button
|
86 |
+
st.download_button(
|
87 |
+
"Download Excel File",
|
88 |
+
data=output.getvalue(),
|
89 |
+
file_name="validated_steam_lines.xlsx",
|
90 |
+
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
91 |
+
)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
pandas
|
2 |
+
numpy
|
3 |
+
streamlit
|
steam_density.csv
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Pressure (bar),Density Saturated (kg/m³)
|
2 |
+
1,0.6
|
3 |
+
2,0.848528137423857
|
4 |
+
3,1.0392304845413263
|
5 |
+
4,1.2
|
6 |
+
5,1.3416407864998738
|
7 |
+
6,1.4696938456699067
|
8 |
+
7,1.5874507866387544
|
9 |
+
8,1.697056274847714
|
10 |
+
9,1.7999999999999998
|
11 |
+
10,1.8973665961010275
|
12 |
+
11,1.9899748742132397
|
13 |
+
12,2.0784609690826525
|
14 |
+
13,2.1633307652783933
|
15 |
+
14,2.244994432064365
|
16 |
+
15,2.32379000772445
|
17 |
+
16,2.4
|
18 |
+
17,2.473863375370596
|
19 |
+
18,2.545584412271571
|
20 |
+
19,2.615339366124404
|
21 |
+
20,2.6832815729997477
|
22 |
+
21,2.7495454169735036
|
23 |
+
22,2.814249455894058
|
24 |
+
23,2.8774989139876315
|
25 |
+
24,2.9393876913398134
|
26 |
+
25,3.0
|
27 |
+
26,3.0594117081556704
|
28 |
+
27,3.117691453623979
|
29 |
+
28,3.1749015732775088
|
30 |
+
29,3.2310988842807022
|
31 |
+
30,3.2863353450309964
|
32 |
+
31,3.3406586176980126
|
33 |
+
32,3.394112549695428
|
34 |
+
33,3.4467375879228173
|
35 |
+
34,3.4985711369071804
|
36 |
+
35,3.5496478698597698
|
37 |
+
36,3.5999999999999996
|
38 |
+
37,3.6496575181789312
|
39 |
+
38,3.6986484017813854
|
40 |
+
39,3.746998799039039
|
41 |
+
40,3.794733192202055
|
42 |
+
41,3.841874542459709
|
43 |
+
42,3.888444419044716
|
44 |
+
43,3.9344631145812
|
45 |
+
44,3.9799497484264794
|
46 |
+
45,4.024922359499621
|
47 |
+
46,4.069397989875161
|
48 |
+
47,4.113392760240626
|
49 |
+
48,4.156921938165305
|
50 |
+
49,4.2
|
51 |
+
50,4.242640687119285
|