Skip to main content

curve_roi_counts

Function curve_roi_counts 

Source
pub fn curve_roi_counts(
    roi: &Roi,
    x: &[f64],
    y: &[f64],
) -> Option<CurveRoiCounts>
Expand description

Per-ROI raw/net counts and raw/net area for a curve, mirroring silx CurvesROIWidget (ROI.computeRawAndNetCounts / computeRawAndNetArea).

Selects the curve points whose x lies in the ROI’s inclusive x-span (from ≤ x ≤ to, from roi_x_span), preserving the curve’s array order (silx does not sort, and neither does this — numpy.trapezoid integrates in sequence, so a curve whose x is not monotonic yields the same order-dependent areas silx produces). Unlike curve_roi_stats, NaN y samples are not filtered (silx computeRawAndNetCounts sums them as-is, so a NaN in range propagates to the counts) — this is faithful to silx, not an oversight. Points with non-finite x fall outside any finite span and are excluded. x and y are paired by index; the shorter array bounds the pair count.

Returns None for a ROI with no x-span (e.g. an HRange, which selects on y); such ROIs are not curve ROIs in silx’s 1D sense.

The background models:

  • Net counts: a line through the first and last selected points (background[i] = y₀ + slope·(xᵢ − x₀), slope = (yₙ − y₀)/(xₙ − x₀)), subtracting Σ background. When xₙ == x₀ (zero width) net counts is 0.
  • Net area: the trapezoid under the straight line joining the y values at the points closest to from and to to (silx’s numpy.trapezoid over a two-value background, which reduces to (x_last − x_first)·(y_left + y_right)/2).