Subversion Repositories Projects

Rev

Rev 596 | Rev 600 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
584 FredericG 1
#!/usr/bin/env python
2
# -*- coding: iso-8859-15 -*-
3
# generated by wxGlade 0.6.3 on Thu Sep 24 15:46:36 2009
4
 
586 FredericG 5
import sys
584 FredericG 6
import wx
585 FredericG 7
import wx.lib
8
import wx.lib.plot
584 FredericG 9
 
585 FredericG 10
# Needs Numeric or numarray or NumPy
11
try:
12
    import numpy.oldnumeric as _Numeric
13
except:
14
    try:
15
        import numarray as _Numeric  #if numarray is used it is renamed Numeric
16
    except:
17
        try:
18
            import Numeric as _Numeric
19
        except:
20
            msg= """
21
            This module requires the Numeric/numarray or NumPy module,
22
            which could not be imported.  It probably is not installed
23
            (it's not part of the standard Python distribution). See the
24
            Numeric Python site (http://numpy.scipy.org) for information on
25
            downloading source or binaries."""
26
            raise ImportError, "Numeric,numarray or NumPy not found. \n" + msg
27
 
584 FredericG 28
# begin wxGlade: extracode
29
# end wxGlade
30
 
31
 
32
 
587 FredericG 33
class MenuBar(wx.MenuBar):
34
    def __init__(self, *args, **kwds):
35
        # content of this block not found: did you rename this class?
36
        pass
37
 
38
    def __set_properties(self):
39
        # content of this block not found: did you rename this class?
40
        pass
41
 
42
    def __do_layout(self):
43
        # content of this block not found: did you rename this class?
44
        pass
45
 
46
# end of class MenuBar
47
 
48
 
585 FredericG 49
class wxFrame(wx.Panel):
50
    def __init__(self, *args, **kwds):
586 FredericG 51
        # content of this block not found: did you rename this class?
52
        pass
585 FredericG 53
 
54
    def __set_properties(self):
586 FredericG 55
        # content of this block not found: did you rename this class?
585 FredericG 56
        pass
57
 
58
    def __do_layout(self):
586 FredericG 59
        # content of this block not found: did you rename this class?
585 FredericG 60
        pass
61
 
62
# end of class wxFrame
63
 
64
 
65
class MyFrame(wx.Frame):
66
    def __init__(self, *args, **kwds):
67
        # content of this block not found: did you rename this class?
68
        pass
69
 
70
    def __set_properties(self):
71
        # content of this block not found: did you rename this class?
72
        pass
73
 
74
    def __do_layout(self):
75
        # content of this block not found: did you rename this class?
76
        pass
77
 
78
# end of class MyFrame
79
 
80
 
584 FredericG 81
class MainFrame(wx.Frame):
82
    def __init__(self, *args, **kwds):
83
        # begin wxGlade: MainFrame.__init__
84
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
85
        wx.Frame.__init__(self, *args, **kwds)
587 FredericG 86
 
87
        # Menu Bar
88
        self.frame_1_menubar = wx.MenuBar()
89
        wxglade_tmp_menu = wx.Menu()
90
        wxglade_tmp_menu.Append(wx.NewId(), "Exit", "", wx.ITEM_NORMAL)
91
        self.frame_1_menubar.Append(wxglade_tmp_menu, "File")
92
        wxglade_tmp_menu = wx.Menu()
93
        wxglade_tmp_menu.Append(wx.NewId(), "Clear", "", wx.ITEM_NORMAL)
94
        wxglade_tmp_menu.Append(wx.NewId(), "Import", "", wx.ITEM_NORMAL)
95
        self.frame_1_menubar.Append(wxglade_tmp_menu, "TestSet")
96
        wxglade_tmp_menu = wx.Menu()
97
        self.frame_1_menubar.Append(wxglade_tmp_menu, "MK")
98
        wxglade_tmp_menu = wx.Menu()
99
        self.frame_1_menubar.Append(wxglade_tmp_menu, "Help")
100
        self.SetMenuBar(self.frame_1_menubar)
101
        # Menu Bar end
584 FredericG 102
        self.Port = wx.StaticText(self, -1, "Port")
103
        self.text_ctrl_1 = wx.TextCtrl(self, -1, "")
104
        self.label_5 = wx.StaticText(self, -1, "label_5")
105
        self.text_ctrl_5 = wx.TextCtrl(self, -1, "")
106
        self.label_2 = wx.StaticText(self, -1, "Motor(s)")
107
        self.text_ctrl_2 = wx.TextCtrl(self, -1, "")
108
        self.label_6 = wx.StaticText(self, -1, "label_6")
109
        self.text_ctrl_6 = wx.TextCtrl(self, -1, "")
110
        self.label_3 = wx.StaticText(self, -1, "Channel(s)")
111
        self.text_ctrl_3 = wx.TextCtrl(self, -1, "")
112
        self.label_7 = wx.StaticText(self, -1, "label_7")
113
        self.text_ctrl_7 = wx.TextCtrl(self, -1, "")
114
        self.label_4 = wx.StaticText(self, -1, "Speed(s)")
115
        self.text_ctrl_4 = wx.TextCtrl(self, -1, "")
116
        self.label_8 = wx.StaticText(self, -1, "label_8")
117
        self.text_ctrl_8 = wx.TextCtrl(self, -1, "")
118
        self.button_1 = wx.Button(self, -1, "button_1")
591 FredericG 119
        self.GraphPanel = wx.Panel(self, -1, style=wx.DOUBLE_BORDER|wx.TAB_TRAVERSAL)
592 FredericG 120
        self.yAxesChoice = wx.ComboBox(self, -1, choices=["10", "25", "50", "100", "250"], style=wx.CB_DROPDOWN)
121
        self.graphTypeChoise = wx.ComboBox(self, -1, choices=["Raw Data", "Filtered Data", "Spectrum"], style=wx.CB_DROPDOWN)
586 FredericG 122
        self.TestListCtrl = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
584 FredericG 123
 
124
        self.__set_properties()
125
        self.__do_layout()
587 FredericG 126
 
127
        self.Bind(wx.EVT_MENU, self.OnImport, id=-1)
599 FredericG 128
        self.Bind(wx.EVT_COMBOBOX, self.onYAxisChange, self.yAxesChoice)
129
        self.Bind(wx.EVT_COMBOBOX, self.onYAxisChange, self.graphTypeChoise)
584 FredericG 130
        # end wxGlade
131
 
587 FredericG 132
    def setApp(self, app):
133
        self.app = app
585 FredericG 134
 
584 FredericG 135
    def __set_properties(self):
136
        # begin wxGlade: MainFrame.__set_properties
587 FredericG 137
        self.SetTitle("VibrationTest")
599 FredericG 138
        self.GraphPanel.SetMinSize((800,350))
592 FredericG 139
        self.yAxesChoice.SetSelection(2)
140
        self.graphTypeChoise.SetSelection(0)
584 FredericG 141
        # end wxGlade
142
 
143
    def __do_layout(self):
144
        # begin wxGlade: MainFrame.__do_layout
145
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
586 FredericG 146
        grid_sizer_2 = wx.GridSizer(2, 1, 4, 4)
591 FredericG 147
        sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
584 FredericG 148
        grid_sizer_1 = wx.GridSizer(5, 4, 4, 4)
591 FredericG 149
        sizer_1.Add((20, 20), 0, 0, 0)
584 FredericG 150
        grid_sizer_1.Add(self.Port, 0, wx.ALIGN_RIGHT, 0)
151
        grid_sizer_1.Add(self.text_ctrl_1, 0, 0, 0)
152
        grid_sizer_1.Add(self.label_5, 0, wx.ALIGN_RIGHT, 0)
153
        grid_sizer_1.Add(self.text_ctrl_5, 0, 0, 0)
154
        grid_sizer_1.Add(self.label_2, 0, wx.ALIGN_RIGHT, 0)
155
        grid_sizer_1.Add(self.text_ctrl_2, 0, 0, 0)
156
        grid_sizer_1.Add(self.label_6, 0, wx.ALIGN_RIGHT, 0)
157
        grid_sizer_1.Add(self.text_ctrl_6, 0, 0, 0)
158
        grid_sizer_1.Add(self.label_3, 0, wx.ALIGN_RIGHT, 0)
159
        grid_sizer_1.Add(self.text_ctrl_3, 0, 0, 0)
160
        grid_sizer_1.Add(self.label_7, 0, wx.ALIGN_RIGHT, 0)
161
        grid_sizer_1.Add(self.text_ctrl_7, 0, 0, 0)
162
        grid_sizer_1.Add(self.label_4, 0, wx.ALIGN_RIGHT, 0)
163
        grid_sizer_1.Add(self.text_ctrl_4, 0, 0, 0)
164
        grid_sizer_1.Add(self.label_8, 0, wx.ALIGN_RIGHT, 0)
165
        grid_sizer_1.Add(self.text_ctrl_8, 0, 0, 0)
166
        grid_sizer_1.Add(self.button_1, 0, 0, 0)
167
        sizer_1.Add(grid_sizer_1, 0, 0, 2)
591 FredericG 168
        sizer_1.Add((20, 20), 0, 0, 0)
592 FredericG 169
        sizer_1.Add(self.GraphPanel, 1, 0, 0)
170
        sizer_2.Add(self.yAxesChoice, 0, 0, 0)
171
        sizer_2.Add(self.graphTypeChoise, 0, 0, 0)
591 FredericG 172
        sizer_1.Add(sizer_2, 0, wx.EXPAND, 0)
173
        sizer_1.Add((20, 20), 0, 0, 0)
586 FredericG 174
        grid_sizer_2.Add(self.TestListCtrl, 1, wx.ALL|wx.EXPAND, 0)
175
        sizer_1.Add(grid_sizer_2, 1, wx.EXPAND, 0)
584 FredericG 176
        self.SetSizer(sizer_1)
177
        sizer_1.Fit(self)
178
        self.Layout()
179
        # end wxGlade
180
 
590 FredericG 181
        # List events
182
        self.TestListCtrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnTestSelected, self.TestListCtrl)
183
 
586 FredericG 184
        # Configure Graph
593 FredericG 185
        self.client = wx.lib.plot.PlotCanvas(self.GraphPanel, size=(800,300))
186
 
585 FredericG 187
        self.client.SetPointLabelFunc(self.DrawPointLabel)
188
 
189
        self.client.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.NORMAL))
190
        self.client.SetFontSizeAxis(10)
191
        self.client.SetFontSizeLegend(7)
192
        self.client.setLogScale((False,False))
193
 
586 FredericG 194
 
195
        # Configure TestListCtrl
594 FredericG 196
        self.TestListCtrl.InsertColumn(0, "Description")
197
        self.TestListCtrl.InsertColumn(1, "Speed")
198
        self.TestListCtrl.InsertColumn(2, "Channel")
199
        self.TestListCtrl.InsertColumn(3, "Result")
586 FredericG 200
 
585 FredericG 201
    def DrawPointLabel(self, dc, mDataDict):
202
        """This is the fuction that defines how the pointLabels are plotted
203
            dc - DC that will be passed
204
            mDataDict - Dictionary of data that you want to use for the pointLabel
205
 
206
            As an example I have decided I want a box at the curve point
207
            with some text information about the curve plotted below.
208
            Any wxDC method can be used.
209
        """
210
        # ----------
211
        dc.SetPen(wx.Pen(wx.BLACK))
212
        dc.SetBrush(wx.Brush( wx.BLACK, wx.SOLID ) )
213
 
214
        sx, sy = mDataDict["scaledXY"] #scaled x,y of closest point
215
        dc.DrawRectangle( sx-5,sy-5, 10, 10)  #10by10 square centered on point
216
        px,py = mDataDict["pointXY"]
217
        cNum = mDataDict["curveNum"]
218
        pntIn = mDataDict["pIndex"]
219
        legend = mDataDict["legend"]
220
        #make a string to display
221
        s = "Crv# %i, '%s', Pt. (%.2f,%.2f), PtInd %i" %(cNum, legend, px, py, pntIn)
222
        dc.DrawText(s, sx , sy+1)
223
        # -----------
224
 
596 FredericG 225
 
226
    def onNewTest(self, test):
227
        index = self.TestListCtrl.InsertStringItem(sys.maxint, test.descr)
228
        self.TestListCtrl.SetStringItem(index, 1, str(test.speed))
229
        self.TestListCtrl.SetStringItem(index, 2, test.channel)
230
        self.TestListCtrl.SetStringItem(index, 3, "OK")
231
 
232
 
590 FredericG 233
    def OnTestSelected(self, event):
234
         testId = event.m_itemIndex
235
         print "Test Selected id=%d" % (testId)
592 FredericG 236
         self.activeTestId = testId
237
         self.drawGraph()
590 FredericG 238
 
592 FredericG 239
    def drawGraph(self):
240
         vibTest = self.app.getTest(self.activeTestId)
590 FredericG 241
         nb = vibTest.getDataLen()
592 FredericG 242
         y = int(self.yAxesChoice.GetStringSelection())
590 FredericG 243
 
599 FredericG 244
         if self.graphTypeChoise.GetSelection() == 0:
245
             xydata = _Numeric.linspace(0,0.09*nb,2*nb)
246
             xydata.shape = (nb, 2)
247
             xydata[:,1] = vibTest.getRawData()
248
             line = wx.lib.plot.PolyLine(xydata, legend= 'Raw Data', colour='red')
249
 
250
             title = "Raw Signal: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
251
             self.client.Draw(wx.lib.plot.PlotGraphics([line], title, "Time (ms)", "Acc"), yAxis= (-y,y))
252
             self.client.SetEnableGrid('Horizontal')
596 FredericG 253
 
599 FredericG 254
         elif self.graphTypeChoise.GetSelection() == 2:
255
             xydata = _Numeric.linspace(0,5555,nb)
256
             xydata.shape = (nb/2, 2)
257
 
258
             xydata[:,1] = vibTest.getSpectrum()
590 FredericG 259
 
599 FredericG 260
             line = wx.lib.plot.PolyLine(xydata, legend= 'Spectrum', colour='red')
261
             markers = wx.lib.plot.PolyMarker(xydata, legend= '', colour='red', marker='circle',size=1)
262
 
263
             title = "Spectrum: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
264
             self.client.Draw(wx.lib.plot.PlotGraphics([line,markers], title, "Freq (Hz)", "Acc"), xAxis=(0,500), yAxis= (-0,y))
265
             self.client.SetEnableGrid('Horizontal')
590 FredericG 266
 
599 FredericG 267
 
587 FredericG 268
    def OnImport(self, event): # wxGlade: MainFrame.<event_handler>
269
        self.app.Import()
270
 
599 FredericG 271
    def onYAxisChange(self, event): # wxGlade: MainFrame.<event_handler>
592 FredericG 272
        self.drawGraph()
273
 
599 FredericG 274
    def onYAxisChange(self, event): # wxGlade: MainFrame.<event_handler>
275
        self.drawGraph()
276
 
584 FredericG 277
# end of class MainFrame
278
 
279
 
586 FredericG 280
class VibTest:
596 FredericG 281
    def __init__(self, descr, motor, speed, channel, rawData):
594 FredericG 282
        self.descr = descr
283
        self.motor = motor
284
        self.speed = speed
596 FredericG 285
        self.channel = channel
599 FredericG 286
 
287
        self.dataLen = len(rawData)
288
        print self.dataLen
289
 
590 FredericG 290
        self.rawData = _Numeric.array(rawData)
291
        self.dc = self.rawData.mean()
292
        self.rawData -= self.dc
586 FredericG 293
 
599 FredericG 294
        self.fft = _Numeric.fft.fft(self.rawData)
295
 
594 FredericG 296
    def getDescr(self):
297
        return self.Descr
587 FredericG 298
 
590 FredericG 299
    def getRawData(self):
300
        return self.rawData
301
 
302
    def getDataLen(self):
303
        return self.dataLen
304
 
599 FredericG 305
    def getSpectrum(self):
306
        return _Numeric.absolute(self.fft[1:self.dataLen/2+1]) / (self.dataLen/2)
590 FredericG 307
 
599 FredericG 308
 
584 FredericG 309
class App(wx.App):
586 FredericG 310
    def __init__(self, par):
311
        self.VibTests = []
312
 
313
        wx.App.__init__(self, par)
314
 
315
 
596 FredericG 316
    def AddTest(self, descr, motor, speed, channel, rawData):
317
        test = VibTest(descr, motor, speed, channel, rawData)
586 FredericG 318
        self.VibTests.append(test)
596 FredericG 319
        self.frame_1.onNewTest(test)
586 FredericG 320
 
590 FredericG 321
    def getTest(self, testId):
322
        return self.VibTests[testId]
323
 
584 FredericG 324
    def OnInit(self):
325
        wx.InitAllImageHandlers()
586 FredericG 326
        self.frame_1 = MainFrame(None, -1, "")
587 FredericG 327
        self.frame_1.setApp(self);
586 FredericG 328
        self.SetTopWindow(self.frame_1)
329
 
587 FredericG 330
        self.frame_1.Show()
331
        return 1
332
 
333
    def Import(self):
599 FredericG 334
        filePath = "./unbal200.txt"
335
        #filePath = "./nikivan.txt"
596 FredericG 336
 
337
        print "Import %s" % filePath
338
 
339
        logfile = open(filePath, "r")
590 FredericG 340
        data = None
596 FredericG 341
 
342
        headers = (logfile.readline()).split(',')
343
        nbCols = len(headers)
344
        print "NbCols =", nbCols
345
 
346
        data = []
347
        descr = []
348
        speed = []
349
        channel = []
350
        for c in range(nbCols):
351
            data.append([])
352
            h = headers[c].split(' ')
353
            print h
354
            descr.append(h[0]);
355
            speed.append(h[1]);
356
            channel.append(h[2]);
357
 
590 FredericG 358
        for line in logfile:
359
            values = line.split(',')
596 FredericG 360
            for i in range(nbCols):
361
                data[i].append(int(values[i]))
590 FredericG 362
        logfile.close()
596 FredericG 363
 
364
        for c in range(nbCols):
599 FredericG 365
            if (len(data[c]) % 2) != 0:
366
                data[c].append(data[c][-1])
596 FredericG 367
            self.AddTest(descr[c], 0, int(speed[c]), channel[c], data[c])
590 FredericG 368
 
369
 
370
 
586 FredericG 371
 
590 FredericG 372
 
584 FredericG 373
# end of class App
374
 
375
if __name__ == "__main__":
376
    VibrationTestGui = App(0)
377
    VibrationTestGui.MainLoop()