-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFluidsLab_interface.py
More file actions
175 lines (145 loc) · 7.03 KB
/
FluidsLab_interface.py
File metadata and controls
175 lines (145 loc) · 7.03 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
import json
import numpy as np
import streamlit as st
from numpy import sin, arcsin, cos, arccos, tan, arctan, pi, sqrt, log, exp, deg2rad
from pathlib import Path
from streamlit_code.sandbox import sandbox_chart
from streamlit_code.pair_plot import pairplot
from streamlit_code.nullspace import explore_nullspace
from streamlit_code.csv_processor import process_csv
from streamlit_code.buckingham_pi import buckingham_pi_reduction
from streamlit_code.streamlit_util import add_constants, Plotter
from streamlit_code.image_processor import process_image
from streamlit_code.auto_exploration import explore_pi_groups
from general_dimensional_analysis.data_reader import Data
from governing_equations.navier_stokes import NavierStokes
sind = lambda degrees: sin(deg2rad(degrees))
cosd = lambda degrees: cos(deg2rad(degrees))
tand = lambda degrees: tan(deg2rad(degrees))
@st.cache_data
def read_markdown_file(markdown_file):
return Path(markdown_file).read_text()
st.set_page_config(page_title="Data Processor", layout="wide")
@st.cache_data
def file_reader(file):
dataframe = Data.csv_to_dataframe(file)
st.subheader('Original Data')
st.dataframe(dataframe)
return df_to_group(dataframe), dataframe
@st.cache_data
def df_to_group(dataframe):
group, labels = Data.dataframe_to_group(dataframe)
return group, labels
def image_options(files):
st.subheader('Edges Detection and Contour Tracking')
with st.expander('Instructions'):
st.write('Upload images and then select the number of operations to perform on the image. A typical place to start is to crop the image to show just the region of interest, then search for edges with canny.')
process_image(files)
def csv_options(file):
st.subheader('Dimensional Analysis')
# with st.expander('What is Dimensional Analysis?'):
# intro_markdown = read_markdown_file("buckingham_pi.md")
# st.markdown(intro_markdown)
tab1, tab2, tab3 = st.tabs(['Analysis', 'Global Plot Options', 'Data Table'])
p = Plotter()
with tab3:
(group, labels), dataframe = file_reader(file)
p.set_labels(labels)
if 'operation_dict' not in st.session_state:
st.session_state['operation_dict'] = {name[0]: ('x', lambda x: x) for name in dataframe.columns}
include_labels = []
col1, col2 = st.columns(2)
with col1:
st.subheader('Modify')
selected = st.selectbox('Edit', [name[0] for name in dataframe.columns])
# st.write(st.session_state['operation_dict'][selected][0])
operation = st.text_input('formula', value=st.session_state['operation_dict'][selected][0], key=selected, help='Use x as the variable to represent the variable being modified. Availbe functions include: sin, sind, arcsin, cos, cosd, arcos, tan, arctan, pi, sqrt, log, and exp. Note: to raise a value to a power use ** instead of the commonly used ^.')
if operation == '':
operation = 'x'
st.session_state['operation_dict'][selected] = operation, lambda x: eval(operation)
# with col2:
# st.subheader('Add')
# name = st.text_input('Name')
# units = st.text_input('Units')
# input_values = st.text_input('Values')
# if input_values:
# values = np.array(input_values.split(','), dtype=float)
# dataframe[name, units] = values
with col2:
if labels:
st.subheader('Filter')
for parameter in st.session_state['operation_dict']:
dataframe[parameter] = dataframe[parameter].apply(st.session_state['operation_dict'][parameter][1])
for label in set(labels):
if st.checkbox(f'{label}', value=True):
include_labels.append(label)
mask = [item in include_labels for item in dataframe['Label'].values]
st.subheader('Edited Data')
dataframe = st.experimental_data_editor(dataframe[mask]) if labels else st.experimental_data_editor(dataframe)
group, labels = df_to_group(dataframe)
with tab2:
p.options(group)
p.set_masks(labels)
supplemented_group = add_constants(group)
option = st.sidebar.selectbox('Select the type of analysis to be completed', ('Select an Option',
'Pair Plot',
'Sandbox',
'Buckingham Pi',
'Auto Exploration'))
# jsonStr = json.dumps(p)
# st.write(p.__dict__)
with tab1:
# if option == 'Buckingham Pi':
# process_csv()
if option == 'Sandbox':
sandbox_chart(supplemented_group, p)
elif option == 'Buckingham Pi':
buckingham_pi_reduction(supplemented_group, p)
elif option == 'Auto Exploration':
explore_pi_groups(supplemented_group, p)
elif option == 'Pair Plot':
pairplot(group)
def governing_equations():
st.subheader('Find the Governing Equations')
ns = NavierStokes()
assumptions = st.text_input('Assumptions', value='2D, no gravity, steady', help="Acceptable assumptions: no gravity, steady, u=0, 2D, constant pressure, inviscid, external flow")
assumptions = [assume.strip() for assume in assumptions.split(',')]
eqn_x, eqn_y, eqn_z = ns.simplify_naiver(assumptions)
st.markdown('The $Navier$-$Stokes$ equations are:')
st.markdown(f'x-direction: {eqn_x}')
st.markdown(f'y-direction: {eqn_y}')
st.markdown(f'z-direction: {eqn_z}')
# st.set_page_config(layout="wide")
st.title("Data Processor")
uploaded_file = st.sidebar.file_uploader('File', type=['csv', 'tif', 'png', 'jpg', 'jpeg'], accept_multiple_files=True)
if uploaded_file:
if uploaded_file[0].name[-3:] == 'csv':
csv_options(uploaded_file[0])
else:
image_options(uploaded_file)
else:
instructions = 'Upload either images or data in a csv file'
with st.expander('Instructions', expanded=True):
st.markdown(instructions)
st.markdown('### Instructions for Uploading a CSV File')
st.image(r'information_files/basic_table.png')
st.markdown(Path(r'information_files/csv_file.md').read_text())
with st.expander('BETA feature: Governing Equations'):
governing_equations()
# if 'stuff' not in st.session_state:
# st.session_state['stuff'] = {}
# # st.write(st.session_state.stuff)
#
# item = tuple(st.text_input('stuff_adder').split())
# if item and item not in st.session_state.stuff:
# st.session_state.stuff[item] = True
#
# # st.write
# st.write(st.session_state.stuff)
# for element in st.session_state.stuff:
# if st.checkbox(element, value=True):
# st.session_state.stuff[element] = True
# else:
# # st.write('remove')
# st.session_state.stuff[element] = False
# st.write(st.session_state.stuff)