functions
Fovea-specific GA calculation functions.
The shared low-level primitives (convert_nan_to_zero,
get_max_ga_bscan_index, get_lesion_sizes,
get_shortest_distance_from_image_centre, parse_bscan_predictions,
compute_ga_metrics_for_scan) live in
bitfount.steps.data_utils.ga_metrics and are used by both the
with-fovea and without-fovea steps.
This module provides the fovea-specific helpers and the high-level
compute_ga_metrics_with_fovea_for_scan function.
Module
Functions
compute_ga_metrics_with_fovea_for_scan
def compute_ga_metrics_with_fovea_for_scan( bscan_predictions: tuple[str, ...], slice_thickness: float, pixel_spacing_column: float, all_segmentation_labels: dict[str, int], ga_area_include_segmentations: list[str], ga_area_exclude_segmentations: list[str], central_slice_fovea: int | None, landmarks_fovea: FoveaLandmarks | None, fovea_landmark_idx: int = 2, n_scan_biomarker_thresholds: Mapping[str, float] | None = None, include_raw_pathology_probabilities: bool = False,) ‑> GAMetricsWithFovea:Compute GA metrics for a single scan, including fovea distance.
This encapsulates the per-file computation loop body from
_BaseWorkerSideWithFovea.run() (lines 865-987 in the original).
Arguments
bscan_predictions: The raw per-B-scan prediction JSON strings.slice_thickness: The distance between B-scans in mm.pixel_spacing_column: The pixel spacing along the B-scan column axis.all_segmentation_labels: All segmentation label names to class index.ga_area_include_segmentations: Segmentation labels to include when computing the GA area column mask.ga_area_exclude_segmentations: Segmentation labels to exclude when computing the GA area column mask.central_slice_fovea: Central slice of the fovea prediction.landmarks_fovea: List of 3-element lists of fovea landmarks.fovea_landmark_idx: Index of the middle landmark in the tuple.n_scan_biomarker_thresholds: Per-biomarker>=probability threshold used to computen_scan_run_lengths. Keys define which N-scan biomarkers are evaluated; whenNone, every label inN_SCAN_BIOMARKER_LABELSdefaults to0.5.include_raw_pathology_probabilities: Whether to include the raw per-B-scan pathology probability arrays on the returned metrics.
Raises
Exception: Propagates any exception from prediction parsing or metric computation so that the caller can handle/skip.
get_shortest_distance_from_fovea
def get_shortest_distance_from_fovea( fovea_coordinates: NDArray[Any] | None, labeled_array: NDArray[Any], num_lesions: int, slice_thickness: float, pixel_spacing_column: float, na_bscan_indices: tuple[int, ...] = (),) ‑> float | None:Calculate the distance from the fovea to the nearest lesion.
Arguments
fovea_coordinates: Numpy array of fovea coordinates in the image, as(bscan, column, row)in the ORIGINAL (uncompacted) B-scan index space — the space a fovea landmark arrives in.labeled_array: Numpy array of shape (num_bscans, num_cols) where each pixel is labelled with the lesion number it belongs to. Its first axis is compacted:parse_bscan_predictionsgives it a row only for a B-scan that carried model output.num_lesions: Number of lesions in the image.slice_thickness: Thickness of each B-scan in mm.pixel_spacing_column: Spacing between columns in mm.na_bscan_indices: The dropped input B-scan indices, fromParsedBScanPredictions.na_bscan_indices. Used to shift fovea_coordinates' B-scan component into labeled_array's compacted space. Defaults to(), i.e. no compaction, for a caller that genuinely has none.
Returns
Distance from the fovea to the nearest lesion in mm, or None.