ソースを参照

add main.py & move program start there

ricet8ur 2 年 前
コミット
1e256f07f6
4 ファイル変更37 行追加55 行削除
  1. 2 1
      README.md
  2. 1 1
      TODO.md
  3. 30 53
      source/frontend/front.py
  4. 4 0
      source/main.py

+ 2 - 1
README.md

@@ -1,5 +1,6 @@
 # calc-factor-of-vna
+
 Calculation of Random and Systematic Uncertainties of Reflection-Type Q-factor measurement with automatic vector network analyzer
 
 How to start:
-streamlit run front.py
+streamlit run source/main.py

+ 1 - 1
TODO.md

@@ -4,7 +4,7 @@
     * What does it do?
     * What is Q circle?
     * What data formats are supported?
-2. Change startup file to main.py and remove os and sys calls from frontend. Pass calc function to frontend function as an argument.
+2. [x] Change startup file to main.py and remove os and sys calls from frontend. Pass calc function to frontend function as an argument.
 3. Add validation of separator + convertor to std backend input
 4. Should we apply corrections for coupling losses? - yes, please add this option.
 5. Draw continuous Q circle on a Smith chart using coefficients a[0..2]

+ 30 - 53
source/frontend/front.py

@@ -1,18 +1,6 @@
 import streamlit as st
 import matplotlib.pyplot as plt
 import numpy as np
-import sys
-  
-### don't do it this way!
-import os
-absolute_path = os.path.abspath(__file__)
-# print("Full path: " + absolute_path)
-# print("Directory Path: " + os.path.dirname(absolute_path))
-
-# adding /backend to use its functions here
-sys.path.append("/".join(os.path.dirname(absolute_path).split('/')[:-1]))
-# print("/".join(os.path.dirname(absolute_path).split('/')[:-1]))
-from backend.calc import *
 
 def plot_data(r,i, g):
     # unit circle
@@ -50,55 +38,44 @@ def plot_data(r,i, g):
     st.pyplot(fig)
 
 
-# ../../resource/data/1_M450.MEA
-# with open("/".join(os.path.dirname(absolute_path).split('/')[:-2]) + "/resource/data/1_M450.MEA") as f:
-#     row = f.readlines()
-#     f, r, i = [], [], []
-#     for x in row:
-#         a, b, c = (float(y) for y in x.split())
-#         f.append(a)  # frequency
-#         r.append(b)  # Re of something
-#         i.append(c)  # Im of something
-#     plot_data(r,i)
+def run(calc_function):
+    data = []
+    uploaded_file = st.file_uploader('Upload a csv')
+    if uploaded_file is not None:
+        data = uploaded_file.readlines()
 
-### move all that into to a function
-data = []
-uploaded_file = st.file_uploader('Upload a csv')
-if uploaded_file is not None:
-    data = uploaded_file.readlines()
 
+    col1, col2 = st.columns(2)
 
-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_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',['","' ,'" "','";"'])
 
-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)  # frequency
+            r.append(b)  # Re of S11
+            i.append(c)  # Im of S11
+        return f, r, i, 'very nice'
 
-def unpack_data(data):
-    f, r, i = [], [], []  
-    for x in data:
-        a, b, c = (float(y) for y in x.split())
-        f.append(a)  # frequency
-        r.append(b)  # Re of S11
-        i.append(c)  # Im of S11
-    return f, r, i, 'very nice'
+    validator_status = 'nice'
+    # calculate
+    circle_params=[]
+    if len(data) > 0:
+        f,r,i,validator_status = unpack_data(data)
 
-validator_status = 'nice'
-# calculate
-circle_params=[]
-if len(data) > 0:
-    f,r,i,validator_status = unpack_data(data)
-    
-    Q0,sigmaQ0,QL,sigmaQl, circle_params =fl_fitting(f,r,i)
-    st.write("Cable attenuation")
-    st.write(f"Q0 = {Q0} +- {sigmaQ0}, epsilon Q0 ={sigmaQ0/Q0}")
-    st.write(f"QL = {QL} +- {sigmaQl}, epsilon QL ={sigmaQl/QL}")
+        Q0,sigmaQ0,QL,sigmaQl, circle_params =calc_function(f,r,i)
+        st.write("Cable attenuation")
+        st.write(f"Q0 = {Q0} +- {sigmaQ0}, epsilon Q0 ={sigmaQ0/Q0}")
+        st.write(f"QL = {QL} +- {sigmaQl}, epsilon QL ={sigmaQl/QL}")
 
 
-st.write("Status: " +validator_status)
+    st.write("Status: " +validator_status)
 
-if len(data) > 0:
-    f,r,i,validator_status = unpack_data(data)
-    plot_data(r,i,circle_params)
-  
+    if len(data) > 0:
+        f,r,i,validator_status = unpack_data(data)
+        plot_data(r,i,circle_params)
+    

+ 4 - 0
source/main.py

@@ -0,0 +1,4 @@
+import backend.calc as calc
+import frontend.front as front
+
+front.run(calc.fl_fitting)