kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
fixed db conversation bug
accidently used e^x instead of 10^x in db conversation. Added testcases for comparison in test_touchstone.pypull/143/head
rodzic
60d58015c4
commit
7aa0e335cd
|
@ -139,7 +139,7 @@ class Touchstone:
|
|||
z = cmath.rect(float(v), math.radians(float(next(vals))))
|
||||
next(data_list).append(Datapoint(freq, z.real, z.imag))
|
||||
if self.opts.format == "db":
|
||||
z = cmath.rect(math.exp(float(v) / 20), math.radians(float(next(vals))))
|
||||
z = cmath.rect(10 ** (float(v) / 20), math.radians(float(next(vals))))
|
||||
next(data_list).append(Datapoint(freq, z.real, z.imag))
|
||||
|
||||
def load(self):
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
sys.exit(1)
|
Plik diff jest za duży
Load Diff
Plik diff jest za duży
Load Diff
|
@ -21,7 +21,8 @@ from NanoVNASaver.RFTools import Datapoint, \
|
|||
norm_to_impedance, impedance_to_norm, \
|
||||
reflection_coefficient, gamma_to_impedance, clamp_value, \
|
||||
parallel_to_serial, serial_to_parallel, \
|
||||
impedance_to_capacitance, impedance_to_inductance
|
||||
impedance_to_capacitance, impedance_to_inductance, \
|
||||
groupDelay
|
||||
import math
|
||||
|
||||
|
||||
|
@ -77,7 +78,7 @@ class TestRFTools(unittest.TestCase):
|
|||
complex(50, 10))
|
||||
|
||||
def test_serial_to_parallel(self):
|
||||
self.assertRaises(ZeroDivisionError, serial_to_parallel, 0)
|
||||
self.assertEqual(serial_to_parallel(0),0)
|
||||
self.assertAlmostEqual(
|
||||
serial_to_parallel(complex(50, 10)),
|
||||
complex(52, 260))
|
||||
|
@ -95,6 +96,20 @@ class TestRFTools(unittest.TestCase):
|
|||
impedance_to_inductance(complex(50, 159.1549), 100000),
|
||||
2.533e-4)
|
||||
|
||||
def test_groupDelay(self):
|
||||
dpoints = [
|
||||
Datapoint(100000, 0.1091, 0.3118),
|
||||
Datapoint(100001, 0.1091, 0.3124),
|
||||
Datapoint(100002, 0.1091, 0.3130),
|
||||
]
|
||||
dpoints0 = [
|
||||
Datapoint(100000, 0.1091, 0.3118),
|
||||
Datapoint(100000, 0.1091, 0.3124),
|
||||
Datapoint(100000, 0.1091, 0.3130),
|
||||
]
|
||||
self.assertAlmostEqual(groupDelay(dpoints, 1), -9.514e-5)
|
||||
self.assertEqual(groupDelay(dpoints0, 1), 0.0)
|
||||
|
||||
|
||||
class TestRFToolsDatapoint(unittest.TestCase):
|
||||
|
||||
|
@ -102,6 +117,7 @@ class TestRFToolsDatapoint(unittest.TestCase):
|
|||
self.dp = Datapoint(100000, 0.1091, 0.3118)
|
||||
self.dp0 = Datapoint(100000, 0, 0)
|
||||
self.dp50 = Datapoint(100000, 1, 0)
|
||||
self.dp75 = Datapoint(100000, 0.2, 0)
|
||||
|
||||
def test_properties(self):
|
||||
self.assertEqual(self.dp.z, complex(0.1091, 0.3118))
|
||||
|
@ -115,4 +131,7 @@ class TestRFToolsDatapoint(unittest.TestCase):
|
|||
self.assertAlmostEqual(self.dp.impedance(75),
|
||||
complex(74.99628755, 52.49617517))
|
||||
self.assertEqual(self.dp0.qFactor(), 0.0)
|
||||
self.assertEqual(self.dp75.qFactor(), 0.0)
|
||||
self.assertAlmostEqual(self.dp.qFactor(), 0.6999837)
|
||||
self.assertAlmostEqual(self.dp.capacitiveEquivalent(), -4.54761539e-08)
|
||||
self.assertAlmostEqual(self.dp.inductiveEquivalent(), 5.57001e-05)
|
||||
|
|
|
@ -73,6 +73,16 @@ class TestTouchstoneTouchstone(unittest.TestCase):
|
|||
self.assertEqual(len(ts.s22data), 1020)
|
||||
self.assertIn("! Vector Network Analyzer VNA R2", ts.comments)
|
||||
|
||||
def test_db_conversation(self):
|
||||
ts_db = Touchstone("./test/data/attenuator-0643_DB.s2p")
|
||||
ts_db.load()
|
||||
ts_ri = Touchstone("./test/data/attenuator-0643_RI.s2p")
|
||||
ts_ri.load()
|
||||
self.assertEqual(len(ts_db.s11data), len(ts_ri.s11data))
|
||||
for dps_db, dps_ri in zip(ts_db.s11data, ts_ri.s11data):
|
||||
self.assertAlmostEqual(dps_db.z, dps_ri.z, places=5)
|
||||
|
||||
|
||||
def test_load_scikit(self):
|
||||
ts = Touchstone("./test/data/scikit_unordered.s2p")
|
||||
with self.assertLogs(level=logging.WARNING) as cm:
|
||||
|
|
|
@ -31,7 +31,7 @@ import unittest
|
|||
if __name__ == '__main__':
|
||||
sys.path.append('.')
|
||||
loader = unittest.TestLoader()
|
||||
tests = loader.discover('.')
|
||||
tests = loader.discover('./test')
|
||||
testRunner = unittest.runner.TextTestRunner(
|
||||
failfast=False,
|
||||
verbosity=2)
|
||||
|
|
Ładowanie…
Reference in New Issue