Commit 6f127e5e authored by payno's avatar payno
Browse files

[refactoring] add pymca and larch modules in process

parent d3997301
......@@ -29,7 +29,8 @@ __date__ = "07/08/2019"
from silx.gui import qt
from xas.core.process.progress import Progress
from xas.core.process.pymca.progress import Progress
class QProgress(Progress, qt.QObject):
......
......@@ -28,19 +28,23 @@ __license__ = "MIT"
__date__ = "06/07/2019"
from silx.gui import qt
from silx.gui.plot import LegendSelector
import functools
import logging
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from PyMca5.PyMcaGui.physics.xas.XASPostEdgeParameters import \
XASPostEdgeParameters
from silx.gui import qt
from silx.gui.plot import LegendSelector
import xas.core.process.pymca.exafs
from orangecontrib.xas.process import _PyMcaProcessForOrangeMixIn, \
ProcessRunnable
from xas.core.types import XASObject, Spectrum
import xas.core.process.exafs
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
from ..progress import QProgress
from orangecontrib.xas.process import _PyMcaProcessForOrangeMixIn, ProcessRunnable
from PyMca5.PyMcaGui.physics.xas.XASPostEdgeParameters import XASPostEdgeParameters
import functools
import logging
_logger = logging.getLogger(__file__)
......@@ -164,7 +168,7 @@ class ExafsOW(_PyMcaProcessForOrangeMixIn, OWWidget):
inputs = [("spectra", XASObject, "process")]
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.exafs.PyMca_exafs
process_function = xas.core.process.pymca.exafs.PyMca_exafs
_pymcaSettings = Setting(dict())
"""Store the configuration of the PyMca XASClass"""
......@@ -223,20 +227,20 @@ class ExafsOW(_PyMcaProcessForOrangeMixIn, OWWidget):
self._progress.widget.progressBarSet(value)
class QPyMca_exafs(xas.core.process.exafs.PyMca_exafs):
class QPyMca_exafs(xas.core.process.pymca.exafs.PyMca_exafs):
"""
Normalization able to give advancement using qt.Signal and QThreadPool
"""
def __init__(self):
xas.core.process.exafs.PyMca_exafs.__init__(self)
xas.core.process.pymca.exafs.PyMca_exafs.__init__(self)
self._advancement = QProgress('normalization')
def _pool_process(self, xas_obj):
self.pool = qt.QThreadPool()
self.pool.setMaxThreadCount(5)
for spectrum in xas_obj.spectra:
runnable = ProcessRunnable(fct=xas.core.process.exafs.process_spectr_exafs,
runnable = ProcessRunnable(fct=xas.core.process.pymca.exafs.process_spectr_exafs,
spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement)
......
......@@ -28,19 +28,23 @@ __license__ = "MIT"
__date__ = "06/07/2019"
from silx.gui import qt
from silx.gui.plot import LegendSelector
import functools
import logging
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from PyMca5.PyMcaGui.physics.xas.XASFourierTransformParameters import \
XASFourierTransformParameters
from silx.gui import qt
from silx.gui.plot import LegendSelector
import xas.core.process.pymca.ft
from orangecontrib.xas.process import _PyMcaProcessForOrangeMixIn, \
ProcessRunnable
from xas.core.types import XASObject, Spectrum
import xas.core.process.ft
from ..progress import QProgress
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
from PyMca5.PyMcaGui.physics.xas.XASFourierTransformParameters import XASFourierTransformParameters
from orangecontrib.xas.process import _PyMcaProcessForOrangeMixIn, ProcessRunnable
import functools
import logging
from ..progress import QProgress
_logger = logging.getLogger(__file__)
......@@ -188,7 +192,7 @@ class FTOW(_PyMcaProcessForOrangeMixIn, OWWidget):
inputs = [("spectra", XASObject, "process")]
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.ft.PyMca_ft
process_function = xas.core.process.pymca.ft.PyMca_ft
_pymcaSettings = Setting(dict())
"""Store the configuration of the PyMca XASClass"""
......@@ -247,19 +251,19 @@ class FTOW(_PyMcaProcessForOrangeMixIn, OWWidget):
self._progress.widget.progressBarSet(value)
class QPyMca_ft(xas.core.process.ft.PyMca_ft):
class QPyMca_ft(xas.core.process.pymca.ft.PyMca_ft):
"""
Normalization able to give advancement using qt.Signal and QThreadPool
"""
def __init__(self):
xas.core.process.ft.PyMca_ft.__init__(self)
xas.core.process.pymca.ft.PyMca_ft.__init__(self)
self._advancement = QProgress('normalization')
def _pool_process(self, xas_obj):
self.pool = qt.QThreadPool()
self.pool.setMaxThreadCount(5)
for spectrum in xas_obj.spectra:
runnable = ProcessRunnable(fct=xas.core.process.ft.process_spectr_ft,
runnable = ProcessRunnable(fct=xas.core.process.pymca.ft.process_spectr_ft,
spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement)
......
......@@ -27,19 +27,19 @@ __authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "06/07/2019"
import functools
import logging
from silx.gui.plot import LegendSelector
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from silx.gui import qt
from xas.core.types import XASObject, Spectrum
import xas.core.process.k_weight
import xas.core.process.pymca.k_weight
from orangecontrib.xas.process import _PyMcaProcessForOrangeMixIn, \
ProcessRunnable
from xas.core.types import XASObject
from ..progress import QProgress
from orangecontrib.xas.process import _PyMcaProcessForOrangeMixIn, ProcessRunnable
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
import functools
import logging
_logger = logging.getLogger(__file__)
......@@ -82,7 +82,7 @@ class KWeightOW(_PyMcaProcessForOrangeMixIn, OWWidget):
inputs = [("spectra", XASObject, "process")]
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.k_weight.PyMca_k_weight
process_function = xas.core.process.pymca.k_weight.PyMca_k_weight
_kWeightSetting = Setting(int(3))
"""Store the configuration of the PyMca XASClass"""
......@@ -140,12 +140,12 @@ class KWeightOW(_PyMcaProcessForOrangeMixIn, OWWidget):
self._progress.widget.progressBarSet(value)
class QPyMca_k_weight(xas.core.process.k_weight.PyMca_k_weight):
class QPyMca_k_weight(xas.core.process.pymca.k_weight.PyMca_k_weight):
"""
Normalization able to give advancement using qt.Signal and QThreadPool
"""
def __init__(self):
xas.core.process.k_weight.PyMca_k_weight.__init__(self)
xas.core.process.pymca.k_weight.PyMca_k_weight.__init__(self)
self._advancement = QProgress('normalization')
def _pool_process(self, xas_obj):
......@@ -153,7 +153,7 @@ class QPyMca_k_weight(xas.core.process.k_weight.PyMca_k_weight):
self.pool.setMaxThreadCount(5)
for spectrum in xas_obj.spectra:
assert 'KWeight' in xas_obj.configuration
runnable = ProcessRunnable(fct=xas.core.process.k_weight.process_spectr_k,
runnable = ProcessRunnable(fct=xas.core.process.pymca.k_weight.process_spectr_k,
spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement)
......
......@@ -28,19 +28,23 @@ __license__ = "MIT"
__date__ = "06/07/2019"
from silx.gui import qt
from silx.gui.plot import LegendSelector
import functools
import logging
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from Orange.widgets.settings import Setting
from PyMca5.PyMcaGui.physics.xas.XASNormalizationParameters import XASNormalizationParameters
from ..progress import QProgress
from Orange.widgets.widget import OWWidget
from PyMca5.PyMcaGui.physics.xas.XASNormalizationParameters import \
XASNormalizationParameters
from silx.gui import qt
from silx.gui.plot import LegendSelector
import xas.core.process.pymca.normalization
from orangecontrib.xas.process import _PyMcaProcessForOrangeMixIn, \
ProcessRunnable
from xas.core.types import XASObject, Spectrum
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
import xas.core.process.normalization
from orangecontrib.xas.process import _PyMcaProcessForOrangeMixIn, ProcessRunnable
import functools
import logging
from ..progress import QProgress
_logger = logging.getLogger(__file__)
......@@ -173,7 +177,7 @@ class NormalizationOW(_PyMcaProcessForOrangeMixIn, OWWidget):
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.normalization.PyMca_normalization
process_function = xas.core.process.pymca.normalization.PyMca_normalization
_pymcaSettings = Setting(dict())
"""Store the configuration of the PyMca XASClass"""
......@@ -230,20 +234,21 @@ class NormalizationOW(_PyMcaProcessForOrangeMixIn, OWWidget):
thread.start(priority=qt.QThread.LowPriority)
class QPyMca_normalization(xas.core.process.normalization.PyMca_normalization):
class QPyMca_normalization(
xas.core.process.pymca.normalization.PyMca_normalization):
"""
Normalization able to give advancement using qt.Signal and QThreadPool
"""
def __init__(self):
xas.core.process.normalization.PyMca_normalization.__init__(self)
xas.core.process.pymca.normalization.PyMca_normalization.__init__(self)
self._advancement = QProgress('normalization')
def _pool_process(self, xas_obj):
self.pool = qt.QThreadPool()
self.pool.setMaxThreadCount(5)
for spectrum in xas_obj.spectra:
runnable = ProcessRunnable(fct=xas.core.process.normalization.process_spectr_norm,
runnable = ProcessRunnable(fct=xas.core.process.pymca.normalization.process_spectr_norm,
spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement)
......
......@@ -28,14 +28,16 @@ __license__ = "MIT"
__date__ = "02/10/2018"
import logging
from silx.gui import qt
from xas.core.types import XASObject
from xas.gui.roiselector import ROISelector
import xas.core.process.roi
from Orange.canvas.registry.description import InputSignal, OutputSignal
from Orange.widgets import gui
from Orange.widgets.widget import OWWidget
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from silx.gui import qt
import xas.core.process.pymca.roi
from xas.core.types import XASObject
from xas.gui.roiselector import ROISelector
_logger = logging.getLogger(__file__)
......@@ -58,7 +60,7 @@ class RoiSelectionOW(OWWidget):
inputs = [InputSignal(name="spectra", type=XASObject, handler='process')]
outputs = [OutputSignal(name="spectra", type=XASObject)]
process_function = xas.core.process.roi.ROIProcess
process_function = xas.core.process.pymca.roi.ROIProcess
want_main_area = True
resizing_enabled = True
......@@ -102,8 +104,8 @@ class RoiSelectionOW(OWWidget):
return
try:
roi_process = xas.core.process.roi.ROIProcess()
xas_roi = xas.core.process.roi._ROI.from_silx_def(
roi_process = xas.core.process.pymca.roi.ROIProcess()
xas_roi = xas.core.process.pymca.roi._ROI.from_silx_def(
self.getROI()).to_dict()
roi_prop = {'roi': xas_roi}
roi_process.setProperties(roi_prop)
......
......@@ -28,16 +28,19 @@ __license__ = "MIT"
__date__ = "06/11/2019"
import logging
import os
from Orange.widgets import gui
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from silx.gui import qt
from silx.io.url import DataUrl
import xas.core.io
from xas.core.types import XASObject
from xas.gui.xas_object_definition import XASObjectDialog
import xas.core.io
from Orange.widgets.settings import Setting
import os
import logging
_logger = logging.getLogger(__file__)
......@@ -103,7 +106,7 @@ class XASInputOW(OWWidget):
qt.QMessageBox.warning(self, '', str(e))
else:
if _DEBUG is True and xas_obj.n_spectrum > 100:
from xas.core.process.roi import ROIProcess, _ROI
from xas.core.process.pymca.roi import ROIProcess, _ROI
roiProcess = ROIProcess()
roiProcess.setRoi(origin=(0, 0), size=(10, 10))
xas_obj = roiProcess.process(xas_obj)
......
......@@ -27,19 +27,21 @@ __license__ = "MIT"
__date__ = "06/26/2019"
import os
import shutil
import tempfile
import unittest
import numpy
from xas.core.process.exafs import PyMca_exafs
from xas.core.process.normalization import PyMca_normalization
from xas.core.process.k_weight import PyMca_k_weight
from xas.core.process.ft import PyMca_ft
from xas.core.utils import spectra as spectra_utils
from xas.core.types import XASObject
from xas.core.process.k_weight import PyMca_k_weight
from xas.core.io import XASWriter
from xas.core.process.pymca.normalization import PyMca_normalization
from xas.core.types import XASObject
from xas.core.utils import spectra as spectra_utils
from ..reprocessing import exec_
import unittest
import tempfile
import shutil
import numpy
import os
class TestReprocessing(unittest.TestCase):
......
......@@ -69,13 +69,19 @@ def process_spectr_exafs(spectrum, configuration, overwrite=True, callback=None,
_logger.warning('spectrum has not been normalized, will not process exafs')
return None, None
print('1')
e0 = pymca_xas.calculateE0()
ddict = spectrum.to_dict()
ddict["Energy"] = pymca_xas._energy
ddict["Mu"] = pymca_xas._mu
cleanMu = pymca_xas._mu - ddict["NormalizedBackground"]
kValues = e2k(pymca_xas._energy - e0)
print('2')
# print(pymca_xas['Knots'])
# TODO: ["Knots"] and ["Knots"]["Values"] should be passed in configuration
# ["Knots"]["Values"]
ddict.update(pymca_xas.postEdge(kValues, cleanMu))
print('3')
dataSet = numpy.zeros((cleanMu.size, 2), numpy.float)
dataSet[:, 0] = kValues
......@@ -95,10 +101,10 @@ def process_spectr_exafs(spectrum, configuration, overwrite=True, callback=None,
res_spectrum = Spectrum.from_dict(ddict=ddict)
def get_output(orignal_spec, res_spec):
def get_output(original_spec, res_spec):
if overwrite:
orignal_spec.update(res_spec)
return orignal_spec
original_spec.update(res_spec)
return original_spec
else:
return res_spec
......
......@@ -27,14 +27,15 @@ __authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "06/11/2019"
from xas.core.types import XASObject, Spectrum
from xas.core.process.exafs import process_spectr_exafs
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass, e2k
import multiprocessing
import functools
import numpy
from .process import Process
import logging
import multiprocessing
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass, e2k
from xas.core.process.pymca.exafs import process_spectr_exafs
from xas.core.types import XASObject, Spectrum
from .process import Process
_logger = logging.getLogger(__name__)
......
......@@ -29,6 +29,7 @@ __license__ = "MIT"
__date__ = "07/08/2019"
import sys
from enum import Enum
import logging
_logger = logging.getLogger(__name__)
......@@ -62,7 +63,7 @@ class _Advancement(Enum):
else:
return _Advancement.step_1
import sys
class Progress(object):
"""Simple interface for defining advancement on a 100 percentage base"""
def __init__(self, name):
......
# coding: utf-8
# /*##########################################################################
# Copyright (C) 2016-2017 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ############################################################################*/
__authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "07/25/2019"
import unittest
from .test_io import suite as test_io_suite
from .test_exafs import suite as test_exafs_suite
from .test_ft import suite as test_ft_suite
from .test_k_weight import suite as test_k_weight_suite
from .test_normalization import suite as test_normalization_suite
from .test_roi import suite as test_roi_suite
from .test_workflow import suite as test_workflow_suite
def suite():
test_suite = unittest.TestSuite()
test_suite.addTest(test_io_suite())
test_suite.addTest(test_exafs_suite())
test_suite.addTest(test_ft_suite())
test_suite.addTest(test_k_weight_suite())
test_suite.addTest(test_normalization_suite())
test_suite.addTest(test_roi_suite())
test_suite.addTest(test_workflow_suite())
return test_suite
......@@ -27,13 +27,15 @@ __license__ = "MIT"
__date__ = "06/11/2019"
import os
import unittest
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.core.process.exafs import pymca_exafs
from xas.core.process.normalization import pymca_normalization
from xas.core.process.pymca.normalization import pymca_normalization
from xas.core.types import Spectrum, XASObject
from xas.io.utils.pymca import read_spectrum
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
import os
class TestEXAFSSingleSpectrum(unittest.TestCase):
......@@ -42,8 +44,10 @@ class TestEXAFSSingleSpectrum(unittest.TestCase):
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(data_file)
spectrum = Spectrum(energy=energy, mu=mu)
exafs_configuration = {"Knots": {"Values": (1, 2, 5), "Number": 3}}
configuration = {'EXAFS': exafs_configuration}
self.input_ = XASObject(energy=energy, spectra=(spectrum,), dim1=1,
dim2=1)
dim2=1, configuration=configuration)
# first process normalization
self.preproc_input_ = pymca_normalization(xas_obj=self.input_)
......
......@@ -27,15 +27,17 @@ __license__ = "MIT"
__date__ = "06/11/2019"
import os
import unittest
from xas.core.process.ft import pymca_ft
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
from xas.io.utils.pymca import read_spectrum
from xas.core.process.normalization import pymca_normalization
from xas.core.process.k_weight import pymca_k_weight
from xas.core.process.exafs import pymca_exafs
from xas.core.process.ft import pymca_ft
from xas.core.process.k_weight import pymca_k_weight
from xas.core.process.pymca.normalization import pymca_normalization
from xas.core.types import XASObject, Spectrum
import os
from xas.io.utils.pymca import read_spectrum
class TestFTSingleSpectrum(unittest.TestCase):
......
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