Commit 9fe65439 authored by Henri Payno's avatar Henri Payno
Browse files

[orangecontrib] normalize display exafs vs autobk

parent 261fddab
......@@ -46,84 +46,29 @@ from orangecontrib.xas.progress import QProgress
_logger = logging.getLogger(__file__)
def _plot_bkg(spectrum):
def _plot_spectrum(spectrum):
assert isinstance(spectrum, Spectrum)
return _CurveOperation(x=spectrum.energy, y=spectrum.mu, legend='spectrum',
yaxis=None, color='blue')
# bkg = dgroup.bkg
# ylabel = plotlabels.mu
# if label is None:
# label = 'mu'
# #endif
# emin, emax = _get_erange(dgroup, emin, emax)
# if norm:
# mu = dgroup.norm
# bkg = (dgroup.bkg - dgroup.pre_edge) / dgroup.edge_step
# ylabel = "%s (norm)" % ylabel
# label = "%s (norm)" % label
# #endif
# title = _get_title(dgroup, title=title)
#
# opts = dict(win=win, show_legend=True, linewidth=3,
# delay_draw=True, _larch=_larch)
# _plot(dgroup.energy, mu+offset, xlabel=plotlabels.energy, ylabel=ylabel,
# title=title, label=label, zorder=20, new=new, xmin=emin, xmax=emax,
# **opts)
# _plot(dgroup.energy, bkg+offset, zorder=18, label='bkg', **opts)
# if show_e0:
# _plot_axvline(dgroup.e0, zorder=2, size=3, label='E0',
# color=plotlabels.e0color, win=win, _larch=_larch)
# disp = _getDisplay(win=win, _larch=_larch)
# if disp is not None:
# disp.panel.conf.draw_legend()
def _plot_bkg(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')
if not hasattr(spectrum, 'bkg'):
_logger.error('missing bkg parameter, unable to compute bkg plot')
return
e0 = spectrum['Edge']
x = spectrum.energy - e0
y = spectrum.mu
return _CurveOperation(x=x, y=y, legend='Spectrum', yaxis=None)
def _plot_chik(spectrum):
# if kweight is None:
# kweight = 0
# xft = getattr(dgroup, 'xftf_details', None)
# if xft is not None:
# kweight = xft.call_args.get('kweight', 0)
# #endif
# #endif
#
# chi = dgroup.chi * dgroup.k ** kweight
# opts = dict(win=win, show_legend=True, delay_draw=True, linewidth=3,
# _larch=_larch)
# if label is None:
# label = 'chi'
# #endif
# title = _get_title(dgroup, title=title)
# _plot(dgroup.k, chi+offset, xlabel=plotlabels.k,
# ylabel=plotlabels.chikw.format(kweight), title=title,
# label=label, zorder=20, new=new, xmax=kmax, **opts)
#
# if show_window and hasattr(dgroup, 'kwin'):
# kwin = dgroup.kwin
# if scale_window:
# kwin = kwin*max(abs(chi))
# _plot(dgroup.k, kwin+offset, zorder=12, label='window', **opts)
assert isinstance(spectrum, Spectrum)
missing_keys = spectrum.get_missing_keys(('Edge', 'NormalizedEnergy',
'NormalizedPlotMin', 'NormalizedPlotMax',
'NormalizedMu'))
if missing_keys:
_logger.error('missing keys:', missing_keys, 'unable to compute normalized spectrum plot')
return None
return _CurveOperation(x=spectrum.energy, y=spectrum.bkg, legend='bkg',
yaxis=None, color='red')
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')
def _plot_knots(spectrum):
assert isinstance(spectrum, Spectrum)
if not hasattr(spectrum, 'autobk_details'):
_logger.error('missing bkg parameter, unable to compute bkg plot')
return
return _CurveOperation(x=spectrum.autobk_details.knots_e,
y=spectrum.autobk_details.knots_y, legend='knots',
yaxis=None, color='green', linestyle="", symbol="o")
class AutobkWindow(qt.QMainWindow):
......@@ -157,7 +102,7 @@ class AutobkWindow(qt.QMainWindow):
self.xasObjViewer._mapView.keySelectionDocker)
# plot settings
for ope in (_plot_bkg, _plot_chik):
for ope in (_plot_bkg, _plot_spectrum, _plot_knots):
self.xasObjViewer._spectrumViews[0].addCurveOperation(ope)
self.setWindowFlags(qt.Qt.Widget)
......
......@@ -547,12 +547,12 @@ class Spectrum(_Base):
@property
def norm(self):
# this alias is needed for larch
return self.normalized_mu
return self.__normalized_mu
@norm.setter
def norm(self, value):
# this alias is needed for larch
self.normalized_energy = value
self.__normalized_mu = value
@property
def normalized_energy(self):
......
......@@ -342,10 +342,12 @@ class SpectrumViewer(qt.QMainWindow):
def _plot_norm(spectrum):
assert isinstance(spectrum, Spectrum)
if not hasattr(spectrum, 'norm'):
assert spectrum.normalized_mu is not None
if spectrum.normalized_mu is None:
_logger.error('norm has not been computed yet')
return
return _CurveOperation(x=spectrum.energy, y=spectrum.norm, legend='norm',
assert len(spectrum.energy) == len(spectrum.normalized_mu)
return _CurveOperation(x=spectrum.energy, y=spectrum.normalized_mu, legend='norm',
color='red')
......@@ -354,24 +356,27 @@ def _plot_norm_area(spectrum):
if not hasattr(spectrum, 'norm_area'):
_logger.error('norm_area has not been computed yet')
return
assert len(spectrum.energy) == len(spectrum.norm_area)
return _CurveOperation(x=spectrum.energy, y=spectrum.norm_area,
legend='norm_area', color='orange')
def _plot_pre_edge(spectrum):
assert isinstance(spectrum, Spectrum)
if not hasattr(spectrum, 'pre_edge'):
if spectrum.pre_edge is None:
_logger.error('pre_edge has not been computed yet')
return
assert len(spectrum.energy) == len(spectrum.pre_edge)
return _CurveOperation(x=spectrum.energy, y=spectrum.pre_edge,
legend='pre edge', color='green')
def _plot_post_edge(spectrum):
assert isinstance(spectrum, Spectrum)
if not hasattr(spectrum, 'post_edge'):
if spectrum.post_edge is None:
_logger.error('post_edge has not been computed yet')
return
assert len(spectrum.energy) == len(spectrum.post_edge)
return _CurveOperation(x=spectrum.energy, y=spectrum.post_edge,
legend='post edge', color='black')
......
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