コード例 #1
0
    def noise_parameters(self, partial=False):
        db = DataBlock()
        db.S = SArray(self.N)
        if isinstance(self.N, ABCDArray):
            CA = self.C / (2 * k * 290)
            CA11 = CA[..., 0, 0]
            CA12 = CA[..., 0, 1]
            CA22 = CA[..., 1, 1]
            Rn = CA11.real
            Yopt = (np.sqrt(CA22 / CA11 - (CA12.imag / CA11) ** 2) +
                    1j * (CA12.imag / CA11))
            Fmin = 1 + (CA12 + CA11 * Yopt.conj()).real
            if partial:
                db.CA = CA
            db.Rn = Rn
            db.Yopt = Yopt
            db.Fmin = Fmin
            db.Gopt = (1 / 50. - Yopt) / (1 / 50. + Yopt)
            return db

        N = self.convert(YArray)
        Y11 = N.N[..., 0, 0]
        Y21 = N.N[..., 1, 0]
        C = N.C / (4 * k * 290)
        CY11 = C[..., 0, 0]
        CY12 = C[..., 0, 1]
        CY22 = C[..., 1, 1]
        Rn = (CY22 / abs(Y21) ** 2).real
        Ycor = Y11 - CY12 / CY22 * Y21
        Gn = (CY11 - abs(Y11 - Ycor) ** 2 * Rn).real
        Yopt = np.sqrt(Gn / Rn + Ycor.real ** 2) - 1j * Ycor.imag
        Fmin = 1 + 2 * Rn * (Ycor.real + Yopt.real)

        db.CY = C
        db.Gn = Gn
        db.Ycor = Ycor
        db.S = SArray(self.N)
        db.Rn = Rn
        db.Fmin = Fmin
        db.Gopt = (1 / 50. - Yopt) / (1 / 50. + Yopt)
        db.Yopt = Yopt
        return db
コード例 #2
0
ファイル: test_data_block.py プロジェクト: arsenovic/hftools
 def test_1(self):
     db = DataBlock()
     Sdims = (DimRep("freq", [1, 2]) ,DimRep("r", [1]), DimMatrix_i("i", 2), DimMatrix_j("j", 2))
     db.S = hfarray(np.array([[11, 12], [21, 22]])[np.newaxis, np.newaxis, :, :] * np.array([[10], [20]])[..., np.newaxis, np.newaxis], dims=Sdims)
     db.V = hfarray([1.23], Sdims[1:2])
     db.Y = hfarray([1.23], (DimRep("k", [1]),))
     out = dset.subset_datablock_by_dims(dset.convert_matrices_to_elements(db), Sdims[:-2])
     self.assertTrue("V" in out)
     self.assertTrue("S11" in out)
     self.assertTrue("S12" in out)
     self.assertTrue("S21" in out)
     self.assertTrue("S22" in out)
     self.assertFalse("Y" in out)
コード例 #3
0
ファイル: test_data_block.py プロジェクト: ychaim/hftools
 def test_1(self):
     db = DataBlock()
     Sdims = (DimRep("freq", [1, 2]), DimRep("r", [1]), DimMatrix_i("i", 2),
              DimMatrix_j("j", 2))
     db.S = hfarray(
         np.array([[11, 12], [21, 22]])[np.newaxis, np.newaxis, :, :] *
         np.array([[10], [20]])[..., np.newaxis, np.newaxis],
         dims=Sdims)
     db.V = hfarray([1.23], Sdims[1:2])
     db.Y = hfarray([1.23], (DimRep("k", [1]), ))
     out = dset.subset_datablock_by_dims(
         dset.convert_matrices_to_elements(db), Sdims[:-2])
     self.assertTrue("V" in out)
     self.assertTrue("S11" in out)
     self.assertTrue("S12" in out)
     self.assertTrue("S21" in out)
     self.assertTrue("S22" in out)
     self.assertFalse("Y" in out)
コード例 #4
0
ファイル: test_touchstone.py プロジェクト: arsenovic/hftools
    def test_2(self):
        d = DataBlock()
        d.comments = Comments(["Vg=10"])
        fi = DimSweep("freq", [0e9, 1e9, 2e9], outputformat="%15.2f")
        dims = (fi, DimMatrix_i("i", 2), DimMatrix_j("j", 2),)
        d.S = hfarray([[[1 + 1j, 1 + 2j], [2 + 1j, 2 + 2j]]] * 3,
                         dims=dims, outputformat="%.3f")
        filename = testpath / "testdata/touchstone/savetest/res_2.txt"
        hftools.file_formats.touchstone.save_touchstone(d, filename)

        resfilename = testpath / "testdata/touchstone/savetest/res_2.txt"
        facitfilename = testpath / "testdata/touchstone/savetest/facit_2.txt"
        with open(resfilename) as resfil:
            with open(facitfilename) as facitfil:
                for idx, (rad1, rad2) in enumerate(zip(resfil, facitfil)):
                    msg = ("\nFailed on line %d\n  result: %r\n  facit: %r" %
                           (idx + 1, rad1, rad2))
                    self.assertEqual(rad1, rad2, msg=msg)
コード例 #5
0
    def test_2(self):
        d = DataBlock()
        d.comments = Comments(["Vg=10"])
        fi = DimSweep("freq", [0e9, 1e9, 2e9], outputformat="%15.2f")
        dims = (
            fi,
            DimMatrix_i("i", 2),
            DimMatrix_j("j", 2),
        )
        d.S = hfarray([[[1 + 1j, 1 + 2j], [2 + 1j, 2 + 2j]]] * 3,
                      dims=dims,
                      outputformat="%.3f")
        filename = testpath / "testdata/touchstone/savetest/res_2.txt"
        hftools.file_formats.touchstone.save_touchstone(d, filename)

        resfilename = testpath / "testdata/touchstone/savetest/res_2.txt"
        facitfilename = testpath / "testdata/touchstone/savetest/facit_2.txt"
        with open(resfilename) as resfil:
            with open(facitfilename) as facitfil:
                for idx, (rad1, rad2) in enumerate(zip(resfil, facitfil)):
                    msg = ("\nFailed on line %d\n  result: %r\n  facit: %r" %
                           (idx + 1, rad1, rad2))
                    self.assertEqual(rad1, rad2, msg=msg)
コード例 #6
0
ファイル: touchstone.py プロジェクト: hftools/hftools
def read_touchstone(filnamn, make_complex=True, property_to_vars=True,
                    guess_unit=True, normalize=True, make_matrix=True,
                    merge=True, verbose=False):
    res = ReadTouchstoneFileFormat.read_file(filnamn,
                                             make_complex=make_complex,
                                             property_to_vars=property_to_vars,
                                             guess_unit=guess_unit,
                                             normalize=normalize,
                                             make_matrix=make_matrix,
                                             merge=merge,
                                             verbose=verbose)
    return res

if __name__ == "__main__":
    a = read_touchstone("tests/testdata/touchstone/test4.s2p",
                        make_complex=True,
                        property_to_vars=True,
                        guess_unit=True,
                        normalize=True,
                        make_matrix=True,
                        merge=True,
                        verbose=True)

    d = DataBlock()
    d.comments = Comments([])
    fi = DimSweep("freq", [0e9, 1e9, 2e9])
    d.S = hfarray([[[1 + 1j, 1 + 2j], [2 + 1j, 2 + 2j]]] * 3,
                  dims=(fi, DimMatrix_i("i", 2), DimMatrix_j("j", 2),))
    save_touchstone(d, "tests/testdata/touchstone/savetest/res_1.txt")

コード例 #7
0
                                             make_complex=make_complex,
                                             property_to_vars=property_to_vars,
                                             guess_unit=guess_unit,
                                             normalize=normalize,
                                             make_matrix=make_matrix,
                                             merge=merge,
                                             verbose=verbose)
    return res


if __name__ == "__main__":
    a = read_touchstone("tests/testdata/touchstone/test4.s2p",
                        make_complex=True,
                        property_to_vars=True,
                        guess_unit=True,
                        normalize=True,
                        make_matrix=True,
                        merge=True,
                        verbose=True)

    d = DataBlock()
    d.comments = Comments([])
    fi = DimSweep("freq", [0e9, 1e9, 2e9])
    d.S = hfarray([[[1 + 1j, 1 + 2j], [2 + 1j, 2 + 2j]]] * 3,
                  dims=(
                      fi,
                      DimMatrix_i("i", 2),
                      DimMatrix_j("j", 2),
                  ))
    save_touchstone(d, "tests/testdata/touchstone/savetest/res_1.txt")