当前位置: 首页>>代码示例>>Python>>正文


Python dataset.DataBlock类代码示例

本文整理汇总了Python中hftools.dataset.DataBlock的典型用法代码示例。如果您正苦于以下问题:Python DataBlock类的具体用法?Python DataBlock怎么用?Python DataBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DataBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_8

 def test_8(self):
     d = DataBlock()
     d.b = hfarray([2], dims=(DimSweep("a", 1),))
     fname = testpath / "testdata/hdf5/v02/savetest/res_8.hdf5"
     with h5py.File(fname, mode="w") as fil:
         self.savefun[0](d, fil)
     fname.unlink()
开发者ID:extrakteon,项目名称:hftools-1,代码行数:7,代码来源:test_hdf5_v02.py

示例2: test_1

    def test_1(self):
        d = DataBlock()
        fi = DimSweep("Freq[Hz]", 3)
        gi = DimSweep("g", 4)
        dims = (fi,)
        d["a"] = hfarray([1, 2, 3], dims=dims,
                            outputformat="%.5f", unit="V")
        d["b"] = hfarray([10, 20, 30], dims=dims,
                            outputformat="%.7f", unit="A")
        d["c"] = hfarray([10, 20, 30, 40], dims=(gi,),
                            outputformat="%.7f", unit="A")

        w = d.filter(d["Freq[Hz]"] <= 1)
        self.assertEqual(id(d.comments), id(w.comments))
        self.assertEqual(w["Freq[Hz]"].dims, (DimSweep("Freq[Hz]", 2),))
        self.assertEqual(w.a.dims, (DimSweep("Freq[Hz]", 2),))
        self.assertEqual(w.b.dims, (DimSweep("Freq[Hz]", 2),))
        self.assertEqual(w.c.dims, (DimSweep("g", 4),))

        self.assertAllclose(w["Freq[Hz]"], [0, 1])
        self.assertAllclose(w.a, [1, 2])
        self.assertAllclose(w.b, [10, 20])
        self.assertAllclose(w.c, [10, 20, 30, 40])
        self.assertEqual(w.a.unit, "V")
        self.assertEqual(w.b.unit, "A")
        self.assertEqual(w.c.unit, "A")
开发者ID:arsenovic,项目名称:hftools,代码行数:26,代码来源:test_data_block.py

示例3: Test_replace_dim

class Test_replace_dim(TestCase):
    def setUp(self):
        self.d = DataBlock()
        self.fi = DimSweep("Freq", 3)
        self.gi = DimSweep("g", 4)
        self.hi = DimSweep("h", 4)
        self.d["Vds"] = hfarray([1, 2, 3], dims=(self.fi,))
        self.d["Id"] = hfarray([1, 2, 3, 4], dims=(self.gi,))

    def test_error_1(self):
        self.assertRaises(KeyError, self.d.replace_dim, self.hi, self.fi)

    def test_error_2(self):
        self.assertRaises(KeyError,
                          self.d.replace_dim, "nonexisting-dim", self.fi)

    def test_1(self):
        self.d.replace_dim("g", self.hi)
        self.assertTrue(self.hi not in self.d["Vds"].dims)
        self.assertTrue(self.hi in self.d["Id"].dims)

    def test_2(self):
        self.d.replace_dim("g", DimRep)
        self.assertIsInstance(self.d.Id.dims[0], DimRep)
        self.assertEqual(self.d.Id.dims[0].name, "g")
开发者ID:arsenovic,项目名称:hftools,代码行数:25,代码来源:test_data_block.py

示例4: test_2

    def test_2(self):
        d = DataBlock()
        d.comments = Comments(["Hej=10"])
#        import pdb;pdb.set_trace()
        d.b = hfarray([2], dims=(DimSweep("a", 1),))
        fname = testpath / "testdata/hdf5/v02/savetest/res_2.hdf5"
        self.savefun[0](d, fname)
        fname.unlink()
开发者ID:extrakteon,项目名称:hftools-1,代码行数:8,代码来源:test_hdf5_v02.py

示例5: test1

    def test1(self):
        a = DataBlock()
        a.i = DimSweep("i", [1, 2, 3])

        def funk(a):
            dims = (DimSweep("i", [1]), DimSweep("j", [1]))
            a.i = hfarray([[1]], dims=dims)
        self.assertRaises(AttributeError, funk, a)
开发者ID:arsenovic,项目名称:hftools,代码行数:8,代码来源:test_data_block.py

示例6: test_4

 def test_4(self):
     d = DataBlock()
     d.comments = Comments(["Hej=10", "Svejs=11"])
     dim = DimSweep("f", 3, outputformat="%.1f")
     d.freq = dim
     fname = testpath / "testdata/hdf5/v02/savetest/res_4.hdf5"
     self.savefun[0](d, fname)
     fname.unlink()
开发者ID:extrakteon,项目名称:hftools-1,代码行数:8,代码来源:test_hdf5_v02.py

示例7: test_none

 def test_none(self):
     db = DataBlock()
     db.x = hfarray(1)
     fname = testpath / "testdata/hdf5/v02/slask.hdf5"
     savefun(db, fname)
     db = readfun(fname)
     self.assertIsNone(db.blockname)
     fname.unlink()
开发者ID:extrakteon,项目名称:hftools-1,代码行数:8,代码来源:test_hdf5_v02.py

示例8: test_normalize_names_3

 def test_normalize_names_3(self):
     db = DataBlock()
     db.b = hfarray(1)
     db["a1/a2 raw"] = hfarray(1)
     db["a12"] = hfarray(2)
     res = common.normalize_names(db)
     self.assertTrue("a1/a2 raw" in res.vardata)
     self.assertTrue("a12" in res.vardata)
开发者ID:arsenovic,项目名称:hftools,代码行数:8,代码来源:test_common.py

示例9: test_10

 def test_10(self):
     d = DataBlock()
     d.blockname = "Foo"
     d.b = hfarray([2], dims=(DimSweep("a", 1), ), unit="V")
     fname = testpath / "testdata/hdf5/v01/savetest/res_10.hdf5"
     self.savefun[0](d, fname)
     d2 = readfun(fname)
     self.assertEqual(d2.blockname, "Foo")
     fname.unlink()
开发者ID:arsenovic,项目名称:hftools,代码行数:9,代码来源:test_hdf5_v01.py

示例10: test_9

 def test_9(self):
     d = DataBlock()
     d.comments = Comments(["Hej=10"])
     d.b = hfarray([2], dims=(DimSweep("a", 1), ), unit="V")
     fname = testpath / "testdata/hdf5/v01/savetest/res_9.hdf5"
     self.savefun[0](d, fname)
     d2 = readfun(fname)
     self.assertEqual(d2.b.unit, "V")
     fname.unlink()
开发者ID:arsenovic,项目名称:hftools,代码行数:9,代码来源:test_hdf5_v01.py

示例11: test_intersection_2

 def test_intersection_2(self):
     d = DataBlock()
     fi = DimSweep("Freq[Hz]", [10, 20, 30, 40, 50])
     gi = DimSweep("g", 4)
     dims = (fi, gi)
     d["a"] = hfarray([[1, 2, 3, 4]] * 5, dims=dims,
                         outputformat="%.5f", unit="V")
     x = DimSweep("Freq[Hz]", [20, 40])
     dres = d.filter(hfarray(x))
     self.assertAllclose(dres["Freq[Hz]"], [20, 40])
开发者ID:arsenovic,项目名称:hftools,代码行数:10,代码来源:test_data_block.py

示例12: read_hdf5_handle

def read_hdf5_handle(filehandle, **kw):
    if isinstance(filehandle, h5py.File):
        db = DataBlock()
        for k in filehandle:
            if "dimtype" not in filehandle[k].attrs:
                db[k] = getvar(filehandle, k)
        db.comments = Comments()
        return db
    else:
        raise IOError("filehandle should be a h5py File, is: %r" % filehandle)
开发者ID:ychaim,项目名称:hftools,代码行数:10,代码来源:v_02.py

示例13: test_setitem_1

 def test_setitem_1(self):
     a = DataBlock()
     a.l = DimSweep("l", [.1, .2, .3])
     self.assertAllclose(a.l, [.1, .2, .3])
     self.assertAllclose(a.xvalue, [.1, .2, .3])
     self.assertEqual(a.xname, "l")
     a.w = DimSweep("w", [1.1, 1.2, 1.3])
     self.assertAllclose(a.w, [1.1, 1.2, 1.3])
     self.assertAllclose(a.xvalue, [.1, .2, .3])
     self.assertEqual(a.xname, "l")
开发者ID:arsenovic,项目名称:hftools,代码行数:10,代码来源:test_data_block.py

示例14: proc_info

def proc_info(info, f, data, fn, noisedata):
    info_list = info.upper().split()
    if len(info_list) == 5:
        info = freq_mult, twoporttype, datatype, rtype, z0 = info_list
    elif len(info_list) == 3:
        info = freq_mult, twoporttype, datatype = info_list
        z0 = 1.
    else:
        msg = ("# format should only have 5 values this one has %d" %
               len(info_list))
        raise TouchstoneError(msg)
    z0 = float(z0)
    f = f * freqmultdict[freq_mult]
    if fn is not None:
        fn = fn * freqmultdict[freq_mult]

    convfunc = dict(RI=re_im_to_complex,
                    DB=dB_angle_to_complex,
                    MA=mag_angle_to_complex)

    if datatype not in convfunc:
        pars = datatype
        msg = "Unknown dataformat: %s, valid formats: RI, DB, MAG" % pars
        raise TouchstoneError(msg)

    out = np.empty((data.shape[0], data.shape[1] // 2), dtype=np.complex128)

    out[...] = convfunc[datatype](data[:, ::2],  data[:, 1::2])
    if out.shape[1] == 1:
        out.shape = (out.shape[0], 1, 1)
    elif out.shape[1] == 4:
        out.shape = (out.shape[0], 2, 2)
        out = out.transpose(0, 2, 1)
    else:
        N = int(sqrt(out.shape[1]))
        out.shape = (out.shape[0], N, N)

    dims = (DimSweep("freq", f, unit="Hz"), )
    if fn is not None and len(f) == len(fn) and np.allclose(f, fn):
        noisedims = dims
    elif fn is None:
        noisedims = None
    else:
        noisedims = (DimSweep("freqn", fn, unit="Hz"), )
    out = make_matrix(out, dims)
    f = hfarray(f, dims)
    db = DataBlock()
    db[info[1]] = out
    if noisedata is not None:
        db.Rn = hfarray(noisedata[..., -1], dims=noisedims) * z0
        db.Fmin = 10 ** (hfarray(noisedata[..., 0], dims=noisedims) / 10)
        db.Gopt = hfarray(convfunc[datatype](noisedata[:, 1], noisedata[:, 2]),
                          dims=noisedims)
    db.Z0 = hfarray(z0, unit="Ohm")
    return db
开发者ID:hftools,项目名称:hftools,代码行数:55,代码来源:touchstone.py

示例15: merge_blocks

def merge_blocks(blocks, hyper=False, indexed=False):
    db = DataBlock()
    dimpartialgroups = OrderedDict()

    for b in blocks:
        parts = get_partials(b)
        partgroup = dimpartialgroups.setdefault(tuple(parts.keys()), {})
        for k, v in parts.items():
            partgroup.setdefault(k, []).extend(v)

    for idx, dims in enumerate(dimpartialgroups.values(), 1):
        for k, v in dims.items():
            dims = (DimSweep("INDEX%s" % idx, len(v)),)
            db[k] = hfarray([x.data[0] for x in v],
                            dims=dims, unit=v[0].unit)

    varnames = set()
    for b in blocks:
        for k, v in b.ivardata.items():
            if k not in db:
                db[k] = v
        for k in b.vardata.keys():
            varnames.add(k)

    for vname in varnames:
        v = []
        for b in blocks:
            if vname not in b:
                continue
            partials = get_partials(b)
            v.append(b[vname])
        if v:
            k = tuple(partials.keys())
            if k:
                ri = (db[tuple(dimpartialgroups[k].keys())[0]].dims[0],)
            else:
                ri = tuple()
            value = hfarray(v, dims=ri + v[0].dims, unit=v[0].unit)
            if v[0].dims and isinstance(v[0].dims[0], DimSweep):
                value = value.reorder_dimensions(v[0].dims[0])
            db[vname] = value
    cmt = Comments()
    for block in blocks:
        if block.comments:
            cmt.extend(block.comments)
    db.comments = cmt
    db.blockname = blocks[0].blockname

    if hyper:
        for vnames in dimpartialgroups.keys():
            if vnames:
                hyperindex = db[vnames[0]].dims[0]
                db = db.hyper(vnames, hyperindex, all=True)
    db = db.squeeze()
    return db
开发者ID:ychaim,项目名称:hftools,代码行数:55,代码来源:merge.py


注:本文中的hftools.dataset.DataBlock类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。