| 1 |
import os |
| 2 |
import unittest |
| 3 |
|
| 4 |
import numpy as np |
| 5 |
|
| 6 |
import skrf as rf |
| 7 |
|
| 8 |
|
| 9 |
class CitiTestCase(unittest.TestCase): |
| 10 |
""" |
| 11 |
Test the IO of CITI files. |
| 12 |
""" |
| 13 |
def setUp(self): |
| 14 |
""" |
| 15 |
Sets up the test directory |
| 16 |
""" |
| 17 |
self.test_dir = os.path.dirname(os.path.abspath(__file__))+'/MDIF_CITI_MDL/' |
| 18 |
|
| 19 |
|
| 20 |
self.oneport_example1 = rf.Citi(self.test_dir + 'test_1p_citi.cti') |
| 21 |
self.oneport_example2 = rf.Citi(self.test_dir + 'test_1p_citi_2_ri.cti') |
| 22 |
self.twoport_example1 = rf.Citi(self.test_dir + 'test_2p_citi.cti') |
| 23 |
self.twoport_example2 = rf.Citi(self.test_dir + 'test_2p_citi_2.cti') |
| 24 |
self.twoport_example3 = rf.Citi(self.test_dir + 'test_2p_citi_2params.cti') |
| 25 |
self.twoport_example4 = rf.Citi(self.test_dir + 'test_2p_citi_2params_db.cti') |
| 26 |
self.twoport_example5 = rf.Citi(self.test_dir + 'test_2p_citi_3_ri.cti') |
| 27 |
self.fourport_example1 = rf.Citi(self.test_dir + 'test_4p_citi.cti') |
| 28 |
|
| 29 |
self.examples = [self.oneport_example1, self.oneport_example2, |
| 30 |
self.twoport_example1, self.twoport_example2, |
| 31 |
self.twoport_example3, self.twoport_example4, |
| 32 |
self.twoport_example5, self.fourport_example1] |
| 33 |
|
| 34 |
|
| 35 |
file = open(self.test_dir + 'test_1p_citi.cti') |
| 36 |
self.oneport_example1_from_fo = rf.Citi(file) |
| 37 |
|
| 38 |
def test_to_networks(self): |
| 39 |
""" Test if CITI data are correctly converted into Networks """ |
| 40 |
for ex in self.examples: |
| 41 |
for ntwk in ex.networks: |
| 42 |
self.assertIsInstance(ntwk, rf.Network) |
| 43 |
|
| 44 |
def test_to_networkset(self): |
| 45 |
""" Test if CITI data are correctly converted into NetworkSet """ |
| 46 |
for example in self.examples: |
| 47 |
self.assertIsInstance(example.to_networkset(), rf.NetworkSet) |
| 48 |
|
| 49 |
def test_params(self): |
| 50 |
""" Test if the params are correctly parsed from the CITI files """ |
| 51 |
self.assertEqual(self.oneport_example1.params, ['Cm']) |
| 52 |
self.assertEqual(self.twoport_example1.params, ['Cm']) |
| 53 |
self.assertEqual(self.fourport_example1.params, ['Cm']) |
| 54 |
|
| 55 |
def test_only_freq_in_var(self): |
| 56 |
""" File without any VAR except for freq should return non empty NetworkSet. """ |
| 57 |
file = self.test_dir + 'test_2p_only_freq_VAR.cti' |
| 58 |
cti = rf.Citi(file) |
| 59 |
ns = cti.to_networkset() |
| 60 |
self.assertTrue(ns) |
| 61 |
self.assertEqual(len(ns), 1) |
| 62 |
|
| 63 |
def test_values_1p_1(self): |
| 64 |
""" Test if the values are correctly parsed from the CITI files """ |
| 65 |
deg = np.array([ |
| 66 |
-0.0178919999, -0.0180179999, -0.0181439998, -0.0182699998, |
| 67 |
-0.0183959998, -0.0185219998, -0.0186479998, -0.0187739998, |
| 68 |
-0.0188999998, -0.0204479998, -0.0205919998, -0.0207359998, |
| 69 |
-0.0208799998, -0.0210239998, -0.0211679998, -0.0213119998, |
| 70 |
-0.0214559997, -0.0215999997, -0.0230039997, -0.0231659997, |
| 71 |
-0.0233279997, -0.0234899997, -0.0236519997, -0.0238139997, |
| 72 |
-0.0239759997, -0.0241379996, -0.0242999996, -0.0255599996, |
| 73 |
-0.0257399996, -0.0259199996, -0.0260999995, -0.0262799995, |
| 74 |
-0.0264599995, -0.0266399995, -0.0268199995, -0.0269999995]) |
| 75 |
f = np.array([ |
| 76 |
710000000, 715000000, 720000000, 725000000, |
| 77 |
730000000, 735000000, 740000000, 745000000, |
| 78 |
750000000, |
| 79 |
]) |
| 80 |
mag = np.ones(len(deg)) |
| 81 |
s1p_1 = rf.magdeg_2_reim(mag, deg) |
| 82 |
ns_1p_1 = self.oneport_example1.to_networkset() |
| 83 |
self.assertEqual(len(ns_1p_1), 4) |
| 84 |
self.assertEqual(len(ns_1p_1[0]), 9) |
| 85 |
np.testing.assert_array_equal(ns_1p_1[0].f, f) |
| 86 |
|
| 87 |
np.testing.assert_array_almost_equal(ns_1p_1[0].s.squeeze(), s1p_1[:9]) |
| 88 |
|
| 89 |
def test_values_1p_2(self): |
| 90 |
""" Test if the values are correctly parsed from the CITI files """ |
| 91 |
s1p_2 = np.array([ |
| 92 |
-1.31189E-3 - 1.47980E-3 * 1j, |
| 93 |
-3.67867E-3 - 0.67782E-3 * 1j, |
| 94 |
-3.43990E-3 + 0.58746E-3 * 1j, |
| 95 |
-2.70664E-4 - 9.76175E-4 * 1j, |
| 96 |
+0.65892E-4 - 9.61571E-4 * 1j]) |
| 97 |
ns_1p_2 = self.oneport_example2.to_networkset() |
| 98 |
self.assertEqual(len(ns_1p_2), 1) |
| 99 |
self.assertEqual(len(ns_1p_2[0]), len(s1p_2)) |
| 100 |
np.testing.assert_array_equal(ns_1p_2[0].f, np.array([1., 2., 3., 4., 5.])) |
| 101 |
np.testing.assert_array_almost_equal(ns_1p_2[0].s.squeeze(), s1p_2) |
| 102 |
|
| 103 |
def test_values_2p_1(self): |
| 104 |
""" Test if the values are correctly parsed from the CITI files """ |
| 105 |
mag = np.array([[[0.999999951, 0.000312274295], [0.000312274295, 0.999999951]]]) |
| 106 |
deg = np.array([[[-0.0178919994, 89.982108], [89.982108, -0.0178919994]]]) |
| 107 |
s_2p_1 = rf.magdeg_2_reim(mag, deg) |
| 108 |
f = np.array([ |
| 109 |
710000000, 715000000, 720000000, 725000000, |
| 110 |
730000000, 735000000, 740000000, 745000000, |
| 111 |
750000000, |
| 112 |
]) |
| 113 |
ns_2p_1 = self.twoport_example1.to_networkset() |
| 114 |
self.assertEqual(len(ns_2p_1), 4) |
| 115 |
self.assertEqual(len(ns_2p_1[0]), 9) |
| 116 |
np.testing.assert_array_equal(ns_2p_1[0].f, f) |
| 117 |
np.testing.assert_array_almost_equal(ns_2p_1[0].s_mag[0], mag.squeeze()) |
| 118 |
np.testing.assert_array_almost_equal(ns_2p_1[0].s_deg[0], deg.squeeze()) |
| 119 |
np.testing.assert_array_almost_equal(ns_2p_1[0].s[0], s_2p_1[0]) |
| 120 |
|
| 121 |
def test_values_2p_2(self): |
| 122 |
""" Test if the values are correctly parsed from the CITI files """ |
| 123 |
mag = np.array([ |
| 124 |
[[0.1, 0.3], |
| 125 |
[0.5, 0.7]], |
| 126 |
[[0.2, 0.4], |
| 127 |
[0.6, 0.8]] |
| 128 |
]) |
| 129 |
deg = np.array([ |
| 130 |
[[2, 4], |
| 131 |
[6, 8]], |
| 132 |
[[3, 5], |
| 133 |
[7, 9]] |
| 134 |
]) |
| 135 |
s2p_2 = rf.magdeg_2_reim(mag, deg) |
| 136 |
ns_2p_2 = self.twoport_example2.to_networkset() |
| 137 |
self.assertEqual(len(ns_2p_2), 1) |
| 138 |
self.assertEqual(len(ns_2p_2[0]), 2) |
| 139 |
np.testing.assert_array_equal(ns_2p_2[0].f, np.array([1e9, 2e9])) |
| 140 |
np.testing.assert_array_almost_equal(ns_2p_2[0].s.squeeze(), s2p_2) |
| 141 |
|
| 142 |
def test_values_4p(self): |
| 143 |
""" Test if the values are correctly parsed from the CITI files """ |
| 144 |
ns_4p = self.fourport_example1.to_networkset() |
| 145 |
self.assertEqual(len(ns_4p), 3) |
| 146 |
self.assertEqual(len(ns_4p[0]), 51) |
| 147 |
self.assertEqual(ns_4p.coords['Cm'], [9e-16, 8e-16, 7e-16]) |
| 148 |
|
| 149 |
suite = unittest.TestLoader().loadTestsFromTestCase(CitiTestCase) |
| 150 |
unittest.TextTestRunner(verbosity=2).run(suite) |