source: branches/blt4_trunk/examples/zoo/curve/curve.py @ 6681

Last change on this file since 6681 was 6681, checked in by ldelgass, 8 years ago

merge rappture trunk to blt4_trunk branch

File size: 5.1 KB
Line 
1# ----------------------------------------------------------------------
2#  EXAMPLE: Rappture <curve> elements
3# ======================================================================
4#  AUTHOR:  Martin Hunt, Purdue University
5#  Copyright (c) 2015  HUBzero Foundation, LLC
6#
7#  See the file "license.terms" for information on usage and
8#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9# ======================================================================
10import Rappture
11import numpy as np
12import sys
13
14# open the XML file containing the run parameters
15rx = Rappture.PyXml(sys.argv[1])
16
17npts = int(rx['input.(points).current'].value)
18
19# generate a single curve
20single = rx['output.curve(single)']
21single['about.label'] = "Single Curve"
22single['about.description'] = 'This is an example of a single curve.'
23single['xaxis.label'] = "Time"
24single['xaxis.description'] = "Time during the experiment."
25single['xaxis.units'] = "s"
26single['yaxis.label'] = "Voltage v(11)"
27single['yaxis.description'] = "Output from the amplifier."
28single['yaxis.units'] = "V"
29
30# generate curve
31xmin, xmax = 0.01, 10.0
32x = np.linspace(xmin, xmax, npts)
33y = np.cos(x)/(1+x)
34
35# plot it
36single['component.xy'] = (x, y)
37
38# These are also acceptable.
39# single['component.xy'] = [x, y]
40# single['component.xy'] = np.row_stack((x, y))
41
42# generate a single curve with x and y axis upper and lower limits
43xminl = xmin+((xmax-xmin)/4.0)
44xmaxl = xmax-((xmax-xmin)/4.0)
45yminl = np.cos(xminl)/(1+xminl)
46ymaxl = np.cos(xmaxl)/(1+xmaxl)
47limited = rx['output.curve(limited)']
48limited['about.label'] = "Axis limits curve"
49limited['about.description'] = \
50    'This is an example of a single curve with x and y axis limits applied.'
51limited['xaxis.label'] = "Time"
52limited['xaxis.description'] = "Time during the experiment."
53limited['xaxis.units'] = "s"
54limited['xaxis.min'] = xminl
55limited['xaxis.max'] = xmaxl
56limited['yaxis.label'] = "Voltage v(11)"
57limited['yaxis.description'] = "Output from the amplifier."
58limited['yaxis.units'] = "V"
59limited['yaxis.min'] = yminl
60limited['yaxis.max'] = ymaxl
61
62# plot it
63limited['component.xy'] = (x, y)
64
65
66# generate multiple curves on the same plot
67for factor in [1, 2]:
68    curve = rx['output.curve(multi%s)' % factor]
69    curve['about.group'] = "Multiple curve"
70    curve['about.label'] = "Factor a=$factor"
71    curve['about.description'] = \
72        "This is an example of a multiple curves on the same plot."
73    curve['xaxis.label'] = "Frequency"
74    curve['xaxis.description'] = \
75        "Frequency of the input source."
76    curve['xaxis.units'] = "Hz"
77    # curve['xaxis.scale'] = "log"
78    curve['yaxis.label'] = "Current"
79    curve['yaxis.description'] = \
80        "Current through the pull-down resistor."
81    curve['yaxis.units'] = "uA"
82    curve['yaxis.log'] = "log"
83    y = np.power(2.0, factor*x)/x
84    curve['component.xy'] = (x, y)
85
86# generate a scatter curve
87curve = rx['output.curve(scatter)']
88curve['about.label'] = "Scatter curve"
89curve['about.description'] = \
90    "This is an example of a scatter curve."
91curve['about.type'] = "scatter"
92curve['xaxis.label'] = "Time"
93curve['xaxis.description'] = "Time during the experiment."
94curve['xaxis.units'] = "s"
95curve['yaxis.label'] = "Voltage v(11)"
96curve['yaxis.description'] = "Output from the amplifier."
97curve['yaxis.units'] = "V"
98
99y = np.cos(x)/(1+x)
100curve['component.xy'] = (x, y)
101
102# generate a bar curve
103curve = rx['output.curve(bars)']
104curve['about.label'] = "Bar chart"
105curve['about.description'] = \
106    "This is an example of a scatter curve."
107curve['about.type'] = "bar"
108curve['xaxis.label'] = "Time"
109curve['xaxis.description'] = "Time during the experiment."
110curve['xaxis.units'] = "s"
111curve['yaxis.label'] = "Voltage v(11)"
112curve['yaxis.description'] = "Output from the amplifier."
113curve['yaxis.units'] = "V"
114
115x = np.arange(0, npts)
116y = np.sin(x)/(1+x)
117curve['component.xy'] = (x, y)
118
119# generate mixed curves on the same plot
120deg2rad = 0.017453292519943295
121
122curve = rx['output.curve(line)']
123curve['about.group'] = "Mixed element types"
124curve['about.label'] = "Sine"
125curve['about.description'] = \
126    "This is an example of a mixed curves on the same plot."
127curve['xaxis.label'] = "Degrees"
128# curve['yaxis.label'] = "Sine"
129curve['about.type'] = "line"
130
131x = np.arange(0, 361, 30)
132y = np.sin(x * deg2rad)
133curve['component.xy'] = (x, y)
134
135curve = rx['output.curve(bar)']
136curve['about.group'] = "Mixed element types"
137curve['about.label'] = "Cosine"
138curve['about.description'] = \
139    "This is an example of a mixed curves on the same plot."
140curve['xaxis.label'] = "Degrees"
141# curve['yaxis.label'] = "Cosine"
142curve['about.type'] = "bar"
143curve['about.style'] = "-barwidth 24.0"
144
145y = np.cos(x * deg2rad)
146curve['component.xy'] = (x, y)
147
148curve = rx['output.curve(point)']
149curve['about.group'] = "Mixed element types"
150curve['about.label'] = "Random"
151curve['about.description'] = \
152    "This is an example of a mixed curves on the same plot."
153curve['xaxis.label'] = "Degrees"
154# curve['yaxis.label'] = "Random"
155curve['about.type'] = "scatter"
156
157x = np.arange(0, 361, 10)
158y = np.random.rand(len(x)) * 2.0 - 1
159curve['component.xy'] = (x, y)
160
161# save the updated XML describing the run...
162rx.close()
Note: See TracBrowser for help on using the repository browser.