Commit 9167f17a authored by Henri Payno's avatar Henri Payno
Browse files

[orangecontrib] move noise to fully use ewoksorange.bindings.owwidget

parent 273525d2
Pipeline #55969 failed with stages
in 12 seconds
......@@ -42,10 +42,6 @@ import functools
_logger = logging.getLogger(__name__)
_USE_MULTIPROCESSING_POOL = False
# note: we cannot use multiprocessing pool with pypushflow for now.
def process_noise_savgol(
spectrum,
configuration,
......@@ -178,10 +174,9 @@ class NoiseProcess(
if self._settings:
_xas_obj.configuration["noise"] = self._settings
self._advancement.reset(max_=_xas_obj.n_spectrum)
self._advancement.startProcess()
self.progress = 0.0
self._pool_process(xas_obj=_xas_obj)
self._advancement.endProcess()
self.progress = 100.0
self.register_process(
_xas_obj,
data_keys=(
......@@ -205,38 +200,15 @@ class NoiseProcess(
def _pool_process(self, xas_obj):
assert isinstance(xas_obj, XASObject)
if not _USE_MULTIPROCESSING_POOL:
for spectrum in xas_obj.spectra:
process_noise_savgol(
spectrum=spectrum,
configuration=xas_obj.configuration,
callbacks=self.callbacks,
overwrite=True,
)
else:
from multiprocessing import Manager
manager = Manager()
output_dict = {}
res_list = manager.list()
for i_spect, spect in enumerate(xas_obj.spectra):
res_list.append(None)
output_dict[spect] = i_spect
with multiprocessing.Pool(1) as p:
partial_ = functools.partial(
process_noise_savgol,
configuration=xas_obj.configuration,
callbacks=self.callbacks,
overwrite=False,
output=res_list,
output_dict=output_dict,
)
p.map(partial_, xas_obj.spectra)
# then update local spectrum
for spectrum, res in zip(xas_obj.spectra, res_list):
spectrum.update(res)
n_s = len(xas_obj.spectra.data.flat)
for i_s, spectrum in enumerate(xas_obj.spectra):
process_noise_savgol(
spectrum=spectrum,
configuration=xas_obj.configuration,
callbacks=self.callbacks,
overwrite=True,
)
self.progress = i_s / n_s * 100.0
def definition(self):
return "noise using Savitsky-Golay algorithm"
......
......@@ -48,7 +48,7 @@ _logger = logging.getLogger(__file__)
class NoiseOW(
_ProcessForOrangeMixIn,
OWWidget,
ewokstaskclass=est.core.process.noise.NoiseProcess,
):
"""
Widget used to make the selection of a region of Interest to treat in a
......@@ -66,8 +66,6 @@ class NoiseOW(
want_main_area = True
resizing_enabled = True
compress_signal = False
ewokstaskclass = est.core.process.noise.NoiseProcess
window_size = Setting(int(-1))
polynomial_order = Setting(int(-1))
......@@ -76,17 +74,6 @@ class NoiseOW(
static_input = Setting({"xas_obj": None, "noise": None})
class Inputs:
xas_obj = Input("xas_obj", XASObject, default=True)
# simple compatibility for some Orange widget and especialy the
# 'spectroscopy add-on'
data_table = Input("Data", Orange.data.Table)
class Outputs:
xas_obj = Output("xas_obj", XASObject)
# by default we want to avoid sending 'Orange.data.Table' to avoid
# loosing the XASObject flow process and results.
def __init__(self):
super().__init__()
self._latest_xas_obj = None
......@@ -127,42 +114,6 @@ class NoiseOW(
if self._latest_xas_obj:
self.process(xas_obj=self._latest_xas_obj)
@Inputs.data_table
def processFrmDataTable(self, data_table):
if data_table is None:
return
self.process(Converter.toXASObject(data_table=data_table))
@Inputs.xas_obj
def process(self, xas_obj):
if xas_obj is None:
return
if not self._canProcess():
_logger.warning(
"There is some processing on going already, will"
"not process the new dataset"
)
self._latest_xas_obj = xas_obj
self._startProcess()
# setup the ft process
process_obj = QNoise(inputs={"xas_obj": xas_obj})
process_obj._advancement.sigProgress.connect(self._setProgressValue)
process_obj.set_properties({"noise": self._window.getParameters()})
# update the processing thread
thread = self.getProcessingThread()
thread.init(process_obj=process_obj, xas_obj=self._latest_xas_obj)
self._callback_finish = functools.partial(
self._endProcess, self._latest_xas_obj
)
thread.finished.connect(self._callback_finish)
# start processing
thread.start(priority=qt.QThread.LowPriority)
def _update_settings(self):
self.window_size = self._window.getWindowSize()
self.polynomial_order = self._window.getPolynomialOrder()
......@@ -178,26 +129,3 @@ class NoiseOW(
"e_max": self.e_max,
},
}
class QNoise(est.core.process.noise.NoiseProcess):
"""
Normalization able to give advancement using qt.Signal and QThreadPool
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# self._advancement = QProgress("noise")
def _pool_process(self, xas_obj):
self.pool = qt.QThreadPool()
self.pool.setMaxThreadCount(5)
for spectrum in xas_obj.spectra:
runnable = ProcessRunnable(
fct=est.core.process.noise.process_noise_savgol,
spectrum=spectrum,
configuration=xas_obj.configuration,
# callback=self._advancement.increaseAdvancement,
)
self.pool.start(runnable)
self.pool.waitForDone()
Markdown is supported
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