X-shooter Pipeline Reference Manual 3.8.15
Functions
xsh_ksigma_clip.h File Reference
#include <cpl.h>
#include <xsh_cpl_size.h>

Go to the source code of this file.

Functions

cpl_error_code xsh_ksigma_clip (const cpl_image *, const int, const int, const int, const int, const double, const int, const double, double *, double *)
 Apply kappa-sigma clipping on input image.
 

Function Documentation

◆ xsh_ksigma_clip()

cpl_error_code xsh_ksigma_clip ( const cpl_image *  img,
int  llx,
int  lly,
int  urx,
int  ury,
double  kappa,
int  nclip,
double  tolerance,
double *  kmean,
double *  kstdev 
)

Apply kappa-sigma clipping on input image.

Parameters
imgInput image
llxLower left x position (FITS convention)
llyLower left y position (FITS convention)
urxUpper right x position (FITS convention)
uryUpper right y position (FITS convention)
kappaKappa value for the clipping
nclipNumber of clipping iterations
kmeanMean after clipping (output)
kstdevStdev after clipping (output)
Returns
CPL_ERROR_NONE or the relevant #_cpl_error_code_ on error

This function applies an iterative kappa-sigma clipping on the image and returns mean and stdev after the clipping.

The function takes as a starting point the "standard" values of mean and stdev from cpl_stats.

On each iteration, the contribution of pixels outside the range [mean - kappa * stdev, mean + kappa * stdev] is removed, the values of mean and stdev are updated, and so are the limits of the range to be used in the next iteration as well.

The algorithm stops after nclip iterations or when the variation of the range between two consecutive iterations is smaller (absolute value) than the tolerance.

The effectiveness of this function resides on the way the update of the values of mean and stdev is done.

The contribution of a single pixel in variance can be removed as follows:

\sum_{i=1}^{N-1} (x_i - \overline{x}_{n-1})^2 = \sum_{i=1}^ N (x_i - \overline{x}_n )^2 - \frac{N}{N-1} \,( \, \overline{x}_n - x_{n} )^2

For further details on the mathematical aspects, please refer to DFS05126.

Possible #_cpl_error_code_ set in this function:

  • CPL_ERROR_NULL_INPUT if img or kmean is NULL
  • CPL_ERROR_ILLEGAL_INPUT if a) the window specification is illegal (llx > urx or lly > ury) b) the window specification is outside the image c) the tolerance is negative d) kappa is <= 1.0 e) nclip is <= 0.

The values of kmean and kstdev is undefined on error.

Definition at line 150 of file xsh_ksigma_clip.c.

References kappa, llx, lly, nx, ny, tolerance, urx, and ury.