本文整理汇总了Python中hftools.dataset.DataBlock.replace_dim方法的典型用法代码示例。如果您正苦于以下问题:Python DataBlock.replace_dim方法的具体用法?Python DataBlock.replace_dim怎么用?Python DataBlock.replace_dim使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hftools.dataset.DataBlock
的用法示例。
在下文中一共展示了DataBlock.replace_dim方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Test_replace_dim
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import replace_dim [as 别名]
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")
示例2: merge_blocks_do_hyper
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import replace_dim [as 别名]
def merge_blocks_do_hyper(blocks):
#import pdb;pdb.set_trace()
outdata = DataBlock()
data = merge_blocks_to_association_list(blocks)
ivars = {}
for b in blocks:
for vname, v in b.ivardata.items():
if vname not in ivars:
ivars[vname] = v
free_vars = set()
for vname, assoc in data.items():
free_vars.add(zip(*assoc)[0])
free_vars = list(free_vars)
for vname, assoc in data.items():
v, indexvars, dim = merge_variable(assoc)
outdata[vname] = v
for iname, value in indexvars.items():
outdata.ivardata[iname] = value.dims[0]
for v in outdata.vardata.keys():
if v in outdata.ivardata:
del outdata.vardata[v]
for v in outdata.vardata.values():
for k in v.dims:
if k.name in outdata.ivardata:
if ((isinstance(k, DimRep) and
not isinstance(outdata.ivardata[k.name], DimRep))):
outdata.replace_dim(outdata.ivardata[k.name], k)
cmt = Comments()
for block in blocks:
if block.comments:
cmt.extend(block.comments)
outdata.comments = cmt
outdata.blockname = blocks[0].blockname
for vname, v in ivars.items():
if vname not in outdata:
outdata[vname] = v
#import pdb;pdb.set_trace()
return outdata