Exemple #1
0
    def __init__(self, data, radius=15):

        self.data = data

        # Add circular node
        self.node = QGraphicsEllipseItem(0, 0, 1, 1)

        # Set radius
        self.radius = radius

        # Add text label
        self.label = QGraphicsTextItem(data.label)
        font = self.label.font()
        font.setPointSize(10)
        self.label.setFont(font)

        # Add line between label and node
        self.line1 = QGraphicsLineItem(0, 0, 1, 1)
        self.line2 = QGraphicsLineItem(0, 0, 1, 1)

        self.node.setZValue(20)
        self.label.setZValue(10)
        self.line1.setZValue(10)
        self.line2.setZValue(10)

        self.line1.setPen(get_pen('0.5'))
        self.line2.setPen(get_pen('0.5'))

        self.color = '0.8'
Exemple #2
0
    def addPoint(self, text, color, border=None, size=20.0):
        shape = QGraphicsEllipseItem(size / 2.0, size / 2.0, size, size)
        brush = makeBrush(color)
        shape.setBrush(brush)
        shape.setPen(makePen(border))

        self.addEntry(MapLegendEntryItem(shape, text))
    def drawRGBACrosshair(self):
        """
        rgba_topline_item
        rgba_botline_item
        rgba_leftline_item
        rgba_rightline_item:
        rgba_crosshair_item_circle: center portion of crosshair

        """
        # vertical line
        self.rgba_topline_item = DualColoredLineSegment()
        self.rgba_topline_item.setLine(0, 0, 0, self.height())
        self.rgba_botline_item = DualColoredLineSegment()
        self.rgba_botline_item.setLine(0, 0, 0, self.height())

        # horizontal line
        self.rgba_leftline_item = DualColoredLineSegment()
        self.rgba_leftline_item.setLine(0, 0, self.width(), 0)
        self.rgba_rightline_item = DualColoredLineSegment()
        self.rgba_rightline_item.setLine(0, 0, self.width(), 0)

        # crosshair circle
        self.rgba_crosshair_item_circle = QGraphicsEllipseItem()

        self.rgba_crosshair_item_circle.setRect(
            -(self.CROSSHAIR_RADIUS * 0.5),
            -(self.CROSSHAIR_RADIUS * 0.5),
            self.CROSSHAIR_RADIUS,
            self.CROSSHAIR_RADIUS
        )

        # add items
        self.rgba_crosshair_item = QGraphicsItemGroup()

        self.rgba_crosshair_item.addToGroup(self.rgba_crosshair_item_circle)
        self.rgba_crosshair_item.addToGroup(self.rgba_topline_item)
        self.rgba_crosshair_item.addToGroup(self.rgba_botline_item)
        self.rgba_crosshair_item.addToGroup(self.rgba_leftline_item)
        self.rgba_crosshair_item.addToGroup(self.rgba_rightline_item)

        self.addItem(self.rgba_crosshair_item)
Exemple #4
0
    def updateTime(self, frame):
        if frame == self.previousframe:
            return
        self.previousframe = frame
        idx = self.currentPuff.currentIndex()
        currentPuff = self.group.puffs[idx]

        image1 = np.copy(self.I[frame])
        mmax = np.max(self.I)
        image1 = image1 / mmax
        image2 = np.copy(self.I_fits[idx][frame])
        image2 = image2 / mmax
        self.puff_3D.update_images(image1, image2)

        rel_frame = frame - (currentPuff.kinetics['t_start'] -
                             currentPuff.kinetics['before'])
        for line in [self.vLine1, self.vLine2,
                     self.vLine5]:  # self.vLine3,self.vLine4,self.vLine5]:
            line.setValue(rel_frame)
        for bar in self.error_bars:
            bar.plot.removeItem(bar)
        self.error_bars = []
        for item in self.addedItems:
            self.imageview.view.removeItem(item)
        self.addedItems = []

        scatter = pg.ScatterPlotItem(size=8, pen=pg.mkPen(None))
        self.imageview.view.addItem(scatter)
        self.addedItems.append(scatter)
        spots = []
        for i in np.arange(len(self.group.puffs)):
            rel_frame2 = frame - ((currentPuff.kinetics['t_start'] -
                                   currentPuff.kinetics['before']) -
                                  (self.group.puffs[i].kinetics['t_start'] -
                                   self.group.puffs[i].kinetics['before']))
            if self.puffCheckBoxes[i].isChecked(
            ) and rel_frame2 >= 0 and rel_frame2 < self.params[i].shape[0]:
                centers = self.params[i][:, :2] - self.bounds[1:, 0]
                center = centers[rel_frame2, :]
                amps = np.copy(self.params[i][:, -1])
                amps[amps <= 0] = .00000001
                amp = amps[rel_frame2]
                std = self.group.puffs[0].clusters.standard_deviations[i]
                color = np.array(self.colors[i])
                color[3] = 50
                ### FIRST ADD THE POINT TO THE SCATTER PLOT
                if 0.8 / amp < std:  # if the amplitude>0 and the error (0.8/SNR) is within the fitting bounds
                    ### FIRST PLOT THE
                    """ WARNING!!! the amp should really be the signal to noise ratio, so it is only valid when the image has been ratiod by the standard deviation of the noise """
                    sigma = 0.8 / amp
                    sigmas = 0.8 / amps
                    # add error bars to x and y
                    # first add X
                    color[3] = 255
                    err = pg.ErrorBarItem(
                        x=np.array([rel_frame]),
                        y=np.array([self.params[i][rel_frame2, 0]]),
                        top=np.array([sigma]),
                        bottom=np.array([sigma]),
                        beam=0.5,
                        pen=pg.mkPen(pg.mkColor(tuple(color))))
                    self.p3.addItem(err)
                    err.plot = self.p3
                    self.error_bars.append(err)
                    # second add Y
                    err = pg.ErrorBarItem(
                        x=np.array([rel_frame]),
                        y=np.array([self.params[i][rel_frame2, 1]]),
                        top=np.array([sigma]),
                        bottom=np.array([sigma]),
                        beam=0.5,
                        pen=pg.mkPen(pg.mkColor(tuple(color))))
                    self.p4.addItem(err)
                    err.plot = self.p4
                    self.error_bars.append(err)

                    reasonable_fit = sigmas < 2 * std
                    bounds = QRectF(
                        QPointF(center[0] - sigma, center[1] - sigma),
                        QSizeF(2 * sigma, 2 * sigma))

                    ### plot outer circle
                    pathitem = QGraphicsEllipseItem(bounds)
                    color[-1] = 127  # alpha channel
                    pathitem.setPen(pg.mkPen(pg.mkColor(tuple(color))))
                    pathitem.setBrush(pg.mkColor((0, 0, 0, 0)))
                    self.imageview.view.addItem(pathitem)
                    self.addedItems.append(pathitem)

                    ### plot line
                    frame_i = rel_frame2 - 6
                    if frame_i < 0:
                        frame_i = 0
                    alpha = 255
                    for ii in np.arange(rel_frame2, frame_i, -1) - 1:
                        if alpha <= 0 or not reasonable_fit[ii]:
                            break
                        color[-1] = alpha  # alpha channel
                        alpha = alpha - (255 * 1. / 6.)
                        pathitem = QGraphicsPathItem()
                        pathitem.setPen(pg.mkColor(tuple(color)))
                        path = QPainterPath(QPointF(*centers[ii]))
                        path.lineTo(QPointF(*centers[ii + 1]))
                        pathitem.setPath(path)
                        self.imageview.view.addItem(pathitem)
                        self.addedItems.append(pathitem)
                    color[3] = 255  # make the spot transparent
                spots.append({
                    'pos': center,
                    'brush': pg.mkBrush(pg.mkColor(tuple(color)))
                })
        scatter.addPoints(spots)