A Python software toolkit for modelling the x-ray spectra from x-ray tubes
Project description
SpekPy:
A Python software toolkit for modelling the x-ray spectra from x-ray tubes
Table of Contents
- What SpekPy is
- What SpekPy is not
- Try before you install
- How to install SpekPy
- How to use SpekPy
- The software license
- About us
- Contacts
- Our book
- How to reference SpekPy
What SpekPy is
SpekPy is a powerful and free software toolkit for calculating and manipulating the spectra of x-ray tubes. The code is written in the Python programming language. It can be used in a Python interpreter or from a Python script. For more information on SpekPy, please see Further information.
Initially, SpekPy could only model x-ray tubes with the classic "reflection" geometry. With release v2.5.0, however, it was extended to model transmission targets. Currently it is capable of modelling both possibilities for several target materials. For W targets, tube potentials ranging from 10 to 500 kV can be selected. For Cr, Cu, Mo, Rh, Ag, Au targets, the more restricted range of 10 to 50 kV is possible.
What SpekPy is not
SpekPy is a toolkit, not a command-line program or a piece of software with a fancy Graphical User Interface (i.e. a GUI). If you want to use it you will have to write a Python script or type commands yourself. Fortunately, SpekPy is easy to use and both it and Python are free. An alternative, for basic calculations, is to use SpekPy Web, our online web application.
SpekPy also isn't a "medical device" (or "software as a medical device"). This means that it shouldn't be used in any way that influences diagnosis, prevention, monitoring, prediction, prognosis, or treatment of human beings.
Try before you install
SpekPy Web
The easiest way to get started with SpekPy is via the web app. You can find the SpekPy Web app here.
Binder
Alternatively, this link launches a Jupyter notebook running SpekPy.
Binder can be slow to load, but gives you a chance to try scripting with SpekPy before installing.
Tips:
- Click on a code-block and press Run to run the code snippet
- If the plot doesn't show after running the code-block, try pressing Run again
How to install SpekPy
New for 2024
SpekPy is now available in the PyPI package index. This means that it can be installed in a Python environment using pip, without dowloading the source from this repository:
pip install spekpy
Thanks go to Xandra Campo Blanco for making this possible.
Install from source
You can download the source from here. Click on Source on the menu to the left to go to the source code. Then you can clone the git repository (click on the Clone button on that page for more info). Alternatively, you can download the software as a zip file by clicking on Downloads.
SpekPy is designed to be compatible with both Python2 (2.6 or higher) and Python3 (3.6 or higher). Note, however, that Python2 is officially depreciated by the Python Software Foundation as of 1st January 2020.
We typically install and uninstall SpekPy using the standard Python pip utility. You can do this by navigating to the SpekPy directory in a command window and typing:
pip install .
The package needs the standard NumPy and SciPy libraries. If these are not installed already, the SpekPy installation process will try to install them for you.
To be able to save spectrum states and create new filter materials, you need write permission for where you install. If you don't have admin rights on the account you want to use for SpekPy, you can try:
pip install . --user
This should install SpekPy to you local user space. You can probably successfully install SpekPy via running the setup.py script or easy_install. The latter is depreciated, however, and the former is less convenient if you want to uninstall/reinstall.
Advice for Anaconda Python
If you use Anaconda Python, it is good to be aware that in some cases pip and conda installations of packages can cause conflicts. We recommend creating a clean conda environment:
conda create -n spekpy-env python=3.7 numpy scipy matplotlib
before proceeding with:
conda activate spekpy-env
pip install .
Installing NumPy and SciPy first, using the conda installer, should ensure that you have no conflicts.
How to use SpekPy
Here's an example of some Python code, to model a tungsten target (default) reflection-type (default) tube:
#!python
import spekpy as sp
r = sp.Spek(kvp=80, th=12) # Generate a spectrum (80 kV, 12 degree tube angle)
r.filter('Al', 4.0) # Filter by 4 mm of Al
hvl = r.get_hvl1() # Get the 1st half-value layer in mm Al
print(hvl) # Print out the HVL value
Here's an example of how to model a transmission tube with a 10um thick copper target:
import spekpy as sp
t = sp.Spek(kvp=80, trans=True, thick=10, targ='Cu') # Target thickness entered in um
t.filter('Be', 250e-3) # Filter thickness entered in mm i.e. 250 um of Al;
phi = t.get_flu() # Get the total integrated fluence
print(phi) # Print out the fluence
To see a complete list of SpekPy tools (methods and functions), please take a look at the Function glossary.
The software license
The software toolkit is available under the permissive MIT License. Yes, you could put it in your software application and make millions of dollars and not have to pay us a dime! Please do credit and reference us though.
About us
SpekPy was developed by Gavin Poludniowski and Robert Bujila with considerable help from Artur Omar. The work was initiated (by Gavin) at the University of Surrey in the UK and continued in Sweden, at the Karolinska University Hospital (with Robert and Artur). Our academic associations are with Karolinska Institutet [KI] (both Gavin and Artur) and the Royal Technical University [KTH] (Robert). Robert Bujila has now moved to GE Healthcare (Waukesha, WI, USA).
The models underlying SpekPy V2 were developed by Artur Omar, Gavin Poludniowski and Pedro Andreo.
The SpekPy Web app was developed by Robert Vorbau (Karolinska University Hospital) in collaboration with Gavin Poludniowski.
Contacts
Drop me an email if you have a query, suggestion or have found a bug:
Email: gpoludniowski@gmail.com
Please do let us know about any bugs. You can either email or raise an issue using the Issues option in the left-hand panel.
Our book
Calculating X-ray Tube Spectra: Analytical and Monte Carlo Approaches, (CaXTuS) by Gavin Poludniowski, Artur Omar, Pedro Andreo.
Key Features of CaXTuS:
- Covers simple modelling approaches as well as full Monte Carlo simulation of x-ray tubes.
- Bremsstrahlung and characteristic contributions to the spectrum are discussed in detail.
- Learning is supported by free open-source software and an online repository of code.
- An online repository of the code that accompanies this book can be found here.
How to reference SpekPy
Primary references
-
G Poludniowski, A Omar, R Bujila and P Andreo, Technical Note: SpekPy v2.0—a software toolkit for modeling x-ray tube spectra. Med Phys. 2021; https://doi.org/10.1002/mp.14945
-
R Bujila, A Omar and G Poludniowski, A validation of SpekPy: a software toolkit for modelling x-ray tube spectra. Phys Med. 2020; 75:44-54.
-
Vorbau R, Poludniowski G. Technical note: SpekPy Web-online x-ray spectrum calculations using an interface to the SpekPy toolkit. J Appl Clin Med Phys. 2024;25(3):e14301.
Secondary references
-
A Omar, P Andreo and G Poludniowski, A model for the energy and angular distribution of x rays emitted from an x-ray tube. Part I. Bremsstrahlung production. Med Phys. 2020; 47(10):4763-4774
-
A Omar, P Andreo and G Poludniowski, A model for the energy and angular distribution of x rays emitted from an x-ray tube. Part II. Validation of x-ray spectra from 20 to 300 kV. Med Phys. 2020; 47(9):4005-4019
-
A Omar, P Andreo and G Poludniowski, A model for the emission of K and L x rays from an x-ray tube. NIM B 2018; 437:36-47.
-
G Poludniowski, Calculation of x-ray spectra emerging from an x-ray tube. Part II. X-ray production and filtration in x-ray targets. Med Phys. 2007; 34(6):2175-86.
-
G Poludniowski and PM Evans, Calculation of x-ray spectra emerging from an x-ray tube. Part I. electron penetration characteristics in x-ray targets. Med Phys. 2007; 34(6):2164-74.
-
G Poludniowski, et al., SpekCalc: a program to calculate photon spectra from tungsten anode x-ray tubes. Phys Med Biol. 2009; 54(19):N433-8.
-
A Omar, P Andreo and G Poludniowski, Performance of different theories for the angular distribution of bremsstrahlung produced by keV electrons incident upon a target. Radiat. Phys. and Chem. 2018; 148:73-85.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spekpy-2.5.4.tar.gz.
File metadata
- Download URL: spekpy-2.5.4.tar.gz
- Upload date:
- Size: 163.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.12.3 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9ef77ff542761526b6488f8e677b93eb20d25cdf4be05da0ef6ee2aba146d2a
|
|
| MD5 |
e88659c2a3ab0156d8956841787bf86c
|
|
| BLAKE2b-256 |
e997bd10a69620e01f506a309c46258d5b0e7b8254c0ec26eeb08f3c9e5c486c
|
File details
Details for the file spekpy-2.5.4-py3-none-any.whl.
File metadata
- Download URL: spekpy-2.5.4-py3-none-any.whl
- Upload date:
- Size: 164.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.12.3 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f01e805721281b5a3e332500db577cedaf71bde0f0d3838745b915e6f1c258a
|
|
| MD5 |
70c4dced395b924424e74d908b8a29b7
|
|
| BLAKE2b-256 |
b6eacbac7c7bbcec2438c3b4641cfbd11f2452d226812fdd49b404b4977367d5
|