| 1 |
import os |
| 2 |
import unittest |
| 3 |
|
| 4 |
import numpy as np |
| 5 |
|
| 6 |
import skrf as rf |
| 7 |
|
| 8 |
|
| 9 |
class ConvenienceTestCase(unittest.TestCase): |
| 10 |
""" |
| 11 |
""" |
| 12 |
def setUp(self): |
| 13 |
""" |
| 14 |
""" |
| 15 |
self.test_dir = os.path.dirname(os.path.abspath(__file__))+'/' |
| 16 |
self.hfss_oneport_file = os.path.join(self.test_dir, 'hfss_oneport.s1p') |
| 17 |
self.hfss_twoport_file = os.path.join(self.test_dir, 'hfss_twoport.s2p') |
| 18 |
self.hfss_threeport_file=os.path.join(self.test_dir, 'hfss_threeport_DB.s3p') |
| 19 |
self.hfss_threeport_file_50ohm=os.path.join(self.test_dir, 'hfss_threeport_DB_50Ohm.s3p') |
| 20 |
self.hfss_18dot2 = os.path.join(self.test_dir, 'hfss_18.2.s3p') |
| 21 |
self.hfss_8ports = os.path.join(self.test_dir, 'hfss_19.2.s8p') |
| 22 |
self.hfss_10ports = os.path.join(self.test_dir, 'hfss_19.2.s10p') |
| 23 |
self.ntwk1 = rf.Network(os.path.join(self.test_dir, 'ntwk1.s2p')) |
| 24 |
self.ntwk2 = rf.Network(os.path.join(self.test_dir, 'ntwk2.s2p')) |
| 25 |
self.ntwk3 = rf.Network(os.path.join(self.test_dir, 'ntwk3.s2p')) |
| 26 |
|
| 27 |
def test_hfss_high_port_number(self): |
| 28 |
""" |
| 29 |
Check dimensions s, gamma and z0 of Network from HFSS .sNp files |
| 30 |
|
| 31 |
HFSS exports .sNp files with N > 4 with Gamma and Z0 as comments and |
| 32 |
written on multiple lines. The additional lines start with a '!' that |
| 33 |
need to be escaped to avoid numerical conversion error. |
| 34 |
""" |
| 35 |
_3ports = rf.Network(self.hfss_18dot2) |
| 36 |
self.assertTrue(_3ports.s.shape[1:] == (3,3)) |
| 37 |
self.assertTrue(_3ports.z0.shape[1] == 3) |
| 38 |
self.assertTrue(_3ports.gamma.shape[1] == 3) |
| 39 |
|
| 40 |
_8ports = rf.Network(self.hfss_8ports) |
| 41 |
self.assertTrue(_8ports.s.shape[1:] == (8,8)) |
| 42 |
self.assertTrue(_8ports.z0.shape[1] == 8) |
| 43 |
self.assertTrue(_8ports.gamma.shape[1] == 8) |
| 44 |
|
| 45 |
_10ports = rf.Network(self.hfss_10ports) |
| 46 |
self.assertTrue(_10ports.s.shape[1:] == (10,10)) |
| 47 |
self.assertTrue(_10ports.z0.shape[1] == 10) |
| 48 |
self.assertTrue(_10ports.gamma.shape[1] == 10) |
| 49 |
|
| 50 |
|
| 51 |
def test_hfss_touchstone_2_media(self): |
| 52 |
""" |
| 53 |
currently, this just tests the execution ability. it would |
| 54 |
be better to simulate a uniform line, in hfss and then confirm |
| 55 |
that the hfss network is same as the one generated by the |
| 56 |
media object this function returns |
| 57 |
""" |
| 58 |
med = rf.hfss_touchstone_2_media(self.hfss_oneport_file)[0] |
| 59 |
med.line(1) |
| 60 |
med_p1,med_p2 = rf.hfss_touchstone_2_media(self.hfss_twoport_file) |
| 61 |
med_p1.line(1) |
| 62 |
med_p2.line(1) |
| 63 |
|
| 64 |
def test_hfss_touchstone_renormalization(self): |
| 65 |
""" |
| 66 |
Scattering matrices are given for a given impedance z0, |
| 67 |
which is usually assumed to be 50 Ohm, unless otherwise stated. |
| 68 |
|
| 69 |
Touchstone files are not necessarily indicating such impedances, |
| 70 |
especially if they vary with frequency. |
| 71 |
|
| 72 |
HFSS Touchstone file format supports port information (as an option) for gamma and z0 |
| 73 |
When HFSS files are read with Network() (or hfss_touchstone_2_network()), |
| 74 |
the port information are taken into account. |
| 75 |
""" |
| 76 |
|
| 77 |
nw_50 = rf.Network(self.hfss_threeport_file_50ohm) |
| 78 |
nw = rf.Network(self.hfss_threeport_file) |
| 79 |
nw.renormalize(z_new=50) |
| 80 |
self.assertTrue(np.all(np.abs(nw.s - nw_50.s) < 1e-6)) |
| 81 |
|
| 82 |
def test_is_hfss_touchstone(self): |
| 83 |
""" |
| 84 |
Test if Touchstone files have been generated by HFSS and has port |
| 85 |
impedances for each frequency point. |
| 86 |
""" |
| 87 |
|
| 88 |
self.assertTrue(rf.Touchstone(self.hfss_oneport_file).has_hfss_port_impedances) |
| 89 |
self.assertTrue(rf.Touchstone(self.hfss_twoport_file).has_hfss_port_impedances) |
| 90 |
self.assertTrue(rf.Touchstone(self.hfss_threeport_file).has_hfss_port_impedances) |
| 91 |
self.assertTrue(rf.Touchstone(self.hfss_18dot2).has_hfss_port_impedances) |
| 92 |
self.assertTrue(rf.Touchstone(self.hfss_8ports).has_hfss_port_impedances) |
| 93 |
self.assertTrue(rf.Touchstone(self.hfss_10ports).has_hfss_port_impedances) |
| 94 |
|
| 95 |
self.assertFalse(rf.Touchstone(os.path.join(self.test_dir, 'ntwk1.s2p')).has_hfss_port_impedances) |
| 96 |
|
| 97 |
def test_hfss_touchstone_2_network(self): |
| 98 |
""" |
| 99 |
Test the conversion into a Network of HFSS-generated touchstone files |
| 100 |
""" |
| 101 |
nw_hfss_wo_z0 = rf.Network(os.path.join(self.test_dir, 'hfss_threeport_MA_without_gamma_z0_50Ohm.s3p')) |
| 102 |
nw_hfss_50 = rf.Network(os.path.join(self.test_dir, 'hfss_threeport_MA_50Ohm.s3p')) |
| 103 |
nw_hfss_z0 = rf.Network(os.path.join(self.test_dir, 'hfss_threeport_MA.s3p')) |
| 104 |
|
| 105 |
self.assertTrue(np.allclose(nw_hfss_50.s, nw_hfss_wo_z0.s)) |
| 106 |
nw_hfss_z0.renormalize(50) |
| 107 |
self.assertTrue(np.allclose(nw_hfss_50.s, nw_hfss_z0.s)) |
| 108 |
|
| 109 |
def test_cst_touchstone_2_network(self): |
| 110 |
""" |
| 111 |
Test the conversion into a Network of CST-generated touchstone file |
| 112 |
""" |
| 113 |
nw_cst_4ports = rf.Network(os.path.join(self.test_dir, 'cst_example_4ports.s4p')) |
| 114 |
nw_cst_6ports = rf.Network(os.path.join(self.test_dir, 'cst_example_6ports.s6p')) |
| 115 |
|
| 116 |
def test_cst_touchstone_V2_as_V1_2_network(self): |
| 117 |
""" |
| 118 |
Test the conversion into a Network of a CST-generated |
| 119 |
touchstone V2 format file (.ts) saved like a touchstone V1 file (.sNp) |
| 120 |
""" |
| 121 |
nw_cst_6ports = rf.Network(os.path.join(self.test_dir, 'cst_example_6ports_V2.s6p')) |
| 122 |
|
| 123 |
def test_cst_touchstone_V2_2_network(self): |
| 124 |
""" |
| 125 |
Test the conversion into a Network of a CST-generated touchstone V2 format file (.ts) |
| 126 |
""" |
| 127 |
nw_cst_6ports = rf.Network(os.path.join(self.test_dir, 'cst_example_6ports_V2.ts')) |
| 128 |
|
| 129 |
def test_Agilent_touchstone_4ports(self): |
| 130 |
""" |
| 131 |
Try reading an Agilent touchstone 4-ports measurement file |
| 132 |
""" |
| 133 |
filename = 'Agilent_E5071B.s4p' |
| 134 |
ntwk = rf.Network(os.path.join(self.test_dir, filename)) |
| 135 |
|
| 136 |
self.assertTrue(np.isclose(np.unique(ntwk.z0), 75)) |
| 137 |
|
| 138 |
self.assertTrue(np.allclose(ntwk.s_db[0][1], |
| 139 |
[-5.252684e+001, -2.278388e-001, -4.435702e+001, -8.235984e+001])) |
| 140 |
self.assertTrue(np.allclose(ntwk.s_deg[0][1], |
| 141 |
[-1.350884e+002, 8.767636e+001, -1.585657e+002, 7.708928e+001])) |
| 142 |
|
| 143 |
def test_RS_touchstone_4ports(self): |
| 144 |
""" |
| 145 |
Try reading an R&S touchstone 4-ports measurement file |
| 146 |
""" |
| 147 |
filename = 'RS_ZNB8.s4p' |
| 148 |
ntwk = rf.Network(os.path.join(self.test_dir, filename)) |
| 149 |
|
| 150 |
self.assertTrue(np.isclose(np.unique(ntwk.z0), 50)) |
| 151 |
|
| 152 |
self.assertTrue(ntwk.frequency.f[np.argmin(ntwk.s11.s_mag)], 55.5e6) |
| 153 |
|
| 154 |
self.assertTrue(np.allclose(ntwk.s_re[0][2], |
| 155 |
[-9.748145748042E-6, 5.737806652221E-6, -7.2831384009613E-1, -7.2022385218772E-6])) |
| 156 |
self.assertTrue(np.allclose(ntwk.s_im[0][2], |
| 157 |
[4.4579440784571E-6, 5.3413994843693E-6, -4.5314024673959E-1, 5.6678579987964E-7])) |
| 158 |
|
| 159 |
def test_RS_ZVR_1_20_beta_f(self): |
| 160 |
""" |
| 161 |
Try reading an old R&S ZVR (v1.20 beta F, circa 1998) Touchstone 2-port |
| 162 |
measurement file. |
| 163 |
|
| 164 |
The only difference is that the file contains leading spaces and |
| 165 |
trailing spaces in in all lines, including the "#" line. Applications |
| 166 |
should strip all leading spaces before parsing it, otherwise the option |
| 167 |
lines won't be correctly identified. |
| 168 |
""" |
| 169 |
filename = "RS_ZVR_1.20_beta_f.s2p" |
| 170 |
ntwk = rf.Network(os.path.join(self.test_dir, filename)) |
| 171 |
|
| 172 |
|
| 173 |
self.assertTrue(np.isclose(np.unique(ntwk.z0), 50)) |
| 174 |
|
| 175 |
self.assertTrue(ntwk.frequency.f[np.argmin(ntwk.s11.s_mag)], 1.0e3) |
| 176 |
|
| 177 |
self.assertTrue(np.allclose(ntwk.s_db[0,0,0], -0.00001)) |
| 178 |
self.assertTrue(np.allclose(ntwk.s_db[0,1,0], -0.00002)) |
| 179 |
self.assertTrue(np.allclose(ntwk.s_db[0,0,1], -0.0003)) |
| 180 |
self.assertTrue(np.allclose(ntwk.s_db[0,1,1], -0.00004)) |
| 181 |
|
| 182 |
self.assertTrue(np.allclose(ntwk.s_deg[0,0,0], -100.001)) |
| 183 |
self.assertTrue(np.allclose(ntwk.s_deg[0,1,0], -0.00002)) |
| 184 |
self.assertTrue(np.allclose(ntwk.s_deg[0,0,1], -0.00003)) |
| 185 |
self.assertTrue(np.allclose(ntwk.s_deg[0,1,1], -100.004)) |
| 186 |
|
| 187 |
def test_helic_touchstone_V2_network(self): |
| 188 |
ntwk_helic_ts_extension = rf.Network(os.path.join(self.test_dir, 'helic_example_6ports_V2.ts')) |
| 189 |
ntwk_helic_sp_extension = rf.Network(os.path.join(self.test_dir, 'helic_example_6ports_V2.sp')) |
| 190 |
|
| 191 |
self.assertTrue((ntwk_helic_ts_extension.f == ntwk_helic_sp_extension.f).all()) |
| 192 |
self.assertTrue((ntwk_helic_ts_extension.z0 == ntwk_helic_sp_extension.z0).all()) |
| 193 |
self.assertTrue((ntwk_helic_ts_extension.s == ntwk_helic_sp_extension.s).all()) |
| 194 |
|