X-shooter Pipeline Reference Manual 3.8.15
Macros | Functions
xsh_ksigma_clip.c File Reference
#include <complex.h>
#include <math.h>
#include <string.h>
#include <assert.h>
#include <float.h>
#include <cpl.h>
#include "xsh_ksigma_clip.h"
#include "xsh_detmon_body.h"

Go to the source code of this file.

Macros

#define CONCAT(a, b)   a ## _ ## b
 
#define CONCAT2X(a, b)   CONCAT(a,b)
 
#define CPL_TYPE   double
 
#define CPL_TYPE   float
 
#define CPL_TYPE   int
 

Functions

static cpl_error_code xsh_ksigma_clip_double (const double *pi, cpl_binary *pm, int llx, int lly, int urx, int ury, int nx, double var_sum, int npixs, double kappa, int nclip, double tolerance, double *mean, double *stdev)
 
static cpl_error_code xsh_ksigma_clip_float (const float *pi, cpl_binary *pm, int llx, int lly, int urx, int ury, int nx, double var_sum, int npixs, double kappa, int nclip, double tolerance, double *mean, double *stdev)
 
static cpl_error_code xsh_ksigma_clip_int (const int *pi, cpl_binary *pm, int llx, int lly, int urx, int ury, int nx, double var_sum, int npixs, double kappa, int nclip, double tolerance, double *mean, double *stdev)
 
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.
 

Macro Definition Documentation

◆ CONCAT

#define CONCAT (   a,
 
)    a ## _ ## b

Definition at line 230 of file xsh_ksigma_clip.c.

◆ CONCAT2X

#define CONCAT2X (   a,
 
)    CONCAT(a,b)

Definition at line 231 of file xsh_ksigma_clip.c.

◆ CPL_TYPE [1/3]

#define CPL_TYPE   double

Definition at line 241 of file xsh_ksigma_clip.c.

◆ CPL_TYPE [2/3]

#define CPL_TYPE   float

Definition at line 241 of file xsh_ksigma_clip.c.

◆ CPL_TYPE [3/3]

#define CPL_TYPE   int

Definition at line 241 of file xsh_ksigma_clip.c.

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.

◆ xsh_ksigma_clip_double()

static cpl_error_code xsh_ksigma_clip_double ( const double *  pi,
cpl_binary *  pm,
int  llx,
int  lly,
int  urx,
int  ury,
int  nx,
double  var_sum,
int  npixs,
double  kappa,
int  nclip,
double  tolerance,
double *  mean,
double *  stdev 
)
static

◆ xsh_ksigma_clip_float()

static cpl_error_code xsh_ksigma_clip_float ( const float *  pi,
cpl_binary *  pm,
int  llx,
int  lly,
int  urx,
int  ury,
int  nx,
double  var_sum,
int  npixs,
double  kappa,
int  nclip,
double  tolerance,
double *  mean,
double *  stdev 
)
static

◆ xsh_ksigma_clip_int()

static cpl_error_code xsh_ksigma_clip_int ( const int *  pi,
cpl_binary *  pm,
int  llx,
int  lly,
int  urx,
int  ury,
int  nx,
double  var_sum,
int  npixs,
double  kappa,
int  nclip,
double  tolerance,
double *  mean,
double *  stdev 
)
static