pyfli.simulator.calibration.multicluster#

Multi-cluster priors and images, following the pyfli multi-ROI example.

Functions

_ashman_d(gm, i, j)

_dip_ratio(z, labels, mean_i, mean_j, i, j)

Depth of the density valley between two components: the pixels assigned to either are projected onto the line joining the means, a Gaussian KDE (Scott bandwidth) of the projection is evaluated between the two projected means, and the minimum is divided by the smaller of the densities at the means.

_features(decays, use_intensity)

choose_tile(labels[, shape, seed])

Top-left corner of a tile fully inside the sample mask that contains as many clusters as possible, with the most balanced composition (largest minority share).

cluster_inputs(base, cluster_mask_path, ...)

Inputs for calibrating one cluster: the experiment's inputs restricted to the cluster mask, with the IRF of the whole-experiment calibration (the IRF belongs to the detector, not to a cell population).

detect_clusters(decay, mask[, ...])

Find well-separated pixel populations inside mask; see the module docstring.

irf_tile(json_path, shape[, seed, peak])

Per-pixel IRF cube (H, W, T) with the calibrated OffsetGen behaviour: each pixel gets roll(template, round(a)) + b, a ~ U(a_range), b ~ U(b_range).

roi_config(json_path[, seed])

A calibrated config as a pyfli roi_params entry (tuples restored; optional fixed seed).

simulate_multicluster_tile(labels_tile, ...)

pyfli FLIModelImageGenerator image for a cluster label tile, as in the pyfli multi-ROI example: roi_params follows np.unique(roi_mask).

Classes

ClusterResult(labels, n_clusters, fractions, ...)

class ClusterResult(labels: numpy.ndarray, n_clusters: int, fractions: list[float], report: dict = <factory>)[source]#

Bases: object

Parameters:
labels: ndarray#
n_clusters: int#
fractions: list[float]#
report: dict#
mask(k)[source]#
Parameters:

k (int)

Return type:

ndarray

detect_clusters(decay, mask, max_components=4, separation=2.0, min_fraction=0.05, use_intensity=False, n_fit=20000, smooth=True, seed=0, max_dip_ratio=0.5)[source]#

Find well-separated pixel populations inside mask; see the module docstring.

Two mixture components stay separate only if Ashman’s D is at least separation and the pixel density projected onto the line joining their means has a real dip between them (_dip_ratio() below max_dip_ratio). A mixture fitted to a few hundred pixels of one skewed population can reach D > 2 by chance, but its projected density has no dip (ratio ~0.7-1), while separate populations give ~0.

Parameters:
Return type:

ClusterResult

cluster_inputs(base, cluster_mask_path, whole_irf_path, output_dir)[source]#

Inputs for calibrating one cluster: the experiment’s inputs restricted to the cluster mask, with the IRF of the whole-experiment calibration (the IRF belongs to the detector, not to a cell population).

Parameters:
Return type:

CalibrationInputs

roi_config(json_path, seed=None)[source]#

A calibrated config as a pyfli roi_params entry (tuples restored; optional fixed seed).

Parameters:
  • json_path (str)

  • seed (int | None)

Return type:

dict

irf_tile(json_path, shape, seed=0, peak=1e4)[source]#

Per-pixel IRF cube (H, W, T) with the calibrated OffsetGen behaviour: each pixel gets roll(template, round(a)) + b, a ~ U(a_range), b ~ U(b_range). It is scaled to peak because pyfli’s irf_picker only accepts 3D IRFs whose peak exceeds 500 (each pixel is sum-normalised by the generator anyway).

Parameters:
Return type:

ndarray

choose_tile(labels, shape=(8, 8), seed=0)[source]#

Top-left corner of a tile fully inside the sample mask that contains as many clusters as possible, with the most balanced composition (largest minority share).

Parameters:
Return type:

tuple[int, int]

simulate_multicluster_tile(labels_tile, cluster_configs, irf_json, detector_type='discrete', sample_mask_tile=None, seed=0)[source]#

pyfli FLIModelImageGenerator image for a cluster label tile, as in the pyfli multi-ROI example: roi_params follows np.unique(roi_mask). Label 0 (outside the sample) is background with an empty config and is zeroed by the intensity / bool mask.

Parameters:
Return type:

dict