Skip to main content

Python package for fitting single- and double-component nuclear decay time distributions and estimating optimal bins in the logarithmic form.

Project description

decay-tools

Tools for analyzing decay time distributions in nuclear physics experiments

Installation

pip install decay-tools

Usage

Prepare data

import numpy as np
from decay_tools import estimate_n_bins, get_hist_and_bins

times_mks = np.array([2, 2, ..., 55098.1, 113904.2])
# convert to ln(Δt)
logt = np.log(times_mks)

# find an “optimal” number of bins (IQR or STD method)
nbins = estimate_n_bins(logt, method="iqr")
print(f"Suggested bins: {nbins}")

# build histogram & get bin centers
data, bins = get_hist_and_bins(logt=logt) # default: n_bins_method="iqr"
# or explicitly:
# data, bins = get_hist_and_bins(logt=logt, n_bins=10)
# data, bins = get_hist_and_bins(logt=logt, n_bins_method="std")

Fit a single-component decay curve

from decay_tools import DecayParameters, fit_single_schmidt, visualize_single_fit

# initial guess: half-life=10 μs, N₀=100, background=0
guess = DecayParameters(half_life_us=10, n0=100, c=0)

result = fit_single_schmidt(
    data,
    bins,
    initial_guess=guess,
    check_chi_square=True, # will print chi-squre test results
)

print(result)
# if you want to see the fit overlayed on the histogram:
visualize_single_fit(data, bins, result)

Fit a double-component decay curve

from decay_tools import DoubleDecayParameters, fit_double_schmidt, visualize_double_fit

# initial guess for short & long components
g = DoubleDecayParameters(
    hl_short_us=5, 
    hl_long_us=50,
    n0_short=50, 
    n0_long=20, 
    c=0
)

result = fit_double_schmidt(
    data, 
    bins, 
    initial_guess=g,
)

print(result)
visualize_double_fit(data, bins, result)

Set boundaries

Both fit_single_schmidt and fit_double_schmidt accept an optional bounds argument to constrain the fit parameters. Pass a tuple (lower, upper), where each bound can be either a DecayParameters (or DoubleDecayParameters) instance—whose fields are automatically converted to the log-domain constants—or a scalar/int, which applies the same limit to all parameters.

Note: The fiting procedure is done over decay constant but not half-life. So, when we set a bound of half-life we actually set the lower bound. If the initial guess for half live is lower than bound, the exception will be raised.

from decay_tools import DecayParameters, fit_single_schmidt

bounds = (
    0,
    DecayParameters(half_life_us=10, n0=1e3,  c=0.1)  # NOTE: we actually limit here the lower bound for half life
)
result = fit_single_schmidt(data, bins, initial_guess=guess, bounds=bounds)

Statistical tests to check if there more than one components in the decay curve

TBD

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

decay_tools-0.1.0.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

decay_tools-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file decay_tools-0.1.0.tar.gz.

File metadata

  • Download URL: decay_tools-0.1.0.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for decay_tools-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8bf9cc24cc8c0ab7fd3646e9e61559d43637aab2952735574d43bd14174d0d50
MD5 ba5477377807f50f23c67c9f818f5cda
BLAKE2b-256 05e83d74407d240235784d4016183fa536146588e8ee94f87486cda6df988153

See more details on using hashes here.

File details

Details for the file decay_tools-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: decay_tools-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for decay_tools-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 27157d6f5acbfe5acbcbc37354c026fadedbfa14a6586c086ba4a3687715e2fb
MD5 43fb12163f4dc2b4542bf1eb00b37224
BLAKE2b-256 f58bab4c95a6aa6775c48894094447beff5e397e415d97912218f39bfd736dd2

See more details on using hashes here.

Supported by

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