Skip to main content

Package for fitting XRF spectra. Based on xraylib

Project description

Installation

This package requires xraylib and compwizard. On Windows, xraylib can be installed through the Anaconda interface.

conda install -c conda-forge xraylib=4.0.0
pip instal compwizard

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. For the continuum estimation algorithm, refer to the Continuum.py file.
Test.py file provides a common *.mca file to use with the example.py script provided.

Example 1

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.estimate_continuum(30, 11, 11, 3) #iterations, filter window, sav-gol window, sav-gol order
Spec.fit_fano_and_noise()
Spec.create_pool(pool_file)
Spec.fit()

#Plot ------
fig, ax = plt.subplots()
ax.plot(Spec.energyaxis, Spec.data, color="black", label="Data")
ax.plot(Spec.energyaxis, Spec.continuum, color="green", label="Continuum")
for element in Spec.areas.keys():
     ax.plot(Spec.energyaxis, 
            Spec.plots[element],
            label=element+" fit result", 
            color=ElementColors[element],
            linestyle="--")
ax.legend(loc=1, fancybox=1)
ax.set_yscale("log")
plt.show()

0.11400000005960464 80.00951851146041 (Fano and Noise values found, respectively)
Output

Example 2

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.estimate_continuum(30, 11, 11, 3)
Spec.fit_fano_and_noise()
Spec.pool = fit_pool
Spec.fit()
#or simply: Spec.fit(pool=fit_pool)

#Plot ------
fig, ax = plt.subplots()
ax.plot(Spec.energyaxis, Spec.data, color="black", label="Data")
ax.plot(Spec.energyaxis, Spec.continuum, color="green", label="Continuum")
for element in Spec.areas.keys():
     ax.plot(Spec.energyaxis, 
            Spec.plots[element],
            label=element+" fit result", 
            color=ElementColors[element],
            linestyle="--")
ax.legend(loc=1, fancybox=1)
ax.set_yscale("log")
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.1.0.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

xfit-0.1.1.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file xfit-0.1.1.0.tar.gz.

File metadata

  • Download URL: xfit-0.1.1.0.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/54.1.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for xfit-0.1.1.0.tar.gz
Algorithm Hash digest
SHA256 00e7f067ff001b658456953f2874b6ab1b3fdf97f6da4909d00a7ff8e418f96b
MD5 90dabee0818f42f9afa7d6377dd00268
BLAKE2b-256 87aaf48930b8da2f79ba83b1c36e060c84ef035ea1b8e01d5ebb95a9c8aea1c8

See more details on using hashes here.

File details

Details for the file xfit-0.1.1.0-py3-none-any.whl.

File metadata

  • Download URL: xfit-0.1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/54.1.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for xfit-0.1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f1e7fea44ce729969e2d1cb0917351888ede5c184f595c03ed3b3dedcc821788
MD5 3c278ba0d7fa664a97d102a30dc4b413
BLAKE2b-256 8d73858e746ff5be46899d0fd603201b5145de60914c3298b7f60f002f2812fc

See more details on using hashes here.

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