Spaces:
Sleeping
Sleeping
File size: 2,089 Bytes
0a423b3 203aa61 0a423b3 |
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 |
import streamlit as st
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
st.title("Phase Error Analysis")
# File Uploaders
de_sim_file = st.file_uploader("Upload simulation CSV", type="csv")
de_exp_file = st.file_uploader("Upload experiment CSV", type="csv")
if de_sim_file and de_exp_file:
# Read CSV files
sim_data = pd.read_csv(de_sim_file, header=None)
exp_data = pd.read_csv(de_exp_file, header=None)
center_x, center_y = sim_data.shape[1] // 2, sim_data.shape[0] // 2
sim_data = sim_data.iloc[center_y - 1500:center_y + 1500, center_x - 1500:center_x + 1500]
# User input for line number
line_num = st.slider("Select line number", 0, min(sim_data.shape[0], exp_data.shape[0])-1, 1499)
x_values = np.arange(3000)
sim_selected_row = sim_data.iloc[line_num, :3000]
exp_selected_row = exp_data.iloc[line_num, :3000]
# Linear Regression for simulation and experiment
sim_linear_reg = LinearRegression()
exp_linear_reg = LinearRegression()
sim_linear_reg.fit(x_values.reshape(-1, 1), sim_selected_row)
exp_linear_reg.fit(x_values.reshape(-1, 1), exp_selected_row)
sim_pred_values = sim_linear_reg.predict(np.arange(3000).reshape(-1, 1))
exp_pred_values = exp_linear_reg.predict(np.arange(3000).reshape(-1, 1))
# Cacluate as percentage
chkbox = st.checkbox("Calculate as percentage")
sim_diff = sim_selected_row - sim_pred_values
exp_diff = exp_selected_row - exp_pred_values
if chkbox:
sim_diff = sim_diff / (2 * np.pi) * 100
exp_diff = exp_diff / (2 * np.pi) * 100
# Plotting
plt.figure(figsize=(20, 6))
plt.plot(np.arange(500, 2500), exp_diff[500:2500], color='red', linestyle='-', label='experiment')
plt.plot(np.arange(500, 2500), sim_diff[500:2500], color='blue', linestyle='--', label='simulation')
plt.xlabel('x')
if chkbox:
plt.ylabel('phase error(%)')
else:
plt.ylabel('phase error(rad)')
plt.legend()
plt.grid(True)
st.pyplot(plt) |