tschoonj / xraylib

A library for X-ray matter interaction cross sections for X-ray fluorescence applications
https://github.com/tschoonj/xraylib/wiki
Other
120 stars 54 forks source link

Anomalous scattering factors: switch to Henke #54

Closed tschoonj closed 6 years ago

tschoonj commented 6 years ago

@mdw771

I have changed the anomalous scattering database to Henke's. Can you checkout this branch and let me know if you're getting proper results now?

Thanks

Tom

mdw771 commented 6 years ago

Thanks for the update. I tried to clone the branch on my Mac with OSX 10.11 and Python 2.7 and did autoreconf -i in the directory then ./configure and make install, but got the following error:

Making all in python
swig -DVERSION="'3.3.0'" -I../include -I. -I.. -includeall -o xraylib_wrap.c -python ../src/xraylib.i
:3: Error: Unable to find 'python.swg'
../src/xraylib.i:16: Error: Unable to find 'typemaps.i'
make[2]: *** [xraylib_wrap.c] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Any suggestions on how to fix?

tschoonj commented 6 years ago

You have an incomplete or broken SWIG installation. Are you using MacPorts by any chance? If so, you can fix this error with sudo port install swig-python. Otherwise, please tell me about what platform you are using and how you installed swig.

Thanks!

mdw771 commented 6 years ago

Great! I managed to install the branch with swig fixed. I pulled out and plotted the values of f1 and f2 for C, Si, Fe and Au. In the previous conda-forge distribution with Kissel dataset the curves contained a lot of anomalies - before_filt With the new update, the curves are much smoother - aft_unfilt However I can still see a singularity point for f2 of Si around 19 keV, and not sure if there also exist similar anomalies for other elements. After filtering out abnormal values and keeping only |f1 (f2)| < 500, the curves of Si look better - aft_filt Also here is a plot of the Henke data from another source that I found at http://henke.lbl.gov/optical_constants/asf.html. These datasets seem free of abnormal values, and also extend to a lower energy range - ref_henke Here are my codes for generating the plots. The txt files being read were downloaded from the Henke database mentioned above:

import numpy as np
from xraylib import *
import matplotlib.pyplot as plt

elements = [('C', 6), ('Si', 14), ('Fe', 26), ('Au', 79)]
fig = plt.figure(figsize=(15, 14))

for i, (symb, z) in enumerate(elements):

    fig.add_subplot(2, 2, i+1)
    energy = []
    f1 = []
    f2 = []
    f = open('f_{:s}_henke.txt'.format(symb))
    for line in f.readlines():
        l = map(float, line.split())
        energy.append(l[0])
        f1.append(l[1])
        f2.append(l[2])
    energy = np.array(energy) / 1000
    f1 = np.array(f1)
    f2 = np.array(f2)
    valid = (f1 > -100) * (f1 < 100) * (f2 > -100) * (f2 < 100)
#     plt.semilogx(energy[valid], f1[valid], color='red', linestyle=(0, (1, 1)), linewidth=0.25, label='f1, Henke')
#     plt.semilogx(energy[valid], f2[valid], color='green', linestyle=(0, (1, 1)), linewidth=0.25, label='f2, Henke')
    f.close()

    f = open('f_{:s}_anom_discarded.txt'.format(symb), 'w')
    f.writelines('ev    f1    f2\n')
    f1 = []
    f2 = []
    for e in energy:
        _f1 = Fi(z, e) + z
        _f2 = -Fii(z, e)
        f1.append(_f1)
        f2.append(_f2)
        if (_f1 > -500) * (_f1 < 500) * (_f2 > -500) * (_f2 < 500):
            f.writelines('{:f} {:f} {:f}\n'.format(1000*e, _f1+z, -_f2))
    f1 = np.array(f1)
    f2 = np.array(f2)
    valid = (f1 > -500) * (f1 < 500) * (f2 > -500) * (f2 < 500)
    f.close()
    plt.semilogx(energy[valid], f1[valid], color='red', linewidth=0.25, label='f1, xraylib')
    plt.semilogx(energy[valid], f2[valid], color='green', linewidth=0.25, label='f2, xraylib')
    # plt.plot(energy, f1, color='red', linewidth=0.25, label='f1, Kissel')
    # plt.plot(energy, f2, color='green', linewidth=0.25, label='f2, Kissel')

    plt.legend()
    plt.title('{}'.format(symb))

plt.show()
tschoonj commented 6 years ago

Many thanks for testing this so quickly. I will check the anomalies tomorrow. By the way I didn't know about the official website: the data I use in this branch is coming from Bruce Ravel's Demeter, which may not include the latest changes to the Henke database.

tschoonj commented 6 years ago

I added two more commits:

  1. Use Henke's latest databases
  2. Get rid of the spikes at the absorption edges by setting the second derivatives at these points to 0.0

I cannot go as low for the energies as Henke does since he starts providing the f1 values at 29.3 eV and f2 at 10.0 eV. I am using the same energy data for both datasets so I have to use the one at 29.3 eV. I hope that's ok for you.

The only thing that's really different are the vertical jumps at the first f1 and f2 values: due to rounding errors at these positions will Fi and Fii return 0.0 as the provided energy is essentially out of range, which explains the jumps due to your adding of the atomic number, but that should be fine.

Please let me know what you think about this.

tschoonj commented 6 years ago

Hi @srio

Could you please have a look at these changes and let me know if you approve?

I am not entirely happy about this as the data stops at 30 keV which is a lot lower than the current 10 MeV we have for Kissel... It also stops at Z=92 while Kissel goes up to Z=99...

This branch would affect two functions in xraylib that rely on Fi and Fii: Atomic_Factors and Refractive_Index.

Thanks!

mdw771 commented 6 years ago

Thanks a lot for fixing the problem! Now the spike is gone, and 29.3 eV should be very sufficient as a lower bound for microscopy studies.

tschoonj commented 6 years ago

The data going up to only 30 keV is really bothering me honestly. I will look at EPDL97 tomorrow as an alternative.

altaskier commented 6 years ago

My comments on various x-ray tabulations (from a draft of a book I’m working on) are here: https://www.dropbox.com/s/cl5ybmixwlmvgnv/xray_data_tabulations.pdf?dl=0

On Aug 23, 2017, at 10:50 AM, Tom Schoonjans notifications@github.com wrote:

The data going up to only 30 keV is really bothering me honestly. I will look at EPDL97 tomorrow as an alternative.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

srio commented 6 years ago

My personal opinion:

For calculations far from the edges I never had problems. At the edges is always complicated. There are additional problems of matching the tabulated edge energies with the edges in scattering factors and cross sections.

At the end, we cannot make happy all users unless we follow my old approach in DABAX: put everything you find and let the user choose. But this was not the philosophy when we started xraylib.

srio commented 6 years ago

Chis: thanks for your comments in your appendix. I would be happy to read the last page, so what it follows after "Finally, the European Synchrotron"

Cheers, M

altaskier commented 6 years ago

Oops! Link updated. Originally it said “Finally, the European Synchrotron Radiation Laboratory is clearly inferior to the Advanced Photon Source” but I decided to change that.

CJ

On Aug 23, 2017, at 11:12 AM, Manuel Sanchez del Rio notifications@github.com wrote:

Chis: thanks for your comments in your appendix. I would be happy to read the last page, so what it follows after "Finally, the European Synchrotron"

Cheers, M

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.