edges_cal.xrfi.model_filter

edges_cal.xrfi.model_filter(x: ndarray, data: ndarray, *, model: Model = Polynomial(parameters=None, n_terms=3, transform=IdentityTransform(), offset=0.0), resid_model: Model = Polynomial(parameters=None, n_terms=5, transform=IdentityTransform(), offset=0.0), flags: ndarray | None = None, weights: ndarray | None = None, n_resid: int = -1, threshold: float | None = None, max_iter: int = 20, increase_order: bool = True, min_terms: int = 0, max_terms: int = 10, min_resid_terms: int = 3, decrement_threshold: float = 0, min_threshold: float = 5, watershed: int | dict[float, int] | None = None, flag_if_broken: bool = True, init_flags: ndarray | None = None, std_estimator: Literal['model', 'medfilt', 'std', 'mad', 'sliding_rms'] = 'model', medfilt_width: int = 100, sliding_rms_width: int = 100)[source]

Flag data by subtracting a smooth model and iteratively removing outliers.

On each iteration, a model is fit to the unflagged data, and another model is fit to the absolute residuals. Bins with absolute residuals greater than threshold are flagged, and the process is repeated until no new flags are found.

Parameters:
  • x – The coordinates of the data.

  • data – The data (same shape as x).

  • model – A model to fit to the data.

  • resid_model – The model to fit to the absolute residuals.

  • flags (array-like, optional) – The flags associated with the data (same shape as spectrum).

  • weights (array-like,, optional) – The weights associated with the data (same shape as spectrum).

  • n_resid (int, optional) – The number of polynomial terms to use to fit the residuals.

  • threshold (float, optional) – The factor by which the absolute residual model is multiplied to determine outliers.

  • max_iter (int, optional) – The maximum number of iterations to perform.

  • accumulate (bool, optional) – Whether to accumulate flags on each iteration.

  • increase_order (bool, optional) – Whether to increase the order of the polynomial on each iteration.

  • decrement_threshold (float, optional) – An amount to decrement the threshold by every iteration. Threshold will never go below min_threshold.

  • min_threshold (float, optional) – The minimum threshold to decrement to.

  • watershed – How many data points on each side of a flagged point that should be flagged. If a dictionary, you can give keys as the threshold above which z-scores will be flagged, and as values, the number of bins flagged beside it. Use 0.0 threshold to indicate the base threshold.

  • init_flags – Initial flags that are not remembered after the first iteration. These can help with getting the initial model. If a tuple, should be a min and max frequency of a range to flag.

  • std_estimator – The estimator to use to get the standard deviation of each sample.

  • medfilt_width – Only used if std_estimator=’medfilt’. The width (in number of bins) to use for the median filter.

Returns:

flags – Boolean array of the same shape as data.