Exemplo n.º 1
0
def write_summary(io, h5):
    outstr = StringIO.StringIO()
    write_params(h5, outstr)
    uqtype = h5.attrs['UQtype']
    for v in h5[uqtype]:
        if '[' in v:
            # It is a curve. Ignore.
            continue
        desc = h5['%s/%s' % (uqtype, v)].attrs['description']
        print("QoI: %s (%s)" % (v, desc), file=outstr)
        rs = unpickle(h5['/%s/%s/response' % (uqtype, v)].value)
        if type(rs) == puq.response.ResponseFunc:
            print("\nv=%s\n" % rs.eqn, file=outstr)
            print("SURROGATE MODEL ERROR:{:6.3g}%".format(rs.rmse()[1]), file=outstr)
        sens = puq.unpickle(h5['/%s/%s/sensitivity' % (uqtype, v)].value)
        max_name_len = max(map(len, [p[0] for p in sens]))
        print("\nSENSITIVITY:", file=outstr)
        print("Var%s     u*          dev" % (' '*(max_name_len)), file=outstr)
        print('-'*(28+max_name_len), file=outstr)
        for item in sens:
            pad = ' '*(max_name_len - len(item[0]))
            print("{}{}  {:10.4g}  {:10.4g}".format(pad, item[0],
                item[1]['ustar'], item[1]['std']), file=outstr)
        print('-'*(28+max_name_len), file=outstr)
        print(file=outstr)
    iostr = io['output.string(UQ Summary)']
    iostr['about.label'] = 'UQ Summary'
    iostr['current'] = outstr.getvalue()
    outstr.close()
Exemplo n.º 2
0
def write_params(h5, out):
    params = map(str, h5['/input/params'].keys())
    print('#' * 80, file=out)
    print('INPUT PARAMETERS', file=out)

    for pname in params:
        print('-' * 80, file=out)
        p = puq.unpickle(h5['/input/params/' + pname].value)
        cname = p.__class__.__name__[:-9]
        pdf_str = '%s [%s - %s] mean=%s dev=%s mode=%s' % (cname, p.pdf.range[0], p.pdf.range[1], p.pdf.mean, p.pdf.dev, p.pdf.mode)

        print("Name:", p.name, file=out)
        try:
            print("Label:", p.label, file=out)
        except:
            pass
        print("Desc:", p.description, file=out)
        print('Value:', pdf_str, file=out)
    print('#' * 80, file=out)
    print(file=out)
Exemplo n.º 3
0
Arquivo: read.py Projeto: zoidy/puq
def read_obj(loc):
    name = None
    desc = None
    if loc.startswith('http'):
        try:
            obj = NetObj(loc)
            name, desc = get_name_desc(obj, loc)
            return [(obj, name, desc)]
        except:
            print "Error accessing", loc
            return []
    else:
        extension = loc.split('.')[-1]
        if extension == 'json':
            f = open(loc, 'r')
            obj = unpickle(f.read())
            f.close()
            name, desc = get_name_desc(obj, loc)
            return [(obj, name, desc)]
        elif extension == 'py':
            return python_load(loc)
    print "Don't know how to open %s." % loc
    return []
Exemplo n.º 4
0
def read_obj(loc):
    name = None
    desc = None
    if loc.startswith('http'):
        try:
            obj = NetObj(loc)
            name, desc = get_name_desc(obj, loc)
            return [(obj, name, desc)]
        except:
            print("Error accessing", loc)
            return []
    else:
        extension = loc.split('.')[-1]
        if extension == 'json':
            f = open(loc, 'r')
            obj = unpickle(f.read())
            f.close()
            name, desc = get_name_desc(obj, loc)
            return [(obj, name, desc)]
        elif extension == 'py':
            return python_load(loc)
    print("Don't know how to open %s." % loc)
    return []