Commit 094c93f9 authored by payno's avatar payno
Browse files

[feature noise] fix noise feature

parent 9be52fd5
......@@ -76,6 +76,8 @@ def process_noise_savgol(
"start noise with Savitsky-Golay on spectrum (%s, %s)"
% (spectrum.x, spectrum.y)
)
if "noise" in configuration:
configuration = configuration["noise"]
if not "window_size" in configuration:
raise ValueError("`window_size` should be specify. Missing in " "configuration")
else:
......@@ -91,11 +93,11 @@ def process_noise_savgol(
spectrum.mu, window_size, polynomial_order
)
noise = spectrum.mu - smooth_spectrum
spectrum["noise_savgol"] = noise
spectrum.noise_savgol = noise
if hasattr(spectrum, "edge_step"):
spectrum["norm_noise_savgol"] = numpy.mean(noise) / spectrum.edge_step
spectrum.norm_noise_savgol = numpy.mean(noise) / spectrum.edge_step
else:
spectrum["norm_noise_savgol"] = None
spectrum.norm_noise_savgol = None
_logger.warning(
"Unable to compute Normalized edge."
"Normalization (pre-edge) should be run first"
......
......@@ -135,34 +135,15 @@ class Process(object):
_data = {}
for key in data_keys:
relative_to = None
if key in (
"flat",
"fpp",
"f2",
"dmude",
"norm",
"norm_area",
"post_edge",
"bkg",
"energy",
"mback_mu",
"norm_mback",
"Energy",
"Mu",
"NormalizedEnergy",
"NormalizedMu",
"NormalizedSignal",
"EXAFSKValues",
"EXAFSSignal",
):
relative_to = "energy"
use = "map_to"
elif key in ("chir_re", "chir_im", "chir_mag", "r"):
if key in ("chir_re", "chir_im", "chir_mag", "r"):
relative_to = "r"
use = "map_to"
elif key in ("ft.radius", "ft.intensity", "ft.imaginary"):
relative_to = "radius"
use = "_list_res_ft"
else:
relative_to = "energy"
use = "map_to"
if use == "map_to":
# if we can display the result as a numpy.array 3d
......
......@@ -427,8 +427,12 @@ class SpectrumViewer(qt.QMainWindow):
for res in curves:
# result can be None or nan if the processing fails. So in this
# case we won't display anything
if res is not None and res.x is not None and res.x is not numpy.nan:
if isinstance(res, _CurveOperation):
if res is not None:
if (
isinstance(res, _CurveOperation)
and res.x is not None
and res.x is not numpy.nan
):
kwargs = {
"x": res.x,
"y": res.y,
......@@ -445,10 +449,22 @@ class SpectrumViewer(qt.QMainWindow):
curve = self._plotWidget.addCurve(**kwargs)
curve = self._plotWidget.getCurve(curve)
curve.setAlpha(res.alpha)
elif isinstance(res, _XMarkerOperation):
elif (
isinstance(res, _XMarkerOperation)
and res.x is not None
and res.x is not numpy.nan
):
self._plotWidget.addXMarker(
x=res.x, color=res.color, legend=res.legend
)
elif (
isinstance(res, _YMarkerOperation)
and res.y is not None
and res.y is not numpy.nan
):
self._plotWidget.addYMarker(
y=res.y, color=res.color, legend=res.legend
)
else:
raise TypeError(
"this type of operation is not " "recognized", type(res)
......
......@@ -64,23 +64,27 @@ class _SavitskyGolayNoiseOpts(qt.QWidget):
return self._windowSize.value()
def setWindowSize(self, size):
self._windowSize.setValue(size=size)
if size < 1:
return
self._windowSize.setValue(size)
def getPolynomialOrder(self):
return self._polynomialOrder.value()
def setPolynomialOrder(self, order):
if order < 1:
return
self._polynomialOrder.setValue(order)
def getParameters(self):
return {
"windows_size": self._windowSize.value(),
"window_size": self._windowSize.value(),
"polynomial_order": self._polynomialOrder.value(),
}
def setParameters(self, config):
if "windows_size" in config:
self.setWindowSize(config["windows_size"])
if "window_size" in config:
self.setWindowSize(config["window_size"])
if "polynomial_order" in config:
self.setPolynomialOrder(config["polynomial_order"])
......@@ -101,10 +105,10 @@ class SavitskyGolayNoise(qt.QMainWindow):
self.setWindowFlags(qt.Qt.Widget)
# define centre widget
self.xasObjViewer = SpectrumViewer()
self._plot = SpectrumViewer()
for ope in (_plot_noise_savgol, _plot_norm_noise_savgol):
self.xasObjViewer.addCurveOperation(ope)
self.setCentralWidget(self.xasObjViewer)
self._plot.addCurveOperation(ope)
self.setCentralWidget(self._plot)
# options
self._options = _SavitskyGolayNoiseOpts(parent=self)
......@@ -117,7 +121,7 @@ class SavitskyGolayNoise(qt.QMainWindow):
self._options.sigChanged.connect(self._changed)
def setXASObj(self, xas_obj):
self.xasObjViewer.setXASObj(xas_obj=xas_obj)
self._plot.setXasObject(xas_obj=xas_obj)
def getParameters(self):
return self._options.getParameters()
......
......@@ -74,8 +74,11 @@ class _ProcessForOrangeMixIn(object):
if xas_obj is None:
return
else:
if hasattr(self, "_window") and hasattr(self._window, "xasObjViewer"):
self._window.xasObjViewer.setXASObj(xas_obj=xas_obj)
if hasattr(self, "_window") and hasattr(self._window, "setXASObj"):
self._window.setXASObj(xas_obj=xas_obj)
elif hasattr(self, "_window") and hasattr(self._window, "xasObjViewer"):
if hasattr(self._window.xasObjViewer, "setXASObj"):
self._window.xasObjViewer.setXASObj(xas_obj=xas_obj)
# emit signal for the plot
self.Outputs.res_xas_obj.send(xas_obj)
......
......@@ -38,8 +38,8 @@ from orangecontrib.est.process import ProcessRunnable
import Orange.data
import functools
from orangecontrib.est.utils import Converter
from orangecontrib.est.process import _ProcessForOrangeMixIn
from silx.gui import qt
import est.core.process.noise
from est.core.types import XASObject
from est.gui.noise import SavitskyGolayNoise
......@@ -47,7 +47,7 @@ from est.gui.noise import SavitskyGolayNoise
_logger = logging.getLogger(__file__)
class NoiseOW(OWWidget):
class NoiseOW(_ProcessForOrangeMixIn, OWWidget):
"""
Widget used to make the selection of a region of Interest to treat in a
Dataset.
......@@ -87,9 +87,9 @@ class NoiseOW(OWWidget):
super().__init__()
self._latest_xas_obj = None
self._widget = SavitskyGolayNoise(parent=self)
self._window = SavitskyGolayNoise(parent=self)
layout = gui.vBox(self.mainArea, "noise").layout()
layout.addWidget(self._widget)
layout.addWidget(self._window)
# buttons
types = qt.QDialogButtonBox.Ok
......@@ -100,13 +100,13 @@ class NoiseOW(OWWidget):
self._buttons.hide()
# expose API
self.setWindowSize = self._widget.setWindowSize
self.getWindowSize = self._widget.getWindowSize
self.setPolynomialOrder = self._widget.setPolynomialOrder
self.getPolynomialOrder = self._widget.getPolynomialOrder
self.setWindowSize = self._window.setWindowSize
self.getWindowSize = self._window.getWindowSize
self.setPolynomialOrder = self._window.setPolynomialOrder
self.getPolynomialOrder = self._window.getPolynomialOrder
# manage settings
self._widget.setParameters(
self._window.setParameters(
{
"window_size": self._window_size,
"polynomial_order": self._polynomial_order,
......@@ -115,7 +115,7 @@ class NoiseOW(OWWidget):
# signal / slot connection
# connect signals / slots
self._widget.sigChanged.connect(self._updateProcess)
self._window.sigChanged.connect(self._updateProcess)
def _updateProcess(self, *arv, **kwargs):
self._update_settings()
......@@ -159,8 +159,8 @@ class NoiseOW(OWWidget):
thread.start(priority=qt.QThread.LowPriority)
def _update_settings(self):
self._window_size = self._widget.getWindowSize()
self._polynomial_order = self._widget.getPolynomialOrder()
self._window_size = self._window.getWindowSize()
self._polynomial_order = self._window.getPolynomialOrder()
def _setProgressValue(self, value):
self._progress.widget.progressBarSet(value)
......@@ -180,7 +180,7 @@ class QNoise(est.core.process.noise.NoiseProcess):
self.pool.setMaxThreadCount(5)
for spectrum in xas_obj.spectra:
runnable = ProcessRunnable(
fct=est.core.process.noise.xas_noise,
fct=est.core.process.noise.process_noise_savgol,
spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement,
......
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