Example #1
0
    def draw_average_line(self):
        """
        method for drawing average lines on plot widget

        """
        pen_1 = mkPen(color="#4c96d7", style=Qt.DotLine, width=2)
        average_line_1 = InfiniteLine(angle=90, movable=False, pen=pen_1)
        average_line_2 = InfiniteLine(angle=90, movable=False, pen=pen_1)

        pen_2 = mkPen(color="#4c96d7", style=Qt.SolidLine, width=2)
        average_line_3 = InfiniteLine(angle=90, movable=False, pen=pen_2)
        average_line_4 = InfiniteLine(angle=90, movable=False, pen=pen_2)

        brush = QBrush(QColor(0, 0, 255, 20))

        if sum(self.y_1) != 0:
            average_1 = np.average(self.x_1, weights=self.y_1)
            linear_region_1 = LinearRegionItem([average_1, self.average], movable=False,
                                               brush=brush)
            self.graphics_view_1.addItem(linear_region_1)
            average_line_1.setPos(average_1)
            self.graphics_view_1.addItem(average_line_1)

        if sum(self.y_2) != 0:
            average_2 = np.average(self.x_2, weights=self.y_2)
            linear_region_2 = LinearRegionItem([average_2, self.average], movable=False,
                                               brush=brush)
            self.graphics_view_2.addItem(linear_region_2)
            average_line_2.setPos(average_2)
            self.graphics_view_2.addItem(average_line_2)

        average_line_3.setPos(self.average)
        average_line_4.setPos(self.average)
        self.graphics_view_1.addItem(average_line_3)
        self.graphics_view_2.addItem(average_line_4)
Example #2
0
    def setUI(self):
        self.vlayout = QtWidgets.QVBoxLayout()
        self.parent.setLayout(self.vlayout)

        form = QtWidgets.QWidget()
        self.viewer1D = Viewer1DBasic(form)
        self.vlayout.addWidget(form)
        self.fftbutton1D = QtWidgets.QPushButton()
        self.fftbutton1D.setText("")
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/icons/Icon_Library/FFT.png"), QtGui.QIcon.Normal,
                       QtGui.QIcon.Off)
        self.fftbutton1D.setIcon(icon)
        self.fftbutton1D.setCheckable(True)
        self.fftbutton1D.clicked.connect(self.update_plot)

        vbox = self.viewer1D.parent.layout()
        widg = QtWidgets.QWidget()
        hbox = QtWidgets.QHBoxLayout()
        widg.setLayout(hbox)
        vbox.insertWidget(0, widg)
        hbox.addWidget(self.fftbutton1D)
        hbox.addStretch()

        self.viewer1D.ROI = LinearRegionItem(values=[0, 100])
        self.viewer1D.plotwidget.plotItem.addItem(self.viewer1D.ROI)
        self.data_filtered_plot = self.viewer1D.plotwidget.plotItem.plot()
        self.data_filtered_plot.setPen('w')
        self.viewer1D.ROI.sigRegionChangeFinished.connect(self.set_data)

        self.viewer1D.ROIfft = LinearRegionItem()
        self.viewer1D.plotwidget.plotItem.addItem(self.viewer1D.ROIfft)
        self.viewer1D.ROIfft.sigRegionChangeFinished.connect(self.update_filter)

        self.parent.show()
Example #3
0
    def visualize(self, canvas, **canvases):  # TODO: callables?
        from pyqtgraph import LinearRegionItem

        canvas = canvases["imageview"]
        if callable(canvas):
            canvas = canvas()
        canvas.addItem(LinearRegionItem(*self.range.value, **self.kwargs))
    def set_experiment_view(self):
        self.ui.graphicsView.clear()
        plot = PlotDataItem(pen="k")

        duration = (self.ui.spinBoxExperimentDurationMinutes.value() *
                    60) + self.ui.spinBoxExperimentDurationSeconds.value()
        xs = np.linspace(0, duration, 2)
        ys = [1, 1]
        plot.setData(xs, ys)
        self.ui.graphicsView.addItem(plot)

        for ii in range(len(self.Stims.df)):
            start = self.Stims.df.time_on.iloc[ii]
            stop = self.Stims.df.time_off.iloc[ii]

            if self.Stims.df.message_on.iloc[ii].startswith("w"):
                box = LinearRegionItem(values=(start, stop),
                                       brush=(255, 255, 250, 230),
                                       movable=False)
                self.ui.graphicsView.addItem(box)
            elif self.Stims.df.message_on.iloc[ii].startswith("n"):
                on = self.Stims.df.message_on.iloc[ii][1:]
                r = int(on[:3])
                g = int(on[3:6])
                b = int(on[6:])
                box = LinearRegionItem(values=(start, stop),
                                       brush=(r, g, b, 50),
                                       movable=False)
                self.ui.graphicsView.addItem(box)
            elif self.Stims.df.message_on.iloc[ii].startswith("v"):
                box = LinearRegionItem(values=(start, stop),
                                       brush="k",
                                       movable=False)
                self.ui.graphicsView.addItem(box)

        self.ui.comboBoxSelectStimId.clear()
        for stim_id in set(self.Stims.df.id):
            self.ui.comboBoxSelectStimId.addItem(stim_id)
Example #5
0
 def initPlotView(self):
     self.plot = PlotWidget(enableAutoRange=True)
     self.plot.setXRange(self.lower - self.range * 0.05,
                         self.upper + self.range * 0.05)
     self.plotLegand = self.plot.addLegend()
     self.graphicsView.addWidget(self.plot)
     self.plotRegion = LinearRegionItem()
     self.plotRegion.setZValue(10)
     self.peakPoint = ScatterPlotItem(size=8,
                                      pen=mkPen(color='0000FF', width=2),
                                      symbol="+",
                                      brush=mkBrush(255, 255, 255, 240))
     self.plot.addItem(self.plotRegion, ignoreBounds=True)
     self.plot.addItem(self.peakPoint)
     self.setGraphViewStyle()
Example #6
0
    def initUI(self):
        """
        Initialize user interface.

        """
        L = QGridLayout(self)
        self.resize(500, 300)

        widget_align = Qt.AlignLeft

        # Available columns for recondition: all numeric columns
        self.columns = list(filter(
            lambda c: self.locs[c].dtype in ['float64', 'float32', \
                'uint8', 'uint16', 'int64'],
            self.locs.columns))

        # For the default, choose `I0` if available; otherwise
        # choose the first column
        init_col = 'I0' if ('I0' in self.columns) else self.columns[0]
        self.load_col(init_col)

        # Main plot
        self.PlotWidget = PlotWidget(name="Create Boolean attribute")
        L.addWidget(self.PlotWidget, 0, 0, alignment=widget_align)

        # Histogram
        self.curve = self.PlotWidget.plot(self.bin_c, self.H, clickable=True)

        # User threshold, as a LinearRegionItem from pyqtgraph
        self.LinearRegion = LinearRegionItem([self.hmin, (self.hmax-self.hmin)*0.25+self.hmin])
        self.PlotWidget.addItem(self.LinearRegion)

        # Drop-down menu to select the column
        self.M_select_col = LabeledQComboBox(self.columns, "Attribute",
            init_value=init_col, parent=self)
        self.M_select_col.assign_callback(self.M_select_col_callback)
        L.addWidget(self.M_select_col, 1, 0, alignment=widget_align)

        # Accept the current threshold
        self.B_accept = QPushButton("Accept", parent=self)
        L.addWidget(self.B_accept, 2, 0, alignment=widget_align)
        self.B_accept.clicked.connect(self.B_accept_callback)

        self.update_histogram()
    def initializeBinds(self):
        # aƱadir plots

        self.pushButtonPlay.clicked.connect(self.play)
        self.pushButton.clicked.connect(self.showFFT)
        setConfigOption('leftButtonPan', False)
        self.x = 0
        self.y = 0

        self.zoomedPlot = self.graphicsView.addPlot(row=1, col=0)
        self.fullPlot = self.graphicsView.addPlot(row=2, col=0)

        self.graphicsView.setBackground(background="w")
        # self.zoomedPlot.vb.setBackgroundColor("w")
        # self.fullPlot.vb.setBackgroundColor("w")
        self.penB = mkPen('b')
        self.penR = mkPen('r')
        self.region = LinearRegionItem()
        self.region.setZValue(10)

        self.vb = self.zoomedPlot.vb
        self.region.setRegion([1000, 2000])

        self.fullPlot.addItem(self.region, ignoreBounds=True)
        # pg.dbg()
        self.zoomedPlot.setAutoVisible(y=True)

        self.vLine = InfiniteLine(angle=90, movable=False)
        self.hLine = InfiniteLine(angle=0, movable=False)
        self.zoomedPlot.addItem(self.vLine, ignoreBounds=True)
        self.zoomedPlot.addItem(self.hLine, ignoreBounds=True)

        # signal para capturar evento de raton
        # proxy = SignalProxy(self.zoomedPlot.scene().sigMouseMoved, rateLimit=60, slot=self.mouseMoved)

        self.zoomedPlot.scene().sigMouseMoved.connect(self.mouseMoved)
        self.region.sigRegionChanged.connect(self.update)

        self.zoomedPlot.sigRangeChanged.connect(self.updateRegion)
Example #8
0
    def __init__(self, image=None, fillHistogram=True, bounds: tuple = None):
        GraphicsWidget.__init__(self)
        self.imageItem = lambda: None  # fake a dead weakref

        self.layout = QGraphicsGridLayout()
        self.setLayout(self.layout)
        self.layout.setContentsMargins(1, 1, 1, 1)
        self.layout.setSpacing(0)
        self.vb = ViewBox(parent=self)
        # self.vb.setMaximumHeight(152)
        # self.vb.setMinimumWidth(45)
        self.vb.setMouseEnabled(x=True, y=False)

        self.region = LinearRegionItem([0, 1], 'vertical', swapMode='block', bounds=bounds)
        self.region.setZValue(1000)
        self.vb.addItem(self.region)
        self.region.lines[0].addMarker('<|', 0.5)
        self.region.lines[1].addMarker('|>', 0.5)
        self.region.sigRegionChanged.connect(self.regionChanging)
        self.region.sigRegionChangeFinished.connect(self.regionChanged)

        self.axis = AxisItem('bottom', linkView=self.vb, maxTickLength=-10, parent=self)
        self.layout.addItem(self.axis, 1, 0)
        self.layout.addItem(self.vb, 0, 0)
        self.range = None
        self.vb.sigRangeChanged.connect(self.viewRangeChanged)

        self.plot = PlotCurveItem(pen=(200, 200, 200, 100))
        # self.plot.rotate(90)
        self.vb.addItem(self.plot)

        self.fillHistogram(fillHistogram)
        self._showRegions()

        self.autoHistogramRange()

        if image is not None:
            self.setImageItem(image)
Example #9
0
 def __init__(self, name):
     Node.__init__(self,
                   name,
                   terminals={
                       'dataIn': {
                           'io': 'in'
                       },
                       'dataOut': {
                           'io': 'out'
                       },
                       'plotItems': {
                           'io': 'out'
                       }
                   })
     color = (220, 220, 25, 255)
     self.plotDataItem = PlotDataItem(stepMode=True,
                                      fillLevel=0,
                                      pen={
                                          'color': color,
                                          'width': 2
                                      })
     self.plotRegion = LinearRegionItem([0, 1], movable=True)
     self.plotRegion.sigRegionChangeFinished.connect(self.regionChanged)
     self.sigUpdatePlot.connect(self.updatePlot)
Example #10
0
    def set_GUI(self):
        """

        """
        #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        #main_layout = QtWidgets.QGridLayout()
        #self.area.setLayout(main_layout)

        #vsplitter = QtWidgets.QSplitter(Qt.Vertical)
        # Hsplitter=QtWidgets.QSplitter(Qt.Horizontal)

        params = [
            {'title': 'set data:', 'name': 'set_data_4D', 'type': 'action', 'visible': False},
            {'title': 'set data:', 'name': 'set_data_3D', 'type': 'action', 'visible': False},
            {'title': 'set data:', 'name': 'set_data_2D', 'type': 'action', 'visible': False},
            {'title': 'set data:', 'name': 'set_data_1D', 'type': 'action', 'visible': False},
            {'title': 'Signal shape', 'name': 'data_shape_settings', 'type': 'group', 'children': [
                    {'title': 'Initial Data shape:', 'name': 'data_shape_init', 'type': 'str', 'value': "",
                     'readonly': True},
                    {'title': 'Axes shape:', 'name': 'nav_axes_shapes', 'type': 'group', 'children': [],
                     'readonly': True},
                    {'title': 'Data shape:', 'name': 'data_shape', 'type': 'str', 'value': "", 'readonly': True},
                    {'title': 'Navigator axes:', 'name': 'navigator_axes', 'type': 'itemselect'},
                    {'title': 'Set Nav axes:', 'name': 'set_nav_axes', 'type': 'action', 'visible': True},
                        ]},
                ]

        self.settings = Parameter.create(name='Param', type='group', children=params)
        ##self.signal_axes_selection()

        # connecting from tree
        self.settings.sigTreeStateChanged.connect(self.parameter_tree_changed)  # any changes on the settings
        self.settings.child(('set_data_1D')).sigActivated.connect(lambda: self.set_data_test('1D'))
        self.settings.child(('set_data_2D')).sigActivated.connect(lambda: self.set_data_test('2D'))
        self.settings.child(('set_data_3D')).sigActivated.connect(lambda: self.set_data_test('3D'))
        self.settings.child(('set_data_4D')).sigActivated.connect(lambda: self.set_data_test('4D'))
        self.settings.child('data_shape_settings', 'set_nav_axes').sigActivated.connect(self.update_data)
        ##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        ##% 1D signalviewer
        viewer1D_widget = QtWidgets.QWidget()
        self.ui.viewer1D = Viewer1D(viewer1D_widget)
        self.ROI1D = LinearRegionItem()
        self.ui.viewer1D.viewer.plotwidget.plotItem.addItem(self.ROI1D)
        self.ui.combomath = QtWidgets.QComboBox()
        self.ui.combomath.addItems(['Sum', 'Mean', 'Half-life'])
        self.ui.viewer1D.ui.button_widget.layout().insertWidget(4, self.ui.combomath)
        self.ui.combomath.currentIndexChanged.connect(self.update_Navigator)

        self.ROI1D.sigRegionChangeFinished.connect(self.update_Navigator)

        # % 2D viewer Dock
        viewer2D_widget = QtWidgets.QWidget()
        self.ui.viewer2D = Viewer2D(viewer2D_widget)
        self.ui.viewer2D.ui.Ini_plot_pb.setVisible(False)
        self.ui.viewer2D.ui.FlipUD_pb.setVisible(False)
        self.ui.viewer2D.ui.FlipLR_pb.setVisible(False)
        self.ui.viewer2D.ui.rotate_pb.setVisible(False)
        self.ui.viewer2D.ui.auto_levels_pb.click()
        self.ui.viewer2D.ui.ROIselect_pb.click()
        self.ROI2D = self.ui.viewer2D.ui.ROIselect
        self.ui.viewer2D.ROI_select_signal.connect(self.update_Navigator)

        dock_signal = Dock('Signal')
        dock_signal.addWidget(viewer1D_widget)
        dock_signal.addWidget(viewer2D_widget)

        ##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        ##% Navigator viewer Dock
        navigator1D_widget = QtWidgets.QWidget()
        self.ui.navigator1D = Viewer1D(navigator1D_widget)
        self.ui.navigator1D.ui.crosshair.crosshair_dragged.connect(self.update_viewer_data)
        self.ui.navigator1D.ui.crosshair_pb.click()
        self.ui.navigator1D.data_to_export_signal.connect(self.export_data)
        navigator2D_widget = QtWidgets.QWidget()
        self.ui.navigator2D = Viewer2D(navigator2D_widget)
        self.ui.navigator2D.ui.auto_levels_pb.click()
        self.ui.navigator2D.crosshair_dragged.connect(
            self.update_viewer_data)  # export scaled position in conjonction with 2D scaled axes
        self.ui.navigator2D.ui.crosshair_pb.click()
        self.ui.navigator2D.data_to_export_signal.connect(self.export_data)

        self.ui.navigation_widget = QtWidgets.QWidget()
        # vlayout_navigation = QtWidgets.QVBoxLayout()
        # self.navigator_label = QtWidgets.QLabel('Navigation View')
        # self.navigator_label.setMaximumHeight(15)
        #layout_navigation.addWidget(self.navigator_label)
        self.ui.nav_axes_widget = QtWidgets.QWidget()
        self.ui.nav_axes_widget.setLayout(QtWidgets.QVBoxLayout())
        #vlayout_navigation.addWidget(navigator2D_widget)
        #vlayout_navigation.addWidget(self.ui.nav_axes_widget)
        self.ui.nav_axes_widget.setVisible(False)
        #vlayout_navigation.addWidget(navigator1D_widget)
        #self.ui.navigation_widget.setLayout(vlayout_navigation)
        #vsplitter.insertWidget(0, self.ui.navigation_widget)

        dock_navigation = Dock('Navigation')
        dock_navigation.addWidget(navigator1D_widget)
        dock_navigation.addWidget(navigator2D_widget)

        self.area.addDock(dock_navigation)
        self.area.addDock(dock_signal, 'right', dock_navigation)

        # self.ui.signal_widget = QtWidgets.QWidget()
        # VLayout1 = QtWidgets.QVBoxLayout()
        # self.viewer_label = QtWidgets.QLabel('Data View')
        # self.viewer_label.setMaximumHeight(15)
        # VLayout1.addWidget(self.viewer_label)
        # VLayout1.addWidget(viewer1D_widget)
        # VLayout1.addWidget(viewer2D_widget)
        # self.ui.signal_widget.setLayout(VLayout1)
        #vsplitter.insertWidget(1, self.ui.signal_widget)

        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/icons/Icon_Library/cartesian.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.ui.set_signals_pb_1D = QtWidgets.QPushButton('')
        self.ui.set_signals_pb_1D.setToolTip('Change navigation/signal axes')
        self.ui.set_signals_pb_1D_bis = QtWidgets.QPushButton('')
        self.ui.set_signals_pb_1D_bis.setToolTip('Change navigation/signal axes')
        self.ui.set_signals_pb_1D.setIcon(icon)
        self.ui.set_signals_pb_1D_bis.setIcon(icon)
        self.ui.set_signals_pb_2D = QtWidgets.QPushButton('')
        self.ui.set_signals_pb_2D.setToolTip('Change navigation/signal axes')
        self.ui.set_signals_pb_2D.setIcon(icon)
        self.ui.set_signals_pb_2D_bis = QtWidgets.QPushButton('')
        self.ui.set_signals_pb_2D_bis.setToolTip('Change navigation/signal axes')
        self.ui.set_signals_pb_2D_bis.setIcon(icon)

        self.ui.navigator1D.ui.button_widget.layout().insertWidget(0, self.ui.set_signals_pb_1D)
        self.ui.navigator2D.ui.buttons_layout.insertWidget(0, self.ui.set_signals_pb_2D)
        self.ui.viewer1D.ui.button_widget.layout().insertWidget(0, self.ui.set_signals_pb_1D_bis)
        self.ui.viewer2D.ui.buttons_layout.insertWidget(0, self.ui.set_signals_pb_2D_bis)

        #main_layout.addWidget(vsplitter)

        self.ui.set_signals_pb_1D.clicked.connect(self.signal_axes_selection)
        self.ui.set_signals_pb_2D.clicked.connect(self.signal_axes_selection)
        self.ui.set_signals_pb_1D_bis.clicked.connect(self.signal_axes_selection)
        self.ui.set_signals_pb_2D_bis.clicked.connect(self.signal_axes_selection)

        #to start: display as default a 2D navigator and a 1D viewer
        self.ui.navigator1D.parent.setVisible(False)
        self.ui.viewer2D.parent.setVisible(True)
Example #11
0
    def visualize(self, canvas):  # TODO: callables?
        from pyqtgraph import LinearRegionItem

        self.canvas = canvas
        self.canvas.addItem(LinearRegionItem(*self.range.value, **self.kwargs))
Example #12
0
 def __init_roi__(self):
     self._roi = LinearRegionItem()
     self._roi.hide()
     self._roi.setBrush(QColor(255, 255, 255, 50))
     self.parent.image_view.plot_item.addItem(self.roi)
 def __init__(self, image=None, fillHistogram=True, rgbHistogram=False, levelMode='mono'):
     GraphicsWidget.__init__(self)
     self.overlay = False
     self.lut = None
     self.imageItem = lambda: None  # fake a dead weakref
     self.levelMode = levelMode
     self.rgbHistogram = rgbHistogram
     
     self.layout = QtGui.QGraphicsGridLayout()
     self.setLayout(self.layout)
     self.layout.setContentsMargins(1,1,1,1)
     self.layout.setSpacing(0)
     self.vb = ViewBox(parent=self)
     self.vb.setMaximumWidth(152)
     self.vb.setMinimumWidth(45)
     self.vb.setMouseEnabled(x=False, y=True)
     self.gradient = GradientEditorItem()
     self.gradient.setOrientation('right')
     self.gradient.loadPreset('grey')
     self.regions = [
         LinearRegionItem([0, 1], 'horizontal', swapMode='block'),
         LinearRegionItem([0, 1], 'horizontal', swapMode='block', pen='r',
                          brush=fn.mkBrush((255, 50, 50, 50)), span=(0., 1/3.)),
         LinearRegionItem([0, 1], 'horizontal', swapMode='block', pen='g',
                          brush=fn.mkBrush((50, 255, 50, 50)), span=(1/3., 2/3.)),
         LinearRegionItem([0, 1], 'horizontal', swapMode='block', pen='b',
                          brush=fn.mkBrush((50, 50, 255, 80)), span=(2/3., 1.)),
         LinearRegionItem([0, 1], 'horizontal', swapMode='block', pen='w',
                          brush=fn.mkBrush((255, 255, 255, 50)), span=(2/3., 1.))]
     for region in self.regions:
         region.setZValue(1000)
         self.vb.addItem(region)
         region.lines[0].addMarker('<|', 0.5)
         region.lines[1].addMarker('|>', 0.5)
         region.sigRegionChanged.connect(self.regionChanging)
         region.sigRegionChangeFinished.connect(self.regionChanged)
         
     self.region = self.regions[0]  # for backward compatibility.
     
     self.axis = AxisItem('left', linkView=self.vb, maxTickLength=-10, parent=self)
     self.layout.addItem(self.axis, 0, 0)
     self.layout.addItem(self.vb, 0, 1)
     self.layout.addItem(self.gradient, 0, 2)
     self.range = None
     self.gradient.setFlag(self.gradient.ItemStacksBehindParent)
     self.vb.setFlag(self.gradient.ItemStacksBehindParent)
     
     self.gradient.sigGradientChanged.connect(self.gradientChanged)
     self.vb.sigRangeChanged.connect(self.viewRangeChanged)
     add = QtGui.QPainter.CompositionMode_Plus
     self.plots = [
         PlotCurveItem(pen=(200, 200, 200, 100)),  # mono
         PlotCurveItem(pen=(255, 0, 0, 100), compositionMode=add),  # r
         PlotCurveItem(pen=(0, 255, 0, 100), compositionMode=add),  # g
         PlotCurveItem(pen=(0, 0, 255, 100), compositionMode=add),  # b
         PlotCurveItem(pen=(200, 200, 200, 100), compositionMode=add),  # a
         ]
     
     self.plot = self.plots[0]  # for backward compatibility.
     for plot in self.plots:
         plot.rotate(90)
         self.vb.addItem(plot)
     
     self.fillHistogram(fillHistogram)
     self._showRegions()
         
     self.vb.addItem(self.plot)
     self.autoHistogramRange()
     
     if image is not None:
         self.setImageItem(image)