Skip to main content

A calculator for the Kramers Kronig transform of X-ray spectra

Project description

======
KKcalc
======


Introduction
============

KKcalc is a program to calculate the real part of the refractive index of a material in the X-ray region of the spectrum from measured absorption data via the Kramers-Kronig transform. KKcalc boasts the following features:

- Easily extend measured spectra with published scattering factors.
- Efficient peicewise polynomial (direct integration) algorithm for Kramers-Kronig transform.
- Automatic calculation of the relativistic correction.
- Python source code is easy to read, so you can assess its correctness yourself.
- Freely available on a wide range of platforms.
- Graphical interface for easy use.

For support, please contact benjamin.watts@gmail.com

The major emphasis of this program is to provide **correct** results. I would be glad to be informed of any problems.


Installation
============

Simply download the software (e.g. as a zip file) and run `kk_gui.py`. The zip file contains::

kk.py
kk_gui.py
data.py
test_kk.py
PackRawData.py
ASF.json
LICENSE.txt
README.rst
asf/
elements.dat
h.nff
he.nff
...
u.nff

You will also need to install the following dependencies:

- Python_
- Numpy_ (Numerical Python)
- Scipy_ (Scientific Python) - optional package, needed only for the "fix distortions" option
- wxPython_ - optional package, needed only for the graphical user interface

.. _Python: http://www.python.org/
.. _Numpy: http://numpy.scipy.org/
.. _Scipy: http://scipy.org/
.. _wxPython: http://wxpython.org/


Basic Usage
===========

1. Start program by running `python kk_gui.py`
2. Load NEXAFS data from file by selecting: File>Load. Data is converted to atomic scattering factors and plotted upon successful loading.
3. Check that the selection box knows the type of the raw data, so that it is being converted to scattering factors correctly.
4. Enter molecular formula in the "Material" section.
5. Click on the "Calculate" button. The new real scattering factors are plotted upon completion of the Kramers-Kronig transform calculation (should only take a second, idepending on the number of data points and computing power).
6. Save data by selecting: File>Save.

For more advanced usage and scripting, check out the functions provided in the kk.py module.

Details
=======


"Near-Edge Data" Section
------------------------

Here we define a detailed section of the imaginary spectrum to be inputted into the Kramers-Kronig transform. The "File:" label simply displays the currently loaded data file. To load a new set of near-edge absorption data, select: *File>Load*. Data files must be in columns, the first giving the photon energy in electron volts and the last column giving the absorption spectrum data.

The two text-boxes in the next row, initially containing "Start" and "End" control the energy points between which the loaded data will be used. Valid entries in these controls include energy values and the strings "Start" or "End", which are understood by the program to correspond to the lowest and highest energy points, respectively, in the loaded data set.

There are two further options seen as checkboxes at the bottom of the "Near-Edge Data" section of the GUI. The "Add background" checkbox is for replacing the background (by extrapolating the pre-edge region) that may have been subtracted from the user-supplied data. This function has not been reimplemented to work with the internal data format currently used by KKcalc and the checkbox is disabled. The "Fix distortions" option (whose checkbos is disabled if the program fails to load the Scipy module) will skew the data to fit the slope of the scattering factor data. This is useful for working with data recorded using detectors with an uncalibrated energy dependence. The detector energy dependence is assumed to be approximately linear (which should hold fairly well over a short energy range) and the scattering factors may not be a good reference to fit the data to, so the use of this option is definitely not encouraged (it is always better to understand and properly normalise your data before loading into KKcalc).


"Material" Section
------------------

In this section, we define the material whose optical properties are being investigated. The first textbox is for the density of the material - a value here is only needed in converting data between scattering factors and Beta (the absorption part of the refractive index). This value will have no effect unless you are working with data loaded or saved as Beta. The second textbox is for entering the elemental composition of the material. This will be plotted and used to calculate the appropriate scattering factors to extend the user-supplied near-edge imaginary spectrum as well as to calculate the relativistic correction to the Kramers-Kronig transform.


"Calculation" Section
---------------------

KKcalc implements a piecewise polynomial algorithm that performs direct integration of the area between the data-points. User-supplied data and the scattering factor below 30,000 eV [HEN1993]_ is interpolated linearly, while the high energy scattering factor data is described by Laurent polynomials [BIG1988]_ (the scattering factor data is assembled as described by Henke et al. [HEN1993]_). Using this piecewise-polynomial expression of the imaginary spectrum, the symbolic form of the Kramers-Kronig transform integral is precisely known and can be fully written symbolically (albeit piecewise). This form is then trivial (though tedious) to symbolically integrate in a piecewise fashion everywhere except at the singularity, which is avoided by integrating across two intervals at once (terms referencing the singularity cancel out). The only assumption of this method is that the piecewise-polynomial description of the imaginary spectrum is continuous (which is required by physics), all remaining steps are exact to machine precision. This algorithm is very efficient because it doesn't require equally spaced steps, which would correspond to a very large number of samples over the full energy range of the spectrum.

The calculation of the relativistic correction deserves some mention too, since I have seen a number of programs not calculating it correctly. Information on the types and number of atoms present are taken from the "Material" box and the equation :math:`Z - (\frac{Z}{82.5})^{2.37}` (as described by Henke et al. [HEN1993]_) is applied to each atom separately and the individual corrections then summed.



References
----------

.. [BRU2002] P. Bruzzoni, R.M. Carranza, J.R. Collet Lacoste, and E.A. Crespo
"Kramers-Kronig transforms calculation with a fast convolution algorithm"
*Electrochimica Acta* **48** (2002) 341-347.

.. [HEN1993] B.L. Henke, E.M. Gullikson, and J.C. Davis
"X-ray interactions: photoabsorption, scattering, transmission, and reflection at E=50-30000 eV, Z=1-92"
*Atomic Data and Nuclear Data Tables* **54**\ (2) (1993) 181-342.

.. [MOH2008] N. Mohankumar, and A. Natarajan
"On the numerical solution of Cauchy singular integral equations in neutron transport"
*Annals of Nuclear Energy* **35**\ (10) (2008) 1800-1804.

.. [BIG1988] F. Biggs, and R. Lighthill
"Analytical approximations for X-ray cross-sections III"
*Sandia Report* SAND87-0070 UC-34 (1988).



Project details


Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
kkcalc-0.7.5-py2-none-any.whl (1.5 MB) Copy SHA256 hash SHA256 Wheel py2
kkcalc-0.7.5.tar.gz (1.5 MB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page