pyfli.data_vnp.mono_bi_classifier#

Classify mono- versus bi-exponential fit agreement and visualize parameter correlations.

This module belongs to pyfli.data_vnp and is part of PyFLI visualization, normalization, plotting, and mono-versus-bi-exponential comparison tools. Public API includes classes MonoBiClassifier and ParamCorrelationMatrix.

Classes

MonoBiClassifier(b_bool_mask[, names, ...])

Classify agreement between mono- and bi-exponential fits across one or more datasets.

ParamCorrelationMatrix(all_datasets, bool_mask)

Visualize pairwise parameter relationships under an agreement mask.

class MonoBiClassifier(b_bool_mask, names=None, alpha_upper=0.95, alpha_lower=0.05, tau_tol=0.01, coord=None, figsize=None)[source]#

Bases: object

Classify agreement between mono- and bi-exponential fits across one or more datasets. It builds masks from lifetime and fraction criteria, summarizes agreement, and plots parameter comparisons.

Parameters:
  • b_bool_mask (np.ndarray) – Mask array used to select or label pixels.

  • names (Any | None) – Names used to label datasets, classes, or plotted groups.

  • alpha_upper (float) – Upper alpha-fraction threshold used by the classifier.

  • alpha_lower (float) – Lower alpha-fraction threshold used by the classifier.

  • tau_tol (float) – Lifetime tolerance used by the mono/bi classifier.

  • coord (Any | None) – Pixel or ROI coordinate used for lookup and plotting.

  • figsize (np.ndarray | None) – Figure size passed to Matplotlib.

CMAP_NAMES = ('jet', 'Spectral', 'Spectral_r')#
PALETTE: ClassVar[list[str]] = ['#3a6b8c', '#8c433b', '#3a8c5c', '#8c7824', '#763f8c', '#8c5b2f', '#328c7b', '#3d8c5e', '#3f878c', '#8c473f', '#753f8c', '#3f6e8c', '#3f8c7d']#
classify_one(res, name='Dataset')[source]#

Classify one.

Parameters:
  • res (Any) – Fit result object or dataset result dictionary.

  • name (str) – Dataset, experiment, figure, or output name.

Returns:

Dictionary containing the data produced by classify one.

Return type:

dict[Any, Any]

display_one(result)[source]#

Display one.

Parameters:

result (Any) – Classification or fitting result to display.

Returns:

No object is returned; the function display one.

Return type:

None

classify(all_datasets, names=None, display=True)[source]#

Classify every dataset; store self.results and self.all_datasets.

Parameters:
Return type:

Any

summary()[source]#

Run the summary routine.

Returns:

Object produced by summary.

Return type:

Any

agreement(metric='jaccard', classes_to_show=('mono', 'bi'), cmap='viridis', figsize=None, show=True)[source]#

Pairwise agreement between methods on the mono/bi classification.

metric‘count’ raw # pixels both methods call this class

‘jaccard’ |A∩B| / |A∪B| (symmetric, 0..1) ‘fraction’ |A∩B| / |A| (asymmetric, read by row)

Returns (dict {class: NxN matrix}, fig).

Parameters:
Return type:

tuple[Any, …]

param_scatter_matrix(param='tau1_map', cls='mono', agree='pairwise', max_points=3000, colors=None, figsize=None, rng=None, show=True)[source]#

Cross-method correlation of ONE parameter over the pixels of ONE class.

diagonal (i, i) histogram of param for method i over its cls pixels off-diag (i, j) scatter of method_i (y) vs method_j (x), 1:1 line + r

agree‘pairwise’ (cell uses pixels both i & j call cls)

‘all’ (every cell uses pixels ALL methods agree on)

Parameters:
Return type:

ndarray

agreed_param_table(cls='mono', params=('alpha1_map', 'tau1_map', 'tau2_map'))[source]#

Long-form table of parameter values at pixels where ALL methods agree on cls. One row per (pixel, method) -> groupby(‘method’).describe().

Parameters missing from a dataset (e.g. Phasor has only ‘tau_map’, mono-exp datasets lack ‘alpha1_map’/’tau2_map’) are filled with NaN instead of raising KeyError.

Parameters:

params (tuple[str, ...])

Return type:

Any

class ParamCorrelationMatrix(all_datasets, bool_mask, names=None)[source]#

Bases: object

Visualize pairwise parameter relationships under an agreement mask. It supports subsampling, scalar and distribution-valued maps, uncertainty display, and pairwise scatter panels.

Parameters:
  • all_datasets (np.ndarray) – Sequence or mapping of fitted datasets to compare.

  • bool_mask (np.ndarray) – Boolean mask selecting pixels included in the analysis.

  • names (Any | None) – Names used to label datasets, classes, or plotted groups.

PALETTE: ClassVar[list[str]] = ['#3a6b8c', '#8c433b', '#3a8c5c', '#8c7824', '#763f8c', '#8c5b2f', '#328c7b', '#3d8c5e', '#3f878c', '#8c473f', '#753f8c', '#3f6e8c', '#3f8c7d']#
scatter_matrix(param='tau1_map', agree='pairwise', max_points=3000, colors=None, figsize=None, rng=None, show=True)[source]#

N × N cross-method scatter matrix for a single parameter.

Diagonal : histogram of pixel means within the ROI. Off-diagonal: dataset_i (y) vs dataset_j (x) with identity line + r.

Scalar data → scatter points. Distribution data → mean circle with ± std error bars.

Parameters:
  • param (str   Key present in the dataset dicts.)

  • agree (str 'pairwise' — each cell uses pixels finite in both) – datasets. ‘all’ — restricted to pixels finite in ALL datasets simultaneously.

  • max_points (int   Cap on plotted points (random sub-sample).)

  • colors (list  Per-dataset colours (cycles PALETTE by default).)

  • figsize (tuple Figure size; auto-scaled to N if None.)

  • rng (np.random.Generator  For reproducible sub-sampling.)

  • show (bool  Call plt.show() when True.)

Returns:

fig

Return type:

matplotlib.figure.Figure

pairwise_scatter(idx_a, idx_b, params=('tau1_map', 'tau2_map', 'alpha1_map'), max_points=3000, colors=None, figsize=None, rng=None, show=True)[source]#

Scatter plots for multiple parameters between exactly two datasets.

Scalar parameter (H, W) → plain scatter point per pixel. Distribution parameter (H, W, N) → mean circle with ± std error bars.

Parameters:
  • idx_a (int or str) – Dataset for y-axis (idx_a) and x-axis (idx_b). Accepts integer position or name string.

  • idx_b (int or str) – Dataset for y-axis (idx_a) and x-axis (idx_b). Accepts integer position or name string.

  • params (sequence of str) – Parameter keys to compare; missing keys produce blank panels.

  • max_points (int   Cap on plotted points (random sub-sample).)

  • colors (list  One colour per parameter panel (cycles PALETTE).)

  • figsize (tuple Figure size; auto-sized to number of params if None.)

  • rng (np.random.Generator  For reproducible sub-sampling.)

  • show (bool  Call plt.show() when True.)

Returns:

fig

Return type:

matplotlib.figure.Figure