Ejemplo n.º 1
0
    def xyimage(self, x, y, data, title=None, alpha_mask=None, alpha=None,
                background_color=None, colormap=None,
                interpolation='linear', eliminate_outliers=None,
                xformat='%.1f', yformat='%.1f', zformat='%.1f'):
        """
        Make an xyimage `plot item` (image with non-linear X/Y axes) from data
        (:py:class:`guiqwt.image.XYImageItem` object)

            * x: 1D NumPy array (or tuple, list: will be converted to array)
            * y: 1D NumPy array (or tuple, list: will be converted to array
            * data: 2D NumPy array (image pixel data)
            * title: image title (optional)
            * interpolation: 'nearest', 'linear' (default), 'antialiasing' (5x5)
        """
        param = XYImageParam(title=_("Image"), icon='image.png')
        self.__set_image_param(param, title, alpha_mask, alpha, interpolation,
                               background=background_color, colormap=colormap,
                               xformat=xformat, yformat=yformat,
                               zformat=zformat)
        if isinstance(x, (list, tuple)):
            x = array(x)
        if isinstance(y, (list, tuple)):
            y = array(y)
        image = XYImageItem(x, y, data, param)
        if eliminate_outliers is not None:
            image.set_lut_range(lut_range_threshold(image, 256,
                                                    eliminate_outliers))
        return image
Ejemplo n.º 2
0
Archivo: base.py Proyecto: mindw/guiqwt
    def set_item(self, item):
        """Set associated item -- must be a TrImageItem object"""
        assert isinstance(item, TrImageItem)
        self.item = item
        self.item_original_state = (item.can_select(),
                                    item.can_move(),
                                    item.can_resize(),
                                    item.can_rotate())
        self.item_original_crop = item.get_crop()
        self.item_original_transform = item.get_transform()

        self.item.set_selectable(True)
        self.item.set_movable(True)
        self.item.set_resizable(False)
        self.item.set_rotatable(True)
        
        item.set_lut_range(lut_range_threshold(item, 256, 2.))
        item.set_interpolation(INTERP_LINEAR)
        plot = self.get_plot()
        plot.add_item(self.item)
        
        # Setting the item as active item (even if the cropping rectangle item
        # will also be set as active item just below), for the image tools to
        # register this item (contrast, ...):
        plot.set_active_item(self.item)
        self.item.unselect()
Ejemplo n.º 3
0
    def trimage(self, data=None, filename=None, title=None, alpha_mask=None,
                alpha=None, background_color=None, colormap=None,
                x0=0.0, y0=0.0, angle=0.0, dx=1.0, dy=1.0,
                interpolation='linear', eliminate_outliers=None,
                xformat='%.1f', yformat='%.1f', zformat='%.1f'):
        """
        Make a transformable image `plot item` (image with an arbitrary 
        affine transform)
        (:py:class:`guiqwt.image.TrImageItem` object)

            * data: 2D NumPy array (image pixel data)
            * filename: image filename (if data is not specified)
            * title: image title (optional)
            * x0, y0: position
            * angle: angle (radians)
            * dx, dy: pixel size along X and Y axes
            * interpolation: 'nearest', 'linear' (default), 'antialiasing' (5x5)
        """
        param = TrImageParam(title=_("Image"), icon='image.png')
        data, filename, title = self._get_image_data(data, filename, title,
                                                     to_grayscale=True)
        self.__set_image_param(param, title, alpha_mask, alpha, interpolation,
                               background=background_color, colormap=colormap,
                               x0=x0, y0=y0, angle=angle, dx=dx, dy=dy,
                               xformat=xformat, yformat=yformat,
                               zformat=zformat)
        image = TrImageItem(data, param)
        image.set_filename(filename)
        if eliminate_outliers is not None:
            image.set_lut_range(lut_range_threshold(image, 256,
                                                    eliminate_outliers))
        return image
Ejemplo n.º 4
0
 def maskedimage(
     self,
     data=None,
     mask=None,
     filename=None,
     title=None,
     alpha_mask=False,
     alpha=1.0,
     xdata=[None, None],
     ydata=[None, None],
     pixel_size=None,
     center_on=None,
     background_color=None,
     colormap=None,
     show_mask=False,
     fill_value=None,
     interpolation="linear",
     eliminate_outliers=None,
     xformat="%.1f",
     yformat="%.1f",
     zformat="%.1f",
 ):
     """
     Make a masked image `plot item` from data
     (:py:class:`guiqwt.image.MaskedImageItem` object)
     """
     assert isinstance(xdata, (tuple, list)) and len(xdata) == 2
     assert isinstance(ydata, (tuple, list)) and len(ydata) == 2
     param = MaskedImageParam(title=_("Image"), icon="image.png")
     data, filename, title = self._get_image_data(data, filename, title, to_grayscale=True)
     assert data.ndim == 2, "Data must have 2 dimensions"
     if pixel_size is None:
         assert center_on is None, "Ambiguous parameters: both `center_on`" " and `xdata`/`ydata` were specified"
         xmin, xmax = xdata
         ymin, ymax = ydata
     else:
         xmin, xmax, ymin, ymax = self.compute_bounds(data, pixel_size, center_on)
     self.__set_image_param(
         param,
         title,
         alpha_mask,
         alpha,
         interpolation,
         background=background_color,
         colormap=colormap,
         xmin=xmin,
         xmax=xmax,
         ymin=ymin,
         ymax=ymax,
         show_mask=show_mask,
         fill_value=fill_value,
         xformat=xformat,
         yformat=yformat,
         zformat=zformat,
     )
     image = MaskedImageItem(data, mask, param)
     image.set_filename(filename)
     if eliminate_outliers is not None:
         image.set_lut_range(lut_range_threshold(image, 256, eliminate_outliers))
     return image
Ejemplo n.º 5
0
    def xyimage(self, taurusmodel=None, **kwargs):

        if taurusmodel is None:
            return guiqwt.builder.PlotItemBuilder.xyimage(self, **kwargs)

        title = kwargs.get('title', taurusmodel)
        data = kwargs.get('data', None)
        alpha_mask = kwargs.get('alpha_mask', None)
        alpha = kwargs.get('alpha', None)
        background_color = kwargs.get('background_color', None)
        colormap = kwargs.get('colormap', None)
        interpolation = kwargs.get('interpolation', 'linear')
        eliminate_outliers = kwargs.get('eliminate_outliers', None)
        xformat = kwargs.get('xformat', '%.1f')
        yformat = kwargs.get('yformat', '%.1f')
        zformat = kwargs.get('zformat', '%.1f')
        if data is None:
            x = y = None
        else:
            x = numpy.arange(data.shape[0])
            y = numpy.arange(data.shape[1])

        data = numpy.ones((251, 251))
        x, y = numpy.arange(251) * 333, numpy.arange(251) * 1000

        param = XYImageParam(title=_("Image"), icon='image.png')
        self.set_image_param(param,
                             title,
                             alpha_mask,
                             alpha,
                             interpolation,
                             background=background_color,
                             colormap=colormap,
                             xformat=xformat,
                             yformat=yformat,
                             zformat=zformat)

        image = TaurusXYImageItem(param)
        image.setModel(taurusmodel)
        if eliminate_outliers is not None:
            image.set_lut_range(
                lut_range_threshold(image, 256, eliminate_outliers))
        return image
Ejemplo n.º 6
0
 def image(self, data=None, filename=None, title=None, alpha_mask=None,
           alpha=None, background_color=None, colormap=None,
           xdata=[None, None], ydata=[None, None],
           pixel_size=None, center_on=None,
           interpolation='linear', eliminate_outliers=None,
           xformat='%.1f', yformat='%.1f', zformat='%.1f'):
     """
     Make an image `plot item` from data
     (:py:class:`guiqwt.image.ImageItem` object or 
     :py:class:`guiqwt.image.RGBImageItem` object if data has 3 dimensions)
     """
     assert isinstance(xdata, (tuple, list)) and len(xdata) == 2
     assert isinstance(ydata, (tuple, list)) and len(ydata) == 2
     param = ImageParam(title=_("Image"), icon='image.png')
     data, filename, title = self._get_image_data(data, filename, title,
                                                  to_grayscale=True)
     if data.ndim == 3:
         return self.rgbimage(data=data, filename=filename, title=title,
                              alpha_mask=alpha_mask, alpha=alpha)
     assert data.ndim == 2, "Data must have 2 dimensions"
     if pixel_size is None:
         assert center_on is None, "Ambiguous parameters: both `center_on`"\
                                   " and `xdata`/`ydata` were specified"
         xmin, xmax = xdata
         ymin, ymax = ydata
     else:
         xmin, xmax, ymin, ymax = self.compute_bounds(data, pixel_size,
                                                      center_on)
     self.__set_image_param(param, title, alpha_mask, alpha, interpolation,
                            background=background_color,
                            colormap=colormap,
                            xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
                            xformat=xformat, yformat=yformat,
                            zformat=zformat)
     image = ImageItem(data, param)
     image.set_filename(filename)
     if eliminate_outliers is not None:
         image.set_lut_range(lut_range_threshold(image, 256,
                                                 eliminate_outliers))
     return image
Ejemplo n.º 7
0
    def xyimage(self, taurusmodel=None, **kwargs):

        if taurusmodel is None:
            return guiqwt.builder.PlotItemBuilder.xyimage(self, **kwargs)

        title = kwargs.get('title', taurusmodel)
        data = kwargs.get('data', None)
        alpha_mask = kwargs.get('alpha_mask', None)
        alpha = kwargs.get('alpha', None)
        background_color = kwargs.get('background_color', None)
        colormap = kwargs.get('colormap', None)
        interpolation = kwargs.get('interpolation', 'linear')
        eliminate_outliers = kwargs.get('eliminate_outliers', None)
        xformat = kwargs.get('xformat', '%.1f')
        yformat = kwargs.get('yformat', '%.1f')
        zformat = kwargs.get('zformat', '%.1f')
        if data is None:
            x = y = None
        else:
            x = numpy.arange(data.shape[0])
            y = numpy.arange(data.shape[1])

        data = numpy.ones((251, 251))
        x, y = numpy.arange(251) * 333, numpy.arange(251) * 1000

        param = XYImageParam(title=_("Image"), icon='image.png')
        self.set_image_param(param, title, alpha_mask, alpha, interpolation,
                             background=background_color, colormap=colormap,
                             xformat=xformat, yformat=yformat,
                             zformat=zformat)

        image = TaurusXYImageItem(param)
        image.setModel(taurusmodel)
        if eliminate_outliers is not None:
            image.set_lut_range(lut_range_threshold(image, 256,
                                                    eliminate_outliers))
        return image
Ejemplo n.º 8
0
    def image(self, taurusmodel=None, **kwargs):
        """
        Extension to meth:`guiqwt.builder.PlotItemBuilder.image` to support passing a
        'taurusmodel' as a keyword argument instead passing 'data' or 'filename'.
        """
        if taurusmodel is None:
            image = guiqwt.builder.PlotItemBuilder.image(self, **kwargs)
        else:
            title = kwargs.get('title', taurusmodel)
            data = kwargs.get('data', None)
            filename = kwargs.get('filename', None)
            alpha_mask = kwargs.get('alpha_mask', None)
            alpha = kwargs.get('alpha', None)
            background_color = kwargs.get('background_color', None)
            colormap = kwargs.get('colormap', None)
            xdata = kwargs.get('xdata', [None, None])
            ydata = kwargs.get('ydata', [None, None])
            pixel_size = kwargs.get('pixel_size', None)
            interpolation = kwargs.get('interpolation', 'linear')
            eliminate_outliers = kwargs.get('eliminate_outliers', None)
            xformat = kwargs.get('xformat', '%.1f')
            yformat = kwargs.get('yformat', '%.1f')
            zformat = kwargs.get('zformat', '%.1f')
            forceRGB = kwargs.get('force_rgb', False)

            assert isinstance(xdata, (tuple, list)) and len(xdata) == 2
            assert isinstance(ydata, (tuple, list)) and len(ydata) == 2
            assert filename is None
            assert data is None

            param = ImageParam(title=_("Image"), icon='image.png')

            from taurus import Attribute
            if pixel_size is None:
                xmin, xmax = xdata
                ymin, ymax = ydata
            else:
                attr = Attribute(taurusmodel)
                valueobj = attr.read()
                data = getattr(valueobj, 'rvalue', numpy.zeros((1, 1)))
                attrdata = data
                if isinstance(data, Quantity):
                    attrdata = data.magnitude
                xmin, xmax, ymin, ymax = self.compute_bounds(attrdata,
                                                             pixel_size)

            self.set_image_param(param, title, alpha_mask, alpha, interpolation,
                                 background=background_color,
                                 colormap=colormap,
                                 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
                                 xformat=xformat, yformat=yformat,
                                 zformat=zformat)

            from taurus.core import DataType
            if forceRGB:
                if Attribute(taurusmodel).getType() == DataType.DevEncoded:
                    image = TaurusEncodedRGBImageItem(param)
                else:
                    image = TaurusRGBImageItem(param)
            else:
                if Attribute(taurusmodel).getType() == DataType.DevEncoded:
                    image = TaurusEncodedImageItem(param)
                else:
                    image = TaurusImageItem(param)
            image.setModel(taurusmodel)
            if eliminate_outliers is not None:
                image.set_lut_range(lut_range_threshold(image, 256,
                                                        eliminate_outliers))

        return image
Ejemplo n.º 9
0
 def maskedimage(
     self,
     data=None,
     mask=None,
     filename=None,
     title=None,
     alpha_mask=False,
     alpha=1.0,
     xdata=[None, None],
     ydata=[None, None],
     pixel_size=None,
     center_on=None,
     background_color=None,
     colormap=None,
     show_mask=False,
     fill_value=None,
     interpolation="linear",
     eliminate_outliers=None,
     xformat="%.1f",
     yformat="%.1f",
     zformat="%.1f",
 ):
     """
     Make a masked image `plot item` from data
     (:py:class:`guiqwt.image.MaskedImageItem` object)
     """
     assert isinstance(xdata, (tuple, list)) and len(xdata) == 2
     assert isinstance(ydata, (tuple, list)) and len(ydata) == 2
     param = MaskedImageParam(title=_("Image"), icon="image.png")
     data, filename, title = self._get_image_data(
         data, filename, title, to_grayscale=True
     )
     assert data.ndim == 2, "Data must have 2 dimensions"
     if pixel_size is None:
         assert center_on is None, (
             "Ambiguous parameters: both `center_on`"
             " and `xdata`/`ydata` were specified"
         )
         xmin, xmax = xdata
         ymin, ymax = ydata
     else:
         xmin, xmax, ymin, ymax = self.compute_bounds(data, pixel_size, center_on)
     self.__set_image_param(
         param,
         title,
         alpha_mask,
         alpha,
         interpolation,
         background=background_color,
         colormap=colormap,
         xmin=xmin,
         xmax=xmax,
         ymin=ymin,
         ymax=ymax,
         show_mask=show_mask,
         fill_value=fill_value,
         xformat=xformat,
         yformat=yformat,
         zformat=zformat,
     )
     image = MaskedImageItem(data, mask, param)
     image.set_filename(filename)
     if eliminate_outliers is not None:
         image.set_lut_range(lut_range_threshold(image, 256, eliminate_outliers))
     return image