Commit 9e901b20 authored by payno's avatar payno Committed by Henri Payno
Browse files

[orange contrib] continue adding orange widgets

parent 127693a5
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="64px"
height="64px"
id="svg2985"
version="1.1"
inkscape:version="0.48.5 r10040"
sodipodi:docname="mback.svg">
<defs
id="defs2987" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="5.5"
inkscape:cx="32.363636"
inkscape:cy="17.454545"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:document-units="px"
inkscape:grid-bbox="true"
inkscape:window-width="1920"
inkscape:window-height="1098"
inkscape:window-x="0"
inkscape:window-y="31"
inkscape:window-maximized="1" />
<metadata
id="metadata2990">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<text
xml:space="preserve"
style="font-size:23.98252678px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Amiri;-inkscape-font-specification:Amiri"
x="1.0966778"
y="26.2125"
id="text2993"
sodipodi:linespacing="125%"
transform="scale(0.99101565,1.0090658)"><tspan
sodipodi:role="line"
id="tspan2995"
x="1.0966778"
y="26.2125">mback</tspan><tspan
sodipodi:role="line"
x="1.0966778"
y="56.190655"
id="tspan2984">norm</tspan></text>
</g>
</svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="64px"
height="64px"
id="svg2985"
version="1.1"
inkscape:version="0.48.5 r10040"
sodipodi:docname="New document 2">
<defs
id="defs2987" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="5.5"
inkscape:cx="32"
inkscape:cy="32"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:document-units="px"
inkscape:grid-bbox="true"
inkscape:window-width="1920"
inkscape:window-height="1098"
inkscape:window-x="0"
inkscape:window-y="31"
inkscape:window-maximized="1" />
<metadata
id="metadata2990">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Amiri;-inkscape-font-specification:Amiri"
x="2.1818182"
y="36.545456"
id="text2993"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan2995"
x="2.1818182"
y="36.545456"
style="font-size:18px">pre edge</tspan></text>
</g>
</svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="64px"
height="64px"
id="svg2985"
version="1.1"
inkscape:version="0.48.5 r10040"
sodipodi:docname="New document 2">
<defs
id="defs2987" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="5.5"
inkscape:cx="32"
inkscape:cy="32"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:document-units="px"
inkscape:grid-bbox="true"
inkscape:window-width="1920"
inkscape:window-height="1178"
inkscape:window-x="1920"
inkscape:window-y="0"
inkscape:window-maximized="1" />
<metadata
id="metadata2990">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Amiri;-inkscape-font-specification:Amiri"
x="9.818182"
y="39.81818"
id="text2993"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan2995"
x="9.818182"
y="39.81818"
style="font-size:30px">xftf</tspan></text>
</g>
</svg>
......@@ -121,7 +121,7 @@ class MbackOW(_ProcessForOrangeMixIn, OWWidget):
icon = "icons/mback.png"
priority = 5
category = "esrfWidgets"
keywords = ["spectroscopy", "backm"]
keywords = ["spectroscopy", "mback"]
want_main_area = True
resizing_enabled = True
......@@ -139,7 +139,7 @@ class MbackOW(_ProcessForOrangeMixIn, OWWidget):
super().__init__()
self._latest_xas_obj = None
self._window = MbackWindow(parent=self)
layout = gui.vBox(self.mainArea, 'backm').layout()
layout = gui.vBox(self.mainArea, 'mback').layout()
layout.addWidget(self._window)
self._window.xasObjViewer.setWindowTitle('spectra')
......@@ -190,7 +190,7 @@ class QLarch_mback(xas.core.process.larch.mback.Larch_mback):
def __init__(self):
xas.core.process.larch.mback.Larch_mback.__init__(self)
self._advancement = QProgress('backm')
self._advancement = QProgress('mback')
def _pool_process(self, xas_obj):
self.pool = qt.QThreadPool()
......@@ -198,7 +198,7 @@ class QLarch_mback(xas.core.process.larch.mback.Larch_mback):
for spectrum in xas_obj.spectra:
runnable = ProcessRunnable(fct=xas.core.process.larch.mback.process_spectr_mback,
spectrum=spectrum,
configuration=xas_obj.configuration['mback'],
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement)
self.pool.start(runnable)
self.pool.waitForDone()
# 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__ = "06/07/2019"
import functools
import logging
from Orange.widgets import gui
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from silx.gui import qt
from silx.gui.plot import LegendSelector
import xas.core.process.larch.mback_norm
from orangecontrib.xas.process import _ProcessForOrangeMixIn
from orangecontrib.xas.process import ProcessRunnable
from xas.core.types import XASObject, Spectrum
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
from xas.gui.larch.mback import _MBackParameters
from orangecontrib.xas.progress import QProgress
_logger = logging.getLogger(__file__)
def _plot_fpp(spectrum):
assert isinstance(spectrum, Spectrum)
if not hasattr(spectrum, 'fpp'):
_logger.error('fpp has not been computed yet')
return
return _CurveOperation(x=spectrum.energy, y=spectrum.fpp, legend='fpp')
def _plot_f2(spectrum):
assert isinstance(spectrum, Spectrum)
if not hasattr(spectrum, 'f2'):
_logger.error('f2 has not been computed yet')
return
return _CurveOperation(x=spectrum.energy, y=spectrum.f2, legend='f2')
class Mback_normWindow(qt.QMainWindow):
def __init__(self, parent=None):
qt.QMainWindow.__init__(self, parent)
# xas object viewer
mapKeys = ['Mu', 'fpp', 'f2']
self.xasObjViewer = XasObjectViewer(mapKeys=mapKeys)
self.xasObjViewer._spectrumViews[0]._plot.getXAxis().setLabel("Energy (eV)")
self.setCentralWidget(self.xasObjViewer)
self._parametersWindow = _MBackParameters(parent=self)
dockWidget = qt.QDockWidget(parent=self)
# parameters window
dockWidget.setWidget(self._parametersWindow)
self.addDockWidget(qt.Qt.RightDockWidgetArea, dockWidget)
dockWidget.setAllowedAreas(qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea)
dockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
# legend selector
self.legendDockWidget = LegendSelector.LegendsDockWidget(parent=self,
plot=self.xasObjViewer._spectrumViews[0]._plot)
self.legendDockWidget.setAllowedAreas(qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea)
self.legendDockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
self.addDockWidget(qt.Qt.RightDockWidgetArea, self.legendDockWidget)
# volume key selection
self.addDockWidget(qt.Qt.RightDockWidgetArea,
self.xasObjViewer._mapView.keySelectionDocker)
# plot settings
for ope in (_plot_fpp, _plot_f2):
self.xasObjViewer._spectrumViews[0].addCurveOperation(ope)
self.setWindowFlags(qt.Qt.Widget)
# connect signal / slot
self.xasObjViewer.viewTypeChanged.connect(self._updateLegendView)
# set up
self._updateLegendView()
def _updateLegendView(self):
index, viewType = self.xasObjViewer.getViewType()
self.legendDockWidget.setVisible(viewType is ViewType.spectrum)
self.xasObjViewer._mapView.keySelectionDocker.setVisible(viewType is ViewType.map)
class Mback_normOW(_ProcessForOrangeMixIn, OWWidget):
"""
Widget used for signal extraction
"""
name = "mback norm"
id = "orange.widgets.xas.larch.mback_norm"
description = "simplified version of MBACK to Match mu(E) data for " \
"tabulated f''(E) for normalization"
icon = "icons/mback_norm.svg"
priority = 6
category = "esrfWidgets"
keywords = ["spectroscopy", "mback_norm"]
want_main_area = True
resizing_enabled = True
inputs = [("spectra", XASObject, "process")]
outputs = [("spectra", XASObject), ("curves", tuple)]
process_function = xas.core.process.larch.mback_norm.Larch_mback_norm
_larchSettings = Setting(dict())
"""Store the configuration of the larch configuration"""
def __init__(self):
super().__init__()
self._latest_xas_obj = None
self._window = Mback_normWindow(parent=self)
layout = gui.vBox(self.mainArea, 'mback_norm').layout()
layout.addWidget(self._window)
self._window.xasObjViewer.setWindowTitle('spectra')
# manage settings
if self._larchSettings != dict():
self._window._parametersWindow.setParameters(self._larchSettings)
# connect signals / slots
self._window._parametersWindow.sigChanged.connect(self._updateProcess)
def _updateProcess(self):
self._update_settings()
if self._latest_xas_obj:
self.process(self._latest_xas_obj)
def _update_settings(self):
self._larchSettings = self._window._parametersWindow.getParameters()
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.copy()
self._startProcess()
# setup the normalization process
process_obj = QLarch_mback()
process_obj._advancement.sigProgress.connect(self._setProgressValue)
process_obj.setProperties({
'_larchSettings': self._window._parametersWindow.getParameters()})
# update the processing thread
thread = self.getProcessingThread()
thread.init(process_obj=process_obj, xas_obj=xas_obj)
self._callback_finish = functools.partial(self._endProcess, xas_obj)
thread.finished.connect(self._callback_finish)
# start processing
thread.start(priority=qt.QThread.LowPriority)
class QLarch_mback(xas.core.process.larch.mback_norm.Larch_mback_norm):
"""
Normalization able to give advancement using qt.Signal and QThreadPool
"""
def __init__(self):
xas.core.process.larch.mback_norm.Larch_mback_norm.__init__(self)
self._advancement = QProgress('mback_norm')
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.larch.mback_norm.process_spectr_mback_norm,
spectrum=spectrum,
configuration=xas_obj.configuration,
callback=self._advancement.increaseAdvancement)
self.pool.start(runnable)
self.pool.waitForDone()
# 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__ = "06/07/2019"
import functools
import logging
from Orange.widgets import gui
from Orange.widgets.settings import Setting
from Orange.widgets.widget import OWWidget
from silx.gui import qt
from silx.gui.plot import LegendSelector
import xas.core.process.larch.pre_edge
from orangecontrib.xas.process import _ProcessForOrangeMixIn
from orangecontrib.xas.process import ProcessRunnable
from xas.core.types import XASObject, Spectrum
from xas.gui.XasObjectViewer import XasObjectViewer, _CurveOperation, ViewType
from xas.gui.larch.pre_edge import _MPreEdgeParameters
from orangecontrib.xas.progress import QProgress
_logger = logging.getLogger(__file__)
def _plot_norm(spectrum):
assert isinstance(spectrum, Spectrum)
if not hasattr(spectrum, 'norm'):
_logger.error('norm has not been computed yet')
return
return _CurveOperation(x=spectrum.energy, y=spectrum.norm, legend='norm')
def _plot_norm_area(spectrum):
assert isinstance(spectrum, Spectrum)
if not hasattr(spectrum, 'norm_area'):
_logger.error('norm_area has not been computed yet')
return
return _CurveOperation(x=spectrum.energy, y=spectrum.norm_area, legend='norm_area')
def _plot_flat(spectrum):
assert isinstance(spectrum, Spectrum)
if not hasattr(spectrum, 'flat'):
_logger.error('flat has not been computed yet')
return
return _CurveOperation(x=spectrum.energy, y=spectrum.flat, legend='flat')
def _plot_pre_edge(spectrum):
assert isinstance(spectrum, Spectrum)
if not hasattr(spectrum, 'pre_edge'):
_logger.error('pre_edge has not been computed yet')
return
return _CurveOperation(x=spectrum.energy, y=spectrum.pre_edge, legend='pre_edge')
class MbackWindow(qt.QMainWindow):
def __init__(self, parent=None):
qt.QMainWindow.__init__(self, parent)
# xas object viewer
mapKeys = ['Mu', 'norm', 'norm_area']
self.xasObjViewer = XasObjectViewer(mapKeys=mapKeys)
self.xasObjViewer._spectrumViews[0]._plot.getXAxis().setLabel("Energy (eV)")
self.setCentralWidget(self.xasObjViewer)
self._parametersWindow = _MPreEdgeParameters(parent=self)
dockWidget = qt.QDockWidget(parent=self)
# parameters window
dockWidget.setWidget(self._parametersWindow)
self.addDockWidget(qt.Qt.RightDockWidgetArea, dockWidget)
dockWidget.setAllowedAreas(qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea)
dockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
# legend selector
self.legendDockWidget = LegendSelector.LegendsDockWidget(parent=self,
plot=self.xasObjViewer._spectrumViews[0]._plot)
self.legendDockWidget.setAllowedAreas(qt.Qt.RightDockWidgetArea | qt.Qt.LeftDockWidgetArea)
self.legendDockWidget.setFeatures(qt.QDockWidget.NoDockWidgetFeatures)
self.addDockWidget(qt.Qt.RightDockWidgetArea, self.legendDockWidget)
# volume key selection
self.addDockWidget(qt.Qt.RightDockWidgetArea,
self.xasObjViewer._mapView.keySelectionDocker)
# plot settings
for ope in (_plot_flat, _plot_norm, _plot_norm_area, _plot_pre_edge):
self.xasObjViewer._spectrumViews[0].addCurveOperation(ope)
self.setWindowFlags(qt.Qt.Widget)
# connect signal / slot
self.xasObjViewer.viewTypeChanged.connect(self._updateLegendView)
# set up
self._updateLegendView()
def _updateLegendView(self):
index, viewType = self.xasObjViewer.getViewType()
self.legendDockWidget.setVisible(viewType is ViewType.spectrum)
self.xasObjViewer._mapView.keySelectionDocker.setVisible(viewType is ViewType.map)
class MPreEdgeOW(_ProcessForOrangeMixIn, OWWidget):
"""
Widget used for signal extraction
"""
name = "pre edge"
id = "orange.widgets.xas.larch.pre_edge"
description = """
pre edge subtraction, normalization for XAFS
This performs a number of steps:
1. determine E0 (if not supplied) from max of deriv(mu)