ce-dric
prevent wrong index from simulator
203aa61
raw
history blame
2.09 kB
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)