Commit 0f38191e authored by Wout De Nolf's avatar Wout De Nolf
Browse files

add k^n.chi plot and get kweight from larch_dict

parent b8ec91a4
Pipeline #81471 passed with stages
in 6 minutes and 50 seconds
......@@ -7,16 +7,18 @@ _Y_TO_X_NAME = {
"normalized_mu": "energy",
"flatten_mu": "energy",
"chi": "k",
"ft": "ft",
"chi_weighted_k": "k",
"ft_mag": "R",
"noise_savgol": "energy",
}
_LABELS = {
"energy": "Energy (eV)",
"mu": "μ",
"normalized_mu": "Norm(μ)",
"flatten_mu": "Norm(μ)",
"chi": "k^{kweight} χ(k) (Å^-{kweight})",
"ft": "|χ(k)| (Å^-{kweightp1})",
"mu": "μ(E)",
"normalized_mu": "Norm(μ(E))",
"flatten_mu": "Flat(μ(E))",
"chi": "χ(k)",
"chi_weighted_k": "k^{kweight} χ(k) (Å^-{kweight})",
"ft_mag": "|FT(R)| (Å^-{kweightp1})",
"k": "Wavenumber (Å^-1)",
"R": "Radius (Å)",
"noise_savgol": "Noise(μ)",
......@@ -24,28 +26,31 @@ _LABELS = {
def process_plotspectrumdata(
spectrum, plot_names: Optional[Sequence] = None, **params
spectrum, plot_names: Optional[Sequence] = None
) -> Dict[str, dict]:
kweight = params.setdefault("kweight", 1)
params.setdefault("kweightp1", kweight + 1)
kweight = spectrum.larch_dict["xftf_k_weight"]
params = {"kweight": kweight, "kweightp1": kweight + 1}
plot_data = dict()
if not plot_names:
plot_names = ("flatten_mu", "chi", "ft", "noise_savgol")
plot_names = ("flatten_mu", "chi_weighted_k", "ft_mag", "noise_savgol")
for yname in plot_names:
ylabel = _LABELS[yname]
xname = _Y_TO_X_NAME[yname]
xlabel = _LABELS[xname]
x = getattr(spectrum, xname)
y = getattr(spectrum, yname)
if xname == "ft":
x = x["FTRadius"]
y = y["FTIntensity"]
if yname == "ft_mag":
x = spectrum.ft["FTRadius"]
y = spectrum.ft["FTIntensity"]
xlabel = _LABELS["R"]
ylabel = _LABELS["ft"]
ylabel = _LABELS["ft_mag"]
else:
try:
x = getattr(spectrum, xname)
y = getattr(spectrum, yname)
except Exception:
breakpoint()
xlabel = xlabel.format(**params)
ylabel = ylabel.format(**params)
......@@ -64,15 +69,11 @@ def process_plotspectrumdata(
class PlotSpectrumData(
Task,
input_names=["xas_obj"],
optional_input_names=["plot_names", "kweight"],
optional_input_names=["plot_names"],
output_names=["plot_data"],
):
def run(self):
spectrum = next(iter(self.inputs.xas_obj.spectra.data.flat))
if self.missing_inputs.kweight:
kweight = 1
else:
kweight = self.inputs.kweight
self.outputs.plot_data = process_plotspectrumdata(
spectrum, plot_names=self.inputs.plot_names, kweight=kweight
spectrum, plot_names=self.inputs.plot_names
)
......@@ -34,11 +34,11 @@ def test_larch_plotspectrumdata(filename_cu_from_pymca):
inputs.append(
{
"id": "ft",
"name": "autobk_config",
"name": "xftf_config",
"value": {
"kmin": 0,
"kmax": 20,
"kweight": 0,
"kweight": 2,
"kw": 0,
"dk": 1,
"window": "kaiser",
......@@ -53,16 +53,24 @@ def test_larch_plotspectrumdata(filename_cu_from_pymca):
{
"id": "plotdata",
"name": "plot_names",
"value": ("flatten_mu", "normalized_mu", "mu", "chi", "ft", "noise_savgol"),
"value": (
"mu",
"flatten_mu",
"normalized_mu",
"chi_weighted_k",
"chi",
"ft_mag",
"noise_savgol",
),
}
)
result = execute_graph(_LARCH_WORKFLOW, inputs=inputs)
assert len(result["plot_data"]) == 6
assert len(result["plot_data"]) == 7
for name, data in result["plot_data"].items():
if name == "chi":
if name in ("chi", "chi_weighted_k"):
n = 324
elif name == "ft":
elif name == "ft_mag":
n = 326
else:
n = 1461
......@@ -71,10 +79,12 @@ def test_larch_plotspectrumdata(filename_cu_from_pymca):
assert data["xlabel"]
assert data["ylabel"]
assert "k^2" in result["plot_data"]["chi_weighted_k"]["ylabel"]
if False:
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 2, figsize=(10, 10), constrained_layout=True)
fig, axs = plt.subplots(2, 3, figsize=(10, 10), constrained_layout=True)
for data, ax in zip(result["plot_data"].values(), axs.flatten()):
ax.plot(data["x"], data["y"])
ax.set_xlabel(data["xlabel"])
......
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