123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import streamlit as st
- import matplotlib.pyplot as plt
- import numpy as np
- import sys
-
- import os
- absolute_path = os.path.abspath(__file__)
- sys.path.append("/".join(os.path.dirname(absolute_path).split('/')[:-1]))
- from backend.calc import *
- def plot_data(r,i):
-
- unit_circle_x = []
- unit_circle_y = []
- for x in np.arange(-1, 1, 0.01):
- unit_circle_x.append(x)
- unit_circle_y.append((1-x**2)**0.5)
- unit_circle_x.append(1)
- unit_circle_y.append(0)
- for x in np.arange(-1, 1, 0.01)[::-1]:
- unit_circle_x.append(x)
- unit_circle_y.append(-(1-x**2)**0.5)
- fig, ax = plt.subplots()
- ax.plot(unit_circle_x, unit_circle_y)
-
-
- ax.plot(r, i)
-
- ax.grid(True)
- ax.axis('square')
- ax.set_yticks(np.arange(-1, 1.2, 0.2))
- ax.set_yticks(np.arange(-1, 1.2, 0.2))
- st.pyplot(fig)
- data = []
- uploaded_file = st.file_uploader('Upload a csv')
- if uploaded_file is not None:
- data = uploaded_file.readlines()
- col1, col2 = st.columns(2)
- select_data_format = col1.selectbox('Choose data format from a list',['Frequency, Re(S11), Im(S11)','Frequency, Re(Zin), Im(Zin)'])
- select_separator = col2.selectbox('Choose separator',['","' ,'" "','";"'])
- def unpack_data(data):
- f, r, i = [], [], []
- for x in data:
- a, b, c = (float(y) for y in x.split())
- f.append(a)
- r.append(b)
- i.append(c)
- return f, r, i, 'very nice'
- validator_status = 'nice'
- if len(data) > 0:
- f,r,i,validator_status = unpack_data(data)
-
- calc_data = prepare_data(f, r, i)
- a,c,d = solution(calc_data)
- sigmaQ0=0
- for i in range(2, 10):
- calc_data = recalculation_of_data(calc_data, a, c, d)
- a, c, d = solution(calc_data)
- Ql, diam, k, Q = q_factor(a)
- sigma2A = recalculation_of_data(calc_data, a, c, d, error=True)
- sigmaQ0 = random_deviation(a, sigma2A, diam, k, Ql)
- st.write(f"Q = {Q} +- {sigmaQ0}".format(Q, sigmaQ0))
-
- st.write("Status: " +validator_status)
- if len(data) > 0:
- f,r,i,validator_status = unpack_data(data)
- plot_data(r,i)
-
|