Commit 8e328e49 authored by payno's avatar payno
Browse files

[process] fix plots definition

parent 6edb3bb6
......@@ -25,7 +25,8 @@
"""wrapper to the larch mback process"""
from est.core.types import Spectrum, XASObject
from est.core.process.process import Process, _NexusSpectrumDef
from est.core.process.process import Process
from est.core.process.process import _NexusSpectrumDef
from est.core.process.process import _input_desc
from est.core.process.process import _output_desc
from larch.xafs.pre_edge import pre_edge
......@@ -167,20 +168,38 @@ class Larch_pre_edge(Process):
"e0",
"Mu",
"energy",
# "mu_ref",
# "I0",
# "I1",
# "I2"
"mu_ref",
"I0",
"I1",
"I2",
),
plots=(
_NexusSpectrumDef(
signal="Mu", axes=("energy",), auxiliary_signals=None
signal="Mu",
axes=("energy",),
auxiliary_signals=None,
silx_style={"signal_scale_type": "linear"},
),
# _plot_definition(signal="energy", axes="mu", auxiliary_signal="I0, I1, I2"),
# _plot_definition(signal="energy", axes="mu",
# auxiliary_signal="mu_ref"),
_NexusSpectrumDef(
signal="flat", axes=("energy",), auxiliary_signals=None
signal="Mu",
axes=("energy",),
auxiliary_signals=("I0", "I1", "I2"),
silx_style={
"y_axis": ("I0", "I1", "I2"),
"signal_scale_type": "linear",
},
),
_NexusSpectrumDef(
signal="Mu",
axes=("energy",),
auxiliary_signals=("mu_ref",),
silx_style={"signal_scale_type": "linear"},
),
_NexusSpectrumDef(
signal="flat",
axes=("energy",),
auxiliary_signals=None,
silx_style={"signal_scale_type": "linear"},
),
),
)
......
......@@ -26,12 +26,14 @@
from est.core.types import Spectrum, XASObject
from est.core.process.process import Process
from est.core.process.process import _NexusSpectrumDef
from est.core.process.process import _input_desc
from est.core.process.process import _output_desc
from larch.xafs.xafsft import xftf
import multiprocessing
import functools
import logging
import numpy
_logger = logging.getLogger(__name__)
......@@ -93,6 +95,7 @@ def process_spectr_xftf(
"rmax_out",
"nfft",
"kstep",
"r_max",
):
if opt_name in _conf:
opts[opt_name] = _conf[opt_name]
......@@ -105,6 +108,18 @@ def process_spectr_xftf(
else:
_spectrum = Spectrum().load_frm_dict(spectrum.to_dict())
xftf(_spectrum, **opts)
if hasattr(_spectrum, "k") and hasattr(_spectrum, "chi"):
if "kweight" in opts:
kweight = opts["kweight"]
else:
kweight = 0
if "rmax" in opts and opts["rmax"] is not None:
mask = spectrum.k < opts["rmax"]
else:
mask = numpy.ones_like(spectrum.k).astype(numpy.bool)
_spectrum.masked_chi_weighted_k = spectrum.chi[mask] * (spectrum.k[mask] ** kweight)
_spectrum.masked_k = spectrum.k[mask]
if callbacks:
for callback in callbacks:
callback()
......@@ -156,7 +171,29 @@ class Larch_xftf(Process):
self._pool_process(xas_obj=_xas_obj)
self._advancement.endProcess()
self.register_process(
_xas_obj, data_keys=("chir_im", "chir_re", "chir_mag", "r")
_xas_obj,
data_keys=(
"chir_im",
"chir_re",
"chir_mag",
"r",
"masked_k",
"masked_chi_weighted_k",
),
plots=(
_NexusSpectrumDef(
signal="masked_chi_weighted_k",
axes=("masked_k",),
auxiliary_signals=None,
silx_style={"signal_scale_type": "linear"},
),
_NexusSpectrumDef(
signal="chir_mag",
axes=("r",),
auxiliary_signals=None,
silx_style={"signal_scale_type": "linear"},
),
),
)
return _xas_obj
......
......@@ -32,6 +32,7 @@ from est.core.types import Spectrum
from est.core.process.process import _input_desc
from est.core.process.process import _output_desc
from .process import Process
from .process import _NexusSpectrumDef
import scipy.signal
import logging
import numpy
......@@ -188,7 +189,18 @@ class NoiseProcess(Process):
self._advancement.startProcess()
self._pool_process(xas_obj=_xas_obj)
self._advancement.endProcess()
self.register_process(_xas_obj, data_keys=("norm_noise_savgol", "noise_savgol"))
self.register_process(
_xas_obj,
data_keys=("norm_noise_savgol", "noise_savgol", "noise_savgol_energy"),
plots=(
_NexusSpectrumDef(
signal="noise_savgol",
axes=("noise_savgol_energy",),
auxiliary_signals=None,
silx_style={"signal_scale_type": "log"},
),
),
)
return _xas_obj
def _pool_process(self, xas_obj):
......
......@@ -46,10 +46,11 @@ _output_desc = namedtuple("_output_desc", ["name", "type", "doc"])
class _NexusSpectrumDef:
"""Util function to define a Nexus plot"""
def __init__(self, signal, axes, auxiliary_signals):
def __init__(self, signal, axes, auxiliary_signals, silx_style=None):
self.__signal = None
self.__axes = None
self.__auxiliary_signals = None
self.__silx_style = silx_style
self.signal = signal
self.axes = axes
......@@ -88,6 +89,13 @@ class _NexusSpectrumDef:
else:
self.__auxiliary_signals = auxiliary_signals
@property
def silx_style(self):
if self.__silx_style is None:
return {}
else:
return self.__silx_style
class Process(object):
def __init__(self, name):
......@@ -205,21 +213,44 @@ class Process(object):
"NormalizedSignal",
"EXAFSKValues",
"EXAFSSignal",
"noise_savgol",
"mu_ref",
"I0",
"I1",
"I2",
):
relative_to = "energy"
use = "map_to"
elif key in (
"noise_savgol",
"noise_savgol_energy",
):
relative_to = "noise_savgol_energy"
use = "map_to"
elif key in ("chir_re", "chir_im", "chir_mag", "r"):
relative_to = "r"
use = "map_to"
elif key in ("ft.radius", "ft.intensity", "ft.imaginary"):
relative_to = "radius"
use = "_list_res_ft"
elif key in ("chi",):
elif key in ("masked_chi_weighted_k", "masked_k"):
relative_to = "masked_k"
use = "map_to"
elif key in (
"chi",
"k",
"chi_weighted_k",
):
relative_to = "k"
use = "map_to"
if use == "map_to":
if key == "norm_area":
continue
_data[key] = xas_obj.spectra.map_to(
key=key,
relative_to=relative_to,
)
# if we can display the result as a numpy.array 3d
try:
_data[key] = xas_obj.spectra.map_to(
......
......@@ -423,24 +423,40 @@ def write_xas_proc(
# handle signal
# plot is only handling 1D data
signal_dataset = h5f[get_path_to_result(plot.signal)]
link_dataset(dataset_to_link=signal_dataset, name=plot.signal)
try:
signal_dataset = h5f[get_path_to_result(plot.signal)]
except KeyError:
_logger.info("{} is not available".format(plot.signal))
else:
link_dataset(dataset_to_link=signal_dataset, name=plot.signal)
plot_group.attrs["signal"] = plot.signal
# handle axes
for axe in plot.axes:
axe_dataset = h5f[get_path_to_result(axe)]
link_dataset(dataset_to_link=axe_dataset, name=axe)
try:
axe_dataset = h5f[get_path_to_result(axe)]
except KeyError:
_logger.info("{} is not available".format(axe))
else:
link_dataset(dataset_to_link=axe_dataset, name=axe)
plot_group.attrs["axes"] = plot.axes
# handle auxiliary signals
if plot.auxiliary_signals is not None:
for aux_sig in plot.auxiliary_signals:
aux_sig_dataset = h5f[get_path_to_result(aux_sig)]
link_dataset(dataset_to_link=aux_sig_dataset, name=axe)
plot_group.attrs["auxiliary_signal"] = plot.auxiliary_signals
try:
aux_sig_dataset = h5f[get_path_to_result(aux_sig)]
except KeyError:
_logger.info("{} is not available".format(aux_sig))
else:
link_dataset(dataset_to_link=aux_sig_dataset, name=aux_sig)
plot_group.attrs["auxiliary_signals"] = plot.auxiliary_signals
if plot.silx_style is not None:
import json
plot_group.attrs["SILX_style"] = json.dumps(plot.silx_style)
# save plots
for i_plot, plot in enumerate(plots):
print("try to create plot", plot)
plot_name = "plot_{}".format(i_plot)
save_plot(plot_name=plot_name, plot=plot)
......
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