Package for fitting XRF spectra. Based on xraylib
Project description
Installation
This package requires xraylib. On Windows, it can be installed through the Anaconda interface with
conda install -c conda-forge xraylib=4.0.0
For further information on how to install xraylib on other operational systems, check xraylib wiki.
This module can be installed with:
pip install xfit
#Usage
This module provides the "Spectrum" class. It is possible to initialize this class with a numpy nd.array or loading an *.mca or *.spt file, by giving the path.
Example1
import xfit
import numpy as np
import matplotlib.pyplot as plt
path = r"./test.mca"
pool_file = r"./pool.txt"
Spec = xfit.Spectrum(file_path=path)
Spec.calibrate() #if not input is specified, it gets from the mca or spt header
Spec.fit_fano_and_noise()
Spec.create_pool(pool_file)
Spec.fit()
plt.plot(Spec.energyaxis, Spec.data)
for element in Spec.areas.keys():
plt.plot(Spec.energyaxis,
Spec.plots[element],
label=element,
color=ElementColors[element],
linestyle="--")
plt.show()
Example2
import xfit
import numpy as np
ydata = np.arange(1024)
fit_pool = {}
fit_pool["elements"] = {}
fit_pool["elements"]["Cu"] = ["KA1","KA2","KB1","KB3"]
fit_pool["bg"] = 1 #Forces the use of continuum estimation for the fit
Spec = xfit.Spectrum(array=path)
Spec.calibrate(x=channels, y=energies)
Spec.fit_fano_and_noise()
Spec.pool = fit_pool
Spec.fit()
plt.plot(Spec.energyaxis, Spec.data)
for element in Spec.areas.keys():
plt.plot(Spec.energyaxis,
Spec.plots[element],
label=element,
color=ElementColors[element],
linestyle="--")
plt.show()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
xfit-0.1.0.2.tar.gz
(10.6 kB
view hashes)
Built Distribution
xfit-0.1.0.2-py3-none-any.whl
(11.1 kB
view hashes)