def main(): # Get arguments io = Rappture.library(sys.argv[1]) xmin = float(io.get('input.number(min).current')) xmax = float(io.get('input.number(max).current')) formula = io.get('input.string(formula).current') a = float(io.get('input.number(a).current')) # Get base string my_str_base = 'int_0^root (' + formula + ') dx - ' + str(a) # Get compute root of \int_0^x f(x') dx' - a root = optimize.brentq(calc, xmin, xmax, args=(a, formula)) my_str = 'Root of f(x) in the range ' + str(xmin) + ' to ' + \ str(xmax) + ' is ' + str(root) io.put('output.string(result1).about.label', 'Root') io.put('output.string(result1).current', my_str) Rappture.result(io) # Check check = calc(root, a, formula) my_str2 = '\nCheck: ' + my_str_base + ' = ' + str(check[0]) print(my_str2 + '\n')
def main(): io = Rappture.library(sys.argv[1]) xmin = float(io.get('input.number(min).current')) xmax = float(io.get('input.number(max).current')) y0 = float(io.get('input.number(Y0).current')) npts = int(io.get('input.number(Npts).current')) formula = io.get('input.string(formula).current') x = np.linspace(xmin, xmax, npts) sol = odeint(calc, y0, x, args=(1, formula)) io.put('output.curve(result1).about.label', 'Integral of f(X) vs X', append=0) io.put('output.curve(result1).yaxis.label', 'Integral of f(X)') io.put('output.curve(result1).xaxis.label', 'X') for i in range(npts): io.put('output.curve(result1).component.xy', '%g %g\n' % (x[i], sol[i][0]), append=1) root = optimize.brentq(f, xmin, xmax, args=(1, formula)) my_str = 'Root of f(x) in the range ' + str(xmin) + ' to ' + \ str(xmax) + ' is ' + str(root) io.put('output.string(result2).about.label', 'Root') io.put('output.string(result2).current', my_str) Rappture.result(io)
def finish(): """ Called automatically whenever the program exits. Writes out any results in the global driver to the "run.xml" file representing the entire run. """ # f = open("run.xml","w") # f.write( Rappture.driver.xml() ) # f.close() Rappture.result(Rappture.driver)
def main(): # Get arguments io = Rappture.library(sys.argv[1]) x = 0.0001 dx = 0.0001 psi0 = float(io.get('input.number(psi0).current')) y_init = [psi0, 0] r = [] psi = [] dens = [] yy = 1 while yy >= 1.e-8: sol = odeint(king, y_init, [0, x]) yy = sol[1, 0] r.append(x) psi.append(yy) dens.append(rho(yy)) dx = min(2. * dx, 0.02 * sol[1, 0] / abs(sol[1, 1])) x += dx v_max = np.sqrt(2.) * np.sqrt(psi) for i in range(len(r)): io.put('output.curve(result1).component.xy', '%g %g\n' % (r[i], dens[i]), append=1) io.put('output.curve(result1).about.label', 'density vs. r', append=0) io.put('output.curve(result1).yaxis.label', 'density') io.put('output.curve(result1).xaxis.label', 'radius') for i in range(len(r)): io.put('output.curve(result2).component.xy', '%g %g\n' % (r[i], v_max[i]), append=1) io.put('output.curve(result2).about.label', 'v_max vs. r', append=0) io.put('output.curve(result2).yaxis.label', 'v_max') io.put('output.curve(result2).xaxis.label', 'radius') for i in range(len(r)): io.put('output.curve(result3).component.xy', '%g %g\n' % (r[i], psi[i]), append=1) io.put('output.curve(result3).about.label', 'psi vs. r', append=0) io.put('output.curve(result3).yaxis.label', 'psi') io.put('output.curve(result3).xaxis.label', 'radius') Rappture.result(io)
def main(): io = Rappture.library(sys.argv[1]) xmin = float(io.get('input.number(min).current')) xmax = float(io.get('input.number(max).current')) a = float(io.get('input.number(a).current')) y0 = float(io.get('input.number(Y0).current')) npts = int(io.get('input.number(Npts).current')) formula = io.get('input.string(formula).current') x = np.linspace(xmin, xmax, npts) sol = odeint(calc, y0, x, args=(formula, )) io.put('output.curve(result0).about.label', 'f(X) vs X', append=0) io.put('output.curve(result0).yaxis.label', 'f(X)') io.put('output.curve(result0).xaxis.label', 'X') io.put('output.curve(result1).about.label', 'Integral of f(X) vs X', append=0) io.put('output.curve(result1).yaxis.label', 'Integral of f(X)') io.put('output.curve(result1).xaxis.label', 'X') for i in range(npts): io.put('output.curve(result0).component.xy', '%g %g\n' % (x[i], f(x[i], formula)), append=1) io.put('output.curve(result1).component.xy', '%g %g\n' % (x[i], sol[i][0]), append=1) my_str_base = 'int_0^root (' + formula + ') dx - ' + str(a) root = optimize.brentq(calc, xmin, xmax, args=(a, formula)) my_str = '\nRoot of ' + my_str_base + ' in [' + str(xmin) + \ ', ' + str(xmax) + '] is ' + str(root) io.put('output.string(result1).about.label', 'Root') io.put('output.string(result1).current', my_str) check = calc(root, a, formula) my_str2 = '\nCheck: ' + my_str_base + ' = ' + str(check[0]) io.put('output.string(result2).about.label', 'Diagnostic') io.put('output.string(result2).current', my_str2) Rappture.result(io)
def main(): io = Rappture.library(sys.argv[1]) xmin = float(io.get('input.number(min).current')) xmax = float(io.get('input.number(max).current')) y0 = float(io.get('input.number(Y0).current')) npts = int(io.get('input.number(Npts).current')) formula = io.get('input.string(formula).current') x = np.linspace(xmin, xmax, npts) sol = odeint(calc, y0, x, args=(1, formula)) root = optimize.brentq(f, xmin, xmax, args=(1, formula)) my_str = 'Root of f(x) in the range' + str(xmin) + ' to' + \ str(xmax) + ' is ' + str(root) io.put('output.string(result1).about.label', 'Root') io.put('output.string(result1).current', my_str) Rappture.result(io)
# ---------------------------------------------------------------------- # MAIN PROGRAM - generated by the Rappture Builder # ---------------------------------------------------------------------- import Rappture import sys import numpy as np import math import scipy.linalg from scipy.stats import norm # open the XML file containing the run parameters io = Rappture.library(sys.argv[1]) ######################################################### # Get input values from Rappture ######################################################### # get input value for input.number(lengthscale) lengthscale = float(io.get('input.phase(values).group(inputpara).number(lengthscale).current')) # get input value for input.number(signal_strength) signal_strength = float(io.get('input.phase(values).group(inputpara).number(signal_strength).current')) # get input value for input.number(noise_variance) noise_var = float(io.get('input.phase(values).group(inputpara).number(noise_var).current')) # get input value for input.number(n_samples) n_samples = int(io.get('input.phase(values).integer(n_samples).current')) # get input value for input.phase(values).boolean(manual) # returns value as string "yes" or "no"
# ---------------------------------------------------------------------- # Python wrapper for Nanoconfinement code. # # This wrapper script calls Rappture API to fetch input values and # passes them to nanoconfinement tool. The wrapper can be extended # to do higher level data manipulation to marshall user inputs. # # ---------------------------------------------------------------------- import Rappture import sys, os, commands, string, shutil, math # open the XML file containing the run parameters driver = Rappture.library(sys.argv[1]) # Parse the rappture generated XML file to extract user input values io = Rappture.PyXml(sys.argv[1]) salt_concentration = io[ 'input.group(physical).number(salt_concentration).current'].value print "salt concentration is %s" % salt_concentration positive_valency = io[ 'input.group(physical).integer(positive_valency).current'].value print "positive valency is %s" % positive_valency negative_valency = io[ 'input.group(physical).integer(negative_valency).current'].value print "negative_valency is %s" % negative_valency confinement_length = io[
def interface(argv,*args): """ Clients call this near the top of their simulator. It looks at command line arguments and decides whether the Rappture GUI should be invoked, or perhaps the GUI has already been invoked and the simulator should process a driver file. The argv is a list of command-line arguments. All remaining arguments represent packages that should be imported and interrogated for Rappture components, to feed the GUI. """ try: opts,rest = getopt.getopt(argv[1:],'d:g',["driver","gui"]) except getopt.GetoptError: print 'usage:' print ' %s --gui (launch the graphical interface)' % argv[0] print ' %s --driver file (use the input stored in file)' % argv[0] sys.exit(2) for opt,val in opts: if opt in ('-g','--gui'): # # Launch the GUI. Start by loading the various modules # and interrogating them for symbols. # lib = Rappture.library('<?xml version="1.0"?><run><tool>' + '<about>Press Simulate to view results.</about>' + '<command>python ' +argv[0]+ ' -d @driver</command></tool></run>') for module in args: for symbol in dir(module): s = module.__dict__[symbol] if isinstance(s, Rappture.number): s.put(lib) toolFileName = "tool.xml" f = open(toolFileName,"w") f.write( lib.xml() ) f.close() print 'launch the gui...' # # this doesnt work, but needs to. when we # os.execvp('driver', driverArgs ) with following definition of # driverArgs (and we change the name of toolFileName), program # does not send the driver program the arguments as expected. # #driverArgs = ('-tool', toolFileName) driverArgs = () os.execvp('driver', driverArgs ) sys.exit(0) elif opt in ('-d','--driver'): # # Continue, using input from the driver file. # Register a hook to write out results upon exit. # Rappture.driver = Rappture.library(val) atexit.register(finish) return
def main(argv=None): # initialize the global interface Rappture.Interface(sys.argv,fermi_io) # check the global interface for errors if (Rappture.Interface.error() != 0) { # there were errors while setting up the interface # dump the traceback o = Rappture.Interface.outcome() print >>sys.stderr, "%s", o.context() print >>sys.stderr, "%s", o.remark() return (Rappture.Interface.error()) } # connect variables to the interface # look in the global interface for an object named # "temperature", convert its value to Kelvin, and # store the value into the address of T. # look in the global interface for an object named # "Ef", convert its value to electron Volts and store # the value into the address of Ef # look in the global interface for an object named # factorsTable and set the variable result to # point to it. T = Rappture.Interface.connect(name="temperature", hints=["units=K"]) Ef = Rappture.Interface.connect(name="Ef", hints=["units=eV"]); p1 = Rappture.Interface.connect(name="fdfPlot"); p2 = Rappture.Interface.connect(name="fdfPlot"); # check the global interface for errors if (Rappture.Interface.error() != 0) { # there were errors while retrieving input data values # dump the tracepack o = Rappture.Interface.outcome() print >>sys.stderr, "%s", o.context() print >>sys.stderr, "%s", o.remark() return (Rappture.Interface.error()) } # do science calculations nPts = 200; EArr = list() # [nPts] fArr = list() # [nPts] kT = 8.61734e-5 * T Emin = Ef - (10*kT) Emax = Ef + (10*kT) dE = (1.0/nPts)*(Emax-Emin) E = Emin; for idx in xrange(nPts): E = E + dE f = 1.0/(1.0 + exp((E - Ef)/kT)) fArr.append(f) EArr.append(E) progress = (int)((E-Emin)/(Emax-Emin)*100) Rappture.Utils.progress(progress,"Iterating") # set up the curves for the plot by using the add command # add <name> <xdata> <ydata> -format <fmt> # # to group curves on the same plot, just keep adding curves # to save space, X array values are compared between curves. # the the X arrays contain the same values, we only store # one version in the internal data table, otherwise a new # column is created for the array. for big arrays this may take # some time, we should benchmark to see if this can be done # efficiently. p1.add(name="fdfCurve1", xdata=fArr, ydata=EArr, format="g:o") p2.add(name="fdfCurve2", xdata=fArr, ydata=EArr, format="b-o") p2.add(name="fdfCurve3", xdata=fArr, ydata=EArr, format="p--") # close the global interface # signal to the graphical user interface that science # calculations are complete and to display the data # as described in the views Rappture.Interface.close() return 0
hist['yaxis.label'] = 'Sensitivity' pts = '' for name in sens: n = name[0] try: n = h5['/input/params/%s' % n].attrs['label'] except: pass pts += "\"%s\" %s\n" % (n, name[1]['ustar']) hist['component.xy'] = pts sw = load_from_hdf5(sys.argv[1]) sw.analyze() h5 = h5py.File(sys.argv[1], 'r+') io = Rappture.PyXml('run_uq.xml') # curves built from pdfs pcurves = {} xvals = {} acurves = {} reg1 = re.compile('([ \da-zA-Z_]+)\[([ \d]+)\]') uqtype = h5.attrs['UQtype'] for v in h5[uqtype]: print('v=', v) rsp = h5['/%s/%s/response' % (uqtype, v)].value rs = unpickle(rsp) pdf = rs.pdf(fit=False) odata = h5['/output/data/%s' % v]
except IndexError: return Rappture.Utils.progress(*stage) if __name__ == '__main__': progress_stages = [(0, "Initializing Converter..."), (50, "Converting..."), (70, "Rendering..."), (90, "Loading output files..."), ] progress() # Open driver driver_name = sys.argv[1] driver = Rappture.library(driver_name) if driver is None: print "Error opening file " + driver_name exit(-1) driver_number = Rappture.tools.getDriverNumber(driver_name) # Get the tool root directory tool_path = sys.argv[2] if tool_path == "": tool_path = os.path.dirname(driver.get('tool.version.application.directory(tool)')) # Pre-Processing File Cleanup in case of Aborted sessions for filename in ('field_data', 'mesh_data', 'vtkout', 'vtrout_1.vtr', 'estimate_out', 'faceless_input', 'dupe_output_filename', 'write_dex'):
def main(argv=None): # initialize the global interface Rappture.Interface(sys.argv,fermi_io) # check the global interface for errors if (Rappture.Interface.error() != 0) { # there were errors while setting up the interface # dump the traceback o = Rappture.Interface.outcome() print >>sys.stderr, "%s", o.context() print >>sys.stderr, "%s", o.remark() return (Rappture.Interface.error()) } # connect variables to the interface # look in the global interface for an object named # "temperature", convert its value to Kelvin, and # store the value into the address of T. # look in the global interface for an object named # "Ef", convert its value to electron Volts and store # the value into the address of Ef # look in the global interface for an object named # factorsTable and set the variable result to # point to it. T = Rappture.Interface.connect(name="temperature", hints=["units=K"]) Ef = Rappture.Interface.connect(name="Ef", hints=["units=eV"]); x1 = Rappture.Interface.connect(name="Fermi-Dirac Factor"); y1 = Rappture.Interface.connect(name="Energy"); x2 = Rappture.Interface.connect(name="Fermi-Dirac Factor * 2"); y2 = Rappture.Interface.connect(name="Energy * 2"); # check the global interface for errors if (Rappture.Interface.error() != 0) { # there were errors while retrieving input data values # dump the tracepack o = Rappture.Interface.outcome() print >>sys.stderr, "%s", o.context() print >>sys.stderr, "%s", o.remark() return (Rappture.Interface.error()) } # declare program variables nPts = 200; EArr = list() # [nPts] fArr = list() # [nPts] EArr2 = list() # [nPts] fArr2 = list() # [nPts] # do science calculations kT = 8.61734e-5 * T Emin = Ef - (10*kT) Emax = Ef + (10*kT) dE = (1.0/nPts)*(Emax-Emin) E = Emin; for idx in xrange(nPts): E = E + dE f = 1.0/(1.0 + exp((E - Ef)/kT)) fArr.append(f) fArr2.append(f*2) EArr.append(E) EArr2.append(E*2) progress = (int)((E-Emin)/(Emax-Emin)*100) Rappture.Utils.progress(progress,"Iterating") # store results in the results table # add data to the table pointed to by the variable result. # put the fArr data in the column named "Fermi-Dirac Factor" # put the EArr data in the column named "Energy" x1.store(fArr) y1.store(EArr) x2.store(fArr2) y2.store(EArr2) # close the global interface # signal to the graphical user interface that science # calculations are complete and to display the data # as described in the views Rappture.Interface.close() return 0
f2 = (z2-z1)*(x3-x1) - (z3-z1)*(x2-x1) f3 = (x2-x1)*(y3-y1) - (x3-x1)*(y2-y1) return ((- aux_lon * f1 - aux_lat * f2) / f3 + dc) ########################## ###### MAIN PROGRAM ###### ########################## # INPUT PARAMETERS # READING INPUT PARAMETERS print "Reading input parameters \n" inDeckName = sys.argv[1] lib = Rappture.library(inDeckName) run_name = lib.get('input.string(run_name).current') topo_source = lib.get('input.choice(topography).current') if(topo_source == 'Upload_UTM'): DEM = lib.get('input.string(uploadedFile_UTM).current') east_cen = float(lib.get('input.number(east).current')) north_cen = float(lib.get('input.number(north).current')) elif(topo_source == 'Upload_deg'): DEM = lib.get('input.string(uploadedFile_deg).current') lon_cen = float(lib.get('input.number(lonc).current')) lat_cen = float(lib.get('input.number(latc).current')) else: lon1 = float(lib.get('input.number(lon1).current')) lon2 = float(lib.get('input.number(lon2).current'))
# bug workaround in some PIL versions def fileno(): raise AttributeError # open image from data and rotate image = Image.open(BytesIO(data)) rot = image.rotate(angle, expand=True) # save image to a file in memory memfile = BytesIO() memfile.fileno = fileno # required in some broken PILs rot.save(memfile, image.format) return memfile.getvalue() # open the XML file containing the run parameters rx = Rappture.PyXml(sys.argv[1]) data = rx['input.image.current'].value # image data in B64 encoded in the xml data = decode(data, RPENC_B64) nframes = int(rx['input.integer(nframes).current'].value) image = Image.open(BytesIO(data)) outs = rx['output.sequence(outs)'] outs['about.label'] = 'Animated Sequence' outs['index.label'] = 'Frame' for i in range(nframes): element = outs['element(%s)' % i]
# MAIN PROGRAM - generated by the Rappture Builder # ---------------------------------------------------------------------- import Rappture import sys import os from Creator_lammpsdata import LammpsDataGenerator from Process_output import Process_output from Process_COM import Process_COM from Options import Options from Prepare_jmol import Prepare_jmol import Modify_template from subprocess import Popen, PIPE from math import * # open the XML file containing the run parameters io = Rappture.library(sys.argv[1]) ######################################################### # Get input values from Rappture ######################################################### options = Options() # get input value for input.boolean(value37) # returns value as string "yes" or "no" options.periodic_ = io.get('input.boolean(value37).current') == 'yes' options.limitconcentration_ = io.get('input.boolean(value56).current') == 'yes' options.concentration_ = float(io.get('input.number(value57).current')) # get input value for input.integer(value38)
# # This simple example shows how to use Rappture within a simulator # written in Python. # ====================================================================== # AUTHOR: Michael McLennan, Purdue University # Copyright (c) 2004-2012 HUBzero Foundation, LLC # # See the file "license.terms" for information on usage and # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. # ====================================================================== import Rappture import sys from math import * # open the XML file containing the run parameters driver = Rappture.library(sys.argv[1]) driver.put("tool.version.application.date", "$Date: 2012-09-21 13:01:16 -0400 (Fri, 21 Sep 2012) $") driver.put("tool.version.application.rev", "$LastChangedRevision: 3177 $") driver.put("tool.version.application.url", "$URL: https://nanohub.org/infrastructure/rappture/svn/branches/1.3/examples/app-fermi/python/fermi.py $") Tstr = driver.get('input.(temperature).current') T = Rappture.Units.convert(Tstr, to="K", units="off") Efstr = driver.get('input.(Ef).current') Ef = Rappture.Units.convert(Efstr, to="eV", units="off") kT = 8.61734e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT
# AUTHOR: Michael McLennan, Purdue University # Copyright (c) 2004-2012 HUBzero Foundation, LLC # # See the file "license.terms" for information on usage and # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. # ====================================================================== from math import * import sys import Rappture import fermi_io from fermi_io import * # do this right at the start, to handle command line args Rappture.interface(sys.argv, fermi_io) kT = 8.61734e-5 * T Emin = Ef - 10*kT Emax = Ef + 10*kT E = Emin; dE = 0.005*(Emax-Emin) Rappture.driver.put("output.curve(f12).about.label", "Fermi-Dirac Factor") Rappture.driver.put("output.curve(f12).xaxis.label", "Energy") Rappture.driver.put("output.curve(f12).xaxis.units", "eV") path = "output.curve(f12).component.xy" while E < Emax: f = 1.0/(1.0 + exp((E - Ef)/kT)) # result.append( [E,f] )