1 | ------------------------------------------------------------------------ |
---|
2 | Rappture - Rapid APPlication infrastrucTURE |
---|
3 | ------------------------------------------------------------------------ |
---|
4 | The Rappture toolkit provides the basic building blocks for many |
---|
5 | scientific applications. These blocks can be composed using C++, or |
---|
6 | a high-level language, such as Python. Having a set of blocks for |
---|
7 | basic I/O, meshing, and numerical methods, a scientist can then |
---|
8 | focus on developing his core algorithm. |
---|
9 | ------------------------------------------------------------------------ |
---|
10 | AUTHORS: |
---|
11 | Michael J. McLennan, Purdue University |
---|
12 | Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
13 | |
---|
14 | See the file "license.terms" for information on usage and |
---|
15 | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
16 | ------------------------------------------------------------------------ |
---|
17 | |
---|
18 | |
---|
19 | INSTALLATION |
---|
20 | ------------------------------------------------------------------------ |
---|
21 | This part of the Rappture toolkit works with Python. If you need to |
---|
22 | install Python on your system, visit the Download section of the site |
---|
23 | http://www.python.org. |
---|
24 | |
---|
25 | Assuming you already have Python installed, you can install Rappture |
---|
26 | as follows: |
---|
27 | |
---|
28 | % cd rappture/python |
---|
29 | % python setup.py install |
---|
30 | |
---|
31 | This will make Rappture a part of your normal Python installation, so |
---|
32 | you can use it in your own Python scripts, as shown below. |
---|
33 | |
---|
34 | |
---|
35 | GETTING STARTED |
---|
36 | ------------------------------------------------------------------------ |
---|
37 | Here is a quick tutorial to get you started using Rappture in your |
---|
38 | Python scripts. |
---|
39 | |
---|
40 | Rappture applications load their data from a an XML driver file. |
---|
41 | In the tool.xml file, you should have something like |
---|
42 | |
---|
43 | <command> @tool/path/to/executable @driver </command> |
---|
44 | |
---|
45 | The "@driver" pattern is replaced by the driver xml file generated by |
---|
46 | Rappture. This driver file will contain the values to use for the |
---|
47 | parameters in your application. See |
---|
48 | https://nanohub.org/infrastructure/rappture/wiki/rappture_xml_elements |
---|
49 | for more information. |
---|
50 | |
---|
51 | The first thing your application should do is load the driver file. |
---|
52 | |
---|
53 | import Rappture |
---|
54 | rx = Rappture.PyXml('example.xml') |
---|
55 | |
---|
56 | You can see the xml contents by doing |
---|
57 | print rx.xml() |
---|
58 | |
---|
59 | The "import" statement loads the Rappture toolkit into your Python |
---|
60 | application. The next line creates a library object representing |
---|
61 | the data in the "example.xml" file. The last line prints the |
---|
62 | contents of the XML library to the screen. |
---|
63 | |
---|
64 | You can access values within the XML by using the get() method. |
---|
65 | For example, |
---|
66 | |
---|
67 | import Rappture |
---|
68 | lib = Rappture.PyXml('example.xml') |
---|
69 | tval = lib.get('group(ambient).number(temp).current') |
---|
70 | or alternatively |
---|
71 | tval = lib['group(ambient).number(temp).current'].value |
---|
72 | |
---|
73 | The get() method follows a path through the XML. In this example, |
---|
74 | it looks for a <group id="ambient"> tag, and then finds the |
---|
75 | <number id="temp"> tag within it, then finds the <current> tag |
---|
76 | within it, and then returns the text between that and the closing |
---|
77 | </current> tag. |
---|
78 | |
---|
79 | You can also add new data to the XML by using the put() method. |
---|
80 | For example, we could change the temperature value that we queried |
---|
81 | above as follows: |
---|
82 | |
---|
83 | tval += 10 |
---|
84 | lib.put('group(ambient).number(temp).current', tval) |
---|
85 | or |
---|
86 | lib[group(ambient).number(temp).current'] = tval |
---|
87 | |
---|
88 | This changes the text within the <current>...</current> tag, |
---|
89 | replacing it with the new value, converted to a string if necessary. |
---|
90 | |
---|
91 | You can also append to an existing value. For example, |
---|
92 | |
---|
93 | lib.put('group(ambient).number(temp).current', 'more text', append=1) |
---|
94 | |
---|
95 | This adds the string 'more text' after the value (tval) within the |
---|
96 | <current>...</current> tag. Use of append in a loop is not |
---|
97 | recommended because it can be very slow. It is faster to collect |
---|
98 | data in python and put it all at once. |
---|
99 | |
---|