def on_args_changed(self): self.suspend_autoupdate() available = self._source_argsets() normalized = [] for d in available: w1, w2, L = [(key, d.get(key)) for key in self._args_keys] normalized.append( { w1[0]: round(str2float(w1[1]) * 1e-9, 15), w2[0]: round(str2float(w2[1]) * 1e-9, 15), L[0]: round(str2float(L[1]) * 1e-6, 15), } ) idx = self._get_matched_args(normalized, self.args) valid_args = available[idx] sparams = parser.read_params(self._get_file(valid_args)) self._f, self._s = parser.build_matrix(sparams) self.freq_range = (self._f[0], self._f[-1]) for key, value in normalized[idx].items(): setattr(self, key, value) self.enable_autoupdate()
def on_args_changed(self): self.suspend_autoupdate() available = self._source_argsets() normalized = [{ k: round(str2float(v) * 1e-9, 21) for k, v in d.items() } for d in available] idx = self._get_matched_args(normalized, self.args) valid_args = available[idx] with open(self._get_file(valid_args), "r") as f: params = f.read().rstrip("\n") if self.polarization == "TE": lam0, ne, _, ng, _, nd, _ = params.split(" ") elif self.polarization == "TM": lam0, _, ne, _, ng, _, nd = params.split(" ") raise NotImplementedError self.lam0 = float(lam0) self.ne = float(ne) self.ng = float(ng) self.nd = float(nd) # Updates parameters width and thickness to closest match. for key, value in normalized[idx].items(): setattr(self, key, value) self.enable_autoupdate()
def on_args_changed(self): self.suspend_autoupdate() available = self._source_argsets() normalized = [] for d in available: polarization, thickness, deltaw = [(key, d.get(key)) for key in self._args_keys] normalized.append({ polarization[0]: polarization[1], thickness[0]: round(str2float(thickness[1]) * 1e-9, 15), deltaw[0]: round(str2float(deltaw[1]) * 1e-9, 15), }) idx = self._get_matched_args(normalized, self.args) for key, value in normalized[idx].items(): setattr(self, key, value) valid_args = available[idx] params = np.genfromtxt(self._get_file(valid_args), delimiter="\t") self._f = params[:, 0] self._s = np.zeros((len(self._f), 2, 2), dtype="complex128") self._s[:, 0, 0] = params[:, 1] * np.exp(1j * params[:, 2]) self._s[:, 0, 1] = params[:, 3] * np.exp(1j * params[:, 4]) self._s[:, 1, 0] = params[:, 5] * np.exp(1j * params[:, 6]) self._s[:, 1, 1] = params[:, 7] * np.exp(1j * params[:, 8]) # Arrays are from high frequency to low; reverse it, # for convention's sake. self._f = self._f[::-1] self._s = self._s[::-1] self.freq_range = (self._f[0], self._f[-1]) self.enable_autoupdate()
def on_args_changed(self): self.suspend_autoupdate() available = self._source_argsets() normalized = [{k: round(str2float(v), 15) for k, v in d.items()} for d in available] idx = self._get_matched_args(normalized, self.args) valid_args = available[idx] sparams = parser.read_params(self._get_file(valid_args)) self._f, self._s = parser.build_matrix(sparams) self.freq_range = (self._f[0], self._f[-1]) for key, value in normalized[idx].items(): setattr(self, key, value) self.enable_autoupdate()
def on_args_changed(self) -> None: self.suspend_autoupdate() available = self._source_argsets() normalized = [{ k: round(str2float(v) * 1e-9, 21) for k, v in d.items() } for d in available] idx = self._get_matched_args(normalized, self.args) valid_args = available[idx] sparams = parser.read_params(self._get_file(valid_args)) sparams = list( filter(lambda sparams: sparams["mode"] == self.polarization, sparams)) for key, value in normalized[idx].items(): setattr(self, key, value) self._f, self._s = parser.build_matrix(sparams) self.freq_range = (self._f[0], self._f[-1]) self.enable_autoupdate()
def test_nano(self): assert str2float("158.784n") == 158.784e-9
def test_pico(self): assert str2float("-15.37p") == -15.37e-12
def test_centi(self): assert str2float('14.5c') == 14.5e-2
def test_malformed(self): with pytest.raises(ValueError): str2float("17.3.5e7")
def test_Giga(self): assert str2float('-8.73G') == -8.73e9
def test_Mega(self): assert str2float("15.26M") == 15.26e6
def test_centi(self): assert str2float("14.5c") == 14.5e-2
def visit_number(self, node: RegexNode, visited_children: List[Any]) -> float: # number = ~r"([-+]?[0-9]+[.]?[0-9]*((?:[eE][-+]?[0-9]+)|[a-zA-Z])?)" return str2float(node.text)
def test_kilo(self): assert str2float('-0.257k') == -0.257e3
def test_E(self): assert str2float('0.4E6') == 0.4e6
def test_e(self): assert str2float('15.2e-6') == 15.2e-6
def test_Tera(self): assert str2float('183.4T') == 183.4e12
def test_micro(self): assert str2float("15.26u") == 15.26e-06
def test_milli(self): assert str2float("-15.781m") == -15.781e-3
def test_Tera(self): assert str2float("183.4T") == 183.4e12
def test_kilo(self): assert str2float("-0.257k") == -0.257e3
def test_E(self): assert str2float("0.4E6") == 0.4e6
def test_Giga(self): assert str2float("-8.73G") == -8.73e9
def test_Mega(self): assert str2float('15.26M') == 15.26e6
def test_e(self): assert str2float("15.2e-6") == 15.2e-6
def test_no_suffix(self): assert str2float("2.53") == 2.53
def test_unrecognized(self): with pytest.raises(ValueError): str2float("17.3o")
def test_femto(self): assert str2float("17.83f") == 17.83e-15
def visit_number(self, node, visited_children): # number = ~r"([-+]?[0-9]+[.]?[0-9]*((?:[eE][-+]?[0-9]+)|[a-zA-Z])?)" return str2float(node.text)
def test_milli(self): assert str2float('-15.781m') == -15.781e-3