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

PyPI version License

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.2.0.tar.gz (24.0 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.2.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: decay_tools-0.2.0.tar.gz
  • Upload date:
  • Size: 24.0 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.2.0.tar.gz
Algorithm Hash digest
SHA256 199b0c69e91f99cb66c1a121e0b55795fd90e66216a2e3069c44d46429a378df
MD5 eea6a69bd6e2cf35e862ac8d9c8e96e9
BLAKE2b-256 34ecfd355c51de0aa3604284cd636f693dfd786fb041311d23c33d94fc56802c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: decay_tools-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d23a4d6fb234b77a6cc13df173f93ea44ab3a28ee47891f1530537fd5f734ee9
MD5 65dcaa3aa3daedce88b14a7e6e4ad2b0
BLAKE2b-256 c602ce32196e729ed3185e170714be70959cf1d42619d4cf39b44bbb11c92f85

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