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


Python DataBlock.blockname方法代码示例

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


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

示例1: test_10

# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import blockname [as 别名]
 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,代码行数:11,代码来源:test_hdf5_v01.py

示例2: merge_blocks

# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import blockname [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
开发者ID:ychaim,项目名称:hftools,代码行数:57,代码来源:merge.py

示例3: parse_blocks

# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import blockname [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
开发者ID:jsonbao,项目名称:hftools,代码行数:47,代码来源:citi.py

示例4: read_hdf5

# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import blockname [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
开发者ID:arsenovic,项目名称:hftools,代码行数:45,代码来源:v_01.py

示例5: merge_blocks_do_hyper

# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import blockname [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

示例6: format_citi_block

# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import blockname [as 别名]
def format_citi_block(inblock):
    block = DataBlock()
    for k, v in inblock.vardata.items():
        block[k] = v
    block.blockname = inblock.blockname
    block.comments = inblock.comments
    yield "CITIFILE A.01.01"

    if block.comments:
        for comment in block.comments.fullcomments:
            yield "!" + comment.lstrip("!")
    else:
        pass
    yield "NAME %s" % block.blockname

    for name, value in block.ivardata.items():
        if is_numlike(value.data) and not isinstance(value, _DimMatrix):
            yield "VAR %s MAG %s" % (name, value.data.shape[0])

    for name, value in block.vardata.items():
        if is_numlike(value):
            if hftools.dataset.ismatrix(value):
                names = []
                for i in hfarray(value.dims[-2]):
                    for j in hfarray(value.dims[-1]):
                        names.append("%s%s%s" % (name, i + 1, j + 1))
            else:
                names = [name]
            for n in names:
                if iscomplexobj(value):
                    yield "DATA %s RI" % (n)
                else:
                    yield "DATA %s MAG" % (n)

    for name, value in block.ivardata.items():
        if is_numlike(value.data) and not isinstance(value, _DimMatrix):
            yield "VAR_LIST_BEGIN"
            fmt = value.outputformat
            for rad in value.data:
                yield fmt % rad
            yield "VAR_LIST_END"

    for name, value in block.vardata.items():
        if is_numlike(value):
            if hftools.dataset.ismatrix(value):
                values = []
                for i in hfarray(value.dims[-2]):
                    for j in hfarray(value.dims[-1]):
                        values.append(value[..., i, j])
            else:
                values = [value]
            for val in values:
                yield "BEGIN"
                if iscomplexobj(val):
                    fmt = "%s,%s" % (val.outputformat, val.outputformat)
                    for rad in val.flat:
                        yield fmt % (rad.real, rad.imag)
                else:
                    fmt = val.outputformat
                    for rad in val.flat:
                        yield fmt % rad
                yield "END"
开发者ID:jsonbao,项目名称:hftools,代码行数:64,代码来源:citi.py

示例7: test_2

# 需要导入模块: from hftools.dataset import DataBlock [as 别名]
# 或者: from hftools.dataset.DataBlock import blockname [as 别名]
 def test_2(self):
     d = DataBlock()
     d.FILENAME = hfarray(["foo.txt", "bar.txt"],
                             dims=(DimRep("FILEINDEX", [0, 1]),))
     d.blockname = "baz.txt"
     self.assertEqual(d.blockname, "baz.txt")
开发者ID:arsenovic,项目名称:hftools,代码行数:8,代码来源:test_data_block.py


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