Reporting

All results from the inversion are accessible as an attribute of the IltData class. For example, the distributions can be accessed by IltData.g and fits can be accessed by IltData.fit after inversion.

Generating reports

After inversion, ILTpy can generate a report with relevant results and parameters from the inversion as shown in the example below.

import iltpy as ilt

# Assuming data1D and t1 are numpy arrays with the data and the sampling vector.
data1D_ILT = ilt.iltload(data=data1D,t=t1)
tau = np.logspace(-1,2,100)
data1D_ILT.init(tau,kernel=ilt.Exponential())

# invert
data1D_ILT.invert()

# Generate report
data1D_ILT.report(filepath="data_1d_ILT_report.txt")

This will save the report as data_1d_ILT_report.txt in your current working directory. A full or relative path to a folder can also be specified as filepath. If filepath is not specified, timestamp will be used as the filename.

Note

If an array has number of dimensions greater than 2, it will be reshaped to a 2D array.

Generating parameter files

Parameters used for the inversion can be be saved separately in a parameter file with the extension .param. This file can be re-used for specifying parameters in other inversions as shown below.

# Generate report and save parameters to a separate file by setting `parameters_to_file`=True
data1D_ILT.report(filepath='data_1d_ILT_report.txt',parameters_to_file=True)

This will save data_1d_ILT_report.param in your current working directory. This file can then be used for initializing an IltData object by providing its path during initialization:

import iltpy as ilt

# Assuming data1D and t1 are numpy arrays with the data and the sampling vector.
data1D_ILT = ilt.iltload(data=data1D,t=t1)
tau = np.logspace(-1,2,100)
data1D_ILT.init(tau,kernel=ilt.Exponential(),parameters="data_1d_ILT_report.param")

# invert with the parameters which were read from the parameter file
data1D_ILT.invert()

Report structure

The structure of the report is discussed below. Each section starts with a # — section-name — flag and ends with a # — — flag. First, date and time of report generation, ILTpy version and timings are written.

# --- ILTPY ---
# ILTpy report generated on 2025-04-25 18:30:27.409399
# ILTpy version : 1.0.0
# Time taken for initialization : 0.023 seconds
# Time taken for inversion : 2.373 seconds
# --- ---

This is followed by arrays with their name and shape :

# --- ARRAYS ---
#
# Data
# Shape : (32, 16)
#

Results which are reported in this section include :

  • Data : Data used for inversion.

  • T : Input sampling vectors for each dimension. Dimension is indicated by the ‘Dim’ and the index as per Python conventions, for example ‘Dim 0’ corresponds to the first dimension.

  • TAU : Output sampling vector for each dimension.

  • G : Distribution (or spectrum).

  • FIT : Fit of the data.

  • RESIDUALS : Residuals of the fit.

  • SIGMA : Sigma used for weighted inversions

  • DIM_NDIM : User-defined input sampling vector for the dimension which is regularized but not inverted.

  • G_GUESS : User-defined initial guess for G.

After arrays, kernel used in each dimension are reported based on their defined name, and kernel function in plain-text :

# --- KERNEL ---
# Kernel name Dim 0 : _exponential_
# Kernel function Dim 0 : lambda t, tau: np.exp(-t / tau)
# Kernel name Dim 1 : _exponential_
# Kernel function Dim 1 : lambda t, tau: np.exp(-t / tau)
# --- ---

In the end, parameters are reported :

# --- PARAMETERS ---
{'alpha_0': 0.0001,
 'alpha_00': 1,
 'alpha_p': None,
 'alpha_c': None,
 'alpha_a': 100000,
 'alpha_bc': 50,
 ......
 'zc_nmax': 3,
 'conv_limit': 1e-06}
# --- ---
# --- END OF REPORT ---

Saving results in npz format

Two additional arguments, save_arrays and level can be passed while reporting. save_arrays will save all numpy arrays in npz format. level controls the depth of saved data. Default is 0.

  • 0: Save attributes of type np.ndarray.

  • 1: Additionally, save lists containing only np.ndarray elements.

  • 2: Additionally, save sparse matrices (converted to dense arrays).

An example of reporting with the save_arrays option is shown below.

import iltpy as ilt

# Assuming data1D and t1 are numpy arrays with the data and the sampling vector.
data1D_ILT = ilt.iltload(data=data1D,t=t1)
tau = np.logspace(-1,2,100)
data1D_ILT.init(tau,kernel=ilt.Exponential())

# invert
data1D_ILT.invert()

# Generate report
data1D_ILT.report(filepath='data_1d_ILT_report.txt',save_arrays=True,level=2)

The npz file can be loaded as shown below.

import numpy as np

results  = np.load('data_1d_ILT_report.npz',allow_pickle=True)
g = results['g'] # distribution
fit = results['fit'] # fits
data = results['data'] # data used for inversion

More information about structure of the npz file and loading it can be found in numpy documentation.

Saving specific results

NumPy allows for saving 1D or 2D arrays to text files using np.savetxt as shown below and in its documentation.

import iltpy as ilt

# Assuming data1D and t1 are numpy arrays with the data and the sampling vector.
data1D_ILT = ilt.iltload(data=data1D,t=t1)
tau = np.logspace(-1,2,100)
data1D_ILT.init(tau,kernel=ilt.Exponential())

# invert
data1D_ILT.invert()

# save results
np.savetxt('g.txt',data1D_ILT.g) # distribution
np.savetxt('fit.txt',data1D_ILT.fit) # fits
np.savetxt('data.txt',data1D_ILT.data) # data used for inversion