pyfli.bayes_utils.posterior_pixel_plot#

Posterior-predictive plot of one pixel’s sampled decay reconstructions against its measured decay.

Module Attributes

CENTERS

Valid values for the center argument.

DECAY_STYLES

Valid values for the decay_style argument.

Functions

__annotate__

The type of the None singleton.

_crop_shift(value, x, y)

1x1 crop of an (H, W) shift map; scalars and None pass through.

_pixel_shift(output_combination, key, value, ...)

Per-sample h_shift/v_shift at pixel: the posterior key, else the scalar/(H, W) value, else 0.

_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 with onset h_shift, rescaled so its sum matches the measured decay's sum minus the v_shift baseline, which is then added back).

_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.

DECAY_STYLES: tuple[str, ...] = ('line', 'scatter')#

Valid values for the decay_style 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, decay_style='line', shift_method='zero_pad', h_shift=None, v_shift=None, excitation='bin_start', gate_width=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 or scatter points, see decay_style).

  • 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.

  • decay_style (str) – How the measured decay is drawn: "line" (default) or "scatter" (one point per time bin).

  • shift_method (str) – Forward model, "zero_pad" or "circular", as used for the fit (see pyfli.reconstruction.ParamToDecay).

  • h_shift (float | np.ndarray | None) – Decay onset (ns) and per-bin background, a scalar or an (H, W) map; h_shift/v_shift keys in output_combination take precedence. None means 0 (see ParamSelector).

  • v_shift (float | np.ndarray | None) – Decay onset (ns) and per-bin background, a scalar or an (H, W) map; h_shift/v_shift keys in output_combination take precedence. None means 0 (see ParamSelector).

  • excitation (str) – Forward-model options as used for the fit (see pyfli.reconstruction.ParamToDecay).

  • gate_width (float | None) – Forward-model options as used for the fit (see pyfli.reconstruction.ParamToDecay).

Return type:

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