Exemplo n.º 1
0
class mainFrame(wx.Frame):

    Data = None

    def __init__(self, parent):
        wx.Frame.__init__(self,
                          parent,
                          id=wx.ID_ANY,
                          title=u"Обработка данных детектора",
                          pos=wx.DefaultPosition,
                          size=wx.Size(737, 425),
                          style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)

        self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)

        bSizer1 = wx.BoxSizer(wx.VERTICAL)

        self.m_panel2 = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition,
                                 wx.DefaultSize, wx.TAB_TRAVERSAL)
        self.m_panel2.SetForegroundColour(
            wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW))
        self.m_panel2.SetBackgroundColour(
            wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DLIGHT))

        bSizer61 = wx.BoxSizer(wx.VERTICAL)

        gSizer21 = wx.GridSizer(0, 2, 0, 0)

        bSizer6 = wx.BoxSizer(wx.VERTICAL)

        self.graphPanel1 = wx.Panel(self.m_panel2, wx.ID_ANY,
                                    wx.DefaultPosition, wx.DefaultSize,
                                    wx.TAB_TRAVERSAL)
        bSizer14 = wx.BoxSizer(wx.VERTICAL)

        self.graphPanel1.SetSizer(bSizer14)
        self.graphPanel1.Layout()
        bSizer14.Fit(self.graphPanel1)
        bSizer6.Add(self.graphPanel1, 1, wx.EXPAND | wx.ALL, 5)

        ###########
        self.figure1 = Figure()
        #self.axes1 = self.figure.add_subplot(111)
        self.canvas1 = FigureCanvas(self, wx.ID_ANY, self.figure1)
        bSizer14.Add(self.canvas1, 1, wx.LEFT | wx.TOP | wx.EXPAND)
        self.toolbar1 = NavigationToolbar2Wx(self.canvas1)
        self.toolbar1.Realize()
        bSizer14.Add(self.toolbar1, 0, wx.LEFT | wx.EXPAND)
        self.toolbar1.Show()
        self.Fit()
        ################

        gSizer21.Add(bSizer14, 2, wx.EXPAND, 5)

        bSizer7 = wx.BoxSizer(wx.VERTICAL)

        self.m_staticText4 = wx.StaticText(self.m_panel2, wx.ID_ANY,
                                           u"MyLabel", wx.DefaultPosition,
                                           wx.DefaultSize, 0)
        self.m_staticText4.Wrap(-1)
        self.m_staticText4.SetForegroundColour(
            wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOTEXT))

        bSizer7.Add(self.m_staticText4, 0, wx.ALL, 5)

        self.m_staticText5 = wx.StaticText(self.m_panel2, wx.ID_ANY,
                                           u"MyLabel", wx.DefaultPosition,
                                           wx.DefaultSize, 0)
        self.m_staticText5.Wrap(-1)
        self.m_staticText5.SetForegroundColour(
            wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOTEXT))

        bSizer7.Add(self.m_staticText5, 0, wx.ALL, 5)

        self.m_staticText6 = wx.StaticText(self.m_panel2, wx.ID_ANY,
                                           u"MyLabel", wx.DefaultPosition,
                                           wx.DefaultSize, 0)
        self.m_staticText6.Wrap(-1)
        self.m_staticText6.SetForegroundColour(
            wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOTEXT))

        bSizer7.Add(self.m_staticText6, 0, wx.ALL, 5)

        gSizer21.Add(bSizer7, 0, wx.EXPAND, 5)

        bSizer61.Add(gSizer21, 1, wx.EXPAND, 5)

        gSizer3 = wx.GridSizer(0, 2, 0, 0)

        bSizer62 = wx.BoxSizer(wx.VERTICAL)

        gSizer3.Add(bSizer62, 1, wx.EXPAND, 5)

        bSizer71 = wx.BoxSizer(wx.VERTICAL)

        self.m_staticText41 = wx.StaticText(self.m_panel2, wx.ID_ANY,
                                            u"MyLabel", wx.DefaultPosition,
                                            wx.DefaultSize, 0)
        self.m_staticText41.Wrap(-1)
        self.m_staticText41.SetForegroundColour(
            wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOTEXT))

        bSizer71.Add(self.m_staticText41, 0, wx.ALL, 5)

        self.m_staticText51 = wx.StaticText(self.m_panel2, wx.ID_ANY,
                                            u"MyLabel", wx.DefaultPosition,
                                            wx.DefaultSize, 0)
        self.m_staticText51.Wrap(-1)
        self.m_staticText51.SetForegroundColour(
            wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOTEXT))

        bSizer71.Add(self.m_staticText51, 0, wx.ALL, 5)

        self.m_staticText61 = wx.StaticText(self.m_panel2, wx.ID_ANY,
                                            u"MyLabel", wx.DefaultPosition,
                                            wx.DefaultSize, 0)
        self.m_staticText61.Wrap(-1)
        self.m_staticText61.SetForegroundColour(
            wx.SystemSettings.GetColour(wx.SYS_COLOUR_INFOTEXT))

        bSizer71.Add(self.m_staticText61, 0, wx.ALL, 5)

        gSizer3.Add(bSizer71, 1, wx.EXPAND, 5)

        bSizer61.Add(gSizer3, 1, wx.EXPAND, 5)

        self.m_panel2.SetSizer(bSizer61)
        self.m_panel2.Layout()
        bSizer61.Fit(self.m_panel2)
        bSizer1.Add(self.m_panel2, 1, wx.EXPAND, 5)

        self.SetSizer(bSizer1)
        self.Layout()
        self.m_menubar1 = wx.MenuBar(0)
        self.m_menu1 = wx.Menu()
        self.m_menuItem1 = wx.MenuItem(self.m_menu1, wx.ID_ANY, u"Открыть...",
                                       wx.EmptyString, wx.ITEM_NORMAL)
        self.m_menu1.AppendItem(self.m_menuItem1)

        self.m_menu1.AppendSeparator()

        self.m_menuItem2 = wx.MenuItem(self.m_menu1, wx.ID_ANY, u"Выход",
                                       wx.EmptyString, wx.ITEM_NORMAL)
        self.m_menu1.AppendItem(self.m_menuItem2)

        self.m_menubar1.Append(self.m_menu1, u"Файл")

        self.m_menu2 = wx.Menu()
        self.m_menuItem3 = wx.MenuItem(self.m_menu2, wx.ID_ANY, u"График 1",
                                       wx.EmptyString, wx.ITEM_CHECK)
        self.m_menu2.AppendItem(self.m_menuItem3)
        self.m_menuItem3.Check(True)

        self.m_menuItem4 = wx.MenuItem(self.m_menu2, wx.ID_ANY, u"График 2",
                                       wx.EmptyString, wx.ITEM_CHECK)
        self.m_menu2.AppendItem(self.m_menuItem4)
        self.m_menuItem4.Check(True)

        self.m_menubar1.Append(self.m_menu2, u"Показать")

        self.SetMenuBar(self.m_menubar1)

        self.Centre(wx.BOTH)

        # COnnect events
        self.Bind(wx.EVT_MENU, self.openFile, id=self.m_menuItem1.GetId())
        self.Bind(wx.EVT_MENU, self.showGraph1, id=self.m_menuItem3.GetId())

    def showGraph1(self, event):
        if self.m_menuItem3.IsChecked() == False:
            self.graphPanel1.Hide()
            self.canvas1.Hide()
            self.toolbar1.Hide()
        else:
            self.graphPanel1.Show()
            self.canvas1.Show()
            self.toolbar1.Show()

    def __del__(self):
        pass

    def openFile(self, event):
        with wx.FileDialog(self,
                           "Открыть файл данных детектора",
                           wildcard="DAT файлы (*.dat)|*.dat",
                           style=wx.FD_OPEN
                           | wx.FD_FILE_MUST_EXIST) as fileDialog:

            if fileDialog.ShowModal() == wx.ID_CANCEL:
                return  # the user changed their mind

            # Proceed loading the file chosen by the user
            pathname = fileDialog.GetPath()
            try:
                self.Data = DetectorData(pathname)
                self.axes1 = self.figure1.add_subplot(111)
                self.axes1.plot(self.Data.datTim, self.Data.inten)
                self.axes1.set_xlabel("Время хуемя")
                self.axes1.set_ylabel("Интенсивность")

                self.axes2 = self.figure1.add_subplot(111)
                self.axes2.plot(self.Data.datTim, self.Data.press)
                self.axes2.set_ylabel("Давление")

            except IOError:
                wx.LogError("Не удалось открыть файл '%s'." % newfile)
Exemplo n.º 2
0
class PlotPanel(wx.Panel):
    def __init__(self, parent, pg, *args, **kwargs):
        wx.Panel.__init__(self, parent=parent, *args, **kwargs)
        self.pg = pg

        # various initialization routines
        self.initPieMenu()
        self.initERPCanvas()
        self.initLayout()

    def initPieMenu(self):
        self.pieMenu = widgets.PieMenu(self,
                choices=self.pg.choices,
                rotation=4.0*np.pi/len(self.pg.choices),
                colors=('turquoise', 'red', 'blue violet', 'orange',
                        'blue', 'yellow'))
                #colors=('turquoise', 'red', 'blue', 'green',
                #        'yellow', 'blue violet'))

    def initERPCanvas(self):
        #self.erpFig = plt.Figure()
        #self.erpAx = self.erpFig.add_subplot(1,1,1)
        #self.erpCanvas = FigureCanvas(parent=self, id=wx.ID_ANY, figure=self.erpFig)
        self.erpFig = plt.Figure()
        self.erpFig.subplots_adjust(hspace=0.32, wspace=0.02,
            left=0.065, right=0.95, top=0.97, bottom=0.18)
        gs = pltgs.GridSpec(2,4)
        self.erpAx = self.erpFig.add_subplot(gs[0,:])
        self.h1Ax  = self.erpFig.add_subplot(gs[1,0])
        self.h2Ax  = self.erpFig.add_subplot(gs[1,1])
        self.h3Ax  = self.erpFig.add_subplot(gs[1,2])
        self.h4Ax  = self.erpFig.add_subplot(gs[1,3])
        self.cbAx  = self.erpFig.add_axes([0.05, 0.08, 0.9, 0.05])
        self.erpCanvas = FigureCanvas(parent=self, id=wx.ID_ANY, figure=self.erpFig)

    def initLayout(self):
        plotSizer = wx.BoxSizer(orient=wx.VERTICAL)

        plotSizer.Add(self.pieMenu, proportion=1, flag=wx.EXPAND)
        plotSizer.Add(self.erpCanvas, proportion=1, flag=wx.EXPAND)

        self.SetSizer(plotSizer)

        self.erpCanvas.Hide()
        self.Layout()

    def showPieMenu(self):
        self.erpCanvas.Hide()
        self.pieMenu.Show()
        self.Layout()

    def showERPCanvas(self):
        self.erpCanvas.Show()
        #self.erpCanvas.draw()
        self.pieMenu.Hide()
        self.Layout()

    def plotERP(self, cap):
        chanIndex = cap.getChanIndices(('cz',))[0]
        if chanIndex is None:
            chans = (0,)
            chanIndex = 0
            wx.LogWarning('Could not find channel Cz.  Using first channel instead.')
        else:
            chans = ('Cz',)

        cap = cap.copy().bandpass(0.5, np.inf, order=3)

        seg = cap.segment(start=-0.2, end=0.75)

        targ = seg.select(matchFunc=lambda mark: self.pg.markToStim(mark) == self.pg.targStr)
        nonTarg = seg.select(matchFunc=lambda mark: self.pg.markToStim(mark) == self.pg.nonTargStr)

        for ax in (self.erpAx, self.h1Ax, self.h2Ax, self.h3Ax, self.h4Ax):
            ax.cla()

        targPlot = targ.plotAvg(chans=chans, ax=self.erpAx, linewidth=2, color='blue')
        targPlot['lines'][0].set_label(self.pg.targStr + ' ERP')

        nonTargPlot = nonTarg.plotAvg(chans=chans, ax=self.erpAx, linewidth=2, color='green')
        nonTargPlot['lines'][0].set_label(self.pg.nonTargStr + ' ERP')

        erp = np.mean(targ.data, axis=0)

        mn = np.min(erp[:,chanIndex])
        mx = np.max(erp[:,chanIndex])

        self.erpAx.hlines(0.0, 0.0, 0.8, linestyle='--', linewidth=2, color='grey')
        self.erpAx.vlines(0.0, mn, mx, linestyle='--', linewidth=2, color='grey')
        self.erpAx.vlines((200, 300, 400, 500), mn, mx,
                          linestyle='--', linewidth=1, color='red')

        self.erpAx.legend()
        self.erpAx.set_xlabel('Time (s)')
        self.erpAx.set_ylabel(r'Signal ($\mu V$)')

        sampRate = targ.getSampRate()
        erp1 = erp[int((0.2+0.2)*sampRate),:]
        erp2 = erp[int((0.2+0.3)*sampRate),:]
        erp3 = erp[int((0.2+0.4)*sampRate),:]
        erp4 = erp[int((0.2+0.5)*sampRate),:]

        erpAll = np.concatenate((erp1, erp2, erp3, erp4))

        mn = np.min(erpAll)
        mx = np.max(erpAll)

        interpMethod = 'multiquadric'
        coord = '3d'
        h1 = eeg.plotHeadInterp(erp1, chanNames=targ.getChanNames(),
            method=interpMethod, coord=coord, mn=mn, mx=mx, ax=self.h1Ax)
        self.h1Ax.set_title('200ms')
        h2 = eeg.plotHeadInterp(erp2, chanNames=targ.getChanNames(),
            method=interpMethod, coord=coord, mn=mn, mx=mx, ax=self.h2Ax)
        self.h2Ax.set_title('300ms')
        h3 = eeg.plotHeadInterp(erp3, chanNames=targ.getChanNames(),
            method=interpMethod, coord=coord, mn=mn, mx=mx, ax=self.h3Ax)
        self.h3Ax.set_title('400ms')
        h4 = eeg.plotHeadInterp(erp4, chanNames=targ.getChanNames(),
            method=interpMethod, coord=coord, mn=mn, mx=mx, ax=self.h4Ax)
        self.h4Ax.set_title('500ms')

        cbar = plt.colorbar(h1['im'], ax=self.erpAx, orientation='horizontal', cax=self.cbAx)

        cbar.set_label(r'Target ERP ($\mu V$)')

        self.showERPCanvas()
Exemplo n.º 3
0
Arquivo: pieern.py Projeto: idfah/cebl
class PlotPanel(wx.Panel):
    def __init__(self, parent, choices, rotation, *args, **kwargs):
        wx.Panel.__init__(self, parent=parent, *args, **kwargs)

        self.initPieMenu(choices, rotation)
        self.initFeatureCanvas()
        self.initLayout()

    def initPieMenu(self, choices, rotation):
        self.pieMenu = widgets.PieMenu(self,
                                       choices=choices,
                                       rotation=rotation)

    def initFeatureCanvas(self):
        self.featureFig = plt.Figure()
        ##self.featureFig.subplots_adjust(hspace=0.32, wspace=0.02,
        ##    left=0.065, right=0.95, top=0.97, bottom=0.18)

        self.featureAx = self.featureFig.add_subplot(1, 1, 1)

        self.featureCanvas = FigureCanvas(parent=self,
                                          id=wx.ID_ANY,
                                          figure=self.featureFig)

    def initLayout(self):
        plotSizer = wx.BoxSizer(orient=wx.VERTICAL)

        plotSizer.Add(self.pieMenu, proportion=1, flag=wx.EXPAND | wx.ALL)
        plotSizer.Add(self.featureCanvas,
                      proportion=1,
                      flag=wx.EXPAND | wx.ALL)

        self.SetSizer(plotSizer)

        self.featureCanvas.Hide()
        self.Layout()

    def showPieMenu(self):
        self.featureCanvas.Hide()
        self.pieMenu.Show()
        self.Layout()

    def showFeatureCanvas(self):
        self.featureCanvas.Show()
        self.pieMenu.Hide()
        self.Layout()

    def plotFeatures(self, trainData, freqs, choices, chanNames):
        self.featureAx.cla()

        meanFeat = [np.mean(cls, axis=0) for cls in trainData]
        for cls, choice in zip(meanFeat, choices):
            self.featureAx.plot(cls, label=choice, marker='o', linewidth=2)

        self.featureAx.set_xlabel(r'Frequency ($Hz$)')
        self.featureAx.set_ylabel(r'Power ($uV^2 / Hz$)')
        self.featureAx.legend()

        nFreq = len(freqs)
        mn = np.min(np.concatenate(meanFeat))
        mx = np.max(np.concatenate(meanFeat))
        for i, cn in enumerate(chanNames):
            if i > 0:
                self.featureAx.vlines(i * float(nFreq), mn, mx, linestyle='--')
            self.featureAx.text((i + 0.25) * float(nFreq),
                                0.8 * mx,
                                cn,
                                fontsize=14)

        tickStride = int(np.ceil(nFreq / 3.0))
        tickFreqs = freqs[::tickStride]
        tickPlaces = np.arange(nFreq)[::tickStride]
        tickLocs = np.concatenate(
            [tickPlaces + nFreq * i for i, c in enumerate(chanNames)])
        tickLabels = np.round(np.tile(tickFreqs,
                                      len(chanNames))).astype(np.int)

        self.featureAx.set_xticks(tickLocs)
        self.featureAx.set_xticklabels(tickLabels)

        self.featureAx.autoscale(tight=True)
        self.featureFig.tight_layout()

        self.showFeatureCanvas()