Python Libraries of Interest to Particle Physics
Python libraries of interest to particle physicists. This is meant to be a living document. Therefore, if you have suggestions, click the edit button then make a pull request with your proposed change(s). This is meant to focus on Python resources for new-ish users; if you just want to look for different libraries for a particular purpose, please visit the Python section of the awesome-hep list.
You are more than welcome to join the HSF/PyHEP Gitter channel
and contribute to the informal discussions there.
The channel HSF/PyHEP-newcomers Gitter channel specifically targets, well, newcomers.
See the HSF PyHEP Working Group page
for a full list of Gitter channels and resources.
New to Python
If you are new to Python, the following contains general information on using Python in Science.
| Name |
Use |
| Software Carpentry Python Lesson |
Lesson aimed at people who have never used Python before. |
| Scipy tutorials |
You'll want the beginner courses, the intermediate/advanced courses are actually quite advanced. Setup instructions are linked on the page, videos are here |
| Dive into Python 3 |
Very useful for learning python, though it's a bit old and doesn't cover any of the scientific python stuff you really need. |
| Code academy |
|
| Many EdX and Coursera courses |
Often introductory CS courses which can teach other useful skills (algorithms and datastructures) |
| The python docs |
|
| Level Up Your Python |
Advanced topics: Debuggers, static typing, logging, decorators, generators and more as interactive Jupyter book |
Otherwise, just google python + description of problem, usually answer is on stackoverflow.
Youtube channels with talks / tutorials:
Pycon, e.g.:
Some more advanced talks of interested:
Getting Python
| Name |
Use |
| Conda |
Anaconda packages most scientific Python libraries while also living purely in user space. Therefore, you don't need special permissions to setup. Anaconda is a metapackage of 100 or so scientific Python packages for Conda. |
| pipenv |
Very slick all-in-one combination of virtual environments and package installation, can manage Python installs too. |
| ripa |
ripa solves the packaging issue by letting you install packages (or requirements.txt) where priority given to conda channels, otherwise fetches from PyPI. (Works but rough) |
Scientific Python Stack
The packages that are used in Physics and/or data science within Python grew somewhat organically before forming the current ecosystem. Detailed information on what exists can be found here, but we will summarize here.
| Name |
Use |
| jupyter notebook |
Main one way of doing interactive and/or exploratory analysis. |
| numpy |
Array and matrix operations (including math operations) at C speeds. |
| pandas |
A very elegant way to work with tabular data (i.e. ntuples) with in memory calculations. Especially good at time series. |
| xarray |
Extension of pandas to N-Dim structures. |
| h5py |
Simple numpy to HDF5 bindings (backend for Keras saved models). |
| scipy |
Various scientific routines like minimization. |
| matplotlib |
Main Python plotting library. Start from matplotlib gallery then adapt to your application. |
| scikit-learn |
Very easy to use machine learning routines with great examples. |
| awkward |
Awkward Array is a library for nested, variable-sized data, including arbitrary-length lists, records, mixed types, and missing data, using NumPy-like idioms. |
Visualisation:
| Name |
Use |
| matplotlib |
Main Python plotting library. Start from matplotlib gallery then adapt to your application. |
| seaborn |
Easier to use plotting library with some statistical routines. Builds on matplotlib, but annoying to customize. |
Machine learning:
| Name |
Use |
| scikit-learn |
Popular package. Very easy to use ML routines, with great examples. |
| tensorflow |
By Google, for deep neural networks and more. |
| pytorch |
Deep learning framework for fast, flexible experimentation with dynamic computational graphs. |
| keras |
Higher level neural network interfaces. |
| wandb |
Weights & Biases makes it easy to track your experiments, manage & version your data, and collaborate with your team so you can focus on building the best models. |
General information through talks that may be useful on PyData (various conferences each year):
Data manipulation
| Name |
Use |
| boost-histogram |
Python bindings for the C++14 Boost::Histogram library. |
| hist |
Analyst-friendly front-end for boost-histogram. |
Statistical analysis and fitting
| Name |
Use |
| iminuit |
Jupyter-friendly Python frontend to the MINUIT2 C++ library. |
| uncertainties |
Calculations with numbers with uncertainties. It also yields the derivatives of any expression. |
| pyhf |
Pure python implementation of HistFactory specification with auto-diff enabled backends in tensorflow, pytorch, and MXNet. |
| hepstats |
HEP statistics tools and utilities. |
| zfit |
Scalable pythonic fitting. |
| cabinetry |
Constructing binned template fit models and steering statistical inference using pyhf. |
Particle Physics packages
| Name |
Use |
| DecayLanguage |
Describe, manipulate and display particle decays. |
| hepstats |
HEP statistics tools and utilities. |
| hepunits |
Units and constants in the HEP system of units. |
| Particle |
PDG particle data and identification codes. |
| pylhe |
Interface to read Les Houches Event (LHE) files. |
| fastjet |
Official FastJet bindings to Python and Awkward Array. |
| vector |
Arrays of 2D, 3D, and Lorentz vectors. |
ROOT and interoperability with ROOT
For many particle physics experiments, a lot of data is stored within ROOT files. This means at very least one must have the ability to read ROOT files. ROOT also serves as a tool suite designed to solve many computational problems encountered in HEP, which means that one may want to access some of this tool suite. The following packages below are worth knowing for these situations:
| Package name |
Use |
Pro |
Con |
Further information |
| ostap |
User-friendly & more intuitive interface to(Py)ROOT |
Many decorations to ROOT classes |
Requires C++ code compilation |
|
| uproot |
Native Python ROOT I/O |
Easy to install, fast, no dependence on C++ ROOT |
Although it can read all ROOT files, can only write ROOT files with specific objects. |
|
| Conda-Forge ROOT |
Using ROOT within Anaconda |
Full-featured ROOT and PyROOT on Linux and macOS |
|
|
| PyROOT |
Official ROOT Python bindings |
Good support and many examples |
Raw C++ wrapping results in weird Python code (improved in 6.22) |
|