浏览代码

q-value calculated

Egor 2 年之前
父节点
当前提交
735b34e668

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+# Editor-based HTTP Client requests
+/httpRequests/

+ 8 - 0
.idea/calc-factor-of-vna.iml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 20 - 0
.idea/inspectionProfiles/Project_Default.xml

@@ -0,0 +1,20 @@
+<component name="InspectionProjectProfileManager">
+  <profile version="1.0">
+    <option name="myName" value="Project Default" />
+    <inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
+      <option name="ignoredErrors">
+        <list>
+          <option value="N806" />
+        </list>
+      </option>
+    </inspection_tool>
+    <inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
+      <option name="ignoredIdentifiers">
+        <list>
+          <option value="list.__getitem__" />
+          <option value="str.decode" />
+        </list>
+      </option>
+    </inspection_tool>
+  </profile>
+</component>

+ 6 - 0
.idea/inspectionProfiles/profiles_settings.xml

@@ -0,0 +1,6 @@
+<component name="InspectionProjectProfileManager">
+  <settings>
+    <option name="USE_PROJECT_PROFILE" value="false" />
+    <version value="1.0" />
+  </settings>
+</component>

+ 4 - 0
.idea/misc.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/calc-factor-of-vna.iml" filepath="$PROJECT_DIR$/.idea/calc-factor-of-vna.iml" />
+    </modules>
+  </component>
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 0 - 0
source/backend/__init__.py


+ 44 - 4
source/backend/calc.py

@@ -1,6 +1,20 @@
 import numpy as np
 
 
+def open_file(path):
+    """depends on the format of file we open"""
+    freq, re, im = [], [], []
+    with open(path) as f:
+        for line in f:
+            temp = line[:-1].split('   ')
+            for i in range(3):
+                temp[i] = temp[i].replace(" ", "")
+            freq.append(float(temp[0]))
+            re.append(float(temp[1]))
+            im.append(float(temp[2]))
+    return freq, re, im
+
+
 def prepare_data(freq, re, im):
     """the function takes raw data and gives vectors of eq (8)"""
     fl = freq[re.index(max(re))]
@@ -11,7 +25,7 @@ def prepare_data(freq, re, im):
     for i in range(0, len(freq)):
         # filling vectors
         t = 2 * (freq[i] - fl) / f0
-        g = re[i] + im[i] * j
+        g = re[i] + im[i] * 1j
         e1.append(t)
         e2.append(1)
         e3.append(-t * g)
@@ -21,8 +35,34 @@ def prepare_data(freq, re, im):
     return data
 
 
-def scalar_product():
-    pass
+def solution(data):
+    """ takes projections of equation (8) on vectors e1, e2, e3 and solves the equations"""
+    c = []  # matrix of the system
+    b = []  # matrix extension
+    for i in range(3):
+        c1 = np.vdot(data[i], data[4] * data[0])
+        c2 = np.vdot(data[i], data[4] * data[1])
+        c3 = np.vdot(data[i], data[4] * data[2])
+        c.append([c1, c2, c3])
+        b.append(np.vdot(data[i], data[4] * data[3]))
+    a = np.linalg.solve(c, b)
+    return a
+
+
+def q_factor(a):
+    """calculation of result"""
+    Ql = a[2].imag  # Q-factor of loaded resonator
+    d = abs(a[1] - a[0] / a[2])  # diameter of circle
+    k = 1 / (2 / d - 1)
+    Q = Ql * (1 + k)  # Q-factor = result
+    return Q
+
 
+def calculate(path):
+    """applies all functions"""
+    freq, re, im = open_file(path)
+    data = prepare_data(freq, re, im)
+    a = solution(data)
+    Q = q_factor(a)
+    return Q
 
-print(prepare_data([1, 2, 3, 4, 5, 6, 7, 8], [1, 3, 5, 6, 7, 8, 6, 3], [-1, 1, -2, -3, -4, 2, 5, 7]))

+ 1 - 1
source/frontend/front.py

@@ -11,7 +11,7 @@ absolute_path = os.path.abspath(__file__)
 
 # adding /backend to use functions from it here
 sys.path.insert(0, "/".join(os.path.dirname(absolute_path).split('/')[:-1]))
-from backend.calc import *
+from ..backend.calc import *
 
 # ../../resource/data/1_M450.MEA
 with open("/".join(os.path.dirname(absolute_path).split('/')[:-2]) + "/resource/data/1_M450.MEA") as f: