Changeset 5191


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

append units to uq parameters sent to submit

Location:
branches/uq
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/uq/lang/tcl/scripts/library.tcl

    r5182 r5191  
    10601060#
    10611061# For example, 2 parameters, one gaussian and one uniform might return:
    1062 # [["height",["gaussian",100,10,{"min":0}]],["velocity",["uniform",80,90]]]
     1062# [["height","m",["gaussian",100,10,{"min":0}]],["velocity","m/s",["uniform",80,90]]]
    10631063#
    10641064# Returns "" if there are no UQ parameters.
     
    10921092            }
    10931093
     1094            set units ""
    10941095            set unode [$_n selectNodes units/text()]
    10951096            if {"" != $unode} {
     
    10991100            }
    11001101
    1101             set v \[\"[$_n getAttribute id]\",
     1102            set v \[\"[$_n getAttribute id]\",\"$units\",
    11021103            #set val \"[lindex $val 0]\",[lindex $val 1],[lindex $val 2]
    11031104            set fmt "\[\"%s\",%.16g,%.16g"
     
    11101111                if {"" != $min_node} {
    11111112                    set minv [$min_node nodeValue]
    1112                     if {$unode != ""} {
     1113                    if {$units != ""} {
    11131114                        set minv [Rappture::Units::convert $minv -context $units -units off]
    11141115                    }
     
    11191120                if {"" != $max_node} {
    11201121                    set maxv [$max_node nodeValue]
    1121                     if {$unode != ""} {
     1122                    if {$units != ""} {
    11221123                        set maxv [Rappture::Units::convert $maxv -context $units -units off]
    11231124                    }
  • 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.