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