This package facilitates easy Bayesian inference on X-ray data products.
It is a lightweight implementation based on emcee
which incorporates
astropy.units
.
"Bounds" and other (more generic) parameter prior distributions are implemented via
scipy.stats
.
Please see the examples
folder for some complete examples. (TODO: make them a gallery)
yaff
can be installed from GitHub.
It's recommended to use uv
to manage your Python versions and virtual environments: uv project GitHub page, with installation instructions.
It is very fast and works well.
Clone the repository and run
cd /path/to/where/you/cloned/yaff
# Optionally--but preferably--make a venv to work in
# here is an example of how to do that using the `uv` tool
uv venv
source .venv/bin/activate
uv pip install -e .
# or omit the `uv` if you are just using pip
# If you want to install the packages required by the examples as well:
uv pip install -e .[examples]
All of these can be found in examples
directory. (TODO: make them a gallery)
line_fit
: Fit some synthetic counts data to a line.rhessi_fit
: Fit a (thermal + cold thick target) model to a RHESSI spectrum near the peak of an M9 GOES class flare.stix_fit
: Fit a (thermal + cold thick target) model to a STIX spectrum during part of the impulsive phase of an M1 GOES class flare.simulataneous_nustar_fit
: Fit a thermal bremsstrahlung model to both NuSTAR focal plane modules (FPMA and FPMB) simultaneously to a quiet sun brightening.
Analyzing X-rays from the Sun and other stars is straightforward but distinct from other wavelengths. For X-ray instruments (operating at energies greater than ~1 keV), each photon is counted individually. The intensity is recorded as "counts/second" rather than, e.g., watts.
Furthermore, X-rays are of high enough energy that inelastic photon-matter interactions become very important to consider when performing any kind of serious energy analysis. The interactions between matter and the X-ray photons distinguish the concept of a count from a photon. A photon of a given energy may register as a count of a similar, or significantly smaller, energy.
The details of the photon-matter interaction is captured in a matrix. This matrix goes by various different names, depending on who you ask:
- Instrument response matrix (IRM)
- Detector response matrix (DRM)
- Spectral response matrix (SRM)
- ... probably others.
Sometimes these matrices have units of (count / photon). Sometimes they have other units, like (square centimeter times count / photon / keV).
All of this is confusing. At the most fundamental level, a response matrix converts an "average" photon to an "average" count; it is a probability mapping from incident photon energy to registered count energy. Hereafter: the response matrix quantifies the conversion of photons to counts, and has units of count / photon. The geometric area of a detector may be multipled into this response, when appropriate, to modify units.
As an aside: putting a "per-keV" in the response is a TERRIBLE idea. Photon model energy spacings may be very different from instrument count energy spacings, and this ambiguity can lead to insidious and confusing results.
X-ray spectroscopy consists of just a few steps:
- Compute a model of the photon emission.
- Convert the photon emission model into a measured "count" model using the response matrix.
- Compare the count model to your data.
- Change the model parameters to get a better match.
- Repeat until you're happy.
That's it. Once you are "happy" in a rigorous sense, you are done performing spectroscopy.
TBD