Пример #1
0
    def __init__(self, *args):
        QtGui.QMainWindow.__init__(self, *args)
        self.demo = IzhikevichDemo()
        self.signalMapper = QtCore.QSignalMapper(self)
        self.demoFrame = QtGui.QFrame(self)
        self.controlPanel = QtGui.QFrame(self.demoFrame)
        self.figureNo = {}
        self.buttons = {}
        for key, value in list(IzhikevichDemo.parameters.items()):
            button = QtGui.QPushButton(key, self.controlPanel)
            self.figureNo[value[0]] = key
            self.buttons[key] = button
        keys = list(self.figureNo.keys())
        keys.sort()
        length = len(keys)
        rows = int(numpy.rint(numpy.sqrt(length)))
        cols = int(numpy.ceil(length * 1.0 / rows))
        layout = QtGui.QGridLayout()
        for ii in range(rows):
            for jj in range(cols):
                index = ii * cols + jj
                if  index < length:
                    key = self.figureNo[keys[index]]
                    button = self.buttons[key]
                    button.setToolTip(self.tr(IzhikevichDemo.documentation[key]))
                    layout.addWidget(button, ii, jj)
                    self.connect(button, QtCore.SIGNAL('clicked()'), self.signalMapper, QtCore.SLOT('map()'))
                    self.signalMapper.setMapping(button, key)

        self.connect(self.signalMapper, QtCore.SIGNAL('mapped(const QString &)'), self._simulateAndPlot)         
        self.controlPanel.setLayout(layout)
        self.plotPanel = QtGui.QFrame(self.demoFrame)
        self.VmPlot = Qwt.QwtPlot(self.plotPanel)
        self.VmPlot.setAxisTitle(Qwt.QwtPlot.xBottom, 'time (ms)')
        self.VmPlot.setAxisTitle(Qwt.QwtPlot.yLeft, 'Vm (mV)')
        self.VmPlot.replot()
        self.ImPlot = Qwt.QwtPlot(self.plotPanel)
        self.ImPlot.setAxisTitle(Qwt.QwtPlot.xBottom, 'time (ms)')
        self.ImPlot.setAxisTitle(Qwt.QwtPlot.yLeft, 'Im (nA)')
        self.vmPlotZoomer = self._make_zoomer(self.VmPlot)
        self.imPlotZoomer = self._make_zoomer(self.ImPlot)
        self.descriptionWidget = QtGui.QLabel('Click any of the buttons to simulate and plot the corresponding neuron.')
        self.descriptionWidget.setFrameStyle(QtGui.QFrame.Panel | QtGui.QFrame.Sunken)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
        self.descriptionWidget.setSizePolicy(sizePolicy)
        self.VmPlot.setSizePolicy(sizePolicy)
        self.ImPlot.setSizePolicy(sizePolicy)
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.VmPlot)
        layout.addWidget(self.ImPlot)
        layout.addWidget(self.descriptionWidget)
        self.plotPanel.setLayout(layout)
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.plotPanel)
        layout.addWidget(self.controlPanel)
        self.demoFrame.setLayout(layout)
        self.setCentralWidget(self.demoFrame)
Пример #2
0
class IzhikevichGUI:
    def __init__(self):
        self.demo = IzhikevichDemo()
        self.figureNums = {} # maps figure no. to label
        self.root = Tk()
        self.root.title('MOOSE - Izhikevich Demo')
        self.root.rowconfigure(0, weight=1)
        self.root.columnconfigure(1, weight=1)
        self.controlPanel = Frame(self.root)
        self.buttons = {}
        for key in self.demo.parameters:
            button = Button(self.controlPanel, text=key)
            button.bind('<Button-1>', self._run_model)
            self.buttons[key] = button
            self.figureNums[IzhikevichDemo.parameters[key][0]] = key

        keys = self.figureNums.keys()
        keys.sort()
        ii = 0
        for key in keys:
            label = self.figureNums[key]
            button = self.buttons[label]
            button.grid(row=ii, column=0, sticky=W)
            button.pack(fill=BOTH, expand=1)
            ii = ii + 1
        self.controlPanel.grid(row=0, column=0, sticky=W)
        self.controlPanel.pack(side=LEFT)
        self.plotPanel = Frame(self.root, relief=RIDGE)   
        self.plot = Tkplot(self.plotPanel)
        self.plot.config(scrollregion=self.plot.bbox(ALL))
        self.plot.set_axes(-10, -10, 100, 100, 10, 10)
        self.plot.axes.xmin = -10
        self.plot.axes.ymin = -150
        self.plot.grid(row=0, column=1, sticky=S)
        self.plot.pack(fill=BOTH, expand=1)
        self.plotPanel.grid(row=0, rowspan=len(IzhikevichDemo.parameters), column=1, sticky=N+S+E+W)
        self.plotPanel.pack(fill=BOTH, side=RIGHT, expand=1)
        self.root.update()
        self.plot._do_update(None) # To force drawing the plot in the first place
        self.plot.bind('<Configure>', self.plot._do_update) # Connect the resize event to update of the plot

    def _run_model(self, event):
        key = event.widget['text']
        try:
            (time, Vm, Im) = self.demo.simulate(key)
        except NotImplementedError as (err, msg):
            tkMessageBox.showinfo('%s' % (err), '%s' % (msg))
            return
        length = len(time)
        self.plot.clear()
        self.plot.set_axes(-10, -150, time[length-1], 50, 10, 10)
        self.plot.plot(time, numpy.array(Vm) * 1e3)
        self.plot.plot(time, numpy.array(Im) * 1e9 - 100, color='red')
        self.plot.show()
Пример #3
0
    def __init__(self):
        self.demo = IzhikevichDemo()
        self.figureNums = {} # maps figure no. to label
        self.root = Tk()
        self.root.title('MOOSE - Izhikevich Demo')
        self.root.rowconfigure(0, weight=1)
        self.root.columnconfigure(1, weight=1)
        self.controlPanel = Frame(self.root)
        self.buttons = {}
        for key in self.demo.parameters:
            button = Button(self.controlPanel, text=key)
            button.bind('<Button-1>', self._run_model)
            self.buttons[key] = button
            self.figureNums[IzhikevichDemo.parameters[key][0]] = key

        keys = self.figureNums.keys()
        keys.sort()
        ii = 0
        for key in keys:
            label = self.figureNums[key]
            button = self.buttons[label]
            button.grid(row=ii, column=0, sticky=W)
            button.pack(fill=BOTH, expand=1)
            ii = ii + 1
        self.controlPanel.grid(row=0, column=0, sticky=W)
        self.controlPanel.pack(side=LEFT)
        self.plotPanel = Frame(self.root, relief=RIDGE)   
        self.plot = Tkplot(self.plotPanel)
        self.plot.config(scrollregion=self.plot.bbox(ALL))
        self.plot.set_axes(-10, -10, 100, 100, 10, 10)
        self.plot.axes.xmin = -10
        self.plot.axes.ymin = -150
        self.plot.grid(row=0, column=1, sticky=S)
        self.plot.pack(fill=BOTH, expand=1)
        self.plotPanel.grid(row=0, rowspan=len(IzhikevichDemo.parameters), column=1, sticky=N+S+E+W)
        self.plotPanel.pack(fill=BOTH, side=RIGHT, expand=1)
        self.root.update()
        self.plot._do_update(None) # To force drawing the plot in the first place
        self.plot.bind('<Configure>', self.plot._do_update) # Connect the resize event to update of the plot
Пример #4
0
class IzhikevichGui(QtGui.QMainWindow):
    """This is a Qt version of the GUI"""
    def __init__(self, *args):
        QtGui.QMainWindow.__init__(self, *args)
        self.demo = IzhikevichDemo()
        self.signalMapper = QtCore.QSignalMapper(self)
        self.demoFrame = QtGui.QFrame(self)
        self.controlPanel = QtGui.QFrame(self.demoFrame)
        self.figureNo = {}
        self.buttons = {}
        for key, value in list(IzhikevichDemo.parameters.items()):
            button = QtGui.QPushButton(key, self.controlPanel)
            self.figureNo[value[0]] = key
            self.buttons[key] = button
        keys = list(self.figureNo.keys())
        keys.sort()
        length = len(keys)
        rows = int(numpy.rint(numpy.sqrt(length)))
        cols = int(numpy.ceil(length * 1.0 / rows))
        layout = QtGui.QGridLayout()
        for ii in range(rows):
            for jj in range(cols):
                index = ii * cols + jj
                if index < length:
                    key = self.figureNo[keys[index]]
                    button = self.buttons[key]
                    button.setToolTip(
                        self.tr(IzhikevichDemo.documentation[key]))
                    layout.addWidget(button, ii, jj)
                    self.connect(button, QtCore.SIGNAL('clicked()'),
                                 self.signalMapper, QtCore.SLOT('map()'))
                    self.signalMapper.setMapping(button, key)

        self.connect(self.signalMapper,
                     QtCore.SIGNAL('mapped(const QString &)'),
                     self._simulateAndPlot)
        self.controlPanel.setLayout(layout)
        self.plotPanel = QtGui.QFrame(self.demoFrame)
        self.VmPlot = Qwt.QwtPlot(self.plotPanel)
        self.VmPlot.setAxisTitle(Qwt.QwtPlot.xBottom, 'time (ms)')
        self.VmPlot.setAxisTitle(Qwt.QwtPlot.yLeft, 'Vm (mV)')
        self.VmPlot.replot()
        self.ImPlot = Qwt.QwtPlot(self.plotPanel)
        self.ImPlot.setAxisTitle(Qwt.QwtPlot.xBottom, 'time (ms)')
        self.ImPlot.setAxisTitle(Qwt.QwtPlot.yLeft, 'Im (nA)')
        self.vmPlotZoomer = self._make_zoomer(self.VmPlot)
        self.imPlotZoomer = self._make_zoomer(self.ImPlot)
        self.descriptionWidget = QtGui.QLabel(
            'Click any of the buttons to simulate and plot the corresponding neuron.'
        )
        self.descriptionWidget.setFrameStyle(QtGui.QFrame.Panel
                                             | QtGui.QFrame.Sunken)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                                       QtGui.QSizePolicy.Expanding)
        self.descriptionWidget.setSizePolicy(sizePolicy)
        self.VmPlot.setSizePolicy(sizePolicy)
        self.ImPlot.setSizePolicy(sizePolicy)
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.VmPlot)
        layout.addWidget(self.ImPlot)
        layout.addWidget(self.descriptionWidget)
        self.plotPanel.setLayout(layout)
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.plotPanel)
        layout.addWidget(self.controlPanel)
        self.demoFrame.setLayout(layout)
        self.setCentralWidget(self.demoFrame)

    def _simulateAndPlot(self, key):
        key = str(key)
        equationText = self.demo.getEquation(key).replace('\n', '<br/>')
        doc = IzhikevichDemo.documentation[key].replace('\n', '<br/>')
        text = '<b>%s:</b> %s<p><b>Equation:</b><br/> %s' % (key, doc,
                                                             equationText)
        self.descriptionWidget.setText(self.tr(text))
        #         if key == 'accommodation':
        #             mbox = QtGui.QMessageBox(self)
        #             mbox.setText(self.tr('Accommodation cannot be shown with regular Izhikevich model.'))
        #             mbox.setDetailedText(self.tr('\
        # Equation for u for the accommodating neuron is: \
        # u\' = a * b * (V + 65)\n Which is different from \
        # the regular equation u\' = a * (b*V - u) and cannot \
        # be obtained from the latter by any choice of a and b.'))
        #             mbox.show()
        #             return
        (time, Vm, Im) = self.demo.simulate(key)
        Vm = numpy.array(Vm.vector) * 1e3
        Im = numpy.array(Im.vector) * 1e9
        self.VmPlot.clear()
        self.ImPlot.clear()
        curve = Qwt.QwtPlotCurve(self.tr(key + '_Vm'))
        curve.setPen(QtCore.Qt.red)
        curve.setData(time, numpy.array(Vm))
        curve.attach(self.VmPlot)
        curve = Qwt.QwtPlotCurve(self.tr(key + '_Im'))
        curve.setPen(QtCore.Qt.blue)
        curve.setData(time, Im)
        curve.attach(self.ImPlot)
        self.imPlotZoomer.setZoomBase()
        self.vmPlotZoomer.setZoomBase()
        self.ImPlot.replot()
        self.VmPlot.replot()

    def _make_zoomer(self, plot):
        zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft,
                                   Qwt.QwtPicker.DragSelection,
                                   Qwt.QwtPicker.AlwaysOn, plot.canvas())
        zoomer.setRubberBandPen(QtGui.QPen(QtCore.Qt.white))
        zoomer.setTrackerPen(QtGui.QPen(QtCore.Qt.cyan))
        return zoomer
Пример #5
0
class IzhikevichGui(QtGui.QMainWindow):
    """This is a Qt version of the GUI"""
    def __init__(self, *args):
        QtGui.QMainWindow.__init__(self, *args)
        self.demo = IzhikevichDemo()
        self.signalMapper = QtCore.QSignalMapper(self)
        self.demoFrame = QtGui.QFrame(self)
        self.controlPanel = QtGui.QFrame(self.demoFrame)
        self.figureNo = {}
        self.buttons = {}
        for key, value in list(IzhikevichDemo.parameters.items()):
            button = QtGui.QPushButton(key, self.controlPanel)
            self.figureNo[value[0]] = key
            self.buttons[key] = button
        keys = list(self.figureNo.keys())
        keys.sort()
        length = len(keys)
        rows = int(numpy.rint(numpy.sqrt(length)))
        cols = int(numpy.ceil(length * 1.0 / rows))
        layout = QtGui.QGridLayout()
        for ii in range(rows):
            for jj in range(cols):
                index = ii * cols + jj
                if  index < length:
                    key = self.figureNo[keys[index]]
                    button = self.buttons[key]
                    button.setToolTip(self.tr(IzhikevichDemo.documentation[key]))
                    layout.addWidget(button, ii, jj)
                    self.connect(button, QtCore.SIGNAL('clicked()'), self.signalMapper, QtCore.SLOT('map()'))
                    self.signalMapper.setMapping(button, key)

        self.connect(self.signalMapper, QtCore.SIGNAL('mapped(const QString &)'), self._simulateAndPlot)         
        self.controlPanel.setLayout(layout)
        self.plotPanel = QtGui.QFrame(self.demoFrame)
        self.VmPlot = Qwt.QwtPlot(self.plotPanel)
        self.VmPlot.setAxisTitle(Qwt.QwtPlot.xBottom, 'time (ms)')
        self.VmPlot.setAxisTitle(Qwt.QwtPlot.yLeft, 'Vm (mV)')
        self.VmPlot.replot()
        self.ImPlot = Qwt.QwtPlot(self.plotPanel)
        self.ImPlot.setAxisTitle(Qwt.QwtPlot.xBottom, 'time (ms)')
        self.ImPlot.setAxisTitle(Qwt.QwtPlot.yLeft, 'Im (nA)')
        self.vmPlotZoomer = self._make_zoomer(self.VmPlot)
        self.imPlotZoomer = self._make_zoomer(self.ImPlot)
        self.descriptionWidget = QtGui.QLabel('Click any of the buttons to simulate and plot the corresponding neuron.')
        self.descriptionWidget.setFrameStyle(QtGui.QFrame.Panel | QtGui.QFrame.Sunken)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
        self.descriptionWidget.setSizePolicy(sizePolicy)
        self.VmPlot.setSizePolicy(sizePolicy)
        self.ImPlot.setSizePolicy(sizePolicy)
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.VmPlot)
        layout.addWidget(self.ImPlot)
        layout.addWidget(self.descriptionWidget)
        self.plotPanel.setLayout(layout)
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.plotPanel)
        layout.addWidget(self.controlPanel)
        self.demoFrame.setLayout(layout)
        self.setCentralWidget(self.demoFrame)

    def _simulateAndPlot(self, key):
        key = str(key)
        equationText = self.demo.getEquation(key).replace('\n', '<br/>')
        doc = IzhikevichDemo.documentation[key].replace('\n', '<br/>')
        text = '<b>%s:</b> %s<p><b>Equation:</b><br/> %s' % (key, doc, equationText)
        self.descriptionWidget.setText(self.tr(text))
#         if key == 'accommodation':
#             mbox = QtGui.QMessageBox(self)
#             mbox.setText(self.tr('Accommodation cannot be shown with regular Izhikevich model.'))
#             mbox.setDetailedText(self.tr('\
# Equation for u for the accommodating neuron is: \
# u\' = a * b * (V + 65)\n Which is different from \
# the regular equation u\' = a * (b*V - u) and cannot \
# be obtained from the latter by any choice of a and b.'))
#             mbox.show()
#             return
        (time, Vm, Im) = self.demo.simulate(key)
        Vm = numpy.array(Vm.vector) * 1e3
        Im = numpy.array(Im.vector) * 1e9
        self.VmPlot.clear()
        self.ImPlot.clear()
        curve = Qwt.QwtPlotCurve(self.tr(key + '_Vm'))
        curve.setPen(QtCore.Qt.red)
        curve.setData(time, numpy.array(Vm))
        curve.attach(self.VmPlot)
        curve = Qwt.QwtPlotCurve(self.tr(key + '_Im'))
        curve.setPen(QtCore.Qt.blue)
        curve.setData(time, Im)
        curve.attach(self.ImPlot)
        self.imPlotZoomer.setZoomBase()
        self.vmPlotZoomer.setZoomBase()
        self.ImPlot.replot()
        self.VmPlot.replot()
        

    def _make_zoomer(self, plot):
        zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom,
                                   Qwt.QwtPlot.yLeft,
                                   Qwt.QwtPicker.DragSelection,
                                   Qwt.QwtPicker.AlwaysOn,
                                   plot.canvas())
        zoomer.setRubberBandPen(QtGui.QPen(QtCore.Qt.white))
        zoomer.setTrackerPen(QtGui.QPen(QtCore.Qt.cyan))
        return zoomer