Commit 1fcd2630 authored by Henri Payno's avatar Henri Payno
Browse files

[pymca/larch] start normalization between the two process. Update display and...

[pymca/larch] start normalization between the two process. Update display and check values for normalization vs pre_edge

For now this is just comparaison, no internal process is made to make fit the two libraries.
parent 46565de4
......@@ -10,6 +10,7 @@ TODO
tutorials/index.rst
install.rst
larch_pymca.rst
app/index.rst
......@@ -22,7 +23,8 @@ TODO
:doc:`tutorials/index`
tutorials for using the xas library
:doc:`larch_pymca`
pymca and larch coexistence
--------------
Orange Widgets
......
Larch and pymca compatibility
-----------------------------
Stored values on the 'xas object'. Those values are not refering to any configuration.
+------------------+----------------------+----------------------------------------------------+
| larch variables | pymca variables | info |
+==================+======================+====================================================+
| norm | | normalized spectrum, using polynomial |
+------------------+----------------------+----------------------------------------------------+
| norm_area | | normalized mu(E), using integrated area |
+------------------+----------------------+----------------------------------------------------+
| edge_step | | edge step of spectrum |
+------------------+----------------------+----------------------------------------------------+
| flat | | flattened, normalized mu(E) |
+------------------+----------------------+----------------------------------------------------+
| pre_edge | | determined pre-edge curve |
+------------------+----------------------+----------------------------------------------------+
| post_edge | | determined post-edge, normalization curve |
+------------------+----------------------+----------------------------------------------------+
| dmude | | derivative of mu(E) |
+------------------+----------------------+----------------------------------------------------+
| fpp | | mback matched spectrum |
+------------------+----------------------+----------------------------------------------------+
| f1 | | tabulated f1(E) |
+------------------+----------------------+----------------------------------------------------+
| f2 | | tabulated f2(E) |
+------------------+----------------------+----------------------------------------------------+
| delta_bkg | | |
+------------------+----------------------+----------------------------------------------------+
| delta_chi | | |
+------------------+----------------------+----------------------------------------------------+
| e0 | _energy0 | energy origin/offset |
+------------------+----------------------+----------------------------------------------------+
| chi | | |
+------------------+----------------------+----------------------------------------------------+
| chie | | |
+------------------+----------------------+----------------------------------------------------+
| bkg | | |
+------------------+----------------------+----------------------------------------------------+
| k | k | |
+------------------+----------------------+----------------------------------------------------+
| kmin | kmin | |
+------------------+----------------------+----------------------------------------------------+
| kmax | kmax | |
+------------------+----------------------+----------------------------------------------------+
| | knots | |
+------------------+----------------------+----------------------------------------------------+
| | KWeight | |
+------------------+----------------------+----------------------------------------------------+
| | KnotsX | x position of knots |
+------------------+----------------------+----------------------------------------------------+
| | KnotsY | y position of knots |
+------------------+----------------------+----------------------------------------------------+
| | PostEdgeK | |
+------------------+----------------------+----------------------------------------------------+
| | PostEdgeB | |
+------------------+----------------------+----------------------------------------------------+
| energy | Energy | |
+------------------+----------------------+----------------------------------------------------+
| mu | Mu | |
+------------------+----------------------+----------------------------------------------------+
| | Jump | |
+------------------+----------------------+----------------------------------------------------+
| | edge | |
+------------------+----------------------+----------------------------------------------------+
| | NormalizedEnergy | |
+------------------+----------------------+----------------------------------------------------+
| | NormalizedMu | |
+------------------+----------------------+----------------------------------------------------+
| | NormalizedBackground | |
+------------------+----------------------+----------------------------------------------------+
| | NormalizedSignal | |
+------------------+----------------------+----------------------------------------------------+
| | EXAFSEnergy | |
+------------------+----------------------+----------------------------------------------------+
| | EXAFSValues | |
+------------------+----------------------+----------------------------------------------------+
| | EXAFSSignal | |
+------------------+----------------------+----------------------------------------------------+
| | EXAFSNormalized | |
+------------------+----------------------+----------------------------------------------------+
| | FT | dictionary containing fourier transform result |
| | - WindowRange | |
| | - Set | |
| | - InterpolatedK | |
| | - InterpolatedSignal | |
| | - KWeight | |
| | - K | |
| | - FTRadius | |
| | - FTIntensity | |
| | - FTReal | |
| | - FTImaginary | |
+------------------+----------------------+----------------------------------------------------+
| kwin | | window function Omega(k) (length of input chi(k)) |
+------------------+----------------------+----------------------------------------------------+
| r | | uniform array of R, out to rmax_out |
+------------------+----------------------+----------------------------------------------------+
| chir | | complex array of chi(R) |
+------------------+----------------------+----------------------------------------------------+
| chir_mag | | magnitude of of chi(R) |
+------------------+----------------------+----------------------------------------------------+
| chir_re | | real part of of chi(R) |
+------------------+----------------------+----------------------------------------------------+
| chir_im | | imaginary part of of chi(R) |
+------------------+----------------------+----------------------------------------------------+
| chir_pha | | phase of of chi(R) |
+------------------+----------------------+----------------------------------------------------+
| chir | | complex array of chi(R) |
+------------------+----------------------+----------------------------------------------------+
Original functions goals:
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| larch functions | pymca functions | description | exists in xas |
+=============================+======================+===============================================================+===============+
| | processSpectrum | compute all variables for the given spectrum | YES |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| | fourierTransform | compute spectrum for fourier transform spectroscopy | YES |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| | postEdge | | YES |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| | normalize | spectrum normalization | YES |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| pre_edge | | Pre-edge subtraction and normalization | YES |
| | | - determine E0 | |
| | | - fit a line of polynomial to the region below the edge | |
| | | - fit a polynomial to the region above the edge | |
| | | - extrapolate the two curves to E0 to determine the edge jump | |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| pre_edge_baseline | | needed for metal oxides to determine oxidation state and | NO |
| | | molecular configuration. To analyze the energies and relative | |
| | | strengths of these pre-edge peaks. | |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| mback | | an alternative to pre_edge ? | YES |
| | | data are matched to the tabulated values of the imaginary part| |
| | | of the energy-dependent correction to the Thompson scattering | |
| | | factor | |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| over_absorption correction | | needed for fluorescence when too much of the total | NO |
| | | X-ray absorption coefficient is from the absorbing element | |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| spectral deconvolution | | to compare XAFS data from different source | NO |
| | | | |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| pre-edge peak fitting | | X-ray Absorption Near Edge Structure technique | NO |
| | | | |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| Linear Combination Analysis | | X-ray Absorption Near Edge Structure technique | NO |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| PCA | | X-ray Absorption Near Edge Structure technique | NO |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| autobk | | Post-edge Background Subtraction | YES |
| | | Background subtraction, convert mu to | |
| | | :math:`\chi(k)` for quantitative analysis | |
| | | (post_edge background function) | |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| xftf | | Forward XAFS Fourier transforms | YES |
| | | orward Fourier transform converts :math:`\chi(k)` to | |
| | | :math:`\chi(R)` and is of primary importance for XAFS analysis| |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| xftr | | Reverse XAFS Fourier transforms | NO |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| ftwindow | | Generating Fourier transform windows | NO |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| cauchy_wavelet | | Continuous Cauchy Wavelet transform of Munoz et al | NO |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| reading and using Feff paths| | | NO |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| fitting XAFS to Feff paths | | | NO |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
| computing anomalous | | | NO |
| scattering factors from | | | |
| XAFS data | | | |
+-----------------------------+----------------------+---------------------------------------------------------------+---------------+
therorical function equivalence:
+--------------------------------+---------------------+-------------------+-------------------------------------------+
| goal | larch function(s) | pymca function(s) | Notes |
+================================+=====================+===================+===========================================+
| pre edge sub and normalization | pre_edge | normalize | +
+--------------------------------+---------------------+-------------------+-------------------------------------------+
| post edge substraction | autobk | EXAFS (postEdge | +
| | | (include postEdge)| +
+--------------------------------+---------------------+-------------------+-------------------------------------------+
| fourier transform | xftf | fourier transform | |
+--------------------------------+---------------------+-------------------+-------------------------------------------+
\ No newline at end of file
......@@ -39,20 +39,20 @@ 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.XasObjectViewer import XasObjectViewer, _CurveOperation, _XMarkerOperation, 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')
return _CurveOperation(x=spectrum.energy, y=spectrum.norm, legend='norm',
color='red')
def _plot_norm_area(spectrum):
......@@ -60,23 +60,34 @@ def _plot_norm_area(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')
return _CurveOperation(x=spectrum.energy, y=spectrum.norm_area,
legend='norm_area', color='orange')
def _plot_flat(spectrum):
def _plot_pre_edge(spectrum):
assert isinstance(spectrum, Spectrum)
if not hasattr(spectrum, 'flat'):
_logger.error('flat has not been computed yet')
if not hasattr(spectrum, 'pre_edge'):
_logger.error('pre_edge has not been computed yet')
return
return _CurveOperation(x=spectrum.energy, y=spectrum.flat, legend='flat')
return _CurveOperation(x=spectrum.energy, y=spectrum.pre_edge,
legend='pre edge', color='green')
def _plot_pre_edge(spectrum):
def _plot_post_edge(spectrum):
assert isinstance(spectrum, Spectrum)
if not hasattr(spectrum, 'pre_edge'):
_logger.error('pre_edge has not been computed yet')
if not hasattr(spectrum, 'post_edge'):
_logger.error('post_edge has not been computed yet')
return
return _CurveOperation(x=spectrum.energy, y=spectrum.post_edge,
legend='post edge', color='black')
def _plot_edge(spectrum):
assert isinstance(spectrum, Spectrum)
if not hasattr(spectrum, 'e0'):
_logger.error('e0 has not been computed yet')
return
return _CurveOperation(x=spectrum.energy, y=spectrum.pre_edge, legend='pre_edge')
return _XMarkerOperation(x=spectrum.e0, legend='edge', color='yellow')
class MbackWindow(qt.QMainWindow):
......@@ -109,7 +120,8 @@ class MbackWindow(qt.QMainWindow):
self.xasObjViewer._mapView.keySelectionDocker)
# plot settings
for ope in (_plot_flat, _plot_norm, _plot_norm_area, _plot_pre_edge):
for ope in (_plot_norm, _plot_norm_area, _plot_pre_edge,
_plot_post_edge, _plot_edge):
self.xasObjViewer._spectrumViews[0].addCurveOperation(ope)
self.setWindowFlags(qt.Qt.Widget)
......
......@@ -43,28 +43,19 @@ import xas.core.process.pymca.normalization
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.XasObjectViewer import XasObjectViewer, _CurveOperation, _XMarkerOperation, ViewType
from orangecontrib.xas.progress import QProgress
_logger = logging.getLogger(__file__)
# TODO: we should find a way to normalize the pymca and larch variables and
# have common plot between pymca_normalization and larch_pre_edge
def _spectrum_plot(spectrum):
def _plot_norm(spectrum):
assert isinstance(spectrum, Spectrum)
missing_keys = spectrum.get_missing_keys(('Edge',))
if missing_keys:
_logger.error('missing keys:', missing_keys, 'unable to compute spectrum plot')
return
e0 = spectrum['Edge']
x = spectrum.energy - e0
y = spectrum.mu
return _CurveOperation(x=x, y=y, legend='Spectrum', yaxis=None)
def _normalized_spectrum_plot(spectrum):
assert isinstance(spectrum, Spectrum)
missing_keys = spectrum.get_missing_keys(('Edge', 'NormalizedEnergy',
'NormalizedPlotMin', 'NormalizedPlotMax',
missing_keys = spectrum.get_missing_keys(('NormalizedEnergy',
'NormalizedPlotMin',
'NormalizedPlotMax',
'NormalizedMu'))
if missing_keys:
_logger.error('missing keys:', missing_keys, 'unable to compute normalized spectrum plot')
......@@ -72,38 +63,45 @@ def _normalized_spectrum_plot(spectrum):
idx = (spectrum["NormalizedEnergy"] >= spectrum["NormalizedPlotMin"]) & \
(spectrum["NormalizedEnergy"] <= spectrum["NormalizedPlotMax"])
e0 = spectrum['Edge']
x = spectrum["NormalizedEnergy"][idx] - e0
y = spectrum["NormalizedMu"][idx]
return _CurveOperation(x=x, y=y, legend='Normalized', yaxis='right')
return _CurveOperation(x=spectrum["NormalizedEnergy"][idx],
y=spectrum["NormalizedMu"][idx],
legend='Normalized', yaxis='right',
color='red')
def _post_plot(spectrum):
def _plot_pre_edge(spectrum):
assert isinstance(spectrum, Spectrum)
missing_keys = spectrum.get_missing_keys(('Edge', 'NormalizedEnergy',
'NormalizedSignal'))
missing_keys = spectrum.get_missing_keys(('NormalizedEnergy',
'NormalizedBackground'))
if missing_keys:
_logger.error('missing keys:', missing_keys, 'unable to compute post plot')
_logger.error('missing keys:', missing_keys, 'unable to plot pre edge')
return None
e0 = spectrum['Edge']
x = spectrum['NormalizedEnergy'] - e0
y = spectrum["NormalizedSignal"]
return _CurveOperation(x=x, y=y, legend='Post', yaxis=None)
return _CurveOperation(x=spectrum['NormalizedEnergy'],
y=spectrum["NormalizedBackground"],
legend='pre edge', yaxis=None, color='green')
def _pre_plot(spectrum):
def _plot_post_edge(spectrum):
assert isinstance(spectrum, Spectrum)
missing_keys = spectrum.get_missing_keys(('Edge', 'NormalizedEnergy',
'NormalizedBackground'))
missing_keys = spectrum.get_missing_keys(('NormalizedEnergy',
'NormalizedSignal'))
if missing_keys:
_logger.error('missing keys:', missing_keys, 'unable to compute pre plot')
_logger.error('missing keys:', missing_keys, 'unable to plot post edge')
return None
e0 = spectrum['Edge']
x = spectrum['NormalizedEnergy'] - e0
y = spectrum["NormalizedBackground"]
return _CurveOperation(x=x, y=y, legend='Pre', yaxis=None)
return _CurveOperation(x=spectrum['NormalizedEnergy'],
y=spectrum["NormalizedSignal"],
legend='post edge', yaxis=None, color='black')
def _plot_edge(spectrum):
assert isinstance(spectrum, Spectrum)
missing_keys = spectrum.get_missing_keys(('Edge', ))
if missing_keys:
_logger.error('missing keys:', missing_keys, 'unable to plot edge')
return None
return _XMarkerOperation(x=spectrum['Edge'], legend='edge', color='yellow')
class NormalizationWindow(qt.QMainWindow):
......@@ -137,8 +135,7 @@ class NormalizationWindow(qt.QMainWindow):
self.xasObjViewer._mapView.keySelectionDocker)
# plot settings
for ope in (_spectrum_plot, _normalized_spectrum_plot, _post_plot,
_pre_plot):
for ope in (_plot_norm, _plot_post_edge, _plot_pre_edge, _plot_edge):
self.xasObjViewer._spectrumViews[0].addCurveOperation(ope)
self.setWindowFlags(qt.Qt.Widget)
......
......@@ -692,6 +692,9 @@ class Spectrum(_Base):
keys += list(self.__key_mapper.keys())
return keys
def copy(self):
return Spectrum().load_frm_dict(self.to_dict())
class _FT(object):
......
......@@ -240,6 +240,13 @@ class _CurveOperation(object):
self.ylabel = ylabel
class _XMarkerOperation(object):
def __init__(self, x, legend, color='blue'):
self.x = x
self.legend = legend
self.color = color
class SpectrumViewer(qt.QMainWindow):
def __init__(self, parent=None):
self._curveOperations = []
......@@ -306,16 +313,23 @@ class SpectrumViewer(qt.QMainWindow):
for operation in self._curveOperations:
res = operation(spectrum)
if res is not None and res.x is not None:
assert isinstance(res, _CurveOperation)
self._plot.addCurve(x=res.x,
y=res.y,
legend=res.legend,
yaxis=res.yaxis,
linestyle=res.linestyle,
symbol=res.symbol,
color=res.color,
ylabel=res.ylabel,
)
if isinstance(res, _CurveOperation):
self._plot.addCurve(x=res.x,
y=res.y,
legend=res.legend,
yaxis=res.yaxis,
linestyle=res.linestyle,
symbol=res.symbol,
color=res.color,
ylabel=res.ylabel,
)
elif isinstance(res, _XMarkerOperation):
self._plot.addXMarker(x=res.x,
color=res.color,
legend=res.legend)
else:
raise TypeError('this type of operation is not recognized'
'', type(res))
def clear(self):
self._plot.clear()
......
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