Global, Target & Lifetime Density Analysis (LDA)#

Variable Projection (VARPRO)#

In the bilinear model \(\mathbf{D} \approx \mathbf{C}\,\mathbf{S}^{\mathsf{T}}\), the component spectra \(\mathbf{S}\) enter linearly. For any fixed set of non-linear parameters (lifetimes \(\boldsymbol{\tau}\), time-zero \(t_0\), and IRF width), the best-fit spectra are available in closed form:

\[\mathbf{S}^{\mathsf{T}} = \left(\mathbf{C}^{\mathsf{T}}\mathbf{C}\right)^{-1}\mathbf{C}^{\mathsf{T}}\mathbf{D}\]

Only the non-linear parameters are passed to the optimiser. For a 500-pixel, 3-component fit, Variable Projection reduces the parameter vector from ~1500 entries to 3 and conditions the problem far better than joint amplitude–lifetime optimisation. In practice, the linear solve is evaluated via QR / SVD least-squares rather than forming normal equations.

Fitting Engines#

The Four Fitting Engines in PyRATE-TA#

Engine

Input Data

Output

fit_kinetics()

Single kinetic trace \((t, y)\)

Lifetimes & amplitudes (KineticFit)

fit_global()

Full \(\mathbf{D}\), free \(\mathbf{K}\)

Lifetimes, DAS or EAS (GlobalFit)

fit_target()

Full \(\mathbf{D}\), fixed connectivity

Rate constants, SAS (TargetFit)

solve_lda()

Full \(\mathbf{D}\), dense \(\tau\) grid

Lifetime density map (LDAResult)

import pyrate_ta as pr

# Global analysis
fit = pr.fit_global(data, n_components=3, model_type="Sequential")
print(fit.taus, fit.tau_err)
data.plot_species_spectra(*fit.as_species_args())

# Preview (evaluates linear spectra at fixed lifetimes without optimising)
prev = pr.preview_global(data, taus=[1.0, 10.0, 100.0])

# Target analysis
tfit = pr.fit_target(data, scheme="A_eq_B_to_C", taus=[2.0, 5.0, 20.0, 200.0])

# Single-trace fit
kfit = pr.fit_kinetics(t, y, n_components=2)

# Lifetime Density Analysis (LDA)
lda = pr.fit.lda.solve_lda(data, n_taus=100, alpha="auto", non_negative=True)

The Coherent Artefact Basis#

Around \(t = 0\), ultrafast measurements often contain cross-phase modulation (XPM), two-photon absorption, and stimulated Raman signals from the solvent and cell windows. Setting coherent_artifact=True appends three unit-normalised columns to the design matrix — the Gaussian IRF and its first two derivatives (Kovalenko et al., Phys. Rev. A 59, 2369, 1999):

\[g(t), \qquad g'(t), \qquad g''(t)\]

Their amplitudes are solved per probe pixel via Variable Projection so the artefact is absorbed into its own basis spectra (fit.artefact_spectra) rather than distorting the shortest kinetic lifetime \(\tau_1\). fit.as_species_args() returns only the genuine kinetic species.

Constrained Amplitudes and Sign Masks#

When physical sign constraints are imposed on species spectra, Variable Projection solves a bounded linear least-squares problem per probe pixel (pyrate_ta.fit.constrained):

\[\min_{\mathbf{S}_p}\, \lVert \mathbf{C}_w\,\mathbf{S}_p - \mathbf{d}_{w,p}\rVert^2 \quad\text{subject to}\quad \mathbf{l} \le \mathbf{S}_p \le \mathbf{u}\]

Controlled by a sign_mask array of length \(N_c\): +1 enforces \(S_p \ge 0\), -1 enforces \(S_p \le 0\), and 0 is unconstrained.

Steady-State Spectra & Pure Positive Species Recovery (GSB and SE)#

In transient absorption, the observed differential absorbance \(\Delta A(t, \lambda)\) is a linear superposition of three photophysical contributions:

\[\Delta A(t, \lambda) = S_{\mathrm{ESA}}(t, \lambda) - a(t)\, \sigma_A(\lambda) - b(t)\, F(\lambda)\]

where \(S_{\mathrm{ESA}} \ge 0\) is Excited-State Absorption, \(\sigma_A \ge 0\) is steady-state ground-state absorption (producing negative Ground State Bleach, GSB), and \(F \ge 0\) is steady-state fluorescence (producing negative Stimulated Emission, SE).

When steady-state absorption (\(\sigma_A\)) and/or emission (\(F\)) reference spectra are provided, pyrate_ta.fit.groundstate extracts pure positive species absorption spectra \(S_{\mathrm{abs}}(\lambda) \ge 0\) using constrained non-negative least squares (NNLS):

\[\min_{a, b \ge 0} \int_{\lambda \in \Lambda_{\mathrm{neg}}} \left| S_{\mathrm{diff}}(\lambda) + a\, \sigma_A(\lambda) + b\, F(\lambda) \right|^2 \mathrm{d}\lambda\]

subject to the physical positivity constraint:

\[S_{\mathrm{abs}}(\lambda) = S_{\mathrm{diff}}(\lambda) + a\, \sigma_A(\lambda) + b\, F(\lambda) \ge 0 \quad \forall \lambda\]

In the GUI, checking [✓] Recover pure positive spectra (GSB / SE) switches both the embedded preview and detached Plot DAS/EAS/SAS pop-out from differential spectra to reconstructed positive absorption spectra alongside dashed \(-a\,\sigma_A\) and \(-b\,F\) reference baselines.

Lifetime Density Analysis (LDA)#

Instead of fitting \(N\) discrete lifetimes, LDA solves for a continuous distribution of amplitudes over a dense, logarithmically spaced grid of fixed lifetimes via Tikhonov regularisation (pyrate_ta.fit.lda):

\[\min_{\mathbf{S}^{\mathsf{T}}} \left\lVert \mathbf{W} \odot \left(\mathbf{D} - \mathbf{C}(\boldsymbol{\tau}_{\text{grid}})\, \mathbf{S}^{\mathsf{T}}\right)\right\rVert^2 + \alpha^2 \left\lVert \mathbf{L}\,\mathbf{S}^{\mathsf{T}}\right\rVert^2\]
  • Regularisation operators: Identity (ridge, \(\mathbf{L} = \mathbf{I}\)), first difference (d1, \(\mathbf{L} = \mathbf{D}_1\), penalising slope), and second difference (d2, \(\mathbf{L} = \mathbf{D}_2\), penalising curvature; default).

  • Automatic \(\alpha\) selection (``alpha=”auto”``):

    • lcurve: Corner of the log-residual vs. log-solution-norm curve via maximum Menger curvature (Hansen, 1992; default).

    • gcv: Generalised Cross-Validation (Golub et al., 1979).

    • morozov: Morozov discrepancy principle matching the pre-time-zero noise level.

  • Additional options: non_negative (per-pixel NNLS), svd_components (top-\(K\) SVD pre-filtering), n_bootstraps (Monte Carlo residual resampling), find_peaks (automatic peak centroid detection on \(A(\tau) = \sum_p |S_{p,i}|\)), and coherent_artifact.

  • Export: lda_result.to_pdat(path) exports the 2D lifetime-density map to PyMORGAN’s .pdat format.

Weighting, Reduced \(\chi^2\), Uncertainties & Session Files (.prfit)#

  • Noise weighting & \(\chi^2_\nu\): With weights \(w = 1/\sigma\) from Dataset1D.noise_array(), PyRATE-TA reports the true reduced chi-squared:

    \[\chi^{2}_{\nu} = \frac{1}{N-p}\sum_{n,k} \left(\frac{D_{nk} - \left(\mathbf{C}\mathbf{S}^{\mathsf{T}}\right)_{nk}}{\sigma_{nk}}\right)^{2}\]

    where \(p\) counts both non-linear parameters and the \(N_p N_c\) linear amplitudes (with the non-linear-only denominator also recorded on FitStatistic.value_nonlinear_dof).

  • Reproducible Fit Sessions (.prfit): pyrate_ta.save_fit() writes a compressed archive containing all fitted arrays and a JSON provenance payload (model family, scheme text, initial guesses, bounds, fixed mask, delay/probe limits, and convergence report):

    path = pr.save_fit("scan_fit", fit)     # -> scan_fit.prfit
    prev = pr.load_fit("scan_fit.prfit")
    print(prev.summary())
    print(prev.taus)
    

Tabular CSV, 2D Surface & .zip Bundle Exports#

Every fit result (KineticFit, GlobalFit, TargetFit) and reopened session (LoadedFit) provides direct export methods backed by pyrate_ta.io.export:

  • Single-header CSV/TSV tables (zero # lines by default): Line 1 is the column header and lines 2+ are numeric values, opening directly in OriginPro, Excel, Igor Pro, pandas.read_csv(path), and numpy.loadtxt(path, delimiter=",", skiprows=1).

  • DAS / EAS / SAS spectra (export_spectra()): Exports the fitted probe axis alongside DAS_S1 (...), EAS_S1 (...), or SAS_A columns. When GSB/SE recovery is enabled (recover_gsb=True), de-bleached _abs columns are appended side-by-side in the same CSV.

  • Concentration profiles \(C(t)\) (export_concentrations()): Exports Delay (<unit>), each kinetic population column, and (by default when present) the Gaussian IRF envelope.

  • 2D Data, Fit & Residual surfaces (export_surface(), export_surfaces()): Strictly follows the PyMORGAN .pdat orientation (rows = delays \(N_d\), columns = probe \(N_p\); never transposed). Supports .csv, .tsv, and native .pdat (via pymorgan.write_pdat(), which loads straight back into pymorgan.load_1D). All three surfaces share the exact fitted \((t, \text{probe})\) window so data - fit == residuals holds identically even when reconstructed from a standalone .prfit file.

  • Unified timestamp, companion .txt report & .zip archiving (export_fit_summary(), export_fit_results()): Every file in an export shares the fit’s YYYYMMDD-HHMMSS timestamp, paired with <stem>_fit_summary_<timestamp>.txt (convergence, lifetimes & \(1\sigma\) errors, target \(\mathbf{K}\) matrix & eigenvalues, \(\chi^2_\nu\) / SSR, GSB/SE scale factors, and citations). Pass as_zip=True or a .zip destination path to pack all files into a single archive:

# Export individual CSVs or PDAT surfaces
fit.export_spectra("scan_EAS.csv", dataset=data, recover_gsb=True)
fit.export_concentrations("scan_C.csv", dataset=data)
fit.export_surface("scan_fit.pdat", kind="fit", dataset=data)

# Export complete folder bundle (EAS/DAS/SAS + C(t) + data/fit/residuals + summary.txt)
paths = fit.export_results("exports/", dataset=data, recover_gsb=True)

# Or pack everything (with PDAT surfaces) into a single .zip file
bundle = fit.export_results("exports/scan_bundle.zip", dataset=data, surface_format="pdat")