Ejemplo n.º 1
0
def make_block_iterator(data, first=False):
    if not data.vardata:  # only x-values
        sweepvars = ()
        head = data.ivardata.keys()[0]
        dim = data.ivardata[head]

        header = [
            head,
        ]
        fmts = (data[head].outputformat, )
        columns = (hfarray(dim), )
        blockname = data.blockname
        comments = data.comments
        yield (sweepvars, header, fmts, columns, blockname, comments)
        raise StopIteration
    d = data.vardata.values()[0]
    if ismatrix(d):
        dimsnames = [x.name for x in d.dims[:-2]]
    else:
        dimsnames = [x.name for x in d.dims]
    dimsdata = [hfarray(data.ivardata[iname]) for iname in dimsnames]
    dimsidx = [range(x.shape[0]) for x in dimsdata]
    if first:
        if data.comments:
            comments = data.comments.copy()
            comments.property.clear()
        else:
            comments = Comments()
    else:
        comments = Comments()
    for enum, idx in enumerate(itertools.product(*dimsidx[1:])):
        sweepvars = []
        for iname, dim, i in zip(dimsnames[1:], dimsdata[1:], idx):
            fmt = getattr(dim, "outputformat", "%.16e")
            sweepvars.append((iname, fmt, dim[i]))
        if dimsnames:
            header = [dimsnames[0]] + data.vardata.keys()
            columns = dimsdata[:1] + [
                col[(slice(None), ) + idx] for col in data.vardata.values()
            ]
            fmts = [getattr(x, "outputformat", "%.16e") for x in columns]
        else:
            header = []
            columns = []
            fmts = []
            for k, v in data.vardata.items():
                if v.dims == tuple():
                    comments.property[k] = v

        if enum:
            comments = Comments()
        yield (sweepvars, header, fmts, columns, data.blockname, comments)
Ejemplo n.º 2
0
def make_block_iterator(data, first=False):
    if not data.vardata:   # only x-values
        sweepvars = ()
        head = data.ivardata.keys()[0]
        dim = data.ivardata[head]

        header = [head, ]
        fmts = (data[head].outputformat,)
        columns = (hfarray(dim),)
        blockname = data.blockname
        comments = data.comments
        yield (sweepvars, header, fmts, columns,
               blockname, comments)
        raise StopIteration
    d = data.vardata.values()[0]
    if ismatrix(d):
        dimsnames = [x.name for x in d.dims[:-2]]
    else:
        dimsnames = [x.name for x in d.dims]
    dimsdata = [hfarray(data.ivardata[iname]) for iname in dimsnames]
    dimsidx = [range(x.shape[0]) for x in dimsdata]
    if first:
        if data.comments:
            comments = data.comments.copy()
            comments.property.clear()
        else:
            comments = Comments()
    else:
        comments = Comments()
    for enum, idx in enumerate(itertools.product(*dimsidx[1:])):
        sweepvars = []
        for iname, dim, i in zip(dimsnames[1:], dimsdata[1:], idx):
            fmt = getattr(dim, "outputformat", "%.16e")
            sweepvars.append((iname, fmt, dim[i]))
        if dimsnames:
            header = [dimsnames[0]] + data.vardata.keys()
            columns = dimsdata[:1] + [col[(slice(None), ) + idx]
                                      for col in data.vardata.values()]
            fmts = [getattr(x, "outputformat", "%.16e") for x in columns]
        else:
            header = []
            columns = []
            fmts = []
            for k, v in data.vardata.items():
                if v.dims == tuple():
                    comments.property[k] = v

        if enum:
            comments = Comments()
        yield (sweepvars, header, fmts, columns,
               data.blockname, comments)
Ejemplo n.º 3
0
def db_iterator(indb, fmt_block_generator):
    datablock = {}
    used_ivars = set()
    for vname in indb.vardata.keys():
        if ismatrix(indb.vardata[vname]):
            dimsnames = get_dims_names(*indb[vname].dims)[:-2]
            names = get_dims_names(*indb[vname].dims)[-2:]
            used_ivars = used_ivars.union(names)
        else:
            dimsnames = get_dims_names(*indb[vname].dims)

        q = datablock.setdefault(dimsnames, DataBlock())
        if q.comments is None:
            q.comments = indb.comments
        q[vname] = indb[vname]
        q[vname].outputformat = indb[vname].outputformat

    #
    #Collect dangling ivars
    #
    for names in datablock.keys():
        used_ivars = used_ivars.union(names)

    for vname in set(indb.ivardata).difference(used_ivars):
        q = datablock.setdefault((vname,), DataBlock())
        if q.comments is None:
            q.comments = Comments()
        q[vname] = indb.ivardata[vname]

    first = True

    #Handle block with scalar data first
    dbs = []
    if tuple() in datablock:
        dbs.append(datablock.pop(tuple()))
    for v in datablock.values():
        dbs.append(v)

    for db in dbs:
        for block_content in make_block_iterator(db, first):
            if first:
                first = False
            else:
                yield []
            for rad in fmt_block_generator(*block_content):
                yield rad
Ejemplo n.º 4
0
def make_col_from_matrix(header, columns, fmt_matrix, fortranorder=False):
    fullheader = []
    fullcolumns = []
    for colname, col in zip(header, columns):
        if ismatrix(col):
            for i in range(col.dims[-2].data.shape[0]):
                for j in range(col.dims[-1].data.shape[0]):
                    if fortranorder:
                        I, J = j, i
                    else:
                        I, J = i, j
                    fullheader.append(fmt_matrix % (colname, I + 1, J + 1))
                    fullcolumns.append(col[..., I, J])
        else:
            fullheader.append(colname)
            fullcolumns.append(col)
    return fullheader, fullcolumns
Ejemplo n.º 5
0
def db_iterator(indb, fmt_block_generator):
    datablock = {}
    used_ivars = set()
    for vname in indb.vardata.keys():
        if ismatrix(indb.vardata[vname]):
            dimsnames = get_dims_names(*indb[vname].dims)[:-2]
            names = get_dims_names(*indb[vname].dims)[-2:]
            used_ivars = used_ivars.union(names)
        else:
            dimsnames = get_dims_names(*indb[vname].dims)

        q = datablock.setdefault(dimsnames, DataBlock())
        if q.comments is None:
            q.comments = indb.comments
        q[vname] = indb[vname]
        q[vname].outputformat = indb[vname].outputformat

    #
    #Collect dangling ivars
    #
    for names in datablock.keys():
        used_ivars = used_ivars.union(names)

    for vname in set(indb.ivardata).difference(used_ivars):
        q = datablock.setdefault((vname, ), DataBlock())
        if q.comments is None:
            q.comments = Comments()
        q[vname] = indb.ivardata[vname]

    first = True

    #Handle block with scalar data first
    dbs = []
    if tuple() in datablock:
        dbs.append(datablock.pop(tuple()))
    for v in datablock.values():
        dbs.append(v)

    for db in dbs:
        for block_content in make_block_iterator(db, first):
            if first:
                first = False
            else:
                yield []
            for rad in fmt_block_generator(*block_content):
                yield rad
Ejemplo n.º 6
0
def make_col_from_matrix(header, columns, fmt_matrix, fortranorder=False):
    fullheader = []
    fullcolumns = []
    for colname, col in zip(header, columns):
        if ismatrix(col):
            for i in range(col.dims[-2].data.shape[0]):
                for j in range(col.dims[-1].data.shape[0]):
                    if fortranorder:
                        I, J = j, i
                    else:
                        I, J = i, j
                    fullheader.append(fmt_matrix % (colname, I + 1, J + 1))
                    fullcolumns.append(col[..., I, J])
        else:
            fullheader.append(colname)
            fullcolumns.append(col)
    return fullheader, fullcolumns