packing_defect.core.cluster

Classes

DefectClustering()

Connected-component analysis for defect masks.

class packing_defect.core.cluster.DefectClustering[source]

Bases: object

Connected-component analysis for defect masks.

Methods operate on 2D integer masks, typically produced from DefectGrid. Non-zero entries are treated as part of a defect.

static cluster_sizes_from_mask(matrix: ndarray) list[int][source]

Return sizes of all connected components in a binary mask.

Parameters:

matrix (np.ndarray) – 2D array with 1 for defect cells and 0 otherwise.

Returns:

Sizes (in cells) of each connected component.

Return type:

list[int]

static defect_size(matrices, nbins, bin_max, fname, prob=True)[source]

Compute and write a histogram of defect cluster sizes.

Parameters:
  • matrices (sequence[np.ndarray]) – Iterable of 2D binary masks (1 for defect cell, 0 otherwise).

  • nbins (int) – Number of histogram bins.

  • bin_max (float) – Upper edge of the histogram range.

  • fname (str) – Output path to write two-column text: center, value.

  • prob (bool, optional) – If True, normalize counts to probabilities.