Ignore:
Timestamp:
Apr 4, 2015 9:38:19 AM (8 years ago)
Author:
mmh
Message:

append units to uq parameters sent to submit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/uq/puq/get_params.py

    r5182 r5191  
    88"""
    99
     10from __future__ import print_function
    1011import sys
    1112import os
     
    1819sys.stderr = open("uq_debug.err", 'w')
    1920
    20 print sys.argv
     21print(sys.argv)
    2122pid, varlist, uq_type, args = sys.argv[1:]
    2223
     
    2627
    2728varlist = unpickle(varlist)
    28 print "varlist=", varlist
     29print("varlist=", varlist)
    2930
    3031v = {}
     32units = {}
    3133for p in varlist:
    32     name, dist = p
     34    name, _units, dist = p
    3335    name = str(name)
     36    units[name] = str(_units)
    3437    if dist[0] == u'gaussian':
    3538        try:
     
    3841            kwargs = {}
    3942        v[name] = NormalParameter(name, name, mean=dist[1], dev=dist[2], **kwargs)
    40         print v[name]
     43        print(v[name])
    4144    elif dist[0] == u'uniform':
    4245        v[name] = UniformParameter(name, name, min=dist[1], max=dist[2])
    4346    else:
    44         print "ERROR: Unknown distribution type: %s" % dist[0]
     47        print("ERROR: Unknown distribution type: %s" % dist[0])
    4548        sys.exit(1)
    4649if uq_type == "smolyak":
    4750    uq = Smolyak(v.values(), args)
    4851else:
    49     print "ERROR: Unknown UQ type: %s" % uq_type
     52    print("ERROR: Unknown UQ type: %s" % uq_type)
    5053    os.chdir('..')
    5154    sys.exit(1)
    5255
    5356# save parameter values to CSV file
    54 vals = np.column_stack([p.values for p in uq.params])
    55 names = ['@@'+str(p.name) for p in uq.params]
    56 np.savetxt(cvsname, vals, delimiter=',', header=','.join(names), comments='')
     57with open(cvsname, 'w') as f:
     58    print(','.join(['@@'+str(p.name) for p in uq.params]), file=f)
     59    for i in range(len(uq.params[0].values)):
     60        print(','.join(['%.16g%s' % (p.values[i], units[p.name]) for p in uq.params]), file=f)
    5761
    5862# This just saves PUQ state into HDF5 file, so later we can have PUQ analyze
     
    6367sw.run(hname, overwrite=True)
    6468
    65 print "Finished with get_params.py\n"
     69print("Finished with get_params.py\n")
Note: See TracChangeset for help on using the changeset viewer.