Fit Results API (pyrate_ta.results)#
Kinetic, Global & Target Fit Results (pyrate_ta.results.fits)#
Fit result objects and the linearised uncertainty estimate.
A result carries enough to reproduce itself: the model identity, the initial
guesses, the bounds, the fixed/free mask, the delay and probe ranges actually
fitted (clipping changes what the fit saw), the solver’s report and the
statistic. A lifetime without its uncertainty and its fixed/free flag is not
a result, so tau_err and is_fixed travel with every lifetime.
Uncertainties are 1-sigma from the linearised covariance at the optimum. They
are conditional on the model being right: a three-component fit of
two-component data can return small uncertainties on three meaningless
lifetimes. Fixed parameters get nan, never a small number that might read
as precision.
- pyrate_ta.results.fits.covariance_from_jacobian(J, residuals, *, weighted, dof)[source]#
Linearised parameter covariance at the optimum.
- Parameters:
J (array_like
(N, n_free)) – Jacobian of the residual vector with respect to the free parameters, asscipy.optimize.least_squaresreturns it.residuals (array_like) – The residual vector at the optimum (already weighted, if weights were used – that is what the optimiser saw).
weighted (bool) – With proper
1/sigmaweights the residuals are dimensionless and the covariance is(J^T J)^-1. Unweighted, it is scaled by the residual varianceSSR/dof, which assumes the model is correct and the noise uniform.dof (int) – Degrees of freedom used for that scaling.
- Returns:
(n_free, n_free), orNonewhen the normal matrix is singular – in which case the parameters are not determined and no uncertainty should be invented for them.- Return type:
numpy.ndarray or None
- class pyrate_ta.results.fits.KineticFit(taus, tau_err, is_fixed, S, R, model_type, t, probe=None, C=None, t0=0.0, t0_err=None, irf_fwhm=None, irf_err=None, S_abs=None, gs_scale=None, gs_source=None, a_max=None, statistic=None, report=None, weights=None, param_names=<factory>, initial_params=None, bounds=None, covariance=None, n_components=0, n_artifact=0, delay_range=None, probe_range=None, t_min=None, detector=0, source=None, sorted_by_lifetime=False, permutation=None, settings=<factory>, timestamp=<factory>)[source]#
Bases:
objectResult of a multi-exponential fit to one or more traces.
- Variables:
tau_err (taus,) – Lifetimes and their 1-sigma uncertainties, in the dataset’s time unit. A fixed lifetime has
nanuncertainty.is_fixed (numpy.ndarray of bool) – Per-lifetime fixed/free flag.
S (numpy.ndarray
(Np, Nc)) – Component spectra (amplitudes for a single trace).R (numpy.ndarray
(Nd, Np)) – Residual matrix.model_type (str) –
"Parallel"/"Sequential"/"Target"; decides whether the spectra are DAS, EAS or SAS, and what PyMORGAN prints in the legend.
- Parameters:
taus (ndarray)
tau_err (ndarray)
is_fixed (ndarray)
S (ndarray)
R (ndarray)
model_type (str)
t (ndarray)
probe (ndarray | None)
C (ndarray | None)
t0 (float)
t0_err (float | None)
irf_fwhm (float | None)
irf_err (float | None)
S_abs (ndarray | None)
gs_scale (float | None)
gs_source (str | None)
a_max (float | None)
statistic (Any)
report (Any)
weights (Any)
initial_params (ndarray | None)
covariance (ndarray | None)
n_components (int)
n_artifact (int)
t_min (float | None)
detector (int)
source (str | None)
sorted_by_lifetime (bool)
permutation (ndarray | None)
settings (dict)
timestamp (str)
- n_artifact: int = 0#
Number of coherent-artefact columns appended to
C(and toS). They are not kinetic components and carry no lifetime.
- property spectra_kind: str#
DAS, EAS or SAS.
On the base class because the name is a property of the model family, not of which engine produced the result – a preview has to be able to label its own spectra too.
- Type:
What this model’s amplitude spectra are called
- property artifact_spectra#
Amplitude spectra of the coherent-artefact columns, or
None.Worth looking at: a fitted artefact that does not look like a derivative of the IRF, or that carries amplitude far from time zero, is a sign the artefact is absorbing real kinetics.
- as_species_args()[source]#
The plain-array tuple
plot_species_spectraexpects.Returns
(Sfit, Taus, TauErr, isFixTau, modelType). Keeping this adapter on the PyRATE-TA side is what lets PyMORGAN render a PyRATE-TA fit without ever importingpyrate_ta.Only the kinetic columns are handed over: an artefact column has no lifetime, and passing it would label it with someone else’s.
- summary()[source]#
One-line-per-lifetime summary, with the statistic and convergence.
How the lifetimes are quoted follows the
[plots]settingsshow_uncertaintiesandround_uncertainties, so the summary agrees with the legends rather than reporting a different precision.- Return type:
- format_report(*, dataset=None, timestamp=None, bleach_result=None)[source]#
Format a detailed terminal-style fit report string.
- export_spectra(path=None, *, dataset=None, recover_gsb=False, S_abs=None, bleach_result=None, gs_spectrum=None, em_spectrum=None, include_artifact=False, metadata=False, timestamp=None, write_summary=False, directory=None, fmt='%.12g')[source]#
Export DAS/EAS/SAS spectra to a single-header CSV file.
- export_concentrations(path=None, *, dataset=None, normalise=False, include_irf=True, include_artifact=False, metadata=False, timestamp=None, write_summary=False, directory=None, fmt='%.12g')[source]#
Export concentration profiles
C(t)to a single-header CSV file.
- export_surface(path=None, *, kind='fit', dataset=None, surface_format='csv', include_artifact=True, weighted_residuals=False, metadata=False, timestamp=None, write_summary=False, directory=None, fmt='%.12g')[source]#
Export one 2D surface (
data,fit, orresiduals) as CSV/TSV or PDAT.
- export_surfaces(directory=None, *, dataset=None, surface_format='csv', as_zip=False, zip_path=None, keep_files=False, stem_override=None, include_artifact=True, weighted_residuals=False, metadata=False, timestamp=None, bleach_result=None, fmt='%.12g')[source]#
Export all 3 surfaces (
data,fit,residuals) +.txtsummary.
- export_summary(path=None, *, dataset=None, timestamp=None, bleach_result=None, directory=None)[source]#
Export the companion human-readable
.txtfit report.
- export_results(directory=None, *, dataset=None, recover_gsb=False, S_abs=None, bleach_result=None, gs_spectrum=None, em_spectrum=None, normalise_concentrations=False, include_irf=True, include_artifact=False, include_surfaces=True, surface_format='csv', include_artifact_in_surfaces=True, weighted_residuals=False, as_zip=False, zip_path=None, keep_files=False, stem_override=None, metadata=False, timestamp=None, fmt='%.12g')[source]#
Export spectra, concentrations, 2D surfaces, and summary TXT (or single
.zip).- Parameters:
dataset (Any)
recover_gsb (bool)
S_abs (Any)
bleach_result (Any)
gs_spectrum (Any)
em_spectrum (Any)
normalise_concentrations (bool)
include_irf (bool)
include_artifact (bool)
include_surfaces (bool)
surface_format (str)
include_artifact_in_surfaces (bool)
weighted_residuals (bool)
as_zip (bool)
keep_files (bool)
stem_override (str | None)
metadata (bool)
timestamp (str | None)
fmt (str)
- class pyrate_ta.results.fits.GlobalFit(taus, tau_err, is_fixed, S, R, model_type, t, probe=None, C=None, t0=0.0, t0_err=None, irf_fwhm=None, irf_err=None, S_abs=None, gs_scale=None, gs_source=None, a_max=None, statistic=None, report=None, weights=None, param_names=<factory>, initial_params=None, bounds=None, covariance=None, n_components=0, n_artifact=0, delay_range=None, probe_range=None, t_min=None, detector=0, source=None, sorted_by_lifetime=False, permutation=None, settings=<factory>, timestamp=<factory>)[source]#
Bases:
KineticFitGlobal-analysis result: shared lifetimes, one spectrum per component.
The spectra are DAS for a parallel model and EAS for a sequential one – which of the two is recorded in
model_type, because the distinction is what the legend and the interpretation hang on (seeKineticFit.spectra_kind).- Parameters:
taus (ndarray)
tau_err (ndarray)
is_fixed (ndarray)
S (ndarray)
R (ndarray)
model_type (str)
t (ndarray)
probe (ndarray | None)
C (ndarray | None)
t0 (float)
t0_err (float | None)
irf_fwhm (float | None)
irf_err (float | None)
S_abs (ndarray | None)
gs_scale (float | None)
gs_source (str | None)
a_max (float | None)
statistic (Any)
report (Any)
weights (Any)
initial_params (ndarray | None)
covariance (ndarray | None)
n_components (int)
n_artifact (int)
t_min (float | None)
detector (int)
source (str | None)
sorted_by_lifetime (bool)
permutation (ndarray | None)
settings (dict)
timestamp (str)
- class pyrate_ta.results.fits.TargetFit(taus, tau_err, is_fixed, S, R, model_type, t, probe=None, C=None, t0=0.0, t0_err=None, irf_fwhm=None, irf_err=None, S_abs=None, gs_scale=None, gs_source=None, a_max=None, statistic=None, report=None, weights=None, param_names=<factory>, initial_params=None, bounds=None, covariance=None, n_components=0, n_artifact=0, delay_range=None, probe_range=None, t_min=None, detector=0, source=None, sorted_by_lifetime=False, permutation=None, settings=<factory>, timestamp=<factory>, scheme_key=None, scheme_label=None, scheme_text=None, K=None, eigenvalues=None)[source]#
Bases:
GlobalFitTarget-analysis result, adding the scheme and its rate matrix.
The rates of a branched scheme are generally not identifiable from a single dataset even when the fit is perfect: the data fix the column space of
C, and several rate sets can span it.eigenvaluesis what the data actually determine, and it is stored alongside the rates for that reason.- Parameters:
taus (ndarray)
tau_err (ndarray)
is_fixed (ndarray)
S (ndarray)
R (ndarray)
model_type (str)
t (ndarray)
probe (ndarray | None)
C (ndarray | None)
t0 (float)
t0_err (float | None)
irf_fwhm (float | None)
irf_err (float | None)
S_abs (ndarray | None)
gs_scale (float | None)
gs_source (str | None)
a_max (float | None)
statistic (Any)
report (Any)
weights (Any)
initial_params (ndarray | None)
covariance (ndarray | None)
n_components (int)
n_artifact (int)
t_min (float | None)
detector (int)
source (str | None)
sorted_by_lifetime (bool)
permutation (ndarray | None)
settings (dict)
timestamp (str)
scheme_key (str | None)
scheme_label (str | None)
scheme_text (str | None)
K (ndarray | None)
eigenvalues (ndarray | None)
LDA Result (pyrate_ta.results.lda_result)#
Result object for Lifetime Density Analysis (LDA).
- class pyrate_ta.results.lda_result.LDAResult(tau_grid, S_map, alpha_opt, penalty='d2', alpha_method='lcurve', l_curve_points=None, alphas=None, gcv_scores=None, residuals=None, t=None, probe=None, irf_fwhm=None, t0=0.0, svd_components=0, non_negative=False, n_bootstraps=0, bootstrap_std=None, peaks=<factory>, statistic=None, delay_range=None, probe_range=None, units=<factory>, settings=<factory>)[source]#
Bases:
objectResult of Lifetime Density Analysis (LDA).
- Variables:
tau_grid (numpy.ndarray
(M,)) – Logarithmically spaced grid of lifetimes in dataset time units.S_map (numpy.ndarray
(Np, M)) – 2D matrix of lifetime amplitudes across probe pixels.alpha_opt (float) – Chosen regularisation parameter alpha.
penalty (str) – Penalty type (
"ridge"/"d1"/"d2").alpha_method (str) – Method used to pick alpha (
"lcurve"/"gcv"/"manual").l_curve_points (numpy.ndarray
(K, 2)or None) – (log_residual, log_norm) points across the alpha scan for L-curve plot.alphas (numpy.ndarray
(K,)or None) – Scanned alpha values.gcv_scores (numpy.ndarray
(K,)or None) – Scanned GCV score values.residuals (numpy.ndarray
(Nd, Np)or None) – Residual matrix D - C S^T.t (numpy.ndarray
(Nd,)) – Delays fitted.probe (numpy.ndarray
(Np,)or None) – Probe wavelengths/wavenumbers.irf_fwhm (float or None) – IRF FWHM used in kernel construction.
t0 (float) – Time zero offset used in kernel construction.
- Parameters:
tau_grid (ndarray)
S_map (ndarray)
alpha_opt (float)
penalty (str)
alpha_method (str)
l_curve_points (ndarray | None)
alphas (ndarray | None)
gcv_scores (ndarray | None)
residuals (ndarray | None)
t (ndarray | None)
probe (ndarray | None)
irf_fwhm (float | None)
t0 (float)
svd_components (int)
non_negative (bool)
n_bootstraps (int)
bootstrap_std (ndarray | None)
statistic (Any)
units (dict)
settings (dict)
- integrated_dynamics(metric='abs')[source]#
Integrated dynamics profile across the lifetime grid.
- Parameters:
metric ({"abs", "dynamical_content", "sqrt_sq"}) –
"abs": absolute sum \(A(\tau) = \int |S(\lambda, \tau)| d\lambda\)."dynamical_content"/"sqrt_sq": \(D(\tau) = \sqrt{\int S(\lambda, \tau)^2 d\lambda}\).
- Return type:
numpy.ndarray, shape
(M,)
- find_peaks(metric='abs', prominence=0.05)[source]#
Auto-detect major lifetime peak centroids.
- Parameters:
metric ({"abs", "dynamical_content"}) – Which profile metric to detect peaks on.
prominence (float) – Peak prominence as a fraction of peak maximum.
- Return type:
list of dict with keys
"tau","amplitude","index".