ce-dric commited on
Commit
0a423b3
·
1 Parent(s): ce42e20

upload initial

Browse files
Files changed (2) hide show
  1. app.py +57 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import matplotlib.pyplot as plt
5
+ from sklearn.linear_model import LinearRegression
6
+
7
+ st.title("Phase Error Analysis")
8
+
9
+ # File Uploaders
10
+ de_sim_file = st.file_uploader("Upload simulation CSV", type="csv")
11
+ de_exp_file = st.file_uploader("Upload experiment CSV", type="csv")
12
+
13
+ if de_sim_file and de_exp_file:
14
+ # Read CSV files
15
+ sim_data = pd.read_csv(de_sim_file, header=None)
16
+ exp_data = pd.read_csv(de_exp_file, header=None)
17
+
18
+ # User input for line number
19
+ line_num = st.slider("Select line number", 0, min(sim_data.shape[0], exp_data.shape[0])-1, 1499)
20
+
21
+ x_values = np.arange(3000)
22
+ sim_selected_row = sim_data.iloc[line_num, :3000]
23
+ exp_selected_row = exp_data.iloc[line_num, :3000]
24
+
25
+ # Linear Regression for simulation and experiment
26
+ sim_linear_reg = LinearRegression()
27
+ exp_linear_reg = LinearRegression()
28
+
29
+ sim_linear_reg.fit(x_values.reshape(-1, 1), sim_selected_row)
30
+ exp_linear_reg.fit(x_values.reshape(-1, 1), exp_selected_row)
31
+
32
+ sim_pred_values = sim_linear_reg.predict(np.arange(3000).reshape(-1, 1))
33
+ exp_pred_values = exp_linear_reg.predict(np.arange(3000).reshape(-1, 1))
34
+
35
+ # Cacluate as percentage
36
+ chkbox = st.checkbox("Calculate as percentage")
37
+
38
+ sim_diff = sim_selected_row - sim_pred_values
39
+ exp_diff = exp_selected_row - exp_pred_values
40
+
41
+ if chkbox:
42
+ sim_diff = sim_diff / (2 * np.pi) * 100
43
+ exp_diff = exp_diff / (2 * np.pi) * 100
44
+
45
+ # Plotting
46
+ plt.figure(figsize=(20, 6))
47
+ plt.plot(np.arange(500, 2500), exp_diff[500:2500], color='red', linestyle='-', label='experiment')
48
+ plt.plot(np.arange(500, 2500), sim_diff[500:2500], color='blue', linestyle='--', label='simulation')
49
+ plt.xlabel('x')
50
+ if chkbox:
51
+ plt.ylabel('phase error(%)')
52
+ else:
53
+ plt.ylabel('phase error(rad)')
54
+ plt.legend()
55
+ plt.grid(True)
56
+
57
+ st.pyplot(plt)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ matplotlib
2
+ scikit-learn