예제 #1
0
 def setup_overlay(self):
     color = np.array([[0, 0, 0, 0], self.color], dtype=np.ubyte)
     color_map = ColorMap([0, 1], color)
     self.overlay.setVisible(False)
     lut = color_map.getLookupTable(0, 1, 2)
     self.overlay.setLookupTable(lut)
     self.overlay.setZValue(11)
예제 #2
0
 def setColorMap(self, map=None):
   if not map:
     if not self._cm_colors.any():
       return
     pos = np.linspace(self.cm_min/float(self.data_max_int), self.cm_max/float(self.data_max_int), num=len(self._cm_colors))
     map = ColorMap(pos, self._cm_colors)
   self.getView().setBackgroundColor(map.map(0))
   lut = map.getLookupTable(0.0,1.0,self.data_max_int, alpha=False)
   self.getImageItem().setLookupTable(lut)
   self.getImageItem().setLevels([self.cm_min/float(self.data_max_int),float(self.data_max_int)])
예제 #3
0
 def add_difference_overlay(self, diff):
     diff = -diff
     diff[diff > 0.0] = 1.0
     pos = np.array([0, 1])
     color = np.array([[0, 0, 0, 0], [255, 0, 0, 255]], dtype=np.ubyte)
     map = ColorMap(pos, color)
     self.image_after_overlay.setOpacity(1)
     self.image_after_overlay.setImage(diff)
     lut = map.getLookupTable(0, 1, 2)
     self.image_after_overlay.setLookupTable(lut)
 def add_difference_overlay(self, diff, nan_change):
     diff = np.absolute(diff)
     diff[diff > OVERLAY_THRESHOLD] = 1.0
     diff[nan_change] = 1.0
     pos = np.array([0, 1])
     color = np.array([[0, 0, 0, 0], OVERLAY_COLOUR_DIFFERENCE],
                      dtype=np.ubyte)
     map = ColorMap(pos, color)
     self.image_diff_overlay.setVisible(True)
     self.image_diff_overlay.setImage(diff)
     lut = map.getLookupTable(0, 1, 2)
     self.image_diff_overlay.setLookupTable(lut)
예제 #5
0
 def setColorMap(self, map=None):
     if not map:
         if not self._cm_colors.any():
             return
         pos = np.linspace(0.0, 1.0,
                           num=len(self._cm_colors))  # take default values
         map = ColorMap(pos, self._cm_colors)
     self.getView().setBackgroundColor(map.map(0))
     lut = map.getLookupTable(0.0, 1.0, self.data_max_int, alpha=False)
     self.getImageItem().setLookupTable(lut)
     self.getImageItem().setLevels([
         self.cm_min, float(self.data_max_int)
     ])  # set levels from min to max of image (may improve min here)
예제 #6
0
파일: bp2d_widget.py 프로젝트: evreyuga/rpv
 def __init__(self):
     super(Bp2DWidget, self).__init__()
     # M.B. plot add to params
     self.setXRange(-60, 60)
     self.setYRange(-60, 60)
     self.img = ImageItem()
     self.addItem(self.img)
     _translate = QCoreApplication.translate
     self.setLabels(title=_translate("Bp2DWidget", "Beam pattern"),
                    left=_translate("Bp2DWidget", "Elevation, °"),
                    bottom=_translate("Bp2DWidget", "Azimuth, °"))
     self.setLogMode()
     colormap = ColorMap(*zip(*Gradients["bipolar"]["ticks"]))
     self.img.setLookupTable(colormap.getLookupTable())
예제 #7
0
    def setColorMap(self, cmap=None):
        """
        Update the image colormap.

        Parameters
        ----------
        cmap : ColorMap
        """
        if not cmap:
            if not self._cm_colors.any():
                return
            # Take default values
            pos = np.linspace(0.0, 1.0, num=len(self._cm_colors))
            cmap = ColorMap(pos, self._cm_colors)
        self.getView().setBackgroundColor(cmap.map(0))
        lut = cmap.getLookupTable(0.0, 1.0, alpha=False)
        self.getImageItem().setLookupTable(lut)
예제 #8
0
파일: image.py 프로젝트: slaclab/pydm
    def setColorMap(self, cmap=None):
        """
        Update the image colormap.

        Parameters
        ----------
        cmap : ColorMap
        """
        if not cmap:
            if not self._cm_colors.any():
                return
            # Take default values
            pos = np.linspace(0.0, 1.0, num=len(self._cm_colors))
            cmap = ColorMap(pos, self._cm_colors)
        self.getView().setBackgroundColor(cmap.map(0))
        lut = cmap.getLookupTable(0.0, 1.0, alpha=False)
        self.getImageItem().setLookupTable(lut)
예제 #9
0
    def setColorMap(self, cmap=None):
        """
        Update the image colormap

        Parameters
        ----------
        cmap : ColorMap
        """
        if self.data_max_int is None:
            return
        if not cmap:
            if not self._cm_colors.any():
                return
            pos = np.linspace(0.0, 1.0,
                              num=len(self._cm_colors))  # take default values
            cmap = ColorMap(pos, self._cm_colors)
        self.getView().setBackgroundColor(cmap.map(0))
        lut = cmap.getLookupTable(0.0, 1.0, self.data_max_int, alpha=False)
        self.getImageItem().setLookupTable(lut)
        self.getImageItem().setLevels([
            self.cm_min,
            float(min(self.cm_max, self.data_max_int))
        ])  # set levels from min to max of image (may improve min here)
예제 #10
0
    def add_image(
        self,
        array: np.ndarray,
        plot_pos: int,
        labels: dict,
        normalize: bool = True,
        invert_y: bool = True,
        cmap_style: str = "diverging",
        **kwargs: t.Optional[dict],
    ) -> PlotItem:
        remote_plot = self.get_remote_plots()[plot_pos]
        remote_plot_item = remote_plot._view.centralWidget  # noqa

        remote_plot_item.clear()

        if "levels" in kwargs.keys():
            levels = kwargs.pop("levels")
            auto_levels = False
        else:
            levels = None
            auto_levels = True

        if normalize:
            array = self.normalize_array(array)

        if cmap_style == "diagnostic":
            colormap = ColorMap(pos=np.linspace(
                -1, 1, len(SANITY_PLOT_COLORS[cmap_style])),
                                color=np.array(SANITY_PLOT_COLORS[cmap_style]))

            lut = colormap.getLookupTable(
                start=-1,
                stop=1,
                nPts=1024,
            )

        elif cmap_style == "dissimilarity":
            colormap = ColorMap(pos=np.linspace(
                0, 1, len(SANITY_PLOT_COLORS[cmap_style])),
                                color=np.array(SANITY_PLOT_COLORS[cmap_style]))

            lut = colormap.getLookupTable(
                start=1,
                stop=0,
                nPts=1024,
            )
        else:
            raise ValueError("Invalid colormap style requested.")

        if auto_levels:
            image_item = remote_plot.pg.ImageItem(image=array, lut=lut)
        else:
            image_item = remote_plot.pg.ImageItem(image=array,
                                                  lut=lut,
                                                  autoLevels=auto_levels,
                                                  levels=levels)

        if not auto_levels:
            image_item.setLevels(levels)

        remote_plot_item.addItem(image_item, **kwargs)

        self._set_labels_on_plot(remote_plot_item, labels)
        remote_plot_item.hideAxis('top')
        remote_plot_item.hideAxis('right')

        remote_plot_item.invertY(invert_y)

        return remote_plot_item
예제 #11
0
    def setData(self, *args):
        """
        Set the data to be drawn.

        Parameters
        ----------
        x, y : np.ndarray, optional, default None
            2D array containing the coordinates of the polygons
        z : np.ndarray
            2D array containing the value which will be maped into the polygons
            colors.
            If x and y is None, the polygons will be displaced on a grid
            otherwise x and y will be used as polygons vertices coordinates as::

                (x[i+1, j], y[i+1, j])           (x[i+1, j+1], y[i+1, j+1])
                                    +---------+
                                    | z[i, j] |
                                    +---------+
                    (x[i, j], y[i, j])           (x[i, j+1], y[i, j+1])

            "ASCII from: <https://matplotlib.org/3.2.1/api/_as_gen/
                         matplotlib.pyplot.pcolormesh.html>".
        """

        # Prepare data
        cd = self._prepareData(args)

        # Has the view bounds changed
        shapeChanged = False
        if self.qpicture is None:
            shapeChanged = True
        elif len(args) == 1:
            if args[0].shape[0] != self.x[:, 1][-1] or args[0].shape[
                    1] != self.y[0][-1]:
                shapeChanged = True
        elif len(args) == 3:
            if np.any(self.x != args[0]) or np.any(self.y != args[1]):
                shapeChanged = True

        self.qpicture = QtGui.QPicture()
        p = QtGui.QPainter(self.qpicture)
        # We set the pen of all polygons once
        if self.edgecolors is None:
            p.setPen(fn.mkPen(QtGui.QColor(0, 0, 0, 0)))
        else:
            p.setPen(fn.mkPen(self.edgecolors))
            if self.antialiasing:
                p.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing)

        ## Prepare colormap
        # First we get the LookupTable
        pos = [i[0] for i in Gradients[self.cmap]['ticks']]
        color = [i[1] for i in Gradients[self.cmap]['ticks']]
        cmap = ColorMap(pos, color)
        lut = cmap.getLookupTable(0.0, 1.0, 256)
        # Second we associate each z value, that we normalize, to the lut

        vmin, vmax = self.z.min(), self.z.max()
        if self.levels is not None:
            vmin, vmax = self.levels
            vmin = max(vmin, self.z.min())
            vmax = min(vmax, self.z.max())

        norm = self.z - vmin
        norm_max = vmax - vmin
        norm = norm / norm_max
        norm = (norm * (len(lut) - 1)).astype(int)
        norm[norm < 0] = 0
        norm[norm > 255] = 255

        # Go through all the data and draw the polygons accordingly
        for xi in range(self.z.shape[0]):
            for yi in range(self.z.shape[1]):
                # Set the color of the polygon first
                c = lut[norm[xi][yi]]
                p.setBrush(fn.mkBrush(QtGui.QColor(c[0], c[1], c[2])))

                polygon = QtGui.QPolygonF([
                    QtCore.QPointF(self.x[xi][yi], self.y[xi][yi]),
                    QtCore.QPointF(self.x[xi + 1][yi], self.y[xi + 1][yi]),
                    QtCore.QPointF(self.x[xi + 1][yi + 1],
                                   self.y[xi + 1][yi + 1]),
                    QtCore.QPointF(self.x[xi][yi + 1], self.y[xi][yi + 1])
                ])

                # DrawConvexPlygon is faster
                p.drawConvexPolygon(polygon)

        p.end()
        self.update()

        self.prepareGeometryChange()
        if shapeChanged:
            self.informViewBoundsChanged()