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


Python DataBlock.replace_dim方法代码示例

本文整理汇总了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")
开发者ID:arsenovic,项目名称:hftools,代码行数:27,代码来源:test_data_block.py

示例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
开发者ID:ychaim,项目名称:hftools,代码行数:44,代码来源:merge.py


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