generated from streamlit/app-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamlit_app.py
More file actions
186 lines (145 loc) · 7.13 KB
/
streamlit_app.py
File metadata and controls
186 lines (145 loc) · 7.13 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
from threading import RLock
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
import plotly.figure_factory as ff
st.title('💨 CO2 BCA App')
st.info('This app help in analyzing CO2 breakthrough curves')
with st.expander('Data'):
st.write('**Raw data**')
df = pd.read_csv('https://raw.githubusercontent.com/Ezio-droid/data/refs/heads/main/combine_data_r10.dat', delim_whitespace=True, header=None)
df['time (sec)'] = df[0] - df.iloc[0,0]
df
#with st.expander('Data visualization'):
# _lock = RLock()
# x = df['time (sec)'].values
# y = df.iloc[:,5].values
# with _lock:
# fig, ax = plt.subplots()
# ax.scatter(x,y, s=1)
# plt.xlabel('Time (sec)')
# plt.ylabel('CO2 concentration (%)')
# plt.grid(True)
# st.pyplot(fig)
with st.expander('Data visualization'):
x = df['time (sec)'].values
y = df.iloc[:,5].values
fig = px.scatter(x= df['time (sec)'].values,y= df.iloc[:,5].values,
labels={'x': 'Time (sec)', 'y': '% CO2'},
title='Scatter Plot')
fig.update_traces(marker=dict(size=2)) # Adjust marker size
fig.update_layout(
template='plotly_white',
xaxis=dict(showgrid=True),
yaxis=dict(showgrid=True),
#width=900,
#height=400
)
st.plotly_chart(fig, theme="streamlit", use_container_width=True)
#Parameters
with st.sidebar:
st.header('Input features')
st.subheader('Adsorption', divider=True)
flow_rate_a = st.slider("Flow Rate Adsorption (sccm)", min_value=1.00, max_value=500.00, value=111.00)
start_time_a = st.slider("Start Time Adsorption (sec)", min_value=0, max_value=36000, value=0)
end_time_a = st.slider("End Time Adsorption (sec)", min_value=0, max_value=36000, value=600)
initial_conc_a = st.slider("Initial concentration Adsorption (%CO2)", min_value=1.00, max_value=15.00, value=0.01)
st.subheader('Desorption', divider=True)
flow_rate_d = st.slider("Flow Rate Desorption (sccm)", min_value=1.00, max_value=500.00, value=111.00)
start_time_d = st.slider("Start Time Desorption (sec)", min_value=0, max_value=36000, value=0)
end_time_d = st.slider("End Time Desorption (sec)", min_value=0, max_value=36000, value=600)
initial_conc_d = st.slider("Initial concentration Desorption (%CO2)", min_value=-1.00, max_value=15.00, value=0.01)
#Data frame for input features
input_data_a = {'flow_rate_ads':flow_rate_a,
'start_time_ads':start_time_a,
'end_time_ads':end_time_a,
'initial_conc_ads':initial_conc_a}
input_data_d = {'flow_rate_des':flow_rate_d,
'start_time_des':start_time_d,
'end_time_des':end_time_d,
'initial_conc_des':initial_conc_d}
with st.expander('Input parameters'):
st.badge("Adsorption",icon=":material/check:", color="green")
input_df_a = pd.DataFrame(input_data_a, index=[0])
edited_df_a = st.data_editor(input_df_a)
#edited_df_a
st.badge("Desorption", icon=":material/check:", color="green")
input_df_d = pd.DataFrame(input_data_d, index=[0])
edited_df_d = st.data_editor(input_df_d)
mask_a = (x >= start_time_a) & (x <= end_time_a)
mask_d = (x >= start_time_d) & (x <= end_time_d)
x_filtered_a = x[mask_a]
x_filtered_d = x[mask_d]
y_filtered_a = y[mask_a]
y_filtered_d = y[mask_d]
y_diff_a = np.abs(y_filtered_a - initial_conc_a)
area_percentage_co2_sec_a = np.trapz(y_diff_a, x_filtered_a)
area_fractional_co2_sec_a = area_percentage_co2_sec_a / 100
volume_cm3_a = area_fractional_co2_sec_a * (flow_rate_a / 60)
y_diff_d = np.abs(y_filtered_d - initial_conc_d)
area_percentage_co2_sec_d = np.trapz(y_diff_d, x_filtered_d)
area_fractional_co2_sec_d = area_percentage_co2_sec_d / 100
volume_cm3_d = area_fractional_co2_sec_d * (flow_rate_d / 60)
#with st.expander('Visualization od adsorbed volume'):
# _lock = RLock()
# with _lock:
# fig, ax = plt.subplots()
# plt.plot(x_filtered, y_filtered, label= 'CO2 concentration')
# plt.axhline(y=initial_conc, color= 'r', linestyle='--', label= f'y = {initial_conc}')
# plt.fill_between(x_filtered, y_filtered, initial_conc, where=(y_filtered > initial_conc), interpolate=True, alpha=0.3)
# plt.fill_between(x_filtered, y_filtered, initial_conc, where=(y_filtered < initial_conc), interpolate=True, alpha=0.3)
# plt.xlabel('Time (sec)')
# plt.ylabel('CO2 concentration (%)')
# plt.grid(True)
# plt.legend()
# plt.title('CO2 Concentration vs Time within the specified range')
# st.pyplot(fig)
with st.expander('Visualization of adsorbed volume'):
fig_ads = go.Figure()
# Line plot for CO2 concentration
fig_ads.add_trace(go.Scatter(x=x_filtered_a/60, y=y_filtered_a, mode='lines', name='CO2 concentration'))
# Horizontal line for initial concentration
fig_ads.add_trace(go.Scatter(x=x_filtered_a/60, y=[initial_conc_a]*len(x_filtered_a/60), mode='lines',
line=dict(color='red', dash='dash'), name=f'y = {initial_conc_a}'))
# Shaded area above and below initial concentration
fig_ads.add_trace(go.Scatter(x=x_filtered_a/60, y=y_filtered_a, fill='tonexty', mode='none',
fillcolor='rgba(0,100,200,0.3)', name='Above Initial Conc'))
fig_ads.add_trace(go.Scatter(x=x_filtered_a/60, y=[initial_conc_a]*len(x_filtered_a/60), fill='tonexty', mode='none',
fillcolor='rgba(200,100,0,0.3)', name='Below Initial Conc'))
fig_ads.update_layout(
title='CO2 Concentration vs Time within the specified range',
xaxis_title='Time (min)',
yaxis_title='CO2 concentration (%)',
template='plotly_white',
xaxis=dict(showgrid=True),
yaxis=dict(showgrid=True)
)
st.plotly_chart(fig_ads, theme="streamlit", use_container_width=True)
with st.expander('CO2 adsorbed volume (cm3)'):
volume_cm3_a
with st.expander('Visualization of desorbed volume'):
fig_des = go.Figure()
# Line plot for CO2 concentration
fig_des.add_trace(go.Scatter(x=x_filtered_d/60, y=y_filtered_d, mode='lines', name='CO2 concentration'))
# Horizontal line for initial concentration
fig_des.add_trace(go.Scatter(x=x_filtered_d/60, y=[initial_conc_d]*len(x_filtered_d/60), mode='lines',
line=dict(color='red', dash='dash'), name=f'y = {initial_conc_d}'))
# Shaded area above and below initial concentration
fig_des.add_trace(go.Scatter(x=x_filtered_d/60, y=y_filtered_d, fill='tonexty', mode='none',
fillcolor='rgba(0,100,200,0.3)', name='Above Initial Conc'))
fig_des.add_trace(go.Scatter(x=x_filtered_d/60, y=[initial_conc_d]*len(x_filtered_d/60), fill='tonexty', mode='none',
fillcolor='rgba(200,100,0,0.3)', name='Below Initial Conc'))
fig_des.update_layout(
title='CO2 Concentration vs Time within the specified range',
xaxis_title='Time (min)',
yaxis_title='CO2 concentration (%)',
template='plotly_white',
xaxis=dict(showgrid=True),
yaxis=dict(showgrid=True)
)
st.plotly_chart(fig_des, theme="streamlit", use_container_width=True)
with st.expander('CO2 desorbed volume (cm3)'):
volume_cm3_d