Commit 6187a7c6 authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer
Browse files

[orangecontrib][zsum] Use zsumWidget

parent 91b6b40e
......@@ -26,19 +26,17 @@
__authors__ = ["J. Garriga"]
__license__ = "MIT"
__date__ = "15/12/2020"
__date__ = "20/07/2021"
from silx.gui.colors import Colormap
from silx.gui.plot import Plot2D
from Orange.widgets.widget import OWWidget, Input
from darfix.gui.utils import ChooseDimensionDock
from darfix.gui.zSumWidget import ZSumWidget
class ZSumWidgetOW(OWWidget):
"""
Widget that sums a stack of images by the z axis.
Widget that computes the background substraction from a dataset
"""
name = "z sum"
......@@ -53,57 +51,17 @@ class ZSumWidgetOW(OWWidget):
def __init__(self):
super().__init__()
self._plot = Plot2D(parent=self)
self._plot.setDefaultColormap(Colormap(name='viridis', normalization='linear'))
self.controlArea.layout().addWidget(self._plot)
self._chooseDimensionDock = ChooseDimensionDock(self)
self._chooseDimensionDock.hide()
self.controlArea.layout().addWidget(self._chooseDimensionDock)
self.origin, self.scale = None, None
self._chooseDimensionDock.widget.filterChanged.connect(self._filterStack)
self._chooseDimensionDock.widget.stateDisabled.connect(self._wholeStack)
self._widget = ZSumWidget(parent=self)
self.controlArea.layout().addWidget(self._widget)
@Inputs.dataset
def setDataset(self, dataset):
# Make sum of dataset data
if dataset:
self.dataset = dataset[0]
self.indices = dataset[1]
if len(self.dataset.data.shape) > 3:
self._chooseDimensionDock.show()
self._chooseDimensionDock.widget.setDimensions(self.dataset.dims)
image = self.dataset.zsum(indices=self.indices)
if self.dataset.transformation:
px = self.dataset.transformation[0][0][0]
py = self.dataset.transformation[1][0][0]
xscale = (self.dataset.transformation[0][-1][-1] - px) / len(self.dataset.transformation[0][0])
yscale = (self.dataset.transformation[1][-1][-1] - py) / len(self.dataset.transformation[1][0])
self.origin = (px, py)
self.scale = (xscale, yscale)
self._plot.addImage(image, origin=self.origin, scale=self.scale, xlabel='µm', ylabel='µm')
else:
self._plot.addImage(image, xlabel='pixels', ylabel='pixels')
self._plot.addImage(image)
self.open()
self._widget.setDataset(*dataset)
else:
self._plot.clear()
self._widget._plot.clear()
self.open()
@Inputs.colormap
def setColormap(self, colormap):
self._plot.getImage().setColormap(colormap)
def _filterStack(self, dim=0, val=0):
image = self.dataset.zsum(indices=self.indices, dimension=[dim, val])
if image.shape[0]:
if self.origin:
self._plot.addImage(image, origin=self.origin, scale=self.scale, xlabel='µm', ylabel='µm')
else:
self._plot.addImage(image, xlabel='pixels', ylabel='pixels')
else:
self._plot.clear()
def _wholeStack(self):
if self.origin:
self._plot.addImage(self.dataset.zsum(), origin=self.origin, scale=self.scale, xlabel='µm', ylabel='µm')
else:
self._plot.addImage(self.dataset.zsum(), xlabel='pixels', ylabel='pixels')
self._widget.setColormap(colormap)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment