Skip to content

Commit

Permalink
Merge branch 'xraypy:master' into struct2xas
Browse files Browse the repository at this point in the history
  • Loading branch information
maurov authored Sep 22, 2023
2 parents 040b547 + 0196cc5 commit 98300d1
Show file tree
Hide file tree
Showing 58 changed files with 12,424 additions and 759 deletions.
11,364 changes: 11,364 additions & 0 deletions examples/Jupyter/MonochromatorCalibrationErrors.ipynb

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions examples/feffit/doc_feffit1.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
[[Statistics]]
nvarys, npts = 4, 104
n_independent = 15.260
chi_square = 112.916714
reduced chi_square = 10.0278754
r-factor = 0.00272181
Akaike info crit = 38.5418835
Bayesian info crit = 41.4428977
chi_square = 112.91671
reduced chi_square = 10.027875
r-factor = 0.0027218
Akaike info crit = 38.541883
Bayesian info crit = 41.442898

[[Data]]
fit space = 'r'
Expand All @@ -15,15 +15,15 @@
k window, dk = 'kaiser', 4.000
paths used in fit = ['feffcu01.dat']
k-weight = 2
epsilon_k = Array(mean=6.19100e-4, std=0.00165452)
epsilon_r = 0.02080850
epsilon_k = Array(mean=6.1910e-4, std=0.0016545)
epsilon_r = 0.0208085
n_independent = 15.260

[[Variables]]
amp = 0.93155899 +/- 0.03916328 (init= 1.00000000)
del_e0 = 4.35776725 +/- 0.51134921 (init= 0.00000000)
del_r = -0.00601666 +/- 0.00261331 (init= 0.00000000)
sig2 = 0.00866969 +/- 3.07847e-4 (init= 0.00000000)
amp = 0.9315590 +/- 0.0391633 (init= 1.0000000)
del_e0 = 4.3577673 +/- 0.5113492 (init= 0.0000000)
del_r = -0.0060167 +/- 0.0026133 (init= 0.0000000)
sig2 = 0.0086697 +/- 3.0785e-4 (init= 0.0000000)

[[Correlations]] (unreported correlations are < 0.100)
amp, sig2 = 0.928
Expand All @@ -37,12 +37,12 @@
geometry atom x y z ipot
Cu 0.0000, 0.0000, 0.0000 0 (absorber)
Cu 0.0000, -1.8016, 1.8016 1
reff = 2.54780000
degen = 12.0000000
n*s02 = 0.93155899 +/- 0.03916328 := 'amp'
e0 = 4.35776725 +/- 0.51134921 := 'del_e0'
r = 2.54178334 +/- 0.00261331 := 'reff + del_r'
deltar = -0.00601666 +/- 0.00261331 := 'del_r'
sigma2 = 0.00866969 +/- 3.07847e-4 := 'sig2'
reff = 2.5478000
degen = 12.000000
n*s02 = 0.9315590 +/- 0.0391633 := 'amp'
e0 = 4.3577673 +/- 0.5113492 := 'del_e0'
r = 2.5417833 +/- 0.0026133 := 'reff + del_r'
deltar = -0.0060167 +/- 0.0026133 := 'del_r'
sigma2 = 0.0086697 +/- 3.0785e-4 := 'sig2'

=======================================================
72 changes: 36 additions & 36 deletions examples/feffit/doc_feffit2.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
[[Statistics]]
nvarys, npts = 7, 138
n_independent = 19.717
chi_square = 12.9083391
reduced chi_square = 1.01507616
r-factor = 0.00251319
Akaike info crit = 5.64826681
Bayesian info crit = 12.5185008
chi_square = 12.908339
reduced chi_square = 1.0150762
r-factor = 0.0025132
Akaike info crit = 5.6482668
Bayesian info crit = 12.518501

[[Data]]
fit space = 'r'
Expand All @@ -15,18 +15,18 @@
k window, dk = 'kaiser', 4.000
paths used in fit = ['feff0001.dat', 'feff0002.dat', 'feff0003.dat']
k-weight = 2
epsilon_k = Array(mean=0.00175498, std=0.00580695)
epsilon_r = 0.05898659
epsilon_k = Array(mean=0.0017550, std=0.0058069)
epsilon_r = 0.0589866
n_independent = 19.717

[[Variables]]
alpha = 0.00281139 +/- 0.00298005 (init= 0.00000000)
amp = 0.93628050 +/- 0.03620977 (init= 1.00000000)
c3_1 = 1.44404e-4 +/- 8.21972e-5 (init= 0.00200000)
del_e0 = 5.70426231 +/- 0.81972849 (init= 3.00000000)
sig2_1 = 0.00868052 +/- 2.83895e-4 (init= 0.00200000)
sig2_2 = 0.01310464 +/- 0.00113583 (init= 0.00200000)
sig2_3 = 0.00632924 +/- 0.00309015 (init= 0.00200000)
alpha = 0.0028114 +/- 0.0029801 (init= 0.0000000)
amp = 0.9362805 +/- 0.0362098 (init= 1.0000000)
c3_1 = 1.4440e-4 +/- 8.2197e-5 (init= 0.0020000)
del_e0 = 5.7042623 +/- 0.8197285 (init= 3.0000000)
sig2_1 = 0.0086805 +/- 2.8390e-4 (init= 0.0020000)
sig2_2 = 0.0131046 +/- 0.0011358 (init= 0.0020000)
sig2_3 = 0.0063292 +/- 0.0030901 (init= 0.0020000)

[[Correlations]] (unreported correlations are < 0.100)
alpha, c3_1 = 0.952
Expand Down Expand Up @@ -54,40 +54,40 @@
geometry atom x y z ipot
Cu 0.0000, 0.0000, 0.0000 0 (absorber)
Cu 0.0000, -1.8016, 1.8016 1
reff = 2.54780000
degen = 12.0000000
n*s02 = 0.93628050 +/- 0.03620977 := 'amp'
e0 = 5.70426231 +/- 0.81972849 := 'del_e0'
r = 2.55496285 +/- 0.01138916 := 'reff + alpha*reff'
deltar = 0.00716285 +/- 0.01138916 := 'alpha*reff'
sigma2 = 0.00868052 +/- 2.83895e-4 := 'sig2_1'
third = 1.44404e-4 +/- 8.21972e-5 := 'c3_1'
reff = 2.5478000
degen = 12.000000
n*s02 = 0.9362805 +/- 0.0362098 := 'amp'
e0 = 5.7042623 +/- 0.8197285 := 'del_e0'
r = 2.5549629 +/- 0.0113892 := 'reff + alpha*reff'
deltar = 0.0071629 +/- 0.0113892 := 'alpha*reff'
sigma2 = 0.0086805 +/- 2.8390e-4 := 'sig2_1'
third = 1.4440e-4 +/- 8.2197e-5 := 'c3_1'

= Path 'pj3m4qvfyl' = Cu K Edge
feffdat file = feff0002.dat, from feff run ''
geometry atom x y z ipot
Cu 0.0000, 0.0000, 0.0000 0 (absorber)
Cu -3.6032, 0.0000, 0.0000 1
reff = 3.60320000
degen = 6.00000000
n*s02 = 0.93628050 +/- 0.03620977 := 'amp'
e0 = 5.70426231 +/- 0.81972849 := 'del_e0'
r = 3.61332999 +/- 0.01138916 := 'reff + alpha*reff'
deltar = 0.01012999 +/- 0.01138916 := 'alpha*reff'
sigma2 = 0.01310464 +/- 0.00113583 := 'sig2_2'
reff = 3.6032000
degen = 6.0000000
n*s02 = 0.9362805 +/- 0.0362098 := 'amp'
e0 = 5.7042623 +/- 0.8197285 := 'del_e0'
r = 3.6133300 +/- 0.0113892 := 'reff + alpha*reff'
deltar = 0.0101300 +/- 0.0113892 := 'alpha*reff'
sigma2 = 0.0131046 +/- 0.0011358 := 'sig2_2'

= Path 'pibakl7xet' = Cu K Edge
feffdat file = feff0003.dat, from feff run ''
geometry atom x y z ipot
Cu 0.0000, 0.0000, 0.0000 0 (absorber)
Cu 1.8016, -1.8016, 0.0000 1
Cu 1.8016, 0.0000, -1.8016 1
reff = 3.82180000
degen = 48.0000000
n*s02 = 0.93628050 +/- 0.03620977 := 'amp'
e0 = 5.70426231 +/- 0.81972849 := 'del_e0'
r = 3.83254456 +/- 0.01138916 := 'reff + alpha*reff'
deltar = 0.01074456 +/- 0.01138916 := 'alpha*reff'
sigma2 = 0.00632924 +/- 0.00309015 := 'sig2_3'
reff = 3.8218000
degen = 48.000000
n*s02 = 0.9362805 +/- 0.0362098 := 'amp'
e0 = 5.7042623 +/- 0.8197285 := 'del_e0'
r = 3.8325446 +/- 0.0113892 := 'reff + alpha*reff'
deltar = 0.0107446 +/- 0.0113892 := 'alpha*reff'
sigma2 = 0.0063292 +/- 0.0030901 := 'sig2_3'

=======================================================
74 changes: 37 additions & 37 deletions examples/feffit/doc_feffit3.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
[[Statistics]]
nvarys, npts = 5, 390
n_independent = 56.476
chi_square = 2971.58732
reduced chi_square = 57.7275586
r-factor = 0.01637720
Akaike info crit = 233.816589
Bayesian info crit = 243.985673
chi_square = 2971.5873
reduced chi_square = 57.727559
r-factor = 0.0163772
Akaike info crit = 233.81659
Bayesian info crit = 243.98567

[[Datasets (3)]]
dataset 1:
Expand All @@ -16,8 +16,8 @@
k window, dk = 'kaiser', 4.000
paths used in fit = ['feff0001.dat']
k-weight = 2
epsilon_k = Array(mean=0.00114503, std=9.53192e-4)
epsilon_r = 0.03848548
epsilon_k = Array(mean=0.0011450, std=9.5319e-4)
epsilon_r = 0.0384855
n_independent = 18.825
dataset 2:
fit space = 'r'
Expand All @@ -26,8 +26,8 @@
k window, dk = 'kaiser', 4.000
paths used in fit = ['feff0001.dat']
k-weight = 2
epsilon_k = Array(mean=0.00107963, std=0.00104042)
epsilon_r = 0.03628736
epsilon_k = Array(mean=0.0010796, std=0.0010404)
epsilon_r = 0.0362874
n_independent = 18.825
dataset 3:
fit space = 'r'
Expand All @@ -36,16 +36,16 @@
k window, dk = 'kaiser', 4.000
paths used in fit = ['feff0001.dat']
k-weight = 2
epsilon_k = Array(mean=7.32125e-4, std=0.00131372)
epsilon_r = 0.02460739
epsilon_k = Array(mean=7.3213e-4, std=0.0013137)
epsilon_r = 0.0246074
n_independent = 18.825

[[Variables]]
alpha = 5.26893e-6 +/- 6.66322e-6 (init= 0.00000000)
amp = 0.88870032 +/- 0.03075399 (init= 1.00000000)
del_e0 = 5.37258213 +/- 0.61378630 (init= 2.00000000)
dr_off = -3.08704e-4 +/- 0.00272044 (init= 0.00000000)
theta = 233.135611 +/- 8.08151807 (init= 250.000000)
alpha = 5.2689e-6 +/- 6.6632e-6 (init= 0.0000000)
amp = 0.8887003 +/- 0.0307540 (init= 1.0000000)
del_e0 = 5.3725821 +/- 0.6137863 (init= 2.0000000)
dr_off = -3.0870e-4 +/- 0.0027204 (init= 0.0000000)
theta = 233.13561 +/- 8.0815181 (init= 250.00000)

[[Correlations]] (unreported correlations are < 0.100)
amp, theta = -0.854
Expand All @@ -60,40 +60,40 @@
geometry atom x y z ipot
Cu 0.0000, 0.0000, 0.0000 0 (absorber)
Cu 0.0000, -1.8016, 1.8016 1
reff = 2.54780000
degen = 12.0000000
n*s02 = 0.88870032 +/- 0.03075399 := 'amp'
e0 = 5.37258213 +/- 0.61378630 := 'del_e0'
r = 2.54762554 +/- 0.00266048 := 'reff + dr_off + 10*alpha*reff'
deltar = -1.74462e-4 +/- 0.00266048 := 'dr_off + 10*alpha*reff'
sigma2 = 0.00327433 +/- 1.13503e-4 := 'sigma2_eins(10, theta)'
reff = 2.5478000
degen = 12.000000
n*s02 = 0.8887003 +/- 0.0307540 := 'amp'
e0 = 5.3725821 +/- 0.6137863 := 'del_e0'
r = 2.5476255 +/- 0.0026605 := 'reff + dr_off + 10*alpha*reff'
deltar = -1.7446e-4 +/- 0.0026605 := 'dr_off + 10*alpha*reff'
sigma2 = 0.0032743 +/- 1.1350e-4 := 'sigma2_eins(10, theta)'

dataset 2:
= Path 'p3tf6mewgr' = Cu K Edge
feffdat file = feff0001.dat, from feff run ''
geometry atom x y z ipot
Cu 0.0000, 0.0000, 0.0000 0 (absorber)
Cu 0.0000, -1.8016, 1.8016 1
reff = 2.54780000
degen = 12.0000000
n*s02 = 0.88870032 +/- 0.03075399 := 'amp'
e0 = 5.37258213 +/- 0.61378630 := 'del_e0'
r = 2.54816251 +/- 0.00252272 := 'reff + dr_off + 50*alpha*reff'
deltar = 3.62506e-4 +/- 0.00252272 := 'dr_off + 50*alpha*reff'
sigma2 = 0.00333675 +/- 1.25851e-4 := 'sigma2_eins(50, theta)'
reff = 2.5478000
degen = 12.000000
n*s02 = 0.8887003 +/- 0.0307540 := 'amp'
e0 = 5.3725821 +/- 0.6137863 := 'del_e0'
r = 2.5481625 +/- 0.0025227 := 'reff + dr_off + 50*alpha*reff'
deltar = 3.6251e-4 +/- 0.0025227 := 'dr_off + 50*alpha*reff'
sigma2 = 0.0033367 +/- 1.2585e-4 := 'sigma2_eins(50, theta)'

dataset 3:
= Path 'p3tf6mewgr' = Cu K Edge
feffdat file = feff0001.dat, from feff run ''
geometry atom x y z ipot
Cu 0.0000, 0.0000, 0.0000 0 (absorber)
Cu 0.0000, -1.8016, 1.8016 1
reff = 2.54780000
degen = 12.0000000
n*s02 = 0.88870032 +/- 0.03075399 := 'amp'
e0 = 5.37258213 +/- 0.61378630 := 'del_e0'
r = 2.54950492 +/- 0.00293494 := 'reff + dr_off + 150*alpha*reff'
deltar = 0.00170492 +/- 0.00293494 := 'dr_off + 150*alpha*reff'
sigma2 = 0.00502932 +/- 2.94230e-4 := 'sigma2_eins(150, theta)'
reff = 2.5478000
degen = 12.000000
n*s02 = 0.8887003 +/- 0.0307540 := 'amp'
e0 = 5.3725821 +/- 0.6137863 := 'del_e0'
r = 2.5495049 +/- 0.0029349 := 'reff + dr_off + 150*alpha*reff'
deltar = 0.0017049 +/- 0.0029349 := 'dr_off + 150*alpha*reff'
sigma2 = 0.0050293 +/- 2.9423e-4 := 'sigma2_eins(150, theta)'

=======================================================
92 changes: 92 additions & 0 deletions examples/xafs/fft_benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from time import time
import numpy as np
fft_numpy = np.fft.fft

fft_mkln = fft_mkls = fft_ws = fft_wp = fft_wn = None

try:
import mkl_fft
from mkl_fft.interfaces.numpy_fft import fft as fft_mkln
from mkl_fft.interfaces.scipy_fft import fft as fft_mkls
except ImportError:
print("mkl not available")

try:
from pyfftw.interfaces.scipy_fft import fft as fft_ws
from pyfftw.interfaces.scipy_fftpack import fft as fft_wp
from pyfftw.interfaces.numpy_fft import fft as fft_wn
except:
print("pyfftw not available")

from scipy.fftpack import fft as fft_pack
from scipy.fft import fft as fft_scipy

from larch.io import read_ascii
from larch.xafs import pre_edge, autobk, xftf, xftf_prep


METHODS = {}
for key, val in {'numpy': fft_numpy, 'scipy': fft_scipy,
'fftpack': fft_pack,
'mkl_numpy': fft_mkln, 'mkl_scipy': fft_mkls,
'fftw_numpy': fft_wn, 'fftw_scipy': fft_ws,
'fftw_pack': fft_wp}.items():

if callable(val):
METHODS[key] = val

fname = '../xafsdata/feo_rt1.xdi'
dat = read_ascii(fname, labels='energy mu i0')

pre_edge(dat)
autobk(dat, rbkg=0.9, kweight=2)

xftf(dat, kmin=2, kmax=13, dk=3, window='hanning', kweight=2)

# plot_chir(dat, win=2)


xk = dat.k

xchi, win = xftf_prep(dat.k, dat.chi, kmin=2, kmax=13, dk=3, dk2=3,
kstep=0.05, window='hanning', kweight=2)

nfft = 2048
kstep = 0.05
rstep = np.pi /(nfft*kstep)

cchi = np.zeros(nfft, dtype='complex128')
cchi[0:len(xchi)] = xchi*win
r = rstep * np.arange(nfft//2)

rscale = kstep/np.sqrt(np.pi)
results = {}
for key in METHODS:
results[key] = None

out = {}
for key in METHODS:
out[key] = []

#warm up
for name, meth in METHODS.items():
for i in range(5):
t0 = time()
chir = rscale * meth(cchi)
results[name] = chir.real

for name, meth in METHODS.items():
for i in range(50):
t0 = time()
for j in range(25):
chir = rscale * meth(cchi)
out[name].append(1e4*(time() -t0))


k,m,s,x = 'Method', 'Mean', 'Std', 'Max'
print(f"{k:10s} : {m:8s} {s:8s} {x:8s}")
for k, v in out.items():
vn = np.array(v)
print(f"{k:10s} : {vn.mean():8.3f} {vn.std():8.3f} {vn.max():8.3f}")

print("done")
Loading

0 comments on commit 98300d1

Please sign in to comment.