本文整理汇总了Python中hftools.dataset.DataBlock.squeeze方法的典型用法代码示例。如果您正苦于以下问题:Python DataBlock.squeeze方法的具体用法?Python DataBlock.squeeze怎么用?Python DataBlock.squeeze使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hftools.dataset.DataBlock
的用法示例。
在下文中一共展示了DataBlock.squeeze方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: merge_blocks
# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import squeeze [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