Cat
TestUSB.py
Go to the documentation of this file.
1 import wx
2 from proc import *
3 from plotter import *
4 from libCatKernel import *
5 
6 #import matplotlib
7 #matplotlib.use('wxagg')
8 
9 class TestUSB(proc):
10  def __init__(self, cat, obj, panel, path):
11  proc.__init__(self,cat,obj,panel,path)
12  self.loadxrc()
13  self.s1=self.getControl("s1")
14  self.s2=self.getControl("s2")
15  self.s3=self.getControl("s3")
16  self.s4=self.getControl("s4")
17  self.update()
18  self.panel.Bind(wx.EVT_BUTTON, self.onApply, id=xrc.XRCID("Apply"))
19 
20  def onApply(self, event):
21  v1 = float(self.s1.GetValue())
22  v2 = float(self.s2.GetValue())
23  v3 = float(self.s3.GetValue())
24  v4 = float(self.s4.GetValue())
25  self.obj.setSigma(v1,v2,v3,v4)
26 
27  def update(self):
28  v1=self.obj.sigma(0)
29  v2=self.obj.sigma(1)
30  v3=self.obj.sigma(2)
31  v4=self.obj.sigma(3)
32 
33  self.s1.SetValue(str(v1))
34  self.s2.SetValue(str(v2))
35  self.s3.SetValue(str(v3))
36  self.s4.SetValue(str(v4))
37 
38 #----------------------------------------------------------------------
39 
40 def Edit (cat, obj, panel, path):
41  return TestUSB(cat, obj, panel, path)
42 
43 #----------------------------------------------------------------------
44 
45 def createPlots(cat, obj, run):
46  fig = plt.figure(figsize=(10,10))
47  fig.suptitle("Run "+str(run), fontsize=14, fontweight='bold')
48  for vplot in [1,2]:
49  ax = fig.add_subplot(2,1,vplot)
50  fig.show()
51  return [fig]
52 
53 def updatePlots(figs, obj):
54  fig = figs[0]
55  ax1 = fig.add_subplot(2,1,1)
56  lines, = ax1.plot([],[], 'bo')
57  #Autoscale on unknown axis and known lims on the other
58  ax1.set_autoscaley_on(True)
59 # ax.set_xlim(self.min_x, self.max_x)
60  #Other stuff
61  ax1.grid()
62  lines.set_xdata(obj.data(0))
63  lines.set_ydata(obj.data(1))
64  #Need both of these in order to rescale
65  ax1.relim()
66  ax1.autoscale_view()
67 
68  ax2 = fig.add_subplot(2,1,2)
69  lines, = ax2.plot([],[], 'bo')
70  #Autoscale on unknown axis and known lims on the other
71  ax2.set_autoscaley_on(True)
72 # ax.set_xlim(self.min_x, self.max_x)
73  #Other stuff
74  ax2.grid()
75  lines.set_xdata(obj.data(2))
76  lines.set_ydata(obj.data(3))
77  #Need both of these in order to rescale
78  ax2.relim()
79  ax2.autoscale_view()
80 
81  #We need to draw *and* flush
82  fig.canvas.draw()
83  fig.canvas.flush_events()
84  fig.show()
85  return fig
86 
87 #----------------------------------------------------------------------
88 
89 def Plot(cat, obj, parent, id):
90  from mpl_toolkits.mplot3d import Axes3D
91  from matplotlib import cm
92  import matplotlib as mpl
93  import matplotlib.pyplot as plt
94  import numpy as np
95 
96  plot=plotter(parent,id)
97  fig=plot.current()
98  fig.suptitle('TestSuite - Plot capabilities', fontsize=14, fontweight='bold')
99 
100  # plot of data set 0
101  p1=fig.add_subplot(2,3,1)
102  p1.plot(obj.data(0), 'bo', obj.data().vector(1),'k')
103  p1.set_title(r'$\sigma_0='+str(obj.sigma(0))+'$')
104 
105  # plot of data set 1
106  p2=fig.add_subplot(2,3,2)
107  p2.plot(obj.data(1), 'r--')
108  p2.set_title(r'$\sigma_1='+str(obj.sigma(1))+'$')
109 
110  # plot of data set 0 (histogram)
111  plt.subplot(2,3,3)
112  n, bins, h=plt.hist(obj.data().vector(0), 10)
113  plt.title(obj.data().title(0))
114  plt.grid(True)
115 
116  # plot of data set 1 (histogram)
117  plt.subplot(2,3,4)
118  plt.hist(obj.data().vector(1), 20)
119  plt.title(obj.data().name(1)+" : "+obj.data().title(1))
120  plt.grid(True)
121 
122  # plot histo root
123  p5=fig.add_subplot(2,3,5)
124  h1=h1d(p5, obj.hist1d(0), facecolor='red',linestyle='dashed')
125  p5.grid(True)
126 
127 
144 
145  # plot histo root
146  p7=fig.add_subplot(2,3,6)
147  h7=obj.hist1d(0)
148  print h7.xbins()
149  p7.plot(h7.xbins(),h7.bins(),'ro',color='red')
150  p7.grid(False)
151 
152  # plot histo root
153 # p8=fig.add_subplot(4,3,8)
154 # f8=Axes3D(fig)
155 # h8=obj.hist2d(0)
156 # x,y=np.meshgrid(h8.xbins(),h8.ybins())
157 # z=np.array(h8.bins())
158 
159 # print x
160 # print y
161 # print z
162 
163 # p8.contour(x,y,z)
164 # f8.plot_surface(x,y,z)
165 # p8.plot
166 
167 
177 
178  # return the plot that must be plotted
179  return plot
std::string title()
Definition: Object.h:31
def updatePlots(figs, obj)
Definition: TestUSB.py:53
def h1d(fig, histo, alpha=0.5, facecolor='green', edgecolor='yellow', linestyle='dashed')
Definition: plotter.py:51
def createPlots(cat, obj, run)
Definition: TestUSB.py:45
std::string name() const
Definition: Object.h:28
def Plot(cat, obj, parent, id)
Definition: TestUSB.py:89
def onApply(self, event)
Definition: TestUSB.py:20
Definition: proc.py:1
def Edit(cat, obj, panel, path)
Definition: TestUSB.py:40
def update(self)
Definition: TestUSB.py:27
def __init__(self, cat, obj, panel, path)
Definition: TestUSB.py:10