示例#1
0
    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()
示例#2
0
    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()
示例#3
0
    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()
示例#4
0
    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()
示例#5
0
    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()
示例#6
0
 def test_nano(self):
     assert str2float("158.784n") == 158.784e-9
示例#7
0
 def test_pico(self):
     assert str2float("-15.37p") == -15.37e-12
示例#8
0
 def test_centi(self):
     assert str2float('14.5c') == 14.5e-2
示例#9
0
 def test_malformed(self):
     with pytest.raises(ValueError):
         str2float("17.3.5e7")
示例#10
0
 def test_Giga(self):
     assert str2float('-8.73G') == -8.73e9
示例#11
0
 def test_Mega(self):
     assert str2float("15.26M") == 15.26e6
示例#12
0
 def test_centi(self):
     assert str2float("14.5c") == 14.5e-2
示例#13
0
 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)
示例#14
0
 def test_kilo(self):
     assert str2float('-0.257k') == -0.257e3
示例#15
0
 def test_E(self):
     assert str2float('0.4E6') == 0.4e6
示例#16
0
 def test_e(self):
     assert str2float('15.2e-6') == 15.2e-6
示例#17
0
 def test_Tera(self):
     assert str2float('183.4T') == 183.4e12
示例#18
0
 def test_micro(self):
     assert str2float("15.26u") == 15.26e-06
示例#19
0
 def test_milli(self):
     assert str2float("-15.781m") == -15.781e-3
示例#20
0
 def test_Tera(self):
     assert str2float("183.4T") == 183.4e12
示例#21
0
 def test_kilo(self):
     assert str2float("-0.257k") == -0.257e3
示例#22
0
 def test_E(self):
     assert str2float("0.4E6") == 0.4e6
示例#23
0
 def test_Giga(self):
     assert str2float("-8.73G") == -8.73e9
示例#24
0
 def test_Mega(self):
     assert str2float('15.26M') == 15.26e6
示例#25
0
 def test_e(self):
     assert str2float("15.2e-6") == 15.2e-6
示例#26
0
 def test_no_suffix(self):
     assert str2float("2.53") == 2.53
示例#27
0
 def test_unrecognized(self):
     with pytest.raises(ValueError):
         str2float("17.3o")
示例#28
0
 def test_femto(self):
     assert str2float("17.83f") == 17.83e-15
示例#29
0
 def visit_number(self, node, visited_children):
     # number      = ~r"([-+]?[0-9]+[.]?[0-9]*((?:[eE][-+]?[0-9]+)|[a-zA-Z])?)"
     return str2float(node.text)
示例#30
0
 def test_milli(self):
     assert str2float('-15.781m') == -15.781e-3