edges_cal.xrfi.xrfi_model_nonlinear_window

edges_cal.xrfi.xrfi_model_nonlinear_window(spectrum: ndarray, *, freq: ndarray, model: Model, flags=None, window_frac: int = 16, min_window_size: int = 10, max_iter: int = 100, threshold: float = 2.5, watershed: dict | None = None, reflag_thresh: float = 1.01, fit_kwargs: dict | None = None, weights: ndarray | None)[source]

Flag RFI using a model fit and a sliding RMS window.

This function is algorithmically the same as that used in Bowman+2018. The differences between this and xrfi_model() (which is the recommended function to use) are:

  • This does flagging inside the sliding window – i.e. once you move the window up by one channel, the flags can be different in the previous bins. This is a bit strange, since it makes the process more non-linear. If you were to start from the top of the band and slide the window down, you’d get different results.

  • The watershedding (flagging channels around the “bad” one) only happens if the main central channel is far enough away from the edges of the band.

  • It only flags positive outliers.

Parameters:
  • spectrum (array-like) – The 1D spectrum to flag.

  • freq – The frequencies associated with the spectrum.

  • model (edges_cal.modelling.Model) – The model to fit to the spectrum to get residuals.

  • flags (array-like, optional) – The initial flags to use. If not given, all channels are unflagged.

  • window_frac (int, optional) – The size of the sliding window as a fraction of the number of channels (i.e. the final window is int(Nchannels / window_frac) in size).

  • min_window_size (int, optional) – The minimum size of the sliding window, in number of channels.

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

  • threshold (float, optional) – The threshold for flagging a channel. The threshold is the number of standard deviations the residuals are from zero.

  • watershed (dict, optional) – The parameters for the watershedding algorithm. If not given, no watershedding is performed. Each key should be a float that specifies the number of threshold*stds away from zero that a channel should be flagged. The value should be the number of channels to flag on either side of the flagged channel for that threshold. For example, {3: 2} would flag 2 channels on either side of any channel that is 3*threshold standard deviations away from zero.

  • reflag_thresh (float, optional) – The basic algorithm has “memory”, i.e. if a channel is flagged in one iteration, it will remain flagged for all following iterations, even if it is no longer an outlier for the updated model. This parameter allows you to re-consider a flag on a later iteration, if it was originally flagged at less than reflag_thresh times the threshold. This can improve conformity to the results of Bowman+2018, because the model fits are very slightly different between the codes used, but it is very difficult to predict exactly how the parameter will affect the results.

  • fit_kwargs (dict, optional) – Any additional keyword arguments to pass to the model fit. Use the key “method” with value “alan-qrd” for the closest match to the Bowman+2018 code.

Returns:

  • flags (array-like) – Boolean array of the same shape as spectrum indicated which channels/times have flagged RFI.

  • info (ModelFilterInfo) – A ModelFilterInfo object containing information about the fit at each iteration.