Debian Codegraph @

skrf/calibration/calibrationSet.py

raw symbols SCIP
1 """
2 .. module:: skrf.calibration.calibrationSet
3 ================================================================
4 calibrationSet (:mod:`skrf.calibration.calibrationSet`)
5 ================================================================
6
7
8 Contains the CalibrationSet class, and supporting functions
9
10 CalibrationSet Class
11 ===============
12
13 .. autosummary::
14 :toctree: generated/
15
16 CalibrationSet
17
18 """
19 from itertools import product
20
21 from ..networkSet import NetworkSet
22 from .calibration import Calibration
23
24
25 def cartesian_product(ideals, measured_sets, *args, **kwargs):
26 """
27 """
28 measured_lists = product(*[k[:] for k in measured_sets])
29 return [Calibration(ideals = ideals, measured = measured,
30 **kwargs) for measured in measured_lists ]
31
32 def dot_product(ideals, measured_sets, *args, **kwargs):
33 """
34 """
35 for measured_set in measured_sets:
36 if len(measured_set) != len(measured_sets[0]):
37 raise(IndexError('all measured NetworkSets must have same length for dot product combinatoric function'))
38
39 cal_list = []
40 for k in list(range(len(measured_sets[0]))):
41 measured = [measured_set[k] for measured_set in measured_sets]
42 cal_list.append(
43 Calibration(ideals=ideals, measured= measured,
44 **kwargs)
45 )
46
47 return cal_list
48
49 class CalibrationSet:
50 """
51 A set of Calibrations
52
53 This is designed to support experimental uncertainty analysis [1]_.
54
55 References
56 -----------
57
58 .. [1] A. Arsenovic, L. Chen, M. F. Bauwens, H. Li, N. S. Barker, and R. M. Weikle,
59 "An Experimental Technique for Calibration Uncertainty Analysis,"
60 IEEE Transactions on Microwave Theory and Techniques, vol. 61, no. 1, pp. 263-269, 2013.
61
62 """
63
64 def __init__(self, cal_class, ideals, measured_sets,*args, **kwargs):
65 r"""
66 Parameters
67 ----------
68 cal_class : a Calibration class
69 this is the class of calibration to use on the set. This
70 argument is the actual class itself like OnePort, TRL, SOLT, etc
71
72 ideals : list of Networks
73
74 measured_set : list of NetworkSets, or list of lists
75 each element in this list should be a corresponding measured
76 set to the ideals element of the same index. The sets
77 themselves can be anything list-like
78
79 \*args\**kargs :
80 passed to self.run(),
81
82 """
83 self.cal_class = cal_class
84 self.ideals = ideals
85 self.measured_sets = measured_sets
86 self.args = args
87 self.kwargs = kwargs
88 self.run(*args, **kwargs)
89
90 def __getitem__(self, key):
91 return self.cal_list[key]
92
93 def apply_cal(self, raw_ntwk, *args, **kwargs):
94 """
95 """
96 return NetworkSet([k.apply_cal(raw_ntwk) for k in self.cal_list],
97 *args, **kwargs)
98
99 def plot_uncertainty_per_standard(self):
100 """
101 """
102 self.dankness('std_s','plot_s_mag')
103
104 def dankness(self, prop, func, *args, **kwargs):
105 """
106 """
107 try:
108 [getattr(getattr(k, prop), func) \
109 (*args, **kwargs) for k in self.measured_sets]
110 except (TypeError):
111 return [getattr(getattr(k, prop), func) \
112 for k in self.measured_sets]
113
114 def run(self):
115 NotImplementedError('SubClass must implement this')
116
117 @property
118 def corrected_sets(self):
119 """
120 The set of corrected networks, each is corrected by its corresponding
121 element in the cal_list
122 """
123 n_meas = len(self.cal_list[0].measured)
124 mat = [k.caled_ntwks for k in self.cal_list]
125 return [NetworkSet([k[l] for k in mat]) for l in range(n_meas)]
126
127
128
129 class Dot(CalibrationSet):
130
131 def run(self, *args, **kwargs):
132 ideals = self.ideals
133 measured_sets = self.measured_sets
134 if len(set(map(len, measured_sets))) !=1:
135 raise(IndexError('all measured NetworkSets must have same length for dot product combinatoric function'))
136
137 self.cal_list = []
138 for k in range(len(measured_sets[0])):
139 measured = [measured_set[k] for measured_set in measured_sets]
140 cal = self.cal_class(ideals=ideals, measured= measured,
141 **kwargs)
142 self.cal_list.append(cal)