ska_sdp_instrumental_calibration.xarray_processors.gain_flagging module

class ska_sdp_instrumental_calibration.xarray_processors.gain_flagging.SmoothingFit(order, component)[source]

Bases: object

fit(gains, weights)[source]

Fits a smooth curve on the gains.

Parameters:
  • gains (Array) -- Gains.

  • weights (Array) -- Weights of the gains.

Returns:

Dict of fits.

class ska_sdp_instrumental_calibration.xarray_processors.gain_flagging.PhasorPolyFit(order, freq)[source]

Bases: object

fit(gains, weights, freq_guess)[source]

Fit a phasor model with polynomial envelope.

Parameters:
  • gains (Array) -- Gains.

  • weights (Array) -- Weights of the gains.

  • freq_guess (float) -- Initial frequency to begin.

Returns:

Fitted model.

phasor_envelope_model(x_arr, freq, *params)[source]

Phasor model with polynomial envelope.

Parameters:
  • x_arr (Array) -- gains

  • freq (Array) -- Frequency

  • *params ((tuple[float])) -- Polynomial coefficients.

Returns:

Phasor model array.

real_wrapper(x_arr, *params)[source]

Wrapper for curve_fit to handle complex y_arr.

Parameters:
  • x_arr (Array) -- gains

  • *params ((tuple[float])) -- Fitting parameters.

Returns:

A complex array disguised as a real-valued one.

class ska_sdp_instrumental_calibration.xarray_processors.gain_flagging.RMSFlagger(n_sigma)[source]

Bases: object

pre_flag(arr, weights)[source]

Flag outliers using Median Absolute Deviation (MAD).

Parameters:
  • arr (ndarray) -- Input array containing the data to be flagged.

  • weights (ndarray) -- Weighting factors for each element in the input array.

Returns:

ndarray

Boolean mask where True indicates an outlier based on n_sigma.

flag(arr, weights)[source]

Does flagging using rms.

Parameters:
  • arr (Array) -- Diff of fit and gains.

  • weights (Array) -- Weights of gains.

  • detrend (Bool) -- Whether the array is detrended or not

Returns:

Array fo flags

class ska_sdp_instrumental_calibration.xarray_processors.gain_flagging.RollingRMSFlagger(n_sigma, window)[source]

Bases: object

pre_flag(arr, weights)[source]

Flag outliers based on the rolling RMS and MAD-derived threshold.

Parameters:
  • arr (ndarray) -- Input array to be analyzed.

  • weights (ndarray) -- Weighting factors where zero indicates invalid data points.

Returns:

Boolean mask identifying elements exceeding the n_sigma threshold.

flag(arr, weights)[source]

Does flagging using rolling rms.

Parameters:
  • deterend (Array) -- Diff of fit and gains.

  • weights (Array) -- Weights of gains.

Returns:

Array fo flags

class ska_sdp_instrumental_calibration.xarray_processors.gain_flagging.GainFlagger(soltype, order, max_ncycles, n_sigma, n_sigma_rolling, window_size, freq)[source]

Bases: object

MODE = {'amp-phase': 'poly', 'amplitude': 'poly', 'phase': 'poly', 'real-imag': 'smooth'}
SOLTYPE = {'amp-phase': <function GainFlagger.<lambda>>, 'amplitude': <function GainFlagger.<lambda>>, 'phase': <function GainFlagger.<lambda>>, 'real-imag': <function GainFlagger.<lambda>>}
flag_dimension(gains, weights, antenna_name, receptor1_name, receptor2_name)[source]

Applies flagging to chunk of gaintable with detrending/fitting algorithm for the given gain and weight chunk.

Parameters:
  • gains (ndarray) -- Gain solutions. Shape: (freq,)

  • weights (ndarray) -- Weight of gains. Shape: (freq,)

  • antenna_name (str) -- Antenna name

  • receptor1_name (str) -- Receptor1 name. e.g. 'X'

  • receptor2_name (str) -- Receptor2 name. e.g. 'Y'

Return type:

tuple[ndarray, dict]

Returns:

A tuple of updated weights, and final fits of soltype.

ska_sdp_instrumental_calibration.xarray_processors.gain_flagging.flag_on_gains(gaintable, soltype, order, max_ncycles, n_sigma, n_sigma_rolling, window_size, normalize_gains, skip_cross_pol, apply_flag)[source]

Solves for gain flagging on gaintable for every receptor combination. Optionally applies the weights to the gains.

Parameters:
  • gaintable (Gaintable) -- Gaintable from previous solution.

  • soltype (str) -- Solution type to flag. Can be "real-imag", "phase", "amplitude" or "amp-phase".

  • order (int) -- Order of the function fitted during detrending. If mode=smooth these are the window of the running median (0=all axis).

  • max_ncycles (int) -- Max number of independent flagging cycles, by default 5.

  • n_sigma (float) -- Flag values greated than n_simga * sigma_hat. Where sigma_hat is 1.4826 * MeanAbsoluteDeviation

  • n_sigma_rolling (float, optional) -- Do a running rms and then flag those regions that have a rms higher than n_sigma_rolling*MAD(rmses).

  • window_size (int) -- Window size for the running rms, by default 11.

  • normalize_gains (bool) -- Normailize the amplitude and phase before flagging.

  • skip_cross_pol (bool) -- Cross polarizations is skipped when flagging.

  • apply_flag (bool) -- Weights are applied to the gains.

Return type:

Dataset

Returns:

gaintable: Gaintable

Updated gaintable with weights.

fits: dict

All fits generated.