xraypy / xraylarch

Larch: Applications and Python Library for Data Analysis of X-ray Absorption Spectroscopy (XAS, XANES, XAFS, EXAFS), X-ray Fluorescence (XRF) Spectroscopy and Imaging, and more.
https://xraypy.github.io/xraylarch
Other
133 stars 64 forks source link

kstep detection for xftf #460

Closed Ameyanagi closed 1 year ago

Ameyanagi commented 1 year ago

The group.kwin recorded in the mismatch with the group.k when the when the kstep in the autobk and xftf is different. This will not affect the calculation of the R, since the R is calculated using the interpolated chi(k) and kwin, but it will affect on the plotting.

Sample code to reproduce the problem.

import matplotlib.pyplot as plt
from larch.xafs import pre_edge, autobk, xftf, ftwindow

group = Group()
group.energy = energy
group.mu = mu

pre_edge(group)

# The problem only occurs when we use non-default values for autobk or xftf
autobk(group, kstep=0.1)

# I am using hanning, kmin=2, dk=2 for clarity
xftf(group, window="hanning", kmin=1, dk=1)

correct_kwin = ftwindow(group.k, xmin=1, dx=1)

plt.plot(group.k, group.chi*group.k**2, label='chi(k)')
plt.plot(group.k, group.kwin, label='chi(k)*kwin')
plt.plot(group.k, correct_kwin, label='correct kwin')
plt.legend()
plt.xlim(0, 4)
plt.xlabel('k (A$^{-1}$)')
plt.ylabel('chi(k)')

plt.savefig('xftf.png', dpi=300)

Before correction: xftf_before_correction

After correction: xftf_after_correction

newville commented 1 year ago

@Ameyanagi Thanks -- that's a good catch!