MicroLIA.helper_features

Created on Sat Jun 14 10:05:51 2023

@author: daniel

Module Contents

Functions

_safe_weights(→ numpy.ndarray)

Inverse-variance weights that are finite and positive.

_weighted_percentiles(→ numpy.ndarray)

Weighted value percentiles.

_frac_sigma(→ float)

Fraction of points more than 1σ above (sign=+1) or below (sign=−1) the median.

_weighted_percentile(→ float)

Compute the weighted percentile of a 1D array.

_first_sig_digit(→ numpy.ndarray)

First significant digit (1–9) of absolute values.

_dup_with_tol(→ int)

Detect duplicate values within a tolerance defined by errors.

_weighted_median(→ float)

Weighted median of data x with weights w.

_flux_percentile_ratio(→ float)

(p_hi − p_lo) / (95th − 5th) percentile flux ratio, with optional weighting.

_longest_true_run(→ int)

Length of the longest consecutive True subsequence.

_delta(→ numpy.ndarray)

Stetson normalized residuals (single-band).

MicroLIA.helper_features._safe_weights(magerr: numpy.typing.ArrayLike) numpy.ndarray[source]

Inverse-variance weights that are finite and positive.

Parameters:

magerr (array-like) – Photometric errors.

Returns:

w – Array of weights (1 / magerr²), with invalid entries set to 0.

Return type:

ndarray

MicroLIA.helper_features._weighted_percentiles(x: numpy.typing.ArrayLike, w: numpy.typing.ArrayLike, q: Union[float, Sequence[float], numpy.ndarray]) numpy.ndarray[source]

Weighted value percentiles.

Parameters:
  • x (1-D array (already sorted ascending)) –

  • w (matching 1-D weights (non-negative, same order as x)) –

  • q (scalar or sequence in [0,1] (e.g. 0.95 or [0.05, 0.4, 0.6, 0.95])) –

Returns:

percentiles

Return type:

ndarray

MicroLIA.helper_features._frac_sigma(mag: numpy.typing.ArrayLike, magerr: numpy.typing.ArrayLike, apply_weights: bool = True, sign: int = 1) float[source]

Fraction of points more than 1σ above (sign=+1) or below (sign=−1) the median.

Parameters:
  • mag (array-like) – Magnitude or flux values.

  • magerr (array-like) – Associated errors.

  • sign (int, default=1) – Use +1 for upper tail or −1 for lower tail.

  • apply_weights (bool, default=True) – Whether to use weighted average.

Returns:

frac – Fraction of outliers.

Return type:

float

MicroLIA.helper_features._weighted_percentile(data: numpy.typing.ArrayLike, weights: numpy.typing.ArrayLike, percentile: float) float[source]

Compute the weighted percentile of a 1D array.

Parameters:
  • data (array-like) – Input data values.

  • weights (array-like) – Non-negative weights associated with each data point. Must be the same length as data.

  • percentile (float) – Desired percentile in the range [0, 100].

Returns:

value – The weighted percentile value of the input data.

Return type:

float

MicroLIA.helper_features._first_sig_digit(arr: numpy.typing.ArrayLike) numpy.ndarray[source]

First significant digit (1–9) of absolute values.

Parameters:

arr (array-like) –

Returns:

digits – Vectorized output, same shape as input.

Return type:

int array

MicroLIA.helper_features._dup_with_tol(values: numpy.typing.ArrayLike, errs: numpy.typing.ArrayLike, tol_factor: float = 2.0) int[source]

Detect duplicate values within a tolerance defined by errors.

Parameters:
  • values (array-like) – Magnitude or flux values.

  • errs (array-like) – Associated errors.

  • tol_factor (float) – Scaling factor for the tolerance.

Returns:

1 if duplicates are found within tolerance, else 0.

Return type:

int

MicroLIA.helper_features._weighted_median(x: numpy.typing.ArrayLike, w: numpy.typing.ArrayLike) float[source]

Weighted median of data x with weights w.

Parameters:
  • x (array-like) – Data values.

  • w (array-like) – Associated weights.

Returns:

median – Weighted median.

Return type:

float

MicroLIA.helper_features._flux_percentile_ratio(mag: numpy.typing.ArrayLike, magerr: numpy.typing.ArrayLike, p_lo: float, p_hi: float, apply_weights: bool = True) float[source]

(p_hi − p_lo) / (95th − 5th) percentile flux ratio, with optional weighting.

Parameters:
  • mag (array-like) – Magnitude or flux values.

  • magerr (array-like) – Associated errors.

  • p_lo (float) – Percentile bounds, e.g., 0.4 and 0.6.

  • p_hi (float) – Percentile bounds, e.g., 0.4 and 0.6.

  • apply_weights (bool) – Whether to apply inverse-variance weights.

Returns:

ratio – Flux percentile ratio.

Return type:

float

MicroLIA.helper_features._longest_true_run(mask: numpy.ndarray) int[source]

Length of the longest consecutive True subsequence.

Parameters:

mask (1D bool array) –

Returns:

max_run – Length of the longest run of True values.

Return type:

int

MicroLIA.helper_features._delta(mag: numpy.typing.ArrayLike, magerr: numpy.typing.ArrayLike) numpy.ndarray[source]

Stetson normalized residuals (single-band).

Parameters:
  • mag (array-like) – Magnitudes.

  • magerr (array-like) – Magnitude errors.

Returns:

delta – Normalized residuals.

Return type:

ndarray