Skip to main content

parsing

Image and segmentation mask parsing utilities for steps.

Module

Functions

is_na_prediction

def is_na_prediction(value: Any)> bool:

Whether a per-B-scan prediction cell carries no model output.

None arises for padding B-scan columns: a per-B-scan prediction set is stored as one key per column of a DataFrame that was padded to its widest row, so a scan with fewer frames than the widest in its inference run carries trailing nulls for frames it does not have. An empty/whitespace string is not a valid prediction either; treating it as NA avoids json.loads("") raising "Expecting value: line 1 column 1".

This predicate deliberately cannot tell padding from a frame the model skipped — both are "no output here". parse_bscan_masks draws that distinction, by sizing the B-scan axis to the scan's own frame count before any group's na_bscans policy applies.

Arguments

  • value: The raw cell from a merged predictions row.

Returns True when the cell holds no usable prediction.

load_prediction_envelope

def load_prediction_envelope(    bscan_prediction_str: str,)> AltrisBiomarkerEntry | AltrisGASegmentationModelEntry:

Unwrap one B-scan's prediction payload to its single entry.

Handles both envelope shapes the models have emitted — pre-v11 wraps the entry in two lists, post-v11 in one — and repairs single-quoted JSON, which some cached rows carry.

Arguments

  • bscan_prediction_str: One B-scan's raw prediction string.

Returns The unwrapped prediction entry.

parse_mask_json

def parse_mask_json(    json_data: Any, labels: dict[str, int],)> numpy.ndarray[typing.Any, typing.Any]:

Parse segmentation mask(s) from JSON.

Arguments

  • json_data: The model output JSON data for the masks.
  • labels: The segmentation classes to generate masks for mapped to their index in the mask data.

Returns A (num_segmentations, image_height, image_width) uint8 array valued 1 where a class is present and 0 elsewhere.