34 #include <uves_cpl_size.h>
39 #include <uves_utils_polynomial.h>
40 #include <uves_extract_iterate.h>
41 #include <uves_extract_profile.h>
42 #include <uves_chip.h>
52 #if defined HAVE_DECL___FUNC__ && !HAVE_DECL___FUNC__
55 #define __func__ "<fct.id>"
69 #ifndef WANT_BIG_LOGFILE
70 #define WANT_BIG_LOGFILE 0
77 #ifndef WANT_TIME_MEASURE
78 #define WANT_TIME_MEASURE 0
83 #define UVES_TIME_START(what) uves_msg("Timing (%s, l%d) %s start", \
84 __FILE__, __LINE__, what)
85 #define UVES_TIME_END uves_msg("Timing (%s, l%d) end", \
88 #define UVES_TIME_START(what) uves_msg_debug("Timing (%s, l%d) %s start", \
89 __FILE__, __LINE__, what)
90 #define UVES_TIME_END uves_msg_debug("Timing (%s, l%d) end", \
97 #define stringify(X) #X
98 #define make_str(X) stringify(X)
102 #define TWOSQRT2LN2 2.35482004503095
105 #define M_PI 3.1415926535897932384626433832795
108 #define SPEED_OF_LIGHT 299792458
110 #define COS_DEG(x) cos(((x)/180)*M_PI)
111 #define SIN_DEG(x) sin(((x)/180)*M_PI)
112 #define ACOS_DEG(x) (acos(x)*180/M_PI)
120 const cpl_image *spectrum,
const cpl_image *sky,
121 const cpl_image *cosmic_image,
122 const uves_extract_profile *profile,
146 uves_round_double(
double x)
148 return (x >=0) ? (long)(x+0.5) : (long)(x-0.5);
162 uves_max_double(
double x,
double y)
164 return (x >=y) ? x : y;
177 uves_max_int(
int x,
int y)
179 return (x >=y) ? x : y;
193 uves_min_double(
double x,
double y)
195 return (x <=y) ? x : y;
208 uves_min_int(
int x,
int y)
210 return (x <=y) ? x : y;
226 uves_error_fraction(
double x,
double y,
double dx,
double dy)
231 return sqrt( dx*dx/(y*y) + x*x*dy*dy/(y*y*y*y) );
239 char *
uves_initialize(cpl_frameset *frames,
const cpl_parameterlist *parlist,
240 const char *recipe_id,
const char *short_descr);
241 cpl_error_code
uves_end(
const char *recipe_id,
const cpl_frameset *frames);
244 const char *bunit,
const double bscale,
245 double crval1 ,
double crval2,
246 double crpix1 ,
double crpix2,
247 double crdelt1,
double crdelt2);
253 int ncom,
enum uves_chip);
255 const cpl_image *image2,
const cpl_image *noise2,
261 const cpl_image *master_dark,
266 const char *X1,
const char *X2,
const char *Y,
268 const char *polynomial_fit,
269 const char *residual_square,
270 const char *variance_fit,
271 double *mean_squared_error,
double *red_chisq,
273 int maxdeg1,
int maxdeg2,
double min_rms,
276 const double *min_val,
277 const double *max_val,
278 int npos,
double positions[][2]);
282 const char *X1,
const char *X2,
const char *Y,
284 int degree1,
int degree2,
285 const char *polynomial_fit,
const char *residual_square,
286 const char *variance_fit,
287 double *mse,
double *red_chisq,
292 const char *X,
const char *Y,
const char *sigmaY,
294 const char *polynomial_fit,
const char *residual_square,
295 double *mean_squared_error,
const double kappa);
300 const char *column_y,
int *istart );
302 double uves_spline_hermite(
double xp,
const double *x,
const double *y,
int n,
int *istart );
304 double uves_spline_cubic(
double xp,
double *x,
float *y,
float *y2,
int n,
int *kstart );
310 const char *residual2,
316 int fibre_ID,
double fibre_offset,
int fibre_mask);
319 int uves_moffat(
const double x[],
const double a[],
double *result);
321 int uves_gauss(
const double x[],
const double a[],
double *result);
325 void uves_check_version(
void);
326 void uves_frameset_dump(cpl_frameset* set);
339 uves_image_smooth_x(cpl_image * inp,
const int r);
341 uves_image_smooth_y(cpl_image * inp,
const int r);
344 uves_image_smooth_mean_x(cpl_image * inp,
const int r);
347 uves_image_smooth_median_x(cpl_image * inp,
const int r);
349 uves_image_smooth_fft(cpl_image * inp,
const int fx);
352 uves_ksigma_stack(
const cpl_imagelist *imlist,
double klow,
double khigh,
int kiter);
357 const cpl_table *ordertable,
359 const cpl_vector* gain_vals,
364 const cpl_table *ordertable,
366 const cpl_image* mflat);
375 const cpl_parameterlist *parameters,
376 const cpl_table *ordertable,
377 const cpl_table *linetable,
380 const int first_abs_order,
381 const int last_abs_order,
382 const int slit_size);
const char * uves_string_tolower(char *s)
Convert all uppercase characters in a string into lowercase characters.
bool uves_table_is_sorted_double(const cpl_table *t, const char *column, const bool reverse)
Determine if a table is sorted.
cpl_image * uves_get_wave_map(cpl_image *ima_sci, const char *context, const cpl_parameterlist *parameters, const cpl_table *ordertable, const cpl_table *linetable, const polynomial *order_locations, const polynomial *dispersion_relation, const int first_abs_order, const int last_abs_order, const int slit_size)
Generates wave map.
cpl_error_code uves_rcosmic(cpl_image *ima, cpl_image **flt, cpl_image **out, cpl_image **msk, const double sky, const double ron, const double gain, const int ns, const double rc)
Remove cosmic ray events on single ccd exposure and replace them by interpolation on neighbourhood pi...
cpl_image * uves_define_noise(const cpl_image *image, const uves_propertylist *image_header, int ncom, enum uves_chip)
Create noise image.
cpl_image * uves_flat_create_normalized_master(cpl_imagelist *flats, const cpl_table *ordertable, const polynomial *order_locations, const cpl_vector *gain_vals, double *fnoise)
Stack images using k-sigma clipping.
int uves_absolute_order(int first_abs_order, int last_abs_order, int relative_order)
Get the absolute order number.
const char * uves_get_license(void)
Get the pipeline copyright and license.
int uves_gauss_linear(const double x[], const double a[], double *result)
Evaluate a gaussian with linear background.
double uves_pow_int(double x, int y)
Calculate x to the y'th.
cpl_table * uves_ordertable_traces_new(void)
Create the table that describes fibre traces.
cpl_image * uves_flat_create_normalized_master2(cpl_imagelist *flats, const cpl_table *ordertable, const polynomial *order_locations, const cpl_image *mflat)
Stack images using k-sigma clipping.
cpl_error_code uves_tablename_remove_units(const char *tname)
Remove column units from a table.
cpl_error_code uves_subtract_bias(cpl_image *image, const cpl_image *master_bias)
Subtract bias.
int uves_gauss_derivative(const double x[], const double a[], double result[])
Evaluate the derivatives of a gaussian.
double uves_average_reject(cpl_table *t, const char *column, const char *residual2, double kappa)
Get average with iterative rejection.
cpl_image * uves_image_mflat_detect_blemishes(const cpl_image *flat, const uves_propertylist *head)
Flag blemishes in a flat image.
cpl_error_code uves_table_unify_units(cpl_table **table2, cpl_table **table1)
Unify column units of table2 to table1.
cpl_error_code uves_tablenames_unify_units(const char *tname2, const char *tname1)
Unify column units in tables.
cpl_error_code uves_subtract_dark(cpl_image *image, const uves_propertylist *image_header, const cpl_image *master_dark, const uves_propertylist *mdark_header)
Subtract dark.
uves_propertylist * uves_initialize_image_header(const char *ctype1, const char *ctype2, const char *cunit1, const char *cunit2, const char *bunit, const double bscale, double crval1, double crval2, double crpix1, double crpix2, double crdelt1, double crdelt2)
Initialize image header.
double uves_gaussrand(void)
Pseudo-random gaussian distributed number.
double uves_spline_hermite_table(double xp, const cpl_table *t, const char *column_x, const char *column_y, int *istart)
Spline interpolation based on Hermite polynomials.
int uves_gauss(const double x[], const double a[], double *result)
Evaluate a gaussian.
int uves_moffat(const double x[], const double a[], double *result)
Evaluate a Moffat.
polynomial * uves_polynomial_regression_2d(cpl_table *t, const char *X1, const char *X2, const char *Y, const char *sigmaY, int degree1, int degree2, const char *polynomial_fit, const char *residual_square, const char *variance_fit, double *mse, double *red_chisq, polynomial **variance, double kappa, double min_reject)
Fit a 2d polynomial to three table columns.
int uves_gauss_linear_derivative(const double x[], const double a[], double result[])
Evaluate the derivatives of a gaussian with linear background.
polynomial * uves_polynomial_regression_2d_autodegree(cpl_table *t, const char *X1, const char *X2, const char *Y, const char *sigmaY, const char *polynomial_fit, const char *residual_square, const char *variance_fit, double *mean_squared_error, double *red_chisq, polynomial **variance, double kappa, int maxdeg1, int maxdeg2, double min_rms, double min_reject, bool verbose, const double *min_val, const double *max_val, int npos, double positions[][2])
Fit a 2d polynomial to three table columns.
cpl_vector * uves_imagelist_get_clean_mean_levels(cpl_imagelist *iml, double kappa)
Computes kappa-sigma clean mean (free bad pixels) for each input image of the input imagelist...
const char * uves_remove_string_prefix(const char *s, const char *prefix)
Remove named prefix from string.
cpl_image * uves_create_image(uves_iterate_position *pos, enum uves_chip chip, const cpl_image *spectrum, const cpl_image *sky, const cpl_image *cosmic_image, const uves_extract_profile *profile, cpl_image **image_noise, uves_propertylist **image_header)
Reconstruct echelle image from spectrum.
cpl_error_code uves_table_remove_units(cpl_table **table)
Remove column units from a table.
cpl_image * uves_average_images(const cpl_image *image1, const cpl_image *noise1, const cpl_image *image2, const cpl_image *noise2, cpl_image **noise)
Optimally average images.
char * uves_initialize(cpl_frameset *frames, const cpl_parameterlist *parlist, const char *recipe_id, const char *short_descr)
Recipe initialization.
int uves_moffat_derivative(const double x[], const double a[], double result[])
Evaluate Moffat derivative.
cpl_error_code uves_ordertable_traces_add(cpl_table *traces, int fibre_ID, double fibre_offset, int fibre_mask)
Add a trace.
polynomial * uves_polynomial_regression_1d(cpl_table *t, const char *X, const char *Y, const char *sigmaY, int degree, const char *polynomial_fit, const char *residual_square, double *mean_squared_error, const double kappa)
Fit a 1d polynomial to two table columns.
cpl_image * uves_ksigma_stack(const cpl_imagelist *imlist, double klow, double khigh, int kiter)
Stack images using k-sigma clipping.
cpl_error_code uves_end(const char *recipe_id, const cpl_frameset *frames)
Recipe termination.
cpl_error_code uves_get_version(int *major, int *minor, int *micro)
Get UVES library version number.
const char * uves_string_toupper(char *s)
Convert all lowercase characters in a string into uppercase characters.
double uves_spline_hermite(double xp, const double *x, const double *y, int n, int *istart)
Spline interpolation based on Hermite polynomials.
cpl_parameterlist * uves_parameterlist_duplicate(const cpl_parameterlist *pin)
Extract frames with given tag from frameset.
int uves_get_version_binary(void)
Get UVES library binary version number.
cpl_error_code uves_imagelist_subtract_values(cpl_imagelist **iml, cpl_vector *values)
Subtract from input imagelist values specified in input vector.
double uves_spline_cubic(double xp, double *x, float *y, float *y2, int n, int *kstart)
Natural cubic-spline interpolation.
cpl_frameset * uves_frameset_extract(const cpl_frameset *frames, const char *tag)
Extract frames with given tag from frameset.