Example #1
0
from numpy import arange, sin, pi
from scipy.fftpack import fftfreq
from araucaria.xas import ftwindow, xftf_kwin, xftr_kwin
nfft = 2048  # number of points for FFT
ks = 0.05  # delta k (angstrom^-1)
f1 = 0.5  # freq1 (angstrom)
k = arange(0, 10, ks)
wink = ftwindow(k, x_range=(0, 10), dx1=0.5, win='sine')
chi = 0.5 * sin(2 * pi * k * f1)
chir = xftf_kwin(wink * chi, nfft=nfft, kstep=ks)
freq = fftfreq(nfft, ks)[:nfft // 2]
chiq = xftr_kwin(chir, nfft=nfft, kstep=ks)[:len(k)]
print(chiq.dtype)
# complex128

# plotting reverse FFT signal
import matplotlib.pyplot as plt
from araucaria.plot import fig_xas_template
fig, ax = fig_xas_template(panels='re', fig_pars={'kweight': 0})
line = ax[0].plot(freq, abs(chir))
xlim = ax[0].set_xlim(0, 2)
xlab = ax[0].set_xlabel('$R/\pi$ [$\AA$]')
line = ax[1].plot(k, chiq)
text = ax[1].set_xlabel(r'$q(\AA^{-1})$')
text = ax[1].set_ylabel(r'$\chi(q)$')
fig.tight_layout()
plt.show(block=False)
Example #2
0
from numpy import arange
import matplotlib.pyplot as plt
from araucaria.xas import ftwindow
from araucaria.plot import fig_xas_template
k       = arange(0, 10.1, 0.05)
k_range = [2,8]
windows = ['hanning', 'parzen', 'welch',
           'gaussian', 'sine', 'kaiser']
dk      = 1.0
fig_kws = {'sharex' : True}
fig, axes = fig_xas_template(panels='ee/ee/ee', **fig_kws)
for i, ax in enumerate(axes.flatten()):
    win  = ftwindow(k, k_range, dk, win= windows[i])
    line = ax.plot(k, win, label=windows[i])
    for val in k_range:
        line = ax.axvline(val - dk/2, color='gray', ls=':')
        line = ax.axvline(val + dk/2, color='gray', ls=':')
    leg  = ax.legend()
    text = ax.set_ylabel('')
    text = ax.set_xlabel('')
fig.tight_layout()
plt.show(block=False)
Example #3
0
import matplotlib.pyplot as plt
from araucaria.plot import fig_xas_template
pars = {
    'e_range': (0, 100),
    'mu_range': (0, 1.5),
    'k_range': (0, 15),
    'r_range': (0, 6)
}
fig, axes = fig_xas_template('dx/er', fig_pars=pars)
plt.show(block=False)
Example #4
0
from araucaria import Group
from araucaria.testdata import get_testpath
from araucaria.io import read_xmu
from araucaria.stats import rebin
from araucaria.utils import check_objattrs
fpath = get_testpath('xmu_testfile.xmu')
# extracting mu and mu_ref scans
group_mu = read_xmu(fpath, scan='mu')
bins    = 600             # number of bins
regroup = group_mu.copy() # rebinning copy of group
rebin   = rebin(regroup, bins=bins, update=True)
attrs   = ['energy', 'mu', 'mu_ref', 'rebin_stats']
check_objattrs(regroup, Group, attrs)
# [True, True, True, True]

# plotting rebinned spectrum
from araucaria.plot import fig_xas_template
import matplotlib.pyplot as plt
figpars = {'e_range' : (11850, 11900)}   # energy range
fig, ax = fig_xas_template(panels='x', fig_pars=figpars)
stdev = regroup.rebin_stats['mu_std']    # std of rebinned mu
line  = ax.plot(group_mu.energy, group_mu.mu, label='original')
line  = ax.errorbar(regroup.energy, regroup.mu, yerr=stdev, marker='o',
                    capsize=3.0, label='rebinned')
leg   = ax.legend(edgecolor='k')
lab   = ax.set_ylabel('abs [a.u]')
plt.show(block=False)
Example #5
0
from araucaria.testdata import get_testpath
from araucaria import Group
from araucaria.io import read_dnd
from araucaria.xas import pre_edge, autobk, xftf, xftr
from araucaria.utils import check_objattrs
kw = 2
k_range = [2, 10]
r_range = [0.5, 2]
fpath = get_testpath('dnd_testfile1.dat')
group = read_dnd(fpath, scan='mu')  # extracting mu and mu_ref scans
pre = pre_edge(group, update=True)
autbk = autobk(group, update=True)
fft = xftf(group, k_range=k_range, kweight=kw, update=True)
rft = xftr(group, r_range=r_range, update=True)
attrs = ['rwin', 'q', 'chiq', 'chiq_mag', 'chiq_re', 'chiq_im']
check_objattrs(group, Group, attrs)
# [True, True, True, True, True, True]

# plotting forward FFT signal
import matplotlib.pyplot as plt
from araucaria.plot import fig_xas_template
fig, ax = fig_xas_template(panels='rq', fig_pars={'kweight': kw})
line = ax[0].plot(group.r, group.chir_mag)
line = ax[0].plot(group.r, group.rwin, color='firebrick')
xlim = ax[0].set_xlim(0, 6)
line = ax[1].plot(group.k, group.k**kw * group.chi)
line = ax[1].plot(group.q, group.chiq_re)
xlim = ax[1].set_xlim(0, 12)
fig.tight_layout()
plt.show(block=False)
Example #6
0
from araucaria import Group
from araucaria.io import read_dnd
from araucaria.xas import deglitch, pre_edge, autobk
from araucaria.utils import check_objattrs
fpath = get_testpath('dnd_glitchfile.dat')
group = read_dnd(fpath, scan='fluo')  # extracting fluo and mu_ref scans
cgroup = group.copy()
degli = deglitch(cgroup, update=True)
attrs = ['index_glitches', 'energy_glitches', 'deglitch_pars']
check_objattrs(cgroup, Group, attrs)
# [True, True, True]
allclose(cgroup.energy_glitches, group.energy[cgroup.index_glitches])
# True
print(cgroup.energy_glitches)
# [7552.2789 7548.1747 7390.512  7387.2613]

# plotting original and deglitched spectrum
from araucaria.plot import fig_xas_template
import matplotlib.pyplot as plt
for g in [group, cgroup]:
    pre = pre_edge(g, update=True)
    autbk = autobk(g, update=True)
fig, ax = fig_xas_template(panels='xe')
line = ax[0].plot(group.energy, group.norm, label='original', color='tab:red')
line = ax[0].plot(cgroup.energy, cgroup.norm, label='degliched', color='k')
line = ax[1].plot(group.k, group.k**2 * group.chi, color='tab:red')
line = ax[1].plot(cgroup.k, cgroup.k**2 * cgroup.chi, color='k')
leg = ax[0].legend()
fig.tight_layout()
plt.show(block=False)