Skip to main content

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 no arguments are passed, it gets the parameters 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=ydata)
Spec.calibrate(x=channels, y=energies)
Spec.fit_fano_and_noise()
Spec.pool = fit_pool
Spec.fit()
#or simply: Spec.fit(pool=fit_pool)
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


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.3.tar.gz (10.7 kB view hashes)

Uploaded Source

Built Distribution

xfit-0.1.0.3-py3-none-any.whl (11.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page