UVES Pipeline Reference Manual
5.4.6
|
Data Structures | |
struct | _polynomial |
Functions | |
polynomial * | uves_polynomial_new (const cpl_polynomial *pol) |
Create a polynomial. More... | |
polynomial * | uves_polynomial_new_zero (int dim) |
Create a zero polynomial. More... | |
void | uves_polynomial_delete (polynomial **p) |
Delete a polynomial. More... | |
void | uves_polynomial_delete_const (const polynomial **p) |
Delete a const polynomial. More... | |
int | uves_polynomial_get_degree (const polynomial *p) |
Get degree. More... | |
polynomial * | uves_polynomial_duplicate (const polynomial *p) |
Copy a polynomial. More... | |
cpl_table * | uves_polynomial_convert_to_table (const polynomial *p) |
Convert a polynomial to a table. More... | |
polynomial * | uves_polynomial_convert_from_table (cpl_table *t) |
Convert a table to a polynomial. More... | |
int | uves_polynomial_get_dimension (const polynomial *p) |
Get the dimension of a polynomial. More... | |
void | uves_polynomial_dump (const polynomial *p, FILE *stream) |
Print a polynomial. More... | |
cpl_error_code | uves_polynomial_rescale (polynomial *p, int varno, double scale) |
Rescale a polynomial. More... | |
cpl_error_code | uves_polynomial_shift (polynomial *p, int varno, double shift) |
Shift a polynomial. More... | |
double | uves_polynomial_evaluate_1d (const polynomial *p, double x) |
Evaluate a 1d polynomial. More... | |
double | uves_polynomial_evaluate_2d (const polynomial *p, double x1, double x2) |
Evaluate a 2d polynomial. More... | |
double | uves_polynomial_solve_1d (const polynomial *p, double value, double guess, int multiplicity) |
Solve p(x) = value. More... | |
double | uves_polynomial_solve_2d (const polynomial *p, double value, double guess, int multiplicity, int varno, double x_value) |
Solve p(x1, x2) = value. More... | |
double | uves_polynomial_derivative_2d (const polynomial *p, double x1, double x2, int varno) |
Evaluate the partial derivative of a 2d polynomial. More... | |
double | uves_polynomial_derivative_1d (const polynomial *p, double x) |
Evaluate the derivative of a 1d polynomial. More... | |
polynomial * | uves_polynomial_add_2d (const polynomial *p1, const polynomial *p2) |
Add two polynomials. More... | |
static cpl_error_code | derivative_cpl_polynomial (cpl_polynomial *p, int varno) |
Calculate the partial derivative of a CPL-polynomial. More... | |
cpl_error_code | uves_polynomial_derivative (polynomial *p, int varno) |
Calculate the partial derivative of a polynomial. More... | |
double | uves_polynomial_get_coeff_2d (const polynomial *p, int degree1, int degree2) |
Get a coefficient of a 2D polynomial. More... | |
double | uves_polynomial_get_coeff_1d (const polynomial *p, int degree) |
Get a coefficient of a 1D polynomial. More... | |
polynomial * | uves_polynomial_collapse (const polynomial *p, int varno, double value) |
Collapse a polynomial by fixing one variable to a constant. More... | |
polynomial * | uves_polynomial_fit_1d (const cpl_vector *x_pos, const cpl_vector *values, const cpl_vector *sigmas, int poly_deg, double *mse) |
Fit a 1d function with a polynomial. More... | |
polynomial * | uves_polynomial_fit_2d (const cpl_bivector *xy_pos, const cpl_vector *values, const cpl_vector *sigmas, int poly_deg1, int poly_deg2, double *mse, double *red_chisq, polynomial **variance) |
Fit a 2d surface with a polynomial in x and y. More... | |
This module provides N dimensional polynomials.
This class is a wrapper of CPL's polynomial class, but it improves the accuracy of the fitting routine (related to DFS ticket: DFS02237), and it allows fitting with a 2d polynomial with different degree of the independent variables (which CPL does not support), and also allows propagation of the uncertainty of the fit.
Also, the module adds simple functionalities like shifting a 2d polynomial, collapsing a 2d polynomial to a 1d polynomial, and conversion of a polynomial to/from a CPL table (which can be used for I/O).
The functionality in this module has been implemented only as needed. Therefore, 1) some functionality which "should" to be there (like collapsing a polynomial of any dimension) is missing, but 2) all the functionality present has been tested.
polynomial* uves_polynomial_new | ( | const cpl_polynomial * | pol | ) |
Create a polynomial.
pol | The CPL polynomial to wrap |
uves_polynomial_delete()
, or NULL on error.Definition at line 220 of file uves_utils_polynomial.c.
References assure_mem, check, _polynomial::pol, _polynomial::scale, _polynomial::shift, uves_polynomial_delete(), and _polynomial::vec.
Referenced by test_polynomial(), uves_polynomial_add_2d(), uves_polynomial_collapse(), uves_polynomial_convert_from_table(), uves_polynomial_duplicate(), uves_polynomial_fit_1d(), uves_polynomial_fit_2d(), and uves_polynomial_new_zero().
polynomial* uves_polynomial_new_zero | ( | int | dim | ) |
Create a zero polynomial.
dim | Dimension of polynomial |
uves_polynomial_delete()
, or NULL on error. Definition at line 267 of file uves_utils_polynomial.c.
References assure_mem, and uves_polynomial_new().
Referenced by opt_measure_profile(), opt_measure_profile_order(), and test_extract().
void uves_polynomial_delete | ( | polynomial ** | p | ) |
Delete a polynomial.
p | polynomial to delete |
p is deleted and set to NULL.
Definition at line 295 of file uves_utils_polynomial.c.
References uves_polynomial_delete_const().
Referenced by calibrate_global(), create_line_table(), extract_ff_rebin_merge(), interpolate_wave(), opt_measure_profile(), opt_measure_profile_order(), parse_midas_poly(), repeat_orderdef(), test_extract(), test_iterate(), test_load_linetable(), test_polynomial(), test_polynomial_fit_2d(), uves_combine_flats(), uves_extract(), uves_get_blaze_ratio(), uves_locate_orders(), uves_lt_delete(), uves_physmod_calmap(), uves_physmod_msrawxy(), uves_physmod_regress_echelle(), uves_polynomial_collapse(), uves_polynomial_convert_from_table(), uves_polynomial_duplicate(), uves_polynomial_get_coeff_1d(), uves_polynomial_get_coeff_2d(), uves_polynomial_new(), uves_polynomial_regression_1d(), uves_polynomial_regression_2d(), uves_polynomial_regression_2d_autodegree(), uves_polynomial_solve_2d(), uves_rebin(), uves_reduce_mflat(), uves_reduce_scired(), uves_response_efficiency(), and uves_wavecal_identify().
void uves_polynomial_delete_const | ( | const polynomial ** | p | ) |
Delete a const polynomial.
p | polynomial to delete |
p is deleted and set to NULL.
Definition at line 309 of file uves_utils_polynomial.c.
Referenced by uves_polynomial_delete(), and uves_reduce_scired().
int uves_polynomial_get_degree | ( | const polynomial * | p | ) |
Get degree.
p | polynomial |
Definition at line 328 of file uves_utils_polynomial.c.
References _polynomial::pol.
Referenced by opt_measure_profile(), and uves_polynomial_add_2d().
polynomial* uves_polynomial_duplicate | ( | const polynomial * | p | ) |
Copy a polynomial.
p | polynomial to copy |
Definition at line 347 of file uves_utils_polynomial.c.
References check, _polynomial::pol, _polynomial::scale, _polynomial::shift, uves_polynomial_delete(), uves_polynomial_get_dimension(), and uves_polynomial_new().
Referenced by extract_ff_rebin_merge(), interpolate_wave(), repeat_orderdef(), uves_extract(), uves_polynomial_get_coeff_1d(), and uves_polynomial_get_coeff_2d().
cpl_table* uves_polynomial_convert_to_table | ( | const polynomial * | p | ) |
Convert a polynomial to a table.
p | polynomial to convert |
Currently, only 2d polynomials are supported. The polynomial is written to the table in an internal format ; Therefore the table should not be read or edited manually, but only read using the function uves_polynomial_convert_from_table()
.
Definition at line 389 of file uves_utils_polynomial.c.
References _polynomial::pol, _polynomial::scale, _polynomial::shift, and uves_polynomial_get_dimension().
Referenced by extract_ff_rebin_merge().
polynomial* uves_polynomial_convert_from_table | ( | cpl_table * | t | ) |
Convert a table to a polynomial.
t | Table to convert |
uves_polynomial_delete()
, or NULL on error.Currently, only 2d polynomials are supported. See also uves_polynomial_convert_to_table()
.
Definition at line 473 of file uves_utils_polynomial.c.
References check, uves_msg_debug, uves_polynomial_delete(), uves_polynomial_new(), uves_polynomial_rescale(), uves_polynomial_shift(), and uves_tostring_cpl_type().
int uves_polynomial_get_dimension | ( | const polynomial * | p | ) |
Get the dimension of a polynomial.
p | The input polynomial |
Definition at line 551 of file uves_utils_polynomial.c.
Referenced by compute_lambda(), parse_midas_poly(), uves_draw_lines(), uves_extract(), uves_polynomial_add_2d(), uves_polynomial_collapse(), uves_polynomial_convert_to_table(), uves_polynomial_derivative(), uves_polynomial_derivative_1d(), uves_polynomial_derivative_2d(), uves_polynomial_dump(), uves_polynomial_duplicate(), uves_polynomial_evaluate_1d(), uves_polynomial_get_coeff_1d(), uves_polynomial_get_coeff_2d(), uves_polynomial_rescale(), uves_polynomial_shift(), and uves_polynomial_solve_1d().
void uves_polynomial_dump | ( | const polynomial * | p, |
FILE * | stream | ||
) |
Print a polynomial.
p | The polynomial to print |
stream | Where to dump the polynomial (e.g. "stdout") |
This function does not use CPL's messaging system and should be used only for debugging.
Definition at line 572 of file uves_utils_polynomial.c.
References _polynomial::pol, _polynomial::scale, _polynomial::shift, and uves_polynomial_get_dimension().
Referenced by opt_measure_profile_order().
cpl_error_code uves_polynomial_rescale | ( | polynomial * | p, |
int | varno, | ||
double | scale | ||
) |
Rescale a polynomial.
p | The polynomial to rescale |
varno | Rescale with respect to this variable (number) |
scale | The rescaling factor |
The variable specified by varno is rescaled: p (x_1, ..., x_varno, ..., x_n) :=p (x_1, ..., x_varno / scale, ..., x_n).
If varno is zero, a the polynomial itself is rescaled: p(x) := p(x) * scale . Negative values of varno are illegal.
Definition at line 605 of file uves_utils_polynomial.c.
References _polynomial::scale, _polynomial::shift, and uves_polynomial_get_dimension().
Referenced by interpolate_wave(), test_polynomial(), and uves_polynomial_convert_from_table().
cpl_error_code uves_polynomial_shift | ( | polynomial * | p, |
int | varno, | ||
double | shift | ||
) |
Shift a polynomial.
p | The polynomial to shift |
varno | Shift with respect to this variable (number) |
shift | The amount to shift |
The polynomial is shifted: p (x_1, ..., x_varno, ..., x_n) :=p (x_1, ..., x_varno - shift, ..., x_n).
If varno is zero, a constant is added to the polynomial: p(x) := p(x) + shift . Negative values of varno are illegal.
Definition at line 646 of file uves_utils_polynomial.c.
References _polynomial::shift, and uves_polynomial_get_dimension().
Referenced by opt_measure_profile(), opt_measure_profile_order(), test_extract(), uves_polynomial_convert_from_table(), uves_polynomial_fit_1d(), and uves_polynomial_fit_2d().
double uves_polynomial_evaluate_1d | ( | const polynomial * | p, |
double | x | ||
) |
Evaluate a 1d polynomial.
p | The polynomial to evaluate |
x | Where to evaluate the polynomial |
The polynomial must be 1d. See also uves_polynomial_evaluate_2d()
.
Definition at line 678 of file uves_utils_polynomial.c.
References check, _polynomial::pol, _polynomial::scale, _polynomial::shift, and uves_polynomial_get_dimension().
Referenced by opt_get_redchisq(), opt_measure_profile(), uves_get_blaze_ratio(), uves_polynomial_get_coeff_1d(), and uves_polynomial_regression_1d().
double uves_polynomial_evaluate_2d | ( | const polynomial * | p, |
double | x1, | ||
double | x2 | ||
) |
Evaluate a 2d polynomial.
p | The polynomial to evaluate |
x1 | Where to evaluate the polynomial |
x2 | Where to evaluate the polynomial |
The polynomial must be 2d. See also uves_polynomial_evaluate_1d()
.
Definition at line 709 of file uves_utils_polynomial.c.
References _polynomial::pol, _polynomial::scale, _polynomial::shift, and _polynomial::vec.
Referenced by compute_lambda(), create_line_table(), create_order_table(), detect_lines(), extract_order_simple(), get_offset(), opt_get_order_width(), opt_get_redchisq(), opt_measure_profile(), repeat_orderdef(), test_load_linetable(), test_polynomial_fit_2d(), uves_combine_flats(), uves_draw_lines(), uves_flat_create_normalized_master(), uves_flat_create_normalized_master2(), uves_get_wave_map(), uves_iterate_increment(), uves_iterate_set_first(), uves_physmod_msrawxy(), uves_polynomial_fit_2d(), uves_polynomial_get_coeff_2d(), uves_polynomial_regression_2d(), uves_polynomial_regression_2d_autodegree(), and uves_rebin().
double uves_polynomial_solve_1d | ( | const polynomial * | p, |
double | value, | ||
double | guess, | ||
int | multiplicity | ||
) |
Solve p(x) = value.
p | The input polynomial |
value | The requested value of the polynomial |
guess | A guess solution |
multiplicity | The multiplycity of the root (or 1 if unknown) |
This function uses cpl_polynomial_solve_1d()
to solve the equation p (x) = value . See cpl_polynomial_solve_1d()
for a description of the algorithm.
Definition at line 747 of file uves_utils_polynomial.c.
References check, _polynomial::pol, _polynomial::scale, _polynomial::shift, and uves_polynomial_get_dimension().
Referenced by uves_polynomial_solve_2d(), uves_rebin(), and uves_response_efficiency().
double uves_polynomial_solve_2d | ( | const polynomial * | p, |
double | value, | ||
double | guess, | ||
int | multiplicity, | ||
int | varno, | ||
double | x_value | ||
) |
Solve p(x1, x2) = value.
p | The input polynomial |
value | The requested value of the polynomial |
guess | A guess solution |
multiplicity | The multiplycity of the root (or 1 if unknown) |
varno | The variable number to fix (1 or 2) |
x_value | Variable number varno is fixed to this value |
This function solves the equation p (x1, x2) = value, where either x1 or x2 is already fixed to x_value.
For example, to solve the equation p (37, x) = 500 for x, call uves_polynomial_solve_2d(p, 500, x_guess, 1, 1, 37)
.
Definition at line 801 of file uves_utils_polynomial.c.
References check, uves_polynomial_collapse(), uves_polynomial_delete(), and uves_polynomial_solve_1d().
Referenced by opt_get_order_width(), and uves_draw_lines().
double uves_polynomial_derivative_2d | ( | const polynomial * | p, |
double | x1, | ||
double | x2, | ||
int | varno | ||
) |
Evaluate the partial derivative of a 2d polynomial.
p | The input polynomial |
x1 | Where to evaluate the derivative |
x2 | Where to evaluate the derivative |
varno | Evaluate partial derivative with respect to this variable (1 or 2) |
Definition at line 832 of file uves_utils_polynomial.c.
References _polynomial::pol, _polynomial::scale, _polynomial::shift, and uves_polynomial_get_dimension().
Referenced by compute_lambda(), detect_ripples(), uves_rebin(), and uves_response_efficiency().
double uves_polynomial_derivative_1d | ( | const polynomial * | p, |
double | x | ||
) |
Evaluate the derivative of a 1d polynomial.
p | The input polynomial |
x | Where to evaluate the derivative |
Definition at line 921 of file uves_utils_polynomial.c.
References check, _polynomial::pol, _polynomial::scale, _polynomial::shift, and uves_polynomial_get_dimension().
polynomial* uves_polynomial_add_2d | ( | const polynomial * | p1, |
const polynomial * | p2 | ||
) |
Add two polynomials.
p1 | left |
p2 | right |
Definition at line 946 of file uves_utils_polynomial.c.
References uves_polynomial_get_coeff_2d(), uves_polynomial_get_degree(), uves_polynomial_get_dimension(), and uves_polynomial_new().
Referenced by interpolate_wave(), and test_polynomial().
|
static |
Calculate the partial derivative of a CPL-polynomial.
p | The input polynomial |
varno | Differentiate with respect to this variable number (counting from 1 to dimension) |
The polynomial is transformed from p to dp/dx_varno.
1D and 2D polynomials are supported.
Definition at line 1011 of file uves_utils_polynomial.c.
Referenced by uves_polynomial_derivative().
cpl_error_code uves_polynomial_derivative | ( | polynomial * | p, |
int | varno | ||
) |
Calculate the partial derivative of a polynomial.
p | The input polynomial |
varno | Differentiate with respect to this variable number (counting from 1 to dimension) |
The polynomial is transformed from p to dp/dx_varno.
Definition at line 1077 of file uves_utils_polynomial.c.
References check, derivative_cpl_polynomial(), _polynomial::pol, _polynomial::scale, _polynomial::shift, and uves_polynomial_get_dimension().
Referenced by uves_polynomial_get_coeff_1d(), and uves_polynomial_get_coeff_2d().
double uves_polynomial_get_coeff_2d | ( | const polynomial * | p, |
int | degree1, | ||
int | degree2 | ||
) |
Get a coefficient of a 2D polynomial.
p | The input polynomial |
degree1 | The coefficient degree |
degree2 | The coefficient degree |
Definition at line 1120 of file uves_utils_polynomial.c.
References check, uves_polynomial_delete(), uves_polynomial_derivative(), uves_polynomial_duplicate(), uves_polynomial_evaluate_2d(), and uves_polynomial_get_dimension().
Referenced by test_polynomial(), test_polynomial_fit_2d(), uves_physmod_msrawxy(), uves_physmod_regress_echelle(), and uves_polynomial_add_2d().
double uves_polynomial_get_coeff_1d | ( | const polynomial * | p, |
int | degree | ||
) |
Get a coefficient of a 1D polynomial.
p | The input polynomial |
degree | Coefficient degree |
If the required degree is greater than the polynomial's degree, the function does not fail but returns 0 as it should.
Definition at line 1176 of file uves_utils_polynomial.c.
References check, uves_polynomial_delete(), uves_polynomial_derivative(), uves_polynomial_duplicate(), uves_polynomial_evaluate_1d(), and uves_polynomial_get_dimension().
Referenced by opt_measure_profile_order(), and uves_physmod_calmap().
polynomial* uves_polynomial_collapse | ( | const polynomial * | p, |
int | varno, | ||
double | value | ||
) |
Collapse a polynomial by fixing one variable to a constant.
p | The polynomial to collapse |
varno | Variable number to fix |
value | Fix variable number varno to this value |
uves_polynomial_delete()
, or NULL on error.This function fixes one variable of a polynomial to a constant value, thereby producing a polynomial, p(x1, ..., x_varno = value, ..., xn), with dimension n - 1.
Currently, only n=2 is supported.
Definition at line 1231 of file uves_utils_polynomial.c.
References assure_mem, _polynomial::pol, _polynomial::scale, _polynomial::shift, uves_polynomial_delete(), uves_polynomial_get_dimension(), and uves_polynomial_new().
Referenced by uves_polynomial_solve_2d(), uves_rebin(), and uves_response_efficiency().
polynomial* uves_polynomial_fit_1d | ( | const cpl_vector * | x_pos, |
const cpl_vector * | values, | ||
const cpl_vector * | sigmas, | ||
int | poly_deg, | ||
double * | mse | ||
) |
Fit a 1d function with a polynomial.
x_pos | List of positions of the signal to fit. |
values | List of values of the signal to fit. |
sigmas | List of uncertainties of the surface points. If NULL, constant uncertainties are used. |
poly_deg | Polynomial degree. |
mse | Output mean squared error. |
This function is a straightforward adaption of CPL's cpl_polynomial_fit_1d_create()
. But before performing the fit, all values are shifted, so that they are centered around zero. This improves the accuracy of the fit.
Also, there's support for taking into account the uncertainties of the dependent variable.
See also cpl_polynomial_fit_1d_create()
and uves_polynomial_regression_1d()
.
Definition at line 1337 of file uves_utils_polynomial.c.
References assure_nomsg, check, uves_polynomial_new(), uves_polynomial_shift(), and uves_pow_int().
Referenced by uves_polynomial_regression_1d().
polynomial* uves_polynomial_fit_2d | ( | const cpl_bivector * | xy_pos, |
const cpl_vector * | values, | ||
const cpl_vector * | sigmas, | ||
int | poly_deg1, | ||
int | poly_deg2, | ||
double * | mse, | ||
double * | red_chisq, | ||
polynomial ** | variance | ||
) |
Fit a 2d surface with a polynomial in x and y.
xy_pos | List of positions of the surface to fit. |
values | List of values of the surface points. |
sigmas | List of uncertainties of the surface points. |
poly_deg1 | Polynomial degree of 1st variable (x) |
poly_deg2 | Polynomial degree of 2nd variable (y) |
mse | Output mean squared error |
red_chisq | Output reduced chi square |
variance | Variance polynomial (see below) |
This function fits a 2d polynomial to a surface. The input grid is given in xy_pos and values. xy_pos and values of course must contain the same number of points. If sigmas is NULL, constant sigma (equal to 1) is used.
This function is an adaption of CPL's cpl_polynomial_fit_2d_create()
. But the fit is made with a general rectangular coefficient matrix (the size of which is indicated by the polynomial degrees, poly_deg1 and poly_deg2) instead of the upper-left triangular matrix used by cpl_polynomial_fit_2d_create()
.
And before performing the fit, all values are shifted, so that they are centered around zero, which improves the accuracy of the fit. Rescaling with stdev makes the fit worse (empirically) so this is not done.
If mse is non-NULL, the mean squared error of the fit is returned through this variable. If red_chisq is non-NULL, the reduced chi square of the fit is returned through this variable.
If variance is non-NULL the variance polynomial defined as (using the error propagation formula for correlated coefficients {coeff_i}) variance(x,y) = sum_{ij} d(p_fit)/d(coeff_i) * cov_{ij} * d(p_fit)/d(coeff_j) = sum_{ij} x^degx[i]*y^degy[i] * cov_{ij} * x^degx[j]*y^degy[j] = sum_{ij} cov_{ij} * x^(degx[i]+degx[j]) * y^(degy[i]+degy[j]) will be returned through this variable (i.e. the parameter must be the address of a (polynomial*) variable. The variance polynomial gives the associated uncertainty when evaluating the fitted polynomial, i.e. the variance of p_fit(x, y) = sum_{ij} (a_{ij} * x^i * y^j)
See also cpl_polynomial_fit_2d_create()
and uves_polynomial_regression_2d()
.
Definition at line 1517 of file uves_utils_polynomial.c.
References assure_mem, passure, uves_polynomial_evaluate_2d(), uves_polynomial_new(), uves_polynomial_shift(), and uves_pow_int().
Referenced by test_polynomial_fit_2d(), and uves_polynomial_regression_2d().