| 1 | import unittest |
| 2 | |
| 3 | import skrf as rf |
| 4 | from skrf.calibration import EightTerm, OnePort |
| 5 | from skrf.calibration.calibrationSet import Dot |
| 6 | from skrf.util import suppress_warning_decorator |
| 7 | |
| 8 | |
| 9 | class CalsetTest: |
| 10 | @suppress_warning_decorator("No switch terms") |
| 11 | def test_run(self): |
| 12 | """ |
| 13 | ensure cal_set can be generated |
| 14 | """ |
| 15 | self.calset.run() |
| 16 | |
| 17 | @suppress_warning_decorator("No switch terms") |
| 18 | def test_correct_ntwk(self): |
| 19 | """ |
| 20 | ensure a network can be corrected |
| 21 | """ |
| 22 | ntwk = self.wg.random(n_ports = self.n_ports) |
| 23 | self.calset.apply_cal(ntwk) |
| 24 | |
| 25 | class DotOneport(unittest.TestCase,CalsetTest): |
| 26 | """ |
| 27 | |
| 28 | |
| 29 | """ |
| 30 | def setUp(self): |
| 31 | self.wg = rf.RectangularWaveguide(rf.F(75, 100, 11, unit='GHz'), |
| 32 | a = 100*rf.mil, z0_override = 50) |
| 33 | wg = self.wg |
| 34 | self.n_ports = 1 |
| 35 | self.E = wg.random(n_ports =2, name = 'E') |
| 36 | |
| 37 | |
| 38 | ideals = [ |
| 39 | wg.short( name='short'), |
| 40 | wg.delay_short( 45.,'deg',name='ew'), |
| 41 | wg.delay_short( 90.,'deg',name='qw'), |
| 42 | wg.match( name='load'), |
| 43 | ] |
| 44 | measured_sets = [] |
| 45 | for ideal in ideals: |
| 46 | ns = rf.NetworkSet([self.measure(ideal) for k in range(3)]) |
| 47 | measured_sets.append(ns) |
| 48 | |
| 49 | |
| 50 | self.calset = Dot(cal_class = OnePort, |
| 51 | ideals = ideals, |
| 52 | measured_sets = measured_sets, |
| 53 | is_reciprocal = True) |
| 54 | |
| 55 | def measure(self, ntwk): |
| 56 | out = self.E**ntwk |
| 57 | out.name = ntwk.name |
| 58 | return out |
| 59 | |
| 60 | class DotEightTerm(unittest.TestCase, CalsetTest): |
| 61 | @suppress_warning_decorator("invalid value encountered in multiply") |
| 62 | @suppress_warning_decorator("divide by zero encountered in true_divide") |
| 63 | def setUp(self): |
| 64 | self.n_ports = 2 |
| 65 | self.wg = rf.RectangularWaveguide(rf.F(75, 100, 3, unit='GHz'), |
| 66 | a = 100*rf.mil, z0_override = 50) |
| 67 | wg= self.wg |
| 68 | wg.frequency = rf.F.from_f([100], unit='GHz') |
| 69 | |
| 70 | self.X = wg.random(n_ports =2, name = 'X') |
| 71 | self.Y = wg.random(n_ports =2, name='Y') |
| 72 | self.gamma_f = wg.random(n_ports =1, name='gamma_f') |
| 73 | self.gamma_r = wg.random(n_ports =1, name='gamma_r') |
| 74 | |
| 75 | |
| 76 | ideals = [ |
| 77 | wg.short(nports=2, name='short'), |
| 78 | wg.open(nports=2, name='open'), |
| 79 | wg.match(nports=2, name='load'), |
| 80 | wg.thru(name='thru'), |
| 81 | ] |
| 82 | |
| 83 | measured_sets = [] |
| 84 | for ideal in ideals: |
| 85 | ns = rf.NetworkSet([self.measure(ideal) for k in range(3)]) |
| 86 | measured_sets.append(ns) |
| 87 | |
| 88 | self.calset = Dot( cal_class = EightTerm, |
| 89 | ideals = ideals, |
| 90 | measured_sets = measured_sets, |
| 91 | switch_terms = (self.gamma_f, self.gamma_r) |
| 92 | ) |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | def measure(self,ntwk): |
| 98 | out = self.X**ntwk**self.Y |
| 99 | out.name = ntwk.name |
| 100 | return out |