summaryrefslogtreecommitdiff
path: root/silx/gui/plot/items/image.py
diff options
context:
space:
mode:
authorPicca Frédéric-Emmanuel <picca@debian.org>2017-10-07 07:59:01 +0200
committerPicca Frédéric-Emmanuel <picca@debian.org>2017-10-07 07:59:01 +0200
commitbfa4dba15485b4192f8bbe13345e9658c97ecf76 (patch)
treefb9c6e5860881fbde902f7cbdbd41dc4a3a9fb5d /silx/gui/plot/items/image.py
parentf7bdc2acff3c13a6d632c28c4569690ab106eed7 (diff)
New upstream version 0.6.0+dfsg
Diffstat (limited to 'silx/gui/plot/items/image.py')
-rw-r--r--silx/gui/plot/items/image.py75
1 files changed, 56 insertions, 19 deletions
diff --git a/silx/gui/plot/items/image.py b/silx/gui/plot/items/image.py
index 7e1dd8b..acf7bf6 100644
--- a/silx/gui/plot/items/image.py
+++ b/silx/gui/plot/items/image.py
@@ -28,7 +28,7 @@ of the :class:`Plot`.
__authors__ = ["T. Vincent"]
__license__ = "MIT"
-__date__ = "06/03/2017"
+__date__ = "27/06/2017"
from collections import Sequence
@@ -36,7 +36,8 @@ import logging
import numpy
-from .core import Item, LabelsMixIn, DraggableMixIn, ColormapMixIn, AlphaMixIn
+from .core import (Item, LabelsMixIn, DraggableMixIn, ColormapMixIn,
+ AlphaMixIn, ItemChangedType)
from ..Colors import applyColormapToData
@@ -130,14 +131,23 @@ class ImageBase(Item, LabelsMixIn, DraggableMixIn, AlphaMixIn):
:param bool visible: True to display it, False otherwise
"""
- visibleChanged = self.isVisible() != bool(visible)
- super(ImageBase, self).setVisible(visible)
-
+ visible = bool(visible)
# TODO hackish data range implementation
- if visibleChanged:
+ if self.isVisible() != visible:
plot = self.getPlot()
if plot is not None:
plot._invalidateDataRange()
+ super(ImageBase, self).setVisible(visible)
+
+ def _isPlotLinear(self, plot):
+ """Return True if plot only uses linear scale for both of x and y
+ axes."""
+ linear = plot.getXAxis().LINEAR
+ if plot.getXAxis().getScale() != linear:
+ return False
+ if plot.getYAxis().getScale() != linear:
+ return False
+ return True
def _getBounds(self):
if self.getData(copy=False).size == 0: # Empty data
@@ -156,8 +166,7 @@ class ImageBase(Item, LabelsMixIn, DraggableMixIn, AlphaMixIn):
ymin, ymax = ymax, ymin
plot = self.getPlot()
- if (plot is not None and
- plot.isXAxisLogarithmic() or plot.isYAxisLogarithmic()):
+ if plot is not None and not self._isPlotLinear(plot):
return None
else:
return xmin, xmax, ymin, ymax
@@ -197,7 +206,6 @@ class ImageBase(Item, LabelsMixIn, DraggableMixIn, AlphaMixIn):
origin = float(origin), float(origin)
if origin != self._origin:
self._origin = origin
- self._updated()
# TODO hackish data range implementation
if self.isVisible():
@@ -205,6 +213,8 @@ class ImageBase(Item, LabelsMixIn, DraggableMixIn, AlphaMixIn):
if plot is not None:
plot._invalidateDataRange()
+ self._updated(ItemChangedType.POSITION)
+
def getScale(self):
"""Returns the scale of the image in data coordinates.
@@ -222,9 +232,17 @@ class ImageBase(Item, LabelsMixIn, DraggableMixIn, AlphaMixIn):
scale = float(scale[0]), float(scale[1])
else: # single value scale
scale = float(scale), float(scale)
+
if scale != self._scale:
self._scale = scale
- self._updated()
+
+ # TODO hackish data range implementation
+ if self.isVisible():
+ plot = self.getPlot()
+ if plot is not None:
+ plot._invalidateDataRange()
+
+ self._updated(ItemChangedType.SCALE)
class ImageData(ImageBase, ColormapMixIn):
@@ -240,8 +258,9 @@ class ImageData(ImageBase, ColormapMixIn):
"""Update backend renderer"""
plot = self.getPlot()
assert plot is not None
- if plot.isXAxisLogarithmic() or plot.isYAxisLogarithmic():
- return None # Do not render with log scales
+ if not self._isPlotLinear(plot):
+ # Do not render with non linear scales
+ return None
if self.getAlternativeImageData(copy=False) is not None:
dataToUse = self.getAlternativeImageData(copy=False)
@@ -283,8 +302,7 @@ class ImageData(ImageBase, ColormapMixIn):
else:
# Apply colormap, in this case an new array is always returned
colormap = self.getColormap()
- image = applyColormapToData(self.getData(copy=False),
- **colormap)
+ image = colormap.applyToData(self.getData(copy=False))
return image
def getAlternativeImageData(self, copy=True):
@@ -312,6 +330,14 @@ class ImageData(ImageBase, ColormapMixIn):
"""
data = numpy.array(data, copy=copy)
assert data.ndim == 2
+ if data.dtype.kind == 'b':
+ _logger.warning(
+ 'Converting boolean image to int8 to plot it.')
+ data = numpy.array(data, copy=False, dtype=numpy.int8)
+ elif numpy.issubdtype(data.dtype, numpy.complex):
+ _logger.warning(
+ 'Converting complex image to absolute value to plot it.')
+ data = numpy.absolute(data)
self._data = data
if alternative is not None:
@@ -320,7 +346,6 @@ class ImageData(ImageBase, ColormapMixIn):
assert alternative.shape[2] in (3, 4)
assert alternative.shape[:2] == data.shape[:2]
self._alternativeImage = alternative
- self._updated()
# TODO hackish data range implementation
if self.isVisible():
@@ -328,6 +353,8 @@ class ImageData(ImageBase, ColormapMixIn):
if plot is not None:
plot._invalidateDataRange()
+ self._updated(ItemChangedType.DATA)
+
class ImageRgba(ImageBase):
"""Description of an RGB(A) image"""
@@ -339,8 +366,9 @@ class ImageRgba(ImageBase):
"""Update backend renderer"""
plot = self.getPlot()
assert plot is not None
- if plot.isXAxisLogarithmic() or plot.isYAxisLogarithmic():
- return None # Do not render with log scales
+ if not self._isPlotLinear(plot):
+ # Do not render with non linear scales
+ return None
data = self.getData(copy=False)
@@ -376,10 +404,19 @@ class ImageRgba(ImageBase):
assert data.shape[-1] in (3, 4)
self._data = data
- self._updated()
-
# TODO hackish data range implementation
if self.isVisible():
plot = self.getPlot()
if plot is not None:
plot._invalidateDataRange()
+
+ self._updated(ItemChangedType.DATA)
+
+
+class MaskImageData(ImageData):
+ """Description of an image used as a mask.
+
+ This class is used to flag mask items. This information is used to improve
+ internal silx widgets.
+ """
+ pass