Uncertainty analysis

[1]:
# This file is part of ILTpy examples.
# Author : Dr. Davis Thomas Daniel
# Last updated : 25.08.2025
  • This example shows steps to generate uncertainty estimates for distributions. It is recommended to familiarize yourself with the first example in the EPR section before continuing.

  • As an example, an EPR inversion recovery dataset is used.

  • The same approach and functions can also be used for any multi-dimensional data using ILTpy.

  • The method iltstats of IltData class is used.

  • Results after calling iltstats are stored in IltData.statistics

  • IltData.statistics is a dictionary containing the following keys:

    • g_list : A list with indiviudal distributions from n inversions.

    • fit_list : A list with indiviudal fits from n inversions.

    • residuals_list : A list with indiviudal residuals from n inversions.

    • noise_samples : A list with noise samples used to generate n number of data samples.

    • data_samples : A list with n number of data samples.

    • g_mean : Mean of n distrbutions.

    • fit_mean : Mean of n fits.

    • residuals_mean : Mean of n residuals.

    • g_std : Standard deviation of n distributions.

    • fit_std : Standard deviation of n fits.

    • residuals_std : Standard deviation of n residuals.

    • g_conf_interval : A list containing g_mean-std_mean, g_mean+std_mean.

    • fit_conf_interval : A list containing fit_mean-fit_std, fit_mean+fit_std.

Imports

[2]:
# import iltpy
import iltpy as ilt
print(f"ILTpy version: {ilt.__version__}")

# other libraries for handling data, plotting
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
plt.style.use('../../../examples/latex_style.mplstyle')
ILTpy version: 1.0.0

Loading data

[3]:
# Load data
data_EPR = np.loadtxt('../../../examples/EPR/inversion_recovery/data.txt')
t_EPR = np.loadtxt('../../../examples/EPR/inversion_recovery/dim1.txt')

coalIR = ilt.iltload(data=data_EPR,t=t_EPR)

Data preparation

[4]:
# Set noise variance to 1.
## estimate noise level using some points at the end of inversion recovery trace
noise_lvl  = np.std(coalIR.data[900:])

# Scale the data with the noise level
coalIR.data = coalIR.data/noise_lvl

Initial inversion

[5]:
# Initialize the IltData object
# Tau generated internally
coalIR.init(kernel=ilt.Exponential())

# Invert
coalIR.invert()
/Users/davisthomasdaniel/sciebo/JuGit/iltpy_iet1/iltpy/iltpy/input/parameters.py:697: UserWarning: tau[0] was not specified, proceeding with ILTpy-generated tau. Note that ILTpy-generated tau is only valid in case of NMR/EPR relaxation data.
  warnings.warn(tau_warn)
Starting iterations ...
  0%|          | 0/100 [00:00<?, ?it/s]100%|██████████| 100/100 [00:00<00:00, 686.74it/s]
Done.

Uncertainity analysis

  • n controls the number of data samples which will be generated and n_jobs controls the number of parallel jobs to create.

[6]:
coalIR.iltstats(n=200,n_jobs=-1)
[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.
[Parallel(n_jobs=-1)]: Done  34 tasks      | elapsed:    2.1s
[Parallel(n_jobs=-1)]: Done 184 tasks      | elapsed:    6.2s
[Parallel(n_jobs=-1)]: Done 200 out of 200 | elapsed:    6.6s finished

Plot results

[7]:
fig,ax = plt.subplots(figsize=(3,2.5))
ax.semilogx(coalIR.tau[0].flatten(),-coalIR.statistics['g_mean'],color='k',linewidth=0.5,label='Mean')
ax.fill_between(coalIR.tau[0].flatten(),*[-i for i in coalIR.statistics['g_conf_interval']],color='grey',alpha=0.4,label='Std. Dev.')
ax.legend()
plt.xlim(1e4,2e6)
_=plt.ylim(-1,22)
../_images/Gallery_uncertainty_analysis_15_0.png