tkp.utility.sigmaclip – Generic sigma clipping routine

Generic kappa-sigma clipping routine.

Note: this does not replace the specialized sigma_clip function in utilities.py

tkp.utility.sigmaclip.calcmean(data, errors=None)[source]

Calculate the mean and the standard deviation of the mean

tkp.utility.sigmaclip.calcsigma(data, errors=None, mean=None, axis=None, errors_as_weight=False)[source]

Calculate the sample standard deviation

Parameters:data (numpy.ndarray) – Data to be averaged. No conversion from eg a list to a numpy.array is done.

Kwargs:

errors (numpy.ndarray, None): Eerrors for the data. Errors
needs to be the same shape as data (this is different than for numpy.average). If you want to use weights instead of errors as input, set errors_as_weight=True. If not given, all errors (and thus weights) are assumed to be equal to 1.
mean (float): Provide mean if you don’t want the mean to be
calculated for you. Pay careful attention to the shape if you provide ‘axis’.
axis (int): Specify axis along which the mean and sigma are
calculated. If not provided, calculations are done over the whole array

errors_as_weight (bool): Set to True if errors are weights.

Returns:(2-tuple of floats) mean and sigma
tkp.utility.sigmaclip.clip(data, mean, sigma, siglow, sighigh, indices=None)[source]

Perform kappa-sigma clipping of data around mean

Parameters:
  • data (numpy.ndarray) – N-dimensional array of values
  • mean (float) – value around which to clip (does not have to be the mean)
  • sigma (float) – sigma-value for clipping
  • siglow (float) – lower kappa clipping values
  • sighigh (float) – higher kappa clipping values

Kwargs:

indices (numpy.ndarray): data selection by indices
Returns:(numpy.ndarray) indices of non-clipped data
tkp.utility.sigmaclip.sigmaclip(data, errors=None, niter=0, siglow=3.0, sighigh=3.0, use_median=False)[source]

Remove outliers from data which lie more than siglow/sighigh sample standard deviations from mean.

Parameters:data (numpy.ndarray) – Numpy array containing data values.

Kwargs:

errors (numpy.ndarray, None): Errors associated with the data
values. If None, unweighted mean and standard deviation are used in calculations.
niter (int): Number of iterations to calculate mean & standard
deviation, and reject outliers, If niter is negative, iterations will continue until no more clipping occurs or until abs(‘niter’) is reached, whichever is reached first.
siglow (float): Kappa multiplier for standard deviation. Std *
siglow defines the value below which data are rejected.
sighigh (float): Kappa multiplier for standard deviation. Std *
sighigh defines the value above which data are rejected.

use_median (bool): Use median of data instead of mean.

Returns:
(2-tuple) Boolean numpy array of indices indicating which
elements are clipped (False), with the same shape as the input; number of iterations
Return type:tuple