Commit 96a4b169 authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer
Browse files

[orangecontrib&core] Added callback to shift correction to update the progress...

[orangecontrib&core] Added callback to shift correction to update the progress in orange. Cleared stack when no dataset is linked to widget
parent c643abd5
Pipeline #13426 passed with stage
in 30 seconds
......@@ -197,13 +197,16 @@ def _compute_fft2(img, dx, dy):
return abs(numpy.fft.ifft2(c))
def shift_correction(data, dx=0, dy=0):
def shift_correction(data, dx=0, dy=0, callback=None):
"""
Function to apply FFT technique to stack of images.
:param Dataset dataset: Dataset
:param dxy: The shift
:type dxy: [float, float]
:param dx: Shift in x axis
:param dy: Shift in y axis
:param callback: Callback function to update the progress
:type dx: float
:type dy: float
:returns: ndarray
"""
if dx == 0 and dy == 0:
......@@ -212,12 +215,14 @@ def shift_correction(data, dx=0, dy=0):
shifted_frames = []
count = 0
utils.advancement_display(count, len(data), "Computing shift")
utils.advancement_display(0, len(data), "Computing shift")
for frame in data:
shifted_frames.append(_compute_fft2(frame, dx, dy))
count += 1
utils.advancement_display(count, len(data), "Computing shift")
if callback:
callback(int(count / len(data) * 100))
shifted_frames = numpy.asarray(shifted_frames, dtype=numpy.float32)
if data.dtype.kind == 'f':
......
......@@ -99,6 +99,9 @@ class BackgroundSubstractionWidget(qt.QWidget):
self.dataset = dataset
self.setStack(dataset.data)
def clearStack(self):
self._sv.setStack(None)
def setStack(self, *arg, **kwargs):
"""
Sets the data passed as aguments in the stack.
......
......@@ -107,6 +107,10 @@ class ROISelectionWidget(qt.QWidget):
self._sv.setStack(*arg, **kwargs)
self._sv.setFrameNumber(nframe)
def clearStack(self):
self._sv.setStack(None)
self._roi.setGeometry(origin=(0, 0), size=(10, 10))
def setRoi(self, roi=None, origin=None, size=None, center=None):
"""
Sets Region Of Interest of the stack of images.
......
......@@ -44,6 +44,7 @@ class ShiftCorrectionWidget(qt.QWidget):
A widget to apply shift correction to a stack of images
"""
signalComputed = qt.Signal()
signalProgress = qt.Signal(int)
def __init__(self, parent=None):
qt.QWidget.__init__(self, parent)
......@@ -53,6 +54,7 @@ class ShiftCorrectionWidget(qt.QWidget):
self.setLayout(qt.QVBoxLayout())
self._inputW = _InputWidget()
self._inputW.correctionB.setEnabled(False)
self.layout().addWidget(self._inputW)
self._sv = StackViewMainWindow()
......@@ -70,6 +72,7 @@ class ShiftCorrectionWidget(qt.QWidget):
"""
self.dataset = dataset
self.setStack(dataset.data)
self._inputW.correctionB.setEnabled(True)
def correct(self):
"""
......@@ -79,11 +82,14 @@ class ShiftCorrectionWidget(qt.QWidget):
dx = self._inputW.getDx()
dy = self._inputW.getDy()
self.shift = [dx, dy]
self.thread.setArgs(self.dataset.data, dx, dy)
self.thread.setArgs(self.dataset.data, dx, dy, self.updateProgress)
self.thread.finished.connect(self._updateData)
self._inputW.correctionB.setEnabled(False)
self.thread.start()
def updateProgress(self, progress):
self.signalProgress.emit(progress)
def _updateData(self):
"""
Updates the stack with the data computed in the thread
......@@ -104,6 +110,10 @@ class ShiftCorrectionWidget(qt.QWidget):
self._sv.setStack(*arg, **kwargs)
self._sv.setFrameNumber(nframe)
def clearStack(self):
self._sv.setStack(None)
self._inputW.correctionB.setEnabled(False)
def getStack(self):
"""
Stack getter
......
......@@ -92,6 +92,7 @@ class DataSelectionWidgetOW(OWWidget):
self.updateSettings()
self.__updatingData = True
self.information("Downloading dataset")
self.close()
def _updateProgress(self, progress):
self._progressBar.widget.progressBarSet(progress)
......
......@@ -25,9 +25,14 @@ class BackgroundSubstractionWidgetOW(OWWidget):
@Inputs.dataset
def set_dataset(self, dataset):
assert dataset.dark_frames, "Dark frames must be given in order to compute noise reduction"
self._widget.setDataset(dataset=dataset)
self._widget.computeBS()
if dataset:
assert dataset.dark_frames, "Dark frames must be given in order to compute noise reduction"
self._widget.setDataset(dataset=dataset)
self._widget.computeBS()
else:
self._widget.clearStack()
# Emit None
self.Outputs.dataset.send(dataset)
def _sendSignal(self):
self.Outputs.dataset.send(self._widget.dataset)
......@@ -61,6 +61,7 @@ class RoiSelectionWidgetOW(OWWidget):
self._widget = ROISelectionWidget(parent=self)
self._button = qt.QPushButton('Ok', parent=self)
self._button.setEnabled(False)
self.controlArea.layout().addWidget(self._widget)
self.controlArea.layout().addWidget(self._button)
......@@ -68,8 +69,15 @@ class RoiSelectionWidgetOW(OWWidget):
@Inputs.dataset
def setDataset(self, dataset):
self._widget.setDataset(dataset=dataset)
self.dataset = dataset
if dataset:
self._widget.setDataset(dataset=dataset)
self.dataset = dataset
self._button.setEnabled(True)
else:
self._widget.clearStack()
self._button.setEnabled(False)
# Emit None
self.Outputs.dataset.send(dataset)
# Set saved roi
if len(self.roi_origin) and len(self.roi_size):
......
from Orange.widgets import gui
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget, Input, Output
from linkdick06.gui.shiftCorrectionWidget import ShiftCorrectionWidget
......@@ -21,17 +22,27 @@ class ShiftCorrectionWidgetOW(OWWidget):
def __init__(self):
super().__init__()
self._shiftCorrection = ShiftCorrectionWidget(parent=self)
self._shiftCorrection.signalComputed.connect(self._sendSignal)
self.controlArea.layout().addWidget(self._shiftCorrection)
self._widget = ShiftCorrectionWidget(parent=self)
self._progressBar = gui.ProgressBar(self, 100)
self._widget.signalComputed.connect(self._sendSignal)
self._widget.signalProgress.connect(self._updateProgress)
self.controlArea.layout().addWidget(self._widget)
if self.shift:
self._shiftCorrection.shift = self.shift
self._widget.shift = self.shift
@Inputs.dataset
def set_dataset(self, dataset):
self._shiftCorrection.setDataset(dataset=dataset)
if dataset:
self._widget.setDataset(dataset=dataset)
else:
self._widget.clearStack()
# Emit None
self.Outputs.dataset.send(dataset)
def _sendSignal(self):
self.shift = self._shiftCorrection.shift
self.Outputs.dataset.send(self._shiftCorrection.dataset)
self.shift = self._widget.shift
self.Outputs.dataset.send(self._widget.dataset)
def _updateProgress(self, progress):
self._progressBar.widget.progressBarSet(progress)
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