예제 #1
0
    def set_image(self, image, row, col, cmap=None, vmin=None, vmax=None):
        """
        Sets the data for a single window.

        Parameters
        ----------
        image : ndarray, ndim=2
            The shape should be the same as the `shape` specified when
            constructing the image grid.
        row, col : int
            The zero-index of the row and column to set.
        cmap : cmap (from matplotlib.pylab.cm)
            The color palette to use. Default is grayscale.
        vmin, vmax : numerical or None
            Defines the range of the color palette. None, which is default,
            takes the range of the data.
        """
        import matplotlib as mpl
        import matplotlib.pylab as plt
        from amitgroup.plot.resample import resample_and_arrange_image

        if cmap is None:
            cmap = plt.cm.gray
        if vmin is None:
            vmin = image.min()
        if vmax is None:
            vmax = image.max()

        if vmin == vmax:
            diff = 1
        else:
            diff = vmax - vmin

        image_indices = np.clip((image - vmin) / diff, 0, 1) * 255
        image_indices = image_indices.astype(np.uint8)

        lut = mpl.colors.makeMappingArray(256, cmap)
        rgb = resample_and_arrange_image(image_indices, self._shape, lut)

        x0 = row * (self._shape[0] + self._border)
        x1 = (row + 1) * (self._shape[0] + self._border) + self._border
        y0 = col * (self._shape[1] + self._border)
        y1 = (col + 1) * (self._shape[1] + self._border) + self._border

        self._data[x0:x1, y0:y1] = self._border_color

        anchor = (self._border + row * (self._shape[0] + self._border),
                  self._border + col * (self._shape[1] + self._border))

        self._data[anchor[0]:anchor[0] + rgb.shape[0],
                   anchor[1]:anchor[1] + rgb.shape[1]] = rgb
예제 #2
0
    def set_image(self, image, row, col, cmap=None, vmin=None, vmax=None):
        """
        Sets the data for a single window.

        Parameters
        ----------
        image : ndarray, ndim=2
            The shape should be the same as the `shape` specified when
            constructing the image grid.
        row, col : int
            The zero-index of the row and column to set.
        cmap : cmap (from matplotlib.pylab.cm)
            The color palette to use. Default is grayscale.
        vmin, vmax : numerical or None
            Defines the range of the color palette. None, which is default,
            takes the range of the data.
        """
        import matplotlib as mpl
        import matplotlib.pylab as plt
        from amitgroup.plot.resample import resample_and_arrange_image

        if cmap is None:
            cmap = plt.cm.gray
        if vmin is None:
            vmin = image.min()
        if vmax is None:
            vmax = image.max()

        if vmin == vmax:
            diff = 1
        else:
            diff = vmax - vmin

        image_indices = np.clip((image - vmin) / diff, 0, 1) * 255
        image_indices = image_indices.astype(np.uint8)

        lut = mpl.colors.makeMappingArray(256, cmap)
        rgb = resample_and_arrange_image(image_indices, self._shape, lut)

        x0 = row * (self._shape[0] + self._border)
        x1 = (row + 1) * (self._shape[0] + self._border) + self._border
        y0 = col * (self._shape[1] + self._border)
        y1 = (col + 1) * (self._shape[1] + self._border) + self._border

        self._data[x0:x1, y0:y1] = self._border_color

        anchor = (self._border + row * (self._shape[0] + self._border),
                  self._border + col * (self._shape[1] + self._border))

        self._data[anchor[0]:anchor[0] + rgb.shape[0],
                   anchor[1]:anchor[1] + rgb.shape[1]] = rgb
예제 #3
0
    def set_image(self, image, row, col, cmap=None, vmin=None, vmax=None,
                  vsym=False):
        """
        Sets the data for a single window.

        Parameters
        ----------
        image : ndarray, ndim=2
            The shape should be the same as the `shape` specified when
            constructing the image grid.
        row, col : int
            The zero-index of the row and column to set.
        cmap : cmap (from matplotlib.pylab.cm)
            The color palette to use. Default is grayscale.
        vmin, vmax : numerical or None
            Defines the range of the color palette. None, which is default,
            takes the range of the data.
        vsym : bool
            If True, this means that the color palette will always be centered
            around 0. Even if you have specified both `vmin` and `vmax`, this
            will override that and extend the shorter one. Good practice is to
            specify neither `vmin` or `vmax` or only `vmax` together with this
            option.
        """
        import matplotlib as mpl
        from matplotlib.pylab import cm
        from amitgroup.plot.resample import resample_and_arrange_image

        if cmap is None:
            cmap = cm.gray
        if vmin is None:
            vmin = np.nanmin(image)
        if vmax is None:
            vmax = np.nanmax(image)

        if vsym and -vmin != vmax:
            mx = max(abs(vmin), abs(vmax))
            vmin = -mx
            vmax = mx

        if vmin == vmax:
            diff = 1
        else:
            diff = vmax - vmin

        image_indices = np.clip((image - vmin) / diff, 0, 1) * 255
        image_indices = image_indices.astype(np.uint8)

        nan_mask = np.isnan(image).astype(np.uint8)

        lut = mpl.colors.makeMappingArray(256, cmap)
        rgb = resample_and_arrange_image(image_indices, nan_mask, self._shape,
                                         lut)

        x0 = row * (self._shape[0] + self._border)
        x1 = (row + 1) * (self._shape[0] + self._border) + self._border
        y0 = col * (self._shape[1] + self._border)
        y1 = (col + 1) * (self._shape[1] + self._border) + self._border

        self._data[x0:x1, y0:y1] = self._border_color

        anchor = (self._border + row * (self._shape[0] + self._border),
                  self._border + col * (self._shape[1] + self._border))

        selection = [slice(anchor[0], anchor[0] + rgb.shape[0]),
                     slice(anchor[1], anchor[1] + rgb.shape[1])]

        nan_data = np.isnan(rgb)
        rgb[nan_data] = 0.0

        self._data[selection] = (rgb * ~nan_data +
                                 self._border_color * nan_data)