Changeset 5412 for branches/uq


Ignore:
Timestamp:
May 4, 2015 5:14:03 AM (9 years ago)
Author:
mmh
Message:

update graph.py example

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/uq/examples/graph/graph.py

    r3177 r5412  
    77#
    88# ======================================================================
    9 #  AUTHOR:  Michael McLennan, Purdue University
    10 #  Copyright (c) 2004-2012  HUBzero Foundation, LLC
     9#  AUTHOR:  Martin Hunt, Purdue University
     10#  Copyright (c) 2015  HUBzero Foundation, LLC
    1111#
    1212#  See the file "license.terms" for information on usage and
     
    1414# ======================================================================
    1515
     16# Note: You will not see stdout and stderr when this
     17# tool is run by Rappture.  You can either run this tool from the command
     18# line by passing in a driver xml file like this:
     19# ~/rap/rappture/examples/graph> python graph.py driver1234.xml
     20#
     21# or you can redirect stdout and stderr to files by uncommenting the
     22# two lines after the import sys
     23
    1624import Rappture
     25import numpy as np
    1726import sys
    18 from math import *
    1927
    20 io = Rappture.library(sys.argv[1])
     28# uncomment these for debugging
     29# sys.stderr = open('graph.err', 'w')
     30# sys.stdout = open('graph.out', 'w')
    2131
    22 xmin = float(io.get('input.number(min).current'))
    23 xmax = float(io.get('input.number(max).current'))
    24 formula = io.get('input.string(formula).current')
     32io = Rappture.PyXml(sys.argv[1])
     33
     34# When reading from xml, all values are strings
     35xmin = float(io['input.number(min).current'].value)
     36xmax = float(io['input.number(max).current'].value)
     37formula = io['input.string(formula).current'].value
    2538print 'formula = %s' % formula
    26 npts = 100
    2739
    28 io.put('output.curve(result).about.label','Formula: Y vs X',append=0)
    29 io.put('output.curve(result).yaxis.label','Y')
    30 io.put('output.curve(result).xaxis.label','X')
     40curve = io['output.curve(result)']
     41curve['about.label'] = 'Formula: Y vs X'
     42curve['yaxis.label'] = 'Y'
     43curve['xaxis.label'] = 'X'
    3144
    32 for i in range(npts):
    33     x = (xmax-xmin)/npts * i + xmin;
    34     y = eval(formula)
    35     io.put('output.curve(result).component.xy', '%g %g\n' % (x,y), append=1)
     45num_points = 100
     46x = np.linspace(xmin, xmax, num_points)
     47y = eval(formula)
     48curve['component.xy'] = (x, y)
    3649
    37 Rappture.result(io)
     50# Done. Write out the xml file for Rappture.
     51io.close()
Note: See TracChangeset for help on using the changeset viewer.