This is a python/C++ program for simulating X-Ray Fluorescence (XRF) spectrum acquired at a synchrotron radiation beamline.
- Installation ======= The source files need to be compiled with C++11 (tested with g++ version 4.7 and mingw-w64 x86_64-4.9.1-posix-seh-rt_v3-rev1).
Xraylib with python bindings is also needed at compiling.
Xraylib is available at https://github.com/tschoonj/xraylib.
Instructions on compiling XrayLib can be found at https://github.com/tschoonj/xraylib/wiki.
After compilation of XrayLib, change the "XRL_PATH" in "variables.mk" to the actual installation directory of XrayLib.
In the top directory do "make". If your C++ compiler is not called with "g++", modify the variable "g++" in "variables.mk" according to your actual compiler.
Initialize the program by running ". init.sh" before running the program.
- Running sim-xrf ======= Sim-xrf can be run in C++ mode and Python mode. In both modes, an input file defining the parameters needed in the calculation is required. The output of the C++ mode is a text file; the Python mode can in addition plot the spectrum or read the output files and plot them.
The input file is a text file defining the parameters needed in the calculation. See the example "input.txt" file for instructions.
On linux:
./main.out [input file name] [output file name]
On windows:
main.exe [input file name] [output file name]
python simpy.py [input file name] [output file name]
python read.py [input file name] [output file name]
from python.pyapi import calc
nout = 3000, 30, 500, 500 # N of channels, N of Z, N of lines, N of thetas
xlim = 0, 11
ylim = 1e-14, 1e-4
spec = calc(input_file="input.txt", output_file="output.txt")
spec.show(xlim=xlim, ylim=ylim)
from read import read, plot
fname = "output.txt"
xlim = 0, 11
ylim = 1e-14, 1e-4
# Read data file
ev, a, labels = read(fname)
# Plot spectrum
plt.figure()
plt.title('Spectrum read from %s' % fname)
plot(ev, a, labels, xlim=xlim, ylim=ylim)