Subversion Repositories Projects

Rev

Go to most recent revision | Details | 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
600 FredericG 102
        self.Description = wx.StaticText(self, -1, "Description")
103
        self.text_ctrl_6 = wx.TextCtrl(self, -1, "Test")
104
        self.label_37 = wx.StaticText(self, -1, "Speed(s)")
105
        self.text_ctrl_9 = wx.TextCtrl(self, -1, "100-200:10")
106
        self.label_35 = wx.StaticText(self, -1, "Motor(s)")
107
        self.text_ctrl_7 = wx.TextCtrl(self, -1, "1")
108
        self.label_38 = wx.StaticText(self, -1, "")
109
        self.text_ctrl_10 = wx.TextCtrl(self, -1, "")
110
        self.label_36 = wx.StaticText(self, -1, "Channel")
111
        self.text_ctrl_8 = wx.TextCtrl(self, -1, "6")
112
        self.label_39 = wx.StaticText(self, -1, "")
113
        self.text_ctrl_11 = wx.TextCtrl(self, -1, "")
114
        self.button_4 = wx.Button(self, -1, "Start")
115
        self.GraphPanel = wx.Panel(self, -1)
116
        self.label_40 = wx.StaticText(self, -1, "Graph Type ")
117
        self.graphTypeChoice = wx.Choice(self, -1, choices=["Raw Signal", "Filtered Signal", "Spectrum"])
118
        self.label_41 = wx.StaticText(self, -1, "Y Axis Range ")
119
        self.yAxisChoice = wx.Choice(self, -1, choices=["25", "50", "100", "200"])
586 FredericG 120
        self.TestListCtrl = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
584 FredericG 121
 
122
        self.__set_properties()
123
        self.__do_layout()
587 FredericG 124
 
125
        self.Bind(wx.EVT_MENU, self.OnImport, id=-1)
600 FredericG 126
        self.Bind(wx.EVT_CHOICE, self.onGraphTypeChange, self.graphTypeChoice)
127
        self.Bind(wx.EVT_CHOICE, self.onYAxisChange, self.yAxisChoice)
584 FredericG 128
        # end wxGlade
129
 
587 FredericG 130
    def setApp(self, app):
131
        self.app = app
585 FredericG 132
 
584 FredericG 133
    def __set_properties(self):
134
        # begin wxGlade: MainFrame.__set_properties
587 FredericG 135
        self.SetTitle("VibrationTest")
600 FredericG 136
        self.SetSize((850, 700))
137
        self.Description.SetMinSize((53, 13))
138
        self.GraphPanel.SetMinSize((800,300))
139
        self.graphTypeChoice.SetSelection(0)
140
        self.yAxisChoice.SetSelection(1)
141
        self.TestListCtrl.SetMinSize((800,300))
584 FredericG 142
        # end wxGlade
143
 
144
    def __do_layout(self):
145
        # begin wxGlade: MainFrame.__do_layout
600 FredericG 146
        sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
147
        sizer_8 = wx.BoxSizer(wx.VERTICAL)
148
        sizer_11 = wx.BoxSizer(wx.VERTICAL)
149
        sizer_12 = wx.BoxSizer(wx.HORIZONTAL)
150
        sizer_9 = wx.BoxSizer(wx.HORIZONTAL)
151
        sizer_10 = wx.BoxSizer(wx.HORIZONTAL)
152
        grid_sizer_1 = wx.GridSizer(3, 4, 4, 5)
153
        sizer_3.Add((20, 20), 0, 0, 0)
154
        sizer_8.Add((20, 20), 0, 0, 0)
155
        grid_sizer_1.Add(self.Description, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
584 FredericG 156
        grid_sizer_1.Add(self.text_ctrl_6, 0, 0, 0)
600 FredericG 157
        grid_sizer_1.Add(self.label_37, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
158
        grid_sizer_1.Add(self.text_ctrl_9, 0, 0, 0)
159
        grid_sizer_1.Add(self.label_35, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
584 FredericG 160
        grid_sizer_1.Add(self.text_ctrl_7, 0, 0, 0)
600 FredericG 161
        grid_sizer_1.Add(self.label_38, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
162
        grid_sizer_1.Add(self.text_ctrl_10, 0, 0, 0)
163
        grid_sizer_1.Add(self.label_36, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
584 FredericG 164
        grid_sizer_1.Add(self.text_ctrl_8, 0, 0, 0)
600 FredericG 165
        grid_sizer_1.Add(self.label_39, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
166
        grid_sizer_1.Add(self.text_ctrl_11, 0, 0, 0)
167
        sizer_9.Add(grid_sizer_1, 0, 0, 0)
168
        sizer_10.Add((50, 20), 0, 0, 0)
169
        sizer_10.Add(self.button_4, 0, wx.ALIGN_CENTER_VERTICAL, 0)
170
        sizer_9.Add(sizer_10, 1, wx.EXPAND, 0)
171
        sizer_8.Add(sizer_9, 0, 0, 0)
172
        sizer_8.Add((20, 30), 0, 0, 0)
173
        sizer_11.Add(self.GraphPanel, 1, wx.EXPAND, 0)
174
        sizer_11.Add((20, 5), 0, 0, 0)
175
        sizer_12.Add(self.label_40, 0, wx.ALIGN_CENTER_VERTICAL, 0)
176
        sizer_12.Add(self.graphTypeChoice, 0, 0, 0)
177
        sizer_12.Add((40, 20), 0, 0, 0)
178
        sizer_12.Add(self.label_41, 0, wx.ALIGN_CENTER_VERTICAL, 0)
179
        sizer_12.Add(self.yAxisChoice, 0, 0, 0)
180
        sizer_11.Add(sizer_12, 0, 0, 0)
181
        sizer_8.Add(sizer_11, 0, 0, 0)
182
        sizer_8.Add((20, 30), 0, 0, 0)
183
        sizer_8.Add(self.TestListCtrl, 1, 0, 0)
184
        sizer_8.Add((20, 20), 0, 0, 0)
185
        sizer_3.Add(sizer_8, 1, wx.EXPAND, 0)
186
        self.SetSizer(sizer_3)
584 FredericG 187
        self.Layout()
600 FredericG 188
        self.SetSize((850, 700))
584 FredericG 189
        # end wxGlade
190
 
590 FredericG 191
        # List events
192
        self.TestListCtrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnTestSelected, self.TestListCtrl)
193
 
586 FredericG 194
        # Configure Graph
593 FredericG 195
        self.client = wx.lib.plot.PlotCanvas(self.GraphPanel, size=(800,300))
196
 
585 FredericG 197
        self.client.SetPointLabelFunc(self.DrawPointLabel)
198
 
199
        self.client.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.NORMAL))
200
        self.client.SetFontSizeAxis(10)
201
        self.client.SetFontSizeLegend(7)
202
        self.client.setLogScale((False,False))
203
 
586 FredericG 204
 
205
        # Configure TestListCtrl
594 FredericG 206
        self.TestListCtrl.InsertColumn(0, "Description")
207
        self.TestListCtrl.InsertColumn(1, "Speed")
208
        self.TestListCtrl.InsertColumn(2, "Channel")
209
        self.TestListCtrl.InsertColumn(3, "Result")
586 FredericG 210
 
585 FredericG 211
    def DrawPointLabel(self, dc, mDataDict):
212
        """This is the fuction that defines how the pointLabels are plotted
213
            dc - DC that will be passed
214
            mDataDict - Dictionary of data that you want to use for the pointLabel
215
 
216
            As an example I have decided I want a box at the curve point
217
            with some text information about the curve plotted below.
218
            Any wxDC method can be used.
219
        """
220
        # ----------
221
        dc.SetPen(wx.Pen(wx.BLACK))
222
        dc.SetBrush(wx.Brush( wx.BLACK, wx.SOLID ) )
223
 
224
        sx, sy = mDataDict["scaledXY"] #scaled x,y of closest point
225
        dc.DrawRectangle( sx-5,sy-5, 10, 10)  #10by10 square centered on point
226
        px,py = mDataDict["pointXY"]
227
        cNum = mDataDict["curveNum"]
228
        pntIn = mDataDict["pIndex"]
229
        legend = mDataDict["legend"]
230
        #make a string to display
231
        s = "Crv# %i, '%s', Pt. (%.2f,%.2f), PtInd %i" %(cNum, legend, px, py, pntIn)
232
        dc.DrawText(s, sx , sy+1)
233
        # -----------
234
 
596 FredericG 235
 
236
    def onNewTest(self, test):
237
        index = self.TestListCtrl.InsertStringItem(sys.maxint, test.descr)
238
        self.TestListCtrl.SetStringItem(index, 1, str(test.speed))
239
        self.TestListCtrl.SetStringItem(index, 2, test.channel)
240
        self.TestListCtrl.SetStringItem(index, 3, "OK")
241
 
242
 
590 FredericG 243
    def OnTestSelected(self, event):
244
         testId = event.m_itemIndex
245
         print "Test Selected id=%d" % (testId)
592 FredericG 246
         self.activeTestId = testId
247
         self.drawGraph()
590 FredericG 248
 
592 FredericG 249
    def drawGraph(self):
250
         vibTest = self.app.getTest(self.activeTestId)
590 FredericG 251
         nb = vibTest.getDataLen()
600 FredericG 252
         y = int(self.yAxisChoice.GetStringSelection())
590 FredericG 253
 
600 FredericG 254
         if self.graphTypeChoice.GetSelection() == 0:
599 FredericG 255
             xydata = _Numeric.linspace(0,0.09*nb,2*nb)
256
             xydata.shape = (nb, 2)
257
             xydata[:,1] = vibTest.getRawData()
600 FredericG 258
             line = wx.lib.plot.PolyLine(xydata, legend= 'Raw Data', colour='red', width=2)
599 FredericG 259
 
260
             title = "Raw Signal: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
261
             self.client.Draw(wx.lib.plot.PlotGraphics([line], title, "Time (ms)", "Acc"), yAxis= (-y,y))
262
             self.client.SetEnableGrid('Horizontal')
596 FredericG 263
 
600 FredericG 264
         if self.graphTypeChoice.GetSelection() == 1:
265
             xydata = _Numeric.linspace(0,0.09*nb,2*nb)
266
             xydata.shape = (nb, 2)
267
             xydata[:,1] = vibTest.getFilteredData()
268
             line = wx.lib.plot.PolyLine(xydata, legend= 'Raw Data', colour='red', width=2)
269
 
270
             title = "Filtered Signal: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
271
             self.client.Draw(wx.lib.plot.PlotGraphics([line], title, "Time (ms)", "Acc"), yAxis= (-y,y))
272
             self.client.SetEnableGrid('Horizontal')
273
 
274
         elif self.graphTypeChoice.GetSelection() == 2:
599 FredericG 275
             xydata = _Numeric.linspace(0,5555,nb)
276
             xydata.shape = (nb/2, 2)
277
 
278
             xydata[:,1] = vibTest.getSpectrum()
590 FredericG 279
 
599 FredericG 280
             line = wx.lib.plot.PolyLine(xydata, legend= 'Spectrum', colour='red')
600 FredericG 281
             markers = wx.lib.plot.PolyMarker(xydata, legend= '', colour='red', marker='circle',size=2)
599 FredericG 282
 
283
             title = "Spectrum: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
600 FredericG 284
             self.client.Draw(wx.lib.plot.PlotGraphics([line,markers], title, "Freq (Hz)", "Acc"), xAxis=(0,300), yAxis= (-0,y))
285
             self.client.SetEnableGrid(True)
590 FredericG 286
 
599 FredericG 287
 
587 FredericG 288
    def OnImport(self, event): # wxGlade: MainFrame.<event_handler>
289
        self.app.Import()
290
 
599 FredericG 291
    def onYAxisChange(self, event): # wxGlade: MainFrame.<event_handler>
592 FredericG 292
        self.drawGraph()
293
 
600 FredericG 294
    def onGraphTypeChange(self, event): # wxGlade: MainFrame.<event_handler>
599 FredericG 295
        self.drawGraph()
296
 
584 FredericG 297
# end of class MainFrame
298
 
299
 
586 FredericG 300
class VibTest:
596 FredericG 301
    def __init__(self, descr, motor, speed, channel, rawData):
594 FredericG 302
        self.descr = descr
303
        self.motor = motor
304
        self.speed = speed
596 FredericG 305
        self.channel = channel
599 FredericG 306
 
307
        self.dataLen = len(rawData)
308
 
590 FredericG 309
        self.rawData = _Numeric.array(rawData)
310
        self.dc = self.rawData.mean()
311
        self.rawData -= self.dc
586 FredericG 312
 
600 FredericG 313
        self.fft = _Numeric.fft.rfft(self.rawData)
314
 
315
        self.spectrum = None
316
        self.filteredData = None
599 FredericG 317
 
594 FredericG 318
    def getDescr(self):
319
        return self.Descr
587 FredericG 320
 
590 FredericG 321
    def getRawData(self):
322
        return self.rawData
323
 
324
    def getDataLen(self):
325
        return self.dataLen
326
 
599 FredericG 327
    def getSpectrum(self):
600 FredericG 328
        if self.spectrum == None:
329
            self.spectrum = _Numeric.absolute(self.fft[1:self.dataLen/2+1]) / (self.dataLen/2)
330
        return self.spectrum
590 FredericG 331
 
600 FredericG 332
    def getFilteredData(self):
333
        if self.filteredData == None:
334
            tmpfft = self.fft.copy()
335
            for i in range(0,7):
336
                tmpfft[i] = 0
337
            for i in range(30, len(tmpfft)):
338
                tmpfft[i] = 0
339
            self.filteredData = _Numeric.fft.irfft(tmpfft)
340
        return self.filteredData
599 FredericG 341
 
584 FredericG 342
class App(wx.App):
586 FredericG 343
    def __init__(self, par):
344
        self.VibTests = []
345
 
346
        wx.App.__init__(self, par)
347
 
348
 
596 FredericG 349
    def AddTest(self, descr, motor, speed, channel, rawData):
350
        test = VibTest(descr, motor, speed, channel, rawData)
586 FredericG 351
        self.VibTests.append(test)
596 FredericG 352
        self.frame_1.onNewTest(test)
586 FredericG 353
 
590 FredericG 354
    def getTest(self, testId):
355
        return self.VibTests[testId]
356
 
584 FredericG 357
    def OnInit(self):
358
        wx.InitAllImageHandlers()
586 FredericG 359
        self.frame_1 = MainFrame(None, -1, "")
587 FredericG 360
        self.frame_1.setApp(self);
586 FredericG 361
        self.SetTopWindow(self.frame_1)
362
 
587 FredericG 363
        self.frame_1.Show()
364
        return 1
365
 
366
    def Import(self):
600 FredericG 367
 
368
        filePath = "./unbal150.txt"
599 FredericG 369
        #filePath = "./nikivan.txt"
596 FredericG 370
 
371
        print "Import %s" % filePath
372
 
373
        logfile = open(filePath, "r")
590 FredericG 374
        data = None
596 FredericG 375
 
376
        headers = (logfile.readline()).split(',')
377
        nbCols = len(headers)
378
        print "NbCols =", nbCols
379
 
380
        data = []
381
        descr = []
382
        speed = []
383
        channel = []
384
        for c in range(nbCols):
385
            data.append([])
386
            h = headers[c].split(' ')
387
            descr.append(h[0]);
388
            speed.append(h[1]);
389
            channel.append(h[2]);
390
 
590 FredericG 391
        for line in logfile:
392
            values = line.split(',')
596 FredericG 393
            for i in range(nbCols):
394
                data[i].append(int(values[i]))
590 FredericG 395
        logfile.close()
596 FredericG 396
 
397
        for c in range(nbCols):
599 FredericG 398
            if (len(data[c]) % 2) != 0:
399
                data[c].append(data[c][-1])
596 FredericG 400
            self.AddTest(descr[c], 0, int(speed[c]), channel[c], data[c])
590 FredericG 401
 
402
 
403
 
586 FredericG 404
 
590 FredericG 405
 
584 FredericG 406
# end of class App
407
 
408
if __name__ == "__main__":
409
    VibrationTestGui = App(0)
410
    VibrationTestGui.MainLoop()