<jupyter_start><jupyter_text>Examples of XAFS data analysis with Larch First read in some data<jupyter_code>import numpy as np
from larch.io import read_ascii
feo = read_ascii('./larch_data/feo_xafs.dat', labels = 'energy ctime i0 i1 nothing')
feo.mu = - np.log(feo.i1/feo.i0)<jupyter_output><empty_output><jupyter_text>Normalization and backgroud removal (= EXAFS extraction)<jupyter_code>from larch.xafs import autobk
autobk(feo, kweight=2, rbkg=0.8, e0=7119.0)<jupyter_output><empty_output><jupyter_text>Fourier transform<jupyter_code>from larch.xafs import xftf
xftf(feo, kweight=2, kmin=2, kmax=13.0, dk=5, kwindow='Kaiser-Bessel')<jupyter_output><empty_output><jupyter_text>Basic plots can be done directly with matplotlib. The command `%matplotlib inline` permits in-line plots, that is, images are saved in the notebook. This means that the figures are visible when the notebook is open, even without execution.<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
plt.plot(feo.energy, feo.mu)
from larch.wxlib import plotlabels as plab
plt.plot(feo.k, feo.chi*feo.k**2)
plt.xlabel(plab.k)
plt.ylabel(plab.chikw.format(2))
plt.plot(feo.k, feo.chi*feo.k**2, label='chi(k)')
plt.plot(feo.k, feo.kwin, label='window')
plt.xlabel(plab.k)
plt.ylabel(plab.chikw.format(2))
plt.legend()<jupyter_output><empty_output><jupyter_text>A work-in-progress utility is available in `sloth.utils.xafsplotter`. It is simply a wrapper on top of the wonderful `plt.subplots()`. The goal of this utility is to produce *in-line* nice figures with standard layouts ready for reporting your analysis to colleagues. With little effort/customization, those plots could be converted to publication quality figures... Currently (September 2019), not much is available. To show the idea behind, previous plots are condensed in a single figure.<jupyter_code>from sloth.utils.xafsplotter import XAFSPlotter
p = XAFSPlotter(ncols=2, nrows=2, dpi=150, figsize=(6, 4))
p.plot(feo.energy, feo.mu, label='raw', win=0)
p.plot(feo.energy, feo.i0, label='i0', win=0, side='right')
p.plot(feo.energy, feo.norm, label='norm', win=1)
p.plot(feo.k, feo.chi*feo.k**2, label='chi2', win=2)
p.plot(feo.k, feo.chi*feo.k**2, label='chi(k)', win=3)
p.plot(feo.k, feo.kwin, label='window', win=3)
p.subplots_adjust(top=0.9)
dir(feo)<jupyter_output><empty_output><jupyter_text>Test interactive plot with wxmplot.interactiveWith the following commands is possible to open an external plotting window (based on Wxpython) permitting interactive tasks.<jupyter_code>from wxmplot.interactive import plot
plot(feo.energy, feo.mu, label='mu', xlabel='Energy', ylabel='mu', show_legend=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12831033196568445, 'fraction_numerical': 0.0175307720999627, 'mean_word_length': 6.706896551724138, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '348062', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1042, 'n_tokens_neox': 994, 'n_words': 250, 'path': 'notebooks/larch.ipynb', 'repo_name': 'maurov/xraysloth', 'size': '2681'}