Skip to main content

detect_bad_pixels

Function detect_bad_pixels 

Source
pub fn detect_bad_pixels(
    sample: &Array3<f64>,
    open_beam: Option<&Array3<f64>>,
    hot_k_mad: Option<f64>,
) -> Result<Array2<bool>, IoError>
Expand description

Detect all pipeline-corrupting pixels: dead ∪ hot over sample and (optionally) open beam.

This is the validating entry point that the GUI and Python bindings should use. Deadness/hotness is per-acquisition — a pixel dead only in the open-beam run still corrupts every transmission ratio computed from it — so the masks of both stacks are unioned:

mask = dead(sample) ∪ hot(sample) [∪ dead(open_beam) ∪ hot(open_beam)]

The stacks’ TOF axis lengths may differ (deadness is spatial); only the spatial dimensions must agree.

Both stacks must be raw detected counts (unscaled) — see the “Raw counts required” section of detect_hot_pixels: scaling distorts the Poisson floor of the hot screen. The GUI satisfies this: all three of its raw-counts paths (TIFF pair, HDF5 with open beam, HDF5 without open beam) call this function on the raw sample/open-beam stacks, before any normalization.

§Arguments

  • sample — Raw sample counts, shape (n_tof, height, width).
  • open_beam — Optional raw open-beam counts, shape (n_tof’, height, width).
  • hot_k_madSome(k) to include the detect_hot_pixels screen with multiplier k (use HOT_PIXEL_K_MAD); None for dead-only detection.

§Returns

2D boolean mask, shape (height, width). true = exclude pixel.

§Errors

Returns IoError::InvalidParameter if either stack contains a non-finite or negative value or has an empty TOF axis (shape[0] == 0 — the dead test over zero bins would vacuously mask every pixel) or hot_k_mad is Some of a non-finite/non-positive value, and IoError::ShapeMismatch if the spatial dimensions differ.