def _updateImage(self): selection = self._selector.selection() auxSigIdx = self._auxSigSlider.value() images = [img[selection] for img in self.__signals] image = images[auxSigIdx] x_axis = self.__x_axis y_axis = self.__y_axis if x_axis is None and y_axis is None: xcalib = NoCalibration() ycalib = NoCalibration() else: if x_axis is None: # no calibration x_axis = numpy.arange(image.shape[1]) elif numpy.isscalar(x_axis) or len(x_axis) == 1: # constant axis x_axis = x_axis * numpy.ones((image.shape[1], )) elif len(x_axis) == 2: # linear calibration x_axis = x_axis[0] * numpy.arange(image.shape[1]) + x_axis[1] if y_axis is None: y_axis = numpy.arange(image.shape[0]) elif numpy.isscalar(y_axis) or len(y_axis) == 1: y_axis = y_axis * numpy.ones((image.shape[0], )) elif len(y_axis) == 2: y_axis = y_axis[0] * numpy.arange(image.shape[0]) + y_axis[1] xcalib = ArrayCalibration(x_axis) ycalib = ArrayCalibration(y_axis) self._plot.setData(image) if xcalib.is_affine(): xorigin, xscale = xcalib(0), xcalib.get_slope() else: _logger.warning("Unsupported complex image X axis calibration") xorigin, xscale = 0., 1. if ycalib.is_affine(): yorigin, yscale = ycalib(0), ycalib.get_slope() else: _logger.warning("Unsupported complex image Y axis calibration") yorigin, yscale = 0., 1. self._plot.setOrigin((xorigin, yorigin)) self._plot.setScale((xscale, yscale)) if self.__title: title = self.__title if len(self.__signals_names) > 1: # Append dataset name only when there is many datasets title += '\n' + self.__signals_names[auxSigIdx] else: title = self.__signals_names[auxSigIdx] self._plot.setGraphTitle(title) self._plot.getXAxis().setLabel(self.__x_axis_name) self._plot.getYAxis().setLabel(self.__y_axis_name)
def _updateImage(self): legend = self.__signal_name + "[" for sl in self._selector.selection(): if sl == slice(None): legend += ":, " else: legend += str(sl) + ", " legend = legend[:-2] + "]" self._legend.setText("Displayed data: " + legend) img = self._selector.selectedData() x_axis = self.__x_axis y_axis = self.__y_axis if x_axis is None and y_axis is None: xcalib = NoCalibration() ycalib = NoCalibration() else: if x_axis is None: # no calibration x_axis = numpy.arange(img.shape[-1]) elif numpy.isscalar(x_axis) or len(x_axis) == 1: # constant axis x_axis = x_axis * numpy.ones((img.shape[-1], )) elif len(x_axis) == 2: # linear calibration x_axis = x_axis[0] * numpy.arange(img.shape[-1]) + x_axis[1] if y_axis is None: y_axis = numpy.arange(img.shape[-2]) elif numpy.isscalar(y_axis) or len(y_axis) == 1: y_axis = y_axis * numpy.ones((img.shape[-2], )) elif len(y_axis) == 2: y_axis = y_axis[0] * numpy.arange(img.shape[-2]) + y_axis[1] xcalib = ArrayCalibration(x_axis) ycalib = ArrayCalibration(y_axis) self._plot.remove(kind=("scatter", "image")) if xcalib.is_affine() and ycalib.is_affine(): # regular image xorigin, xscale = xcalib(0), xcalib.get_slope() yorigin, yscale = ycalib(0), ycalib.get_slope() origin = (xorigin, yorigin) scale = (xscale, yscale) self._plot.addImage(img, legend=legend, origin=origin, scale=scale) else: scatterx, scattery = numpy.meshgrid(x_axis, y_axis) self._plot.addScatter(numpy.ravel(scatterx), numpy.ravel(scattery), numpy.ravel(img), legend=legend) self._plot.getXAxis().setLabel(self.__x_axis_name) self._plot.getYAxis().setLabel(self.__y_axis_name) self._plot.resetZoom()
class TestNoCalibration(unittest.TestCase): def setUp(self): self.calib = NoCalibration() def testIsAffine(self): self.assertTrue(self.calib.is_affine()) def testSlope(self): self.assertEqual(self.calib.get_slope(), 1.) def testYIntercept(self): self.assertEqual(self.calib(0.), 0.) def testCall(self): self.assertTrue(numpy.array_equal(self.calib(X), X))
def _updateVolume(self): """Update displayed stack according to the current axes selector data.""" x_axis = self.__x_axis y_axis = self.__y_axis z_axis = self.__z_axis offset = [] scale = [] for axis in [x_axis, y_axis, z_axis]: if axis is None: calibration = NoCalibration() elif len(axis) == 2: calibration = LinearCalibration(y_intercept=axis[0], slope=axis[1]) else: calibration = ArrayCalibration(axis) if not calibration.is_affine(): _logger.warning("Axis has not linear values, ignored") offset.append(0.) scale.append(1.) else: offset.append(calibration(0)) scale.append(calibration.get_slope()) legend = self.__signal_name + "[" for sl in self._selector.selection(): if sl == slice(None): legend += ":, " else: legend += str(sl) + ", " legend = legend[:-2] + "]" self._legend.setText("Displayed data: " + legend) # Update SceneWidget data = self._selector.selectedData() volumeView = self.getVolumeView() volumeView.setData(data, offset=offset, scale=scale) volumeView.setAxesLabels(self.__x_axis_name, self.__y_axis_name, self.__z_axis_name)
def _updateImage(self): selection = self._selector.selection() auxSigIdx = self._auxSigSlider.value() legend = self.__signals_names[auxSigIdx] images = [img[selection] for img in self.__signals] image = images[auxSigIdx] x_axis = self.__x_axis y_axis = self.__y_axis if x_axis is None and y_axis is None: xcalib = NoCalibration() ycalib = NoCalibration() else: if x_axis is None: # no calibration x_axis = numpy.arange(image.shape[1]) elif numpy.isscalar(x_axis) or len(x_axis) == 1: # constant axis x_axis = x_axis * numpy.ones((image.shape[1], )) elif len(x_axis) == 2: # linear calibration x_axis = x_axis[0] * numpy.arange(image.shape[1]) + x_axis[1] if y_axis is None: y_axis = numpy.arange(image.shape[0]) elif numpy.isscalar(y_axis) or len(y_axis) == 1: y_axis = y_axis * numpy.ones((image.shape[0], )) elif len(y_axis) == 2: y_axis = y_axis[0] * numpy.arange(image.shape[0]) + y_axis[1] xcalib = ArrayCalibration(x_axis) ycalib = ArrayCalibration(y_axis) self._plot.remove(kind=( "scatter", "image", )) if xcalib.is_affine() and ycalib.is_affine(): # regular image xorigin, xscale = xcalib(0), xcalib.get_slope() yorigin, yscale = ycalib(0), ycalib.get_slope() origin = (xorigin, yorigin) scale = (xscale, yscale) self._plot.getXAxis().setScale('linear') self._plot.getYAxis().setScale('linear') self._plot.addImage(image, legend=legend, origin=origin, scale=scale, replace=True, resetzoom=False) else: xaxisscale, yaxisscale = self._axis_scales if xaxisscale is not None: self._plot.getXAxis().setScale('log' if xaxisscale == 'log' else 'linear') if yaxisscale is not None: self._plot.getYAxis().setScale('log' if yaxisscale == 'log' else 'linear') scatterx, scattery = numpy.meshgrid(x_axis, y_axis) # fixme: i don't think this can handle "irregular" RGBA images self._plot.addScatter(numpy.ravel(scatterx), numpy.ravel(scattery), numpy.ravel(image), legend=legend) if self.__title: title = self.__title if len(self.__signals_names) > 1: # Append dataset name only when there is many datasets title += '\n' + self.__signals_names[auxSigIdx] else: title = self.__signals_names[auxSigIdx] self._plot.setGraphTitle(title) self._plot.getXAxis().setLabel(self.__x_axis_name) self._plot.getYAxis().setLabel(self.__y_axis_name)
def _updateImage(self): selection = self._selector.selection() auxSigIdx = self._auxSigSlider.value() legend = self.__signals_names[auxSigIdx] images = [img[selection] for img in self.__signals] image = images[auxSigIdx] x_axis = self.__x_axis y_axis = self.__y_axis if x_axis is None and y_axis is None: xcalib = NoCalibration() ycalib = NoCalibration() else: if x_axis is None: # no calibration x_axis = numpy.arange(image.shape[1]) elif numpy.isscalar(x_axis) or len(x_axis) == 1: # constant axis x_axis = x_axis * numpy.ones((image.shape[1], )) elif len(x_axis) == 2: # linear calibration x_axis = x_axis[0] * numpy.arange(image.shape[1]) + x_axis[1] if y_axis is None: y_axis = numpy.arange(image.shape[0]) elif numpy.isscalar(y_axis) or len(y_axis) == 1: y_axis = y_axis * numpy.ones((image.shape[0], )) elif len(y_axis) == 2: y_axis = y_axis[0] * numpy.arange(image.shape[0]) + y_axis[1] xcalib = ArrayCalibration(x_axis) ycalib = ArrayCalibration(y_axis) self._plot.remove(kind=("scatter", "image",)) if xcalib.is_affine() and ycalib.is_affine(): # regular image xorigin, xscale = xcalib(0), xcalib.get_slope() yorigin, yscale = ycalib(0), ycalib.get_slope() origin = (xorigin, yorigin) scale = (xscale, yscale) self._plot.addImage(image, legend=legend, origin=origin, scale=scale, replace=True) else: scatterx, scattery = numpy.meshgrid(x_axis, y_axis) # fixme: i don't think this can handle "irregular" RGBA images self._plot.addScatter(numpy.ravel(scatterx), numpy.ravel(scattery), numpy.ravel(image), legend=legend) title = "" if self.__title: title += self.__title if not title.strip().endswith(self.__signals_names[auxSigIdx]): title += "\n" + self.__signals_names[auxSigIdx] self._plot.setGraphTitle(title) self._plot.getXAxis().setLabel(self.__x_axis_name) self._plot.getYAxis().setLabel(self.__y_axis_name) self._plot.resetZoom()
def _updateImage(self): selection = self._selector.selection() auxSigIdx = self._auxSigSlider.value() legend = self.__signals_names[auxSigIdx] images = [img[selection] for img in self.__signals] image = images[auxSigIdx] x_axis = self.__x_axis y_axis = self.__y_axis if x_axis is None and y_axis is None: xcalib = NoCalibration() ycalib = NoCalibration() else: if x_axis is None: # no calibration x_axis = numpy.arange(image.shape[1]) elif numpy.isscalar(x_axis) or len(x_axis) == 1: # constant axis x_axis = x_axis * numpy.ones((image.shape[1], )) elif len(x_axis) == 2: # linear calibration x_axis = x_axis[0] * numpy.arange(image.shape[1]) + x_axis[1] if y_axis is None: y_axis = numpy.arange(image.shape[0]) elif numpy.isscalar(y_axis) or len(y_axis) == 1: y_axis = y_axis * numpy.ones((image.shape[0], )) elif len(y_axis) == 2: y_axis = y_axis[0] * numpy.arange(image.shape[0]) + y_axis[1] xcalib = ArrayCalibration(x_axis) ycalib = ArrayCalibration(y_axis) self._plot.remove(kind=( "scatter", "image", )) if xcalib.is_affine() and ycalib.is_affine(): # regular image xorigin, xscale = xcalib(0), xcalib.get_slope() yorigin, yscale = ycalib(0), ycalib.get_slope() origin = (xorigin, yorigin) scale = (xscale, yscale) self._plot.addImage(image, legend=legend, origin=origin, scale=scale) else: scatterx, scattery = numpy.meshgrid(x_axis, y_axis) # fixme: i don't think this can handle "irregular" RGBA images self._plot.addScatter(numpy.ravel(scatterx), numpy.ravel(scattery), numpy.ravel(image), legend=legend) title = "" if self.__title: title += self.__title if not title.strip().endswith(self.__signals_names[auxSigIdx]): title += "\n" + self.__signals_names[auxSigIdx] self._plot.setGraphTitle(title) self._plot.getXAxis().setLabel(self.__x_axis_name) self._plot.getYAxis().setLabel(self.__y_axis_name) self._plot.resetZoom()