Utilities#
Various auxiliary functions for calculating stats.
- calc_log_fraction_of_spans(req_xs, req_ys, xs, ys, lower_better=True)[source]#
Calculate fraction of range where the curve complies with requirements.
By default “complies” means the curve is below the requirement points. This function interpollates the curve points linerarly, but does not interpolate the requirement points.
- find_line_segments_by_var_of_prop(cent, prop, lin_threshold)[source]#
Primitive linearity estimator.
Determines linearity by requiring the absolute difference in successive points in
propvaries sufficiently slowly, ie the differences are all small.
- find_positive_spans(xs, ys, where='post')[source]#
Find regions where the provided curve is positive.
- Parameters:
- xs
x-coordinates of the input points
- ys
y-coordinates of the input points
- where:
Where the points provided are supposed to be in the spands of the stepwise function provided. Accepted values are “pre”, “mid”, and “post”, behaving like in
matplotlib.step. Default is “post”
- Returns:
- spanslist[tuple]
A list of tuples, each tuple being the start and stop positions in x.
- Treat input points as a stepwise function and finds the sections
- where the
ysare positive. By default considers each constant - section as starting at point
xs[i]and going toxs[i+1], - having the value
ys[i]in the section. - Results are sensitive to the density of points provided.
- normalize_along_axis(arr: ndarray, axis: int = 1, threshold_frac=0.0001, fill_value=nan) ndarray[source]#
Normalize an ndarray along the given axis so that the sum along that axis is 1.0.
- Parameters:
- arrnp.ndarray
The input array.
- axisint
The axis along which to normalize.
- threshold_frac: float
if the integral along the axis is below this fraction of the total integral, mask off this row as having too low stats to plot. This prevents low-stats values form saturating the color scale
- fill_value:
value to replace low-stats entries with
- Returns:
- np.ndarray
A new array normalized along the specified axis.
- rms_profile_from_2d_hist(hist, density: bool = False, threshold=15) tuple[ndarray, ndarray, ndarray][source]#
Calculate RMS and mean per x-bin in a 2d histogram.
- Parameters:
- hist: Metric|hist.Histogram
Metric to profile, must be 2D
- density: bool
If False, assumes the histogram is proportional to counts per bin; otherwise, assumes it is proportional to a density. For constant bin widths, these are equivalent, but the distinction is important when bin widths vary (see Notes). If None (default), sets
density=Truefor backwards compatibility, but warns if the bin widths are variable. Setdensityexplicitly to silence the warning.
- Returns:
- tuple[np.ndarray, np.ndarray, np.ndarray]:
y_rms, y_mean, x_bin_center