spacr.outlier_filter

Remove robustly defined object outliers before guide annotation.

Optional filters operate on cell or nucleus area and intensity. Each filter uses distance from the median in scaled median absolute deviations (MADs), which is less sensitive to skewed measurements than a standard-deviation threshold. Filtering precedes fraction-based annotation so excluded objects do not contribute to normalization denominators.

Functions

apply(→ Tuple[pandas.DataFrame, List[Dict[str, Any]]])

Apply enabled outlier criteria to an object table.

column_for(→ Optional[str])

Resolve the measurement column used by an outlier criterion.

describe(→ str)

Format the per-criterion outlier report for run output.

outliers(→ numpy.ndarray)

Identify values beyond a scaled-MAD threshold.

Module Contents

spacr.outlier_filter.apply(frame: pandas.DataFrame, settings: Dict[str, Any] | None = None) → Tuple[pandas.DataFrame, List[Dict[str, Any]]][source]

Apply enabled outlier criteria to an object table.

Parameters:
  • frame (pandas.DataFrame) – Object-level measurements.

  • settings (dict, optional) – Thresholds keyed as "<criterion>_outlier_mads". Missing or None values disable that criterion; nonpositive thresholds also disable it without adding a report row.

Returns:

  • pandas.DataFrame – Rows retained after all enabled criteria.

  • list of dict – Per-criterion measurement column, threshold, removal count, and any validation note.

spacr.outlier_filter.column_for(frame: pandas.DataFrame, criterion: str) → str | None[source]

Resolve the measurement column used by an outlier criterion.

Parameters:
  • frame – object-measurement table whose columns are searched.

  • criterion – supported outlier-filter setting from CRITERIA.

Returns:

first matching measurement-column name, or None when this table cannot supply the criterion.

spacr.outlier_filter.describe(report: Sequence[Dict[str, Any]]) → str[source]

Format the per-criterion outlier report for run output.

Parameters:

report – per-criterion records returned by apply().

Returns:

multiline run summary, or "" for an empty report.

spacr.outlier_filter.outliers(values, *, mads: float = DEFAULT_MADS) → numpy.ndarray[source]

Identify values beyond a scaled-MAD threshold.

Parameters:
  • values (array-like) – Values to evaluate. Non-numeric and non-finite values are not flagged.

  • mads (float, default=DEFAULT_MADS) – Distance from the median in robust sigma units, computed as 1.4826 * MAD. Nonpositive or non-finite values disable detection.

Returns:

numpy.ndarray – Boolean outlier mask. Fewer than three finite values or a zero MAD produces an all-false mask.