本文整理汇总了Python中hftools.dataset.DataBlock.comments方法的典型用法代码示例。如果您正苦于以下问题:Python DataBlock.comments方法的具体用法?Python DataBlock.comments怎么用?Python DataBlock.comments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hftools.dataset.DataBlock
的用法示例。
在下文中一共展示了DataBlock.comments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_5
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import comments [as 别名]
def test_5(self):
d = DataBlock()
d.comments = Comments(["Vgs=13", "Ig=14", "Datetime=2011-10-11 20:11:02",
"Vds=-13", "Calibration=SOLT"])
fi = DimSweep("Freq", 3)
gi = DimSweep("g", 4)
d["Vds"] = hfarray([1, 2, 3], dims=(fi,))
d["Id"] = hfarray([1, 2, 3, 4], dims=(gi,))
d.comments.property["Ig"].unit = "mA"
d.guess_units()
d.values_from_property()
self.assertEqual(d.Vds.unit, "V")
self.assertAllclose(d.Vds, [1, 2, 3])
self.assertEqual(d.Id.unit, "A")
self.assertAllclose(d.Id, [1, 2, 3, 4])
self.assertEqual(d.Freq.unit, "Hz")
self.assertEqual(d.comments.property["Vgs"].unit, "V")
self.assertEqual(d.comments.property["Ig"].unit, "mA")
self.assertEqual(d.Ig, 14)
self.assertEqual(d.Vgs, 13)
self.assertEqual(d.Ig.unit, "mA")
self.assertEqual(d.Vgs.unit, "V")
self.assertTrue("Datetime" in d.allvarnames)
示例2: test_4
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import comments [as 别名]
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()
示例3: test_2
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import comments [as 别名]
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()
示例4: test_9
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import comments [as 别名]
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()
示例5: read_hdf5_handle
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import comments [as 别名]
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)
示例6: read_hdf5
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import comments [as 别名]
def read_hdf5(h5file, name="datablock", **kw):
if isinstance(h5file, string_types):
fil = h5py.File(h5file, "r")
else:
fil = h5file
db = DataBlock()
grp = fil[name]
blockname = grp.attrs["Blockname"]
if blockname.lower() == "none":
blockname = None
db.blockname = blockname
comments = grp["Comments"]
if "fullcomments" in comments and len(comments["fullcomments"]):
db.comments = Comments([cast_unicode(x).strip() for x in np.array(comments["fullcomments"])])
else:
db.comments = Comments()
ivardata = grp["ivardata"]
vardata = grp["vardata"]
for k in ivardata:
v = ivardata[k]
datadtype = v.attrs[r"info\dtype"] or None
dimcls = dims_dict.get(v.attrs[r"info\class"], DimRep)
unit = str(v.attrs.get(r"info\unit", "none"))
if unit.lower() == "none":
unit = None
vdata = np.array(np.array(v), dtype=datadtype)
dim = dimcls(k, vdata, unit=unit)
db[k] = dim
for k in vardata:
v = vardata[k]
datadtype = v.attrs[r"data\dtype"] or None
dims = tuple(db.ivardata[cast_unicode(dimname)] for dimname in v.attrs[r"info\name"])
unit = cast_unicode(v.attrs.get(r"data\unit", "none"))
if unit.lower() == "none":
unit = None
db[k] = hfarray(np.array(v), dtype=datadtype, dims=dims, unit=unit)
if isinstance(h5file, string_types):
fil.close()
if kw.get("property_to_vars", False):
db.values_from_property()
return db
示例7: merge_blocks
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import comments [as 别名]
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
示例8: test_5
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import comments [as 别名]
def test_5(self):
d = DataBlock()
d.comments = Comments(["Hej=10", "Svejs=11"])
dim = DimSweep("f", 3, outputformat="%.1f")
d.freq = dim
d.date = hfarray("2012-08-13 08:03:01", dtype="datetime64[us]")
fname = testpath / "testdata/hdf5/v02/savetest/res_5.hdf5"
self.savefun[0](d, fname)
d2 = readfun(fname)
fname.unlink()
self.assertEqual(d2.date, d.date)
示例9: test_10
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import comments [as 别名]
def test_10(self):
d = DataBlock()
d.comments = Comments(["Hej=10"])
# import pdb;pdb.set_trace()
d.b = hfarray([2], dims=(DimSweep("a", 1), ), unit="V")
d.b.outputformat = ""
fname = testpath / "testdata/hdf5/v02/savetest/res_10.hdf5"
self.savefun[0](d, fname)
d2 = readfun(fname)
self.assertEqual(d2.b.outputformat, "%d")
fname.unlink()
示例10: test_11
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import comments [as 别名]
def test_11(self):
ia = DimSweep("a", 1)
d = DataBlock()
d.comments = Comments(["Hej=10"])
# import pdb;pdb.set_trace()
d.b = hfarray([u"kalle"], dims=(ia, ), unit="V")
d.c = hfarray(u"kalle")
fname = testpath / "testdata/hdf5/v02/savetest/res_11.hdf5"
self.savefun[0](d, fname)
d2 = readfun(fname)
self.assertEqual(d2.b[0], u"kalle")
self.assertEqual(d2.c, u"kalle")
fname.unlink()
示例11: test_3
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import comments [as 别名]
def test_3(self):
d = DataBlock()
d.comments = Comments(["Hej=10", "Svejs=11"])
dims = (DimSweep("f", 3, outputformat="%.1f"),
DimSweep("i", 2, outputformat="%.0f"),
DimSweep("j", 2, outputformat="%.0f"), )
d.c = hfarray([[[1, 2], [3, 4]],
[[10, 20], [30, 40]],
[[10, 20], [30, 40]]],
dims=dims,
outputformat="%.2f")
fname = testpath / "testdata/hdf5/v02/savetest/res_3.hdf5"
self.savefun[0](d, fname)
fname.unlink()
示例12: test_4
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import comments [as 别名]
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/sp-data/savetest/res_4.txt"
facitfname = testpath / "testdata/sp-data/savetest/facit_4.txt"
hftools.file_formats.spdata.save_spdata(d, fname)
with open(fname) as resfil:
with open(facitfname) as facitfil:
for idx, (rad1, rad2) in enumerate(zip(resfil, facitfil)):
msg = "\nFailed on line %d\n result: %r\n facit: %r"
args = (idx + 1, rad1, rad2)
self.assertEqual(rad1, rad2, msg=msg % args)
示例13: test_2
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import comments [as 别名]
def test_2(self):
d = DataBlock()
d.comments = Comments(["Hej=10"])
# import pdb;pdb.set_trace()
d.b = hfarray([2], dims=(DimSweep("a", 1),))
f1 = testpath / "testdata/sp-data/savetest/res_2.txt"
f2 = testpath / "testdata/sp-data/savetest/facit_2.txt"
hftools.file_formats.spdata.save_spdata(d, f1)
with open(f1) as resfil:
with open(f2) as facitfil:
for idx, (rad1, rad2) in enumerate(zip(resfil, facitfil)):
msg = "\nFailed on line %d\n result: %r\n facit: %r"
args = (idx + 1, rad1, rad2)
self.assertEqual(rad1, rad2, msg=msg % args)
示例14: parse_blocks
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import comments [as 别名]
def parse_blocks(self, stream):
# raise Exception("HANTERAR INTE KOMMENTARER INNE I MANYOPTIONAL")
comments = []
comments.extend(ManyOptional("COMMENT")(stream))
citifileversion = Optional("CITIFILE")(stream)
comments.extend(ManyOptional("COMMENT")(stream))
name = One("NAME", "Must have END after DATA")(stream)
comments.extend(ManyOptional("COMMENT")(stream))
varnames = ManyOptional("VARDEF")(stream)
comments.extend(ManyOptional("COMMENT")(stream))
datanames = ManyOptional("DATADEF")(stream)
comments.extend(ManyOptional("COMMENT")(stream))
block = DataBlock()
block.blockname = name[0]
for name, typ, N in varnames:
N = int(N)
errmsg = "Missing VAR_LIST_BEGIN or SEG_LIST_BEGIN"
tagname, = OneOf(["VAR_LIST_BEGIN", "SEG_LIST_BEGIN"], errmsg)(stream)
if tagname.startswith("VAR_LIST"):
datalist = handle_data(ManyOptional("DATA")(stream), typ)
block[name] = DimSweep(name, datalist)
One("VAR_LIST_END", "Missing VAR_LIST_END")(stream)
elif tagname.startswith("SEG"): # pragma: no branch
datalist, = One("SEG", "Missing SEG")(stream)
_, start, stop, step = datalist.strip().split()
block[name] = DimSweep(name, np.linspace(float(start), float(stop), int(step)))
One("SEG_LIST_END", "Missing SEG_LIST_END")(stream)
else: # pragma: no cover
pass
comments.extend(ManyOptional("COMMENT")(stream))
for idx, com in enumerate(comments):
if com.startswith("CONSTANT TIME"):
date = tuple(com.strip().split()[2:])
comments[idx] = "Measurement time: %s-%s-%s %s:%s:%s" % date
block.comments = Comments(comments)
shape = tuple(block.ivardata[i[0]].data.shape[0] for i in varnames)
dims = tuple(block.ivardata[i[0]] for i in varnames)
for name, typ in datanames:
One("DATA_LIST_BEGIN", "Missing BEGIN")(stream)
datalist = array(handle_data(ManyOptional("DATA")(stream), typ))
datalist.shape = shape
block[name] = hfarray(datalist, dims=dims)
One("DATA_LIST_END", "Missing END")(stream)
yield block
示例15: test_2
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import comments [as 别名]
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)