Skip to content
Snippets Groups Projects
Commit 1018f44f authored by casagran's avatar casagran
Browse files

implement subtract dark

parent 0d235a2d
No related branches found
No related tags found
1 merge request!6Draft: Resolve "py-bkg-rm"
......@@ -159,7 +159,7 @@ class ROISelectionWidget(qt.QWidget):
def apply(self):
"""
Function that replaces the dataset data with the data shown in the stack of images.
If the stack has a roi applied, it applies the same roi to the dark frames of the dataset.
If the stack has a roi applied, it applies the same roi to the data frames of the dataset.
Signal emitted with the roi parameters.
"""
if self.roi:
......
......@@ -2,4 +2,104 @@
import logging
import numpy as np
from numpy import ndarray
from Orange.widgets import gui, settings, widget
from Orange.widgets.utils.signals import Input, Output
from Orange.widgets.widget import OWWidget
from silx.gui.qt import QThread
_logger = logging.getLogger("orangecontrib.pydct")
class SubtractDarkThread(QThread):
"""todo doc SubtractDarkThread"""
def __init__(self, parent, data, dark):
super().__init__(parent=parent)
self.data = data
self.dark = dark
self.data_processed = None
def run(self):
self.data_processed = self.data - self.dark
class SubtractDark(OWWidget):
name = "subtract dark"
description = "Subtract the dark frame (z-length = 1) from all frames of dataset."
icon = "icons/subtract-dark.svg" # todo get an icon
want_main_area = False
resizing_enabled = True
class Inputs:
data = Input("data", ndarray)
dark = Input("dark", ndarray)
class Outputs:
data = Output("data", ndarray)
def __init__(self):
super().__init__()
self.dark = None
self.data = None
self._computing = False
self.information("waiting for inputs")
@Inputs.data
def set_data(self, data):
# todo add validations here
self.data = data
self.information("needs to update")
self._update()
@Inputs.dark
def set_dark(self, dark):
# todo add validations here
self.dark = dark
self.information("needs to update")
if dark is not None:
nz, nx, ny = self.dark.shape
if nz != 1:
self.error("please squeeze the dark image on the z-axis first (use zwise median)")
return
self._update()
def _update(self):
_logger.debug("updating")
if self._computing:
_logger.warning("already updating")
return
if self.data is None or self.dark is None:
_logger.debug("still missing an input")
return
self._thread = SubtractDarkThread(parent=self, data=self.data, dark=self.dark)
self._thread.finished.connect(self._send_signal)
_logger.debug("computing dark subtraction")
self._computing = True
self.information("computing...")
self._thread.start()
def _send_signal(self):
self._thread.finished.disconnect(self._send_signal)
self._computing = False
_logger.info("done with dark subtraction")
self.information("done")
if self._thread.data_processed is not None:
self.Outputs.data.send(self._thread.data_processed)
else:
self.error("something went wrong and the thread did not return the dark correctly")
......@@ -28,7 +28,7 @@ class ZwiseMedianThread(QThread):
class ZwiseMedian(OWWidget):
"""todo docstring of ZwiseMedian"""
name = "Z-wise median"
name = "z-wise median"
description = (
"Squeeze a volume on the z-axis to get a single frame where each pixel is the median of its position on the input."
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment