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.1.tar.gz (23.2 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.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: decay_tools-0.1.1.tar.gz
  • Upload date:
  • Size: 23.2 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.1.tar.gz
Algorithm Hash digest
SHA256 b186468421b01ec186cf991abbe7178d053ad65cde6f2d100b78fac9e2f1b03d
MD5 249f8e05eeb2d5c187a28b1309e9cc4a
BLAKE2b-256 151e88f4eb1c1df77f185ed11a81a2b8511aaa0cd7d5ed687aaa7a8d56069602

See more details on using hashes here.

File details

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

File metadata

  • Download URL: decay_tools-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 56551774c291ff80fb42b33b564dee465c144456db4b7c699962a7a90fee616f
MD5 3af587eecb8aad8636773869a0571ede
BLAKE2b-256 4ab5dac67507207269557645f5cdeb5aef24c3b3918e6a136cebb6fdf64181eb

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