hispecdrp.primitives.utils.array_utils

Generic Numba / array / polynomial helpers for HISPEC DRP primitives.

Polynomial evaluation, Chebyshev OLS fits, short-circuit any/all, median filters, and related array utilities formerly housed in math.py.

Functions

_calc_median_insertion_sort(vals, m)

all_sc(arr)

Optimized version of np.all which short circuits, unlike numpy.all.

any_sc(arr)

Optimized version of np.any which short circuits, unlike numpy.any.

bitwise_or_reduce_uint32(arr)

median_filter_1d(data, dq, window_size)

median_filter_2d(data, dq, window_size)

nanmedian_axis0_ignore_empty_columns(arr)

Column-wise median of finite values (axis 0).

polyval1d(coeffs, x)

Evaluate a polynomial with given coefficients at specified points using the Horner method.

solve_chebyshev2d_ols(x, y, z, deg_x, deg_y)

Fit a 2D Chebyshev polynomial using ordinary (uncorrelated) weighted least squares.

all_sc(arr)[source]

Optimized version of np.all which short circuits, unlike numpy.all.

any_sc(arr)[source]

Optimized version of np.any which short circuits, unlike numpy.any.

bitwise_or_reduce_uint32(arr)[source]
median_filter_1d(data, dq, window_size)[source]
median_filter_2d(data, dq, window_size)[source]
nanmedian_axis0_ignore_empty_columns(arr)[source]

Column-wise median of finite values (axis 0). Columns with no finite entries are NaN.

np.nanmedian(..., axis=0) emits RuntimeWarning: All-NaN slice when entire columns are NaN; this matches nanmedian for mixed finite/NaN columns but avoids that warning.

polyval1d(coeffs, x)[source]

Evaluate a polynomial with given coefficients at specified points using the Horner method.

Parameters:
  • coeffs (np.ndarray) – Coefficients of the polynomial, ordered from lowest degree to highest (NOTE: numpy is reversed).

  • x (np.ndarray) – Points at which to evaluate the polynomial.

solve_chebyshev2d_ols(x, y, z, deg_x, deg_y, weights=None)[source]

Fit a 2D Chebyshev polynomial using ordinary (uncorrelated) weighted least squares.

Parameters:
  • x – 1D array of x coordinates (length N).

  • y – 1D array of y coordinates (length N).

  • z (np.ndarray) – 1D array of values at coordinates (x,y) (length N).

  • deg_x (int) – X Degree of the Chebyshev polynomial.

  • deg_y (int) – Y Degree of the Chebyshev polynomial.

  • weights (np.ndarray | None) – 1D array of weights (length N). If None, uniform weights are used.

Returns:

coeffs – 2D array of Chebyshev coefficients of shape (deg_x+1, deg_y+1)