OPERA  1.0
Open source echelle spectrograph reduction pipeline
operaFit.c File Reference

Fitting library. More...

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "libraries/operaLMFit.h"
#include "libraries/operaFit.h"
Include dependency graph for operaFit.c:

Data Structures

struct  poly2Ddata_struct
 poly2Ddata_struct - a data structure to transmit model data to function evaluation More...
struct  gauss2Ddata_struct
 gauss2Ddata_struct - a data structure to transmit model data to function evalution More...

Namespaces

namespace  operaFit

Defines

#define NRANSI
#define NR_END   1
#define FREE_ARG   char*
#define EPS   1.0e-7
#define SWAP(a, b)   temp=(a);(a)=(b);(b)=temp;
#define SIGN(a, b)   ((b) >= 0.0 ? fabs(a) : -fabs(a))

Functions

double PolynomialFunction (double x, const double *p, int n_par)
 This function returns the value of a given polynomial function.
void operaLMFitPolynomial (unsigned m_dat, double *x, double *y, int n_par, double *par, double *chi2, int verbose)
 This function performs Polynomial Fitting using the Levenberg-Marquardt method.
double GaussianFunction (double x, const double *p, int n_par)
 This function returns the value for a Gaussian: f(x) = A*exp(-((x-x0)/sqrt(2)*sig)^2)
void operaLMFitGaussian (unsigned m_dat, double *x, double *y, double *a, double *x0, double *sig, double *chi2, int verbose)
 This function performs Gaussian Fitting using the Levenberg-Marquardt method.
double Polynomial2DFunction (double x, double y, const double *p, int n_par)
 This function returns the value of a given 2D polynomial surface function.
void evaluate_surface (int n_par, const double *par, int m_dat, const void *data, double *fvec, int *info)
 This function performs 2D polynomial function evaluation, determination of residues.
void operaLMFit2DPolynomial (unsigned m_dat, double *x, double *y, double *fxy, int n_par, double *par, double *chi2, int verbose)
 This function performs 2D Polynomial Fitting using the Levenberg-Marquardt method.
double Gaussian2DFunction (double x, double y, const double *p, int n_par)
 This function returns the value for a 2D Gaussian: f(x,y) = A*exp(-(((x-x0)/sqrt(2)*sigx)^2 + ((y-y0)/sqrt(2)*sigy)^2))
void evaluate_2DGaussian (int n_par, const double *par, int m_dat, const void *data, double *fvec, int *info)
 This function performs 2D Gaussian function evaluation, determination of residues.
void operaLMFit2DGaussian (unsigned m_dat, double *x, double *y, double *fxy, double *a, double *x0, double *y0, double *sigx, double *sigy, double *chi2, int verbose)
 This function performs 2D Gaussian Fitting using the Levenberg-Marquardt method.
void operaFitSpline (unsigned nin, float *xin, float *yin, unsigned nout, float *xout, float *yout)
 This function performs interpolation of an input array using a sufficiently smooth piecewise-polynomial function (cubic spline)
void operaFit2DSpline (unsigned nxin, float *xin, unsigned nyin, float *yin, double *fxyin, unsigned nxout, float *xout, unsigned nyout, float *yout, float *fxyout)
 This function performs interpolation of an input 2D-array using a sufficiently smooth piecewise-polynomial function (cubic spline)
void spline (float x[], float y[], int n, float yp1, float ypn, float y2[])
void splint (float xa[], float ya[], float y2a[], int n, float x, float *y)
void splin2 (float x1a[], float x2a[], float **ya, float **y2a, int m, int n, float x1, float x2, float *y)
void splie2 (float x1a[], float x2a[], float **ya, int m, int n, float **y2a)
float ** matrix (long nrl, long nrh, long ncl, long nch)
void free_matrix (float **m, long nrl, long nrh, long ncl, long nch)
void operaMedfit (float xin[], float yin[], int ndata, float *a, float *b, float *abdev)
 This function performs robust linear fit: f(x) = a + b*x.
float rofunc (float b)
 This function ...
float select_nr (unsigned long k, unsigned long n, float arr[])
 This function ...
void free_vector (float *v, long nl, long nh)
 This function frees a float vector allocated with vector().
float * vector (long nl, long nh)
 This function allocates a float vector with subscript range v[nl..nh].
void nrerror (char error_text[])

Variables

static int verbose = 0
 Fitting library.
static int debug = 0
int ndatat
float * xt
float * yt
float aa
float abdevt

Detailed Description

Fitting library.


Define Documentation

#define EPS   1.0e-7
#define FREE_ARG   char*
#define NR_END   1
#define NRANSI
#define SIGN (   a,
 
)    ((b) >= 0.0 ? fabs(a) : -fabs(a))
#define SWAP (   a,
 
)    temp=(a);(a)=(b);(b)=temp;

Function Documentation

void evaluate_2DGaussian ( int  n_par,
const double *  par,
int  m_dat,
const void *  data,
double *  fvec,
int *  info 
)

This function performs 2D Gaussian function evaluation, determination of residues.

void evaluate_2DGaussian(int n_par, const double *par, int m_dat, const void *data, double *fvec, int *info )

Parameters:
n_paris an unsigned that ..,
paris a double pointer that ..,
m_datis an int that ..,
datais a double pointer that ..,
fvecis a double pointer that ..,
infois an int pointer that ..,
Returns:
void
void evaluate_surface ( int  n_par,
const double *  par,
int  m_dat,
const void *  data,
double *  fvec,
int *  info 
)

This function performs 2D polynomial function evaluation, determination of residues.

void evaluate_surface(int n_par, const double *par, int m_dat, const void *data, double *fvec, int *info )

Parameters:
n_paris an int that ..,
paris a double pointer that ..,
m_datis an int that ..,
datais a double pointer that ..,
fvexis a double pointer that ..,
infois a double pointer that ..,
Returns:
void
void free_matrix ( float **  m,
long  nrl,
long  nrh,
long  ncl,
long  nch 
)
void free_vector ( float *  v,
long  nl,
long  nh 
)

This function frees a float vector allocated with vector().

fvoid free_vector(float *v, long nl, long nh)

Parameters:
vis a double pointer that ..,
nlis a long that ..,
nhis a long that ..,
Returns:
void
double Gaussian2DFunction ( double  x,
double  y,
const double *  p,
int  n_par 
)

This function returns the value for a 2D Gaussian: f(x,y) = A*exp(-(((x-x0)/sqrt(2)*sigx)^2 + ((y-y0)/sqrt(2)*sigy)^2))

double Gaussian2DFunction(double x, double y, const double *p, int n_par)

Parameters:
xis a double input x-value for which the given 2D Gaussian is evaluated
yis a double input y-value for which the given 2D Gaussian is evaluated
pis a const double pointer for the coefficients of the 2D Gaussian
n_paris an int for the number of coefficients (must be 5!)
Returns:
double value of 2D Gaussian
double GaussianFunction ( double  x,
const double *  p,
int  n_par 
)

This function returns the value for a Gaussian: f(x) = A*exp(-((x-x0)/sqrt(2)*sig)^2)

double GaussianFunction(double x, const double *p, int n_par)

Parameters:
xis a double input value for which the given Gaussian is evaluated
pis a const double pointer for the coefficients of the Gaussian
n_paris an int for the number of coefficients (must be 3!)
Returns:
double value of Gaussian
float** matrix ( long  nrl,
long  nrh,
long  ncl,
long  nch 
)

Here is the call graph for this function:

void nrerror ( char  error_text[])
void operaFit2DSpline ( unsigned  nxin,
float *  xin,
unsigned  nyin,
float *  yin,
double *  fxyin,
unsigned  nxout,
float *  xout,
unsigned  nyout,
float *  yout,
float *  fxyout 
)

This function performs interpolation of an input 2D-array using a sufficiently smooth piecewise-polynomial function (cubic spline)

void operaFitSpline(unsigned nin, float *xin,float *yin, unsigned nout, float *xout, float *yout)

Parameters:
nxinis an unsigned for the number of x input data points
xinis a float array for the input x data points
nyinis an unsigned for the number of y input data points
yinis a float array for the input y data points
fxyinis a float array for the input fxy data points
nxoutis an unsigned for the number of x output data points.
xoutis a float array for the output x data points, which should be provided.
nyoutis an unsigned for the number of y output data points.
youtis a float array for the output y data points, which should be provided.
fxyoutis a float array for the output interpolated fxy data points, which is calculated
Returns:
void

Here is the call graph for this function:

void operaFitSpline ( unsigned  nin,
float *  xin,
float *  yin,
unsigned  nout,
float *  xout,
float *  yout 
)

This function performs interpolation of an input array using a sufficiently smooth piecewise-polynomial function (cubic spline)

void operaFitSpline(unsigned nin, float *xin,float *yin, unsigned nout, float *xout, float *yout)

Parameters:
ninis an unsigned for the number of input data points
xinis a float array for the input x data points
yinis a float array for the input y data points
noutis an unsigned for the number of output data points
xoutis a float array for the output x data points, which should be provided.
youtis a float array for the output interpolated y data points, which is calculated
Returns:
void

Here is the call graph for this function:

void operaLMFit2DGaussian ( unsigned  m_dat,
double *  x,
double *  y,
double *  fxy,
double *  a,
double *  x0,
double *  y0,
double *  sigx,
double *  sigy,
double *  chi2,
int  verbose 
)

This function performs 2D Gaussian Fitting using the Levenberg-Marquardt method.

void operaLMFit2DGaussian(unsigned m_dat, double *x, double *y, double *fxy, double *a, double *x0, double *y0, double *sigx, double *sigy, double *chi2, int verbose)

Parameters:
m_datis an unsigned for the number of data points
xis a double pointer with x data values
yis a double pointer with y data values
ais a double pointer for the amplitude of the Gaussian
x0is a double pointer for the x-center of the Gaussian
y0is a double pointer for the y-center of the Gaussian
sigxis a double pointer for the spread of the Gaussian in the x-direction
sigyis a double pointer for the spread of the Gaussian in the y-direction
chi2is a double pointer that returns the reduced chi-square of the fit
verboseis an int that controls print option: 1=on, 0=off
Returns:
void

Here is the call graph for this function:

void operaLMFit2DPolynomial ( unsigned  m_dat,
double *  x,
double *  y,
double *  fxy,
int  n_par,
double *  par,
double *  chi2,
int  verbose 
)

This function performs 2D Polynomial Fitting using the Levenberg-Marquardt method.

void operaLMFit2DPolynomial(unsigned m_dat, double *x, double *y, double *fxy, int n_par, double *par, double *chi2, int verbose)

Parameters:
m_datis an unsigned for the number of data points
xis a double pointer with x data values
yis a double pointer with y data values
fxyis a double pointer with f(x,y) data values
n_paris an int for the order of the 2D polynomial to be fit
paris a double pointer for the coefficients of the 2D polynomial
chi2is a double pointer that returns the reduced chi-square of the fit
verboseis an int that controls print option: 1=on, 0=off
Returns:
void

Here is the call graph for this function:

void operaLMFitGaussian ( unsigned  m_dat,
double *  x,
double *  y,
double *  a,
double *  x0,
double *  sig,
double *  chi2,
int  verbose 
)

This function performs Gaussian Fitting using the Levenberg-Marquardt method.

void operaLMFitGaussian(unsigned m_dat, double *x, double *y, double *a, double *x0, double *sig, double *chi2, int verbose)

Parameters:
m_datis an unsigned for the number of data points
xis a double pointer with x data values
yis a double pointer with y data values
ais a double pointer for the amplitude of the Gaussian
x0is a double pointer for the center of the Gaussian
sigis a double pointer for the spread of the Gaussian
chi2is a double pointer that returns the reduced chi-square of the fit
verboseis an int that controls print option: 1=on, 0=off
Returns:
void

Here is the call graph for this function:

void operaLMFitPolynomial ( unsigned  m_dat,
double *  x,
double *  y,
int  n_par,
double *  par,
double *  chi2,
int  verbose 
)

This function performs Polynomial Fitting using the Levenberg-Marquardt method.

void operaLMFitPolynomial(unsigned m_dat, double *x, double *y, int n_par, double *par, double *chi2, int verbose)

Parameters:
m_datis an unsigned for the number of data points
xis a double pointer with x data values
yis a double pointer with y data values
n_paris an int for the order of the polynomial to be fit
paris a double pointer for the coefficients of the polynomial
chi2is a double pointer that returns the reduced chi-square of the fit
verboseis an int that controls print option: 1=on, 0=off
Returns:
void

Here is the call graph for this function:

void operaMedfit ( float  xin[],
float  yin[],
int  ndata,
float *  a,
float *  b,
float *  abdev 
)

This function performs robust linear fit: f(x) = a + b*x.

void operaMedfit(float xin[], float yin[], int ndata, float *a, float *b, float *abdev)

Parameters:
xinis a float array with data values
yinis a float array with data values
ndatais an int for the number of data points
ais a double pointer for the linear coefficient
bis a double pointer for the angular coefficient
abdevis a double pointer for the absolute deviation (~chi-square)
Returns:
void

Here is the call graph for this function:

double Polynomial2DFunction ( double  x,
double  y,
const double *  p,
int  n_par 
)

This function returns the value of a given 2D polynomial surface function.

double Polynomial2DFunction(double x, double y, const double *p, int n_par)

Parameters:
xis a double input value for which the given polynomial is evaluated
yis a double input value for which the given polynomial is evaluated
pis a const double pointer that contains the coefficients of the given 2D polynomial
n_paris an int that defines the order of the 2D polynomial
Returns:
double value of the 2D polynomial
double PolynomialFunction ( double  x,
const double *  p,
int  n_par 
)

This function returns the value of a given polynomial function.

double PolynomialFunction(double x, const double *p, int n_par)

Parameters:
xis a double input value for which the given polynomial is evaluated
pis a const double pointer that contains the coefficients of the given polynomial
n_paris an int that defines the order of the polynomial
Returns:
double value of the polynomial
float rofunc ( float  b)

This function ...

float rofunc(float b)

Parameters:
bis a double that ..,
Returns:
float

Here is the call graph for this function:

float select_nr ( unsigned long  k,
unsigned long  n,
float  arr[] 
)

This function ...

float select_nr(unsigned long k, unsigned long n, float arr[])

Parameters:
kis an unsigned long that ..,
nis an unsigned long that ..,
arris a double pointer that ..,
Returns:
float
void splie2 ( float  x1a[],
float  x2a[],
float **  ya,
int  m,
int  n,
float **  y2a 
)

Here is the call graph for this function:

void splin2 ( float  x1a[],
float  x2a[],
float **  ya,
float **  y2a,
int  m,
int  n,
float  x1,
float  x2,
float *  y 
)

Here is the call graph for this function:

void spline ( float  x[],
float  y[],
int  n,
float  yp1,
float  ypn,
float  y2[] 
)

Here is the call graph for this function:

void splint ( float  xa[],
float  ya[],
float  y2a[],
int  n,
float  x,
float *  y 
)

Here is the call graph for this function:

float* vector ( long  nl,
long  nh 
)

This function allocates a float vector with subscript range v[nl..nh].

float *vector(long nl, long nh)

Parameters:
nlis a long that ..,
nhis a long that ..,
Returns:
float

Variable Documentation

float aa
float abdevt
int ndatat
float* xt
float * yt