pyfli.bayes_utils.posterior_pixel_plot#

Plot a single pixel’s posterior-sample decay reconstructions against its measured decay, in the style of a posterior-predictive check: shaded credible- interval bands plus a chosen central curve (best-fitting sample, median, or mean), overlaid on the actual measured decay.

Belongs to pyfli.bayes_utils, downstream of pyfli.bayes_utils.param_combinations.ParamSelector and pyfli.reconstruction.ParamToDecay.

Module Attributes

CENTERS

Valid values for the center argument.

Functions

_reconstruct_sample_stack(...)

Reconstruct every posterior sample's decay curve at one pixel, scaled to that pixel's measured photon count the same way pyfli.reconstruction.compute_detailed_results() scales its fits (unit-amplitude reconstruction, then rescaled so its sum matches the measured decay's sum).

_select_best_sample_idx(output_combination, ...)

Pick the posterior sample that best fits this one pixel, by delegating to ParamSelector on a 1x1-pixel crop -- reuses its tested per-sample goodness-of-fit logic instead of duplicating it here.

plot_pixel_posterior_fit(output_combination, ...)

Plot one pixel's posterior-sample decay reconstructions as nested credible-interval bands, a chosen central curve, and the measured decay.

CENTERS: tuple[str, ...] = ('best', 'median', 'mean')#

Valid values for the center argument.

plot_pixel_posterior_fit(output_combination, decay, irf, freq_acq, pixel, model_type='bi-exponential', center='median', metric='reduced_chi2', ci_levels=(92, 68), decay_color=_DECAY_COLOR, fit_color=_FIT_COLOR, band_alpha=0.88, fit_alpha=1.0, decay_alpha=0.8, title=None, ax=None)[source]#

Plot one pixel’s posterior-sample decay reconstructions as nested credible-interval bands, a chosen central curve, and the measured decay.

Parameters:
  • output_combination (dict[str, np.ndarray]) – Posterior-sample parameter maps, e.g. {'tau1': (H,W,NUM_SAMPLES), 'tau2': (H,W,NUM_SAMPLES), 'alpha1': (H,W,NUM_SAMPLES)} for bi-exponential, or {'tau': (H,W,NUM_SAMPLES)} for mono-exponential – same shape convention as ParamSelector.

  • decay (np.ndarray) – Measured decay, (H, W, T).

  • irf (np.ndarray) – IRF, (T,) (shared) or (H, W, T) (per-pixel).

  • freq_acq (float) – Acquisition frequency (MHz), i.e. freq[1].

  • pixel (tuple[int, int]) – (x, y) pixel to plot.

  • model_type (str) – "bi-exponential" or "mono-exponential".

  • center (str) – Which curve to draw as the central line: "median" or "mean" across posterior samples, or "best" (the single sample that optimizes metric at this pixel, via ParamSelector.select_best_combination()).

  • metric (str) – Only used when center="best"; one of ParamSelector.METRICS ("chi2", "reduced_chi2", "RMSE", "R2").

  • ci_levels (tuple[int, ]) – Nested credible-interval widths to shade, e.g. (92, 68) shades a 92% and a 68% band (percentiles (4, 96) and (16, 84) of the per-bin sample distribution).

  • decay_color (str) – Colour of the measured-decay line (defaults to _DECAY_COLOR).

  • fit_color (str) – Colour of the central fit curve and the credible bands (which are tinted-toward-white shades of it); defaults to _FIT_COLOR.

  • band_alpha (float or tuple[float, ]) – Opacity of the credible bands. A scalar applies to every band; a sequence sets them per band, matched positionally to ci_levels.

  • fit_alpha (float) – Opacity of the central fit curve.

  • decay_alpha (float) – Opacity of the measured-decay line.

  • title (str | None) – Axes title; defaults to f"Pixel ({x}, {y})".

  • ax (matplotlib.axes.Axes | None) – Axes to draw into. If omitted, a new figure/axes is created and shown.

Return type:

tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]