00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 #ifndef UVES_UTILS_H
00211 #define UVES_UTILS_H
00212
00213
00214 #ifdef HAVE_CONFIG_H
00215 # include <config.h>
00216 #endif
00217
00218
00219
00220
00221
00222 #include <uves_utils_polynomial.h>
00223 #include <uves_extract_iterate.h>
00224 #include <uves_extract_profile.h>
00225 #include <uves_chip.h>
00226
00227 #include <cpl.h>
00228 #include <math.h>
00229
00230
00231
00232
00233
00234
00235 #if defined HAVE_DECL___FUNC__ && !HAVE_DECL___FUNC__
00236
00237 #ifndef __func__
00238 #define __func__ "<fct.id>"
00239 #endif
00240 #endif
00241
00242 #ifndef inline
00243 #define inline
00244 #endif
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 #ifndef WANT_BIG_LOGFILE
00257 #define WANT_BIG_LOGFILE 0
00258 #endif
00259
00260
00261
00262
00263
00264 #ifndef WANT_TIME_MEASURE
00265 #define WANT_TIME_MEASURE 0
00266 #endif
00267
00268
00269 #if WANT_TIME_MEASURE
00270 #define UVES_TIME_START(what) uves_msg("Timing (%s, l%d) %s start", \
00271 __FILE__, __LINE__, what)
00272 #define UVES_TIME_END uves_msg("Timing (%s, l%d) end", \
00273 __FILE__, __LINE__)
00274 #else
00275 #define UVES_TIME_START(what) uves_msg_debug("Timing (%s, l%d) %s start", \
00276 __FILE__, __LINE__, what)
00277 #define UVES_TIME_END uves_msg_debug("Timing (%s, l%d) end", \
00278 __FILE__, __LINE__)
00279 #endif
00280
00281
00282 #ifndef stringify
00283 #ifndef make_str
00284 #define stringify(X) #X
00285 #define make_str(X) stringify(X)
00286 #endif
00287 #endif
00288
00289 #define TWOSQRT2LN2 2.35482004503095
00290
00291 #ifndef M_PI
00292 #define M_PI 3.1415926535897932384626433832795
00293 #endif
00294
00295 #define SPEED_OF_LIGHT 299792458
00296
00297 #define COS_DEG(x) cos(((x)/180)*M_PI)
00298 #define SIN_DEG(x) sin(((x)/180)*M_PI)
00299 #define ACOS_DEG(x) (acos(x)*180/M_PI)
00300
00301
00302
00303
00304
00305 cpl_image *
00306 uves_create_image(uves_iterate_position *pos, enum uves_chip chip,
00307 const cpl_image *spectrum, const cpl_image *sky,
00308 const cpl_image *cosmic_image,
00309 const uves_extract_profile *profile,
00310 cpl_image **image_noise, uves_propertylist **image_header);
00311 cpl_frameset *
00312 uves_frameset_extract(const cpl_frameset *frames,const char *tag);
00313
00314 const char*
00315 uves_string_tolower(char* s);
00316 const char*
00317 uves_string_toupper(char* s);
00318
00319 double uves_gaussrand(void);
00320 double uves_pow_int(double x, int y);
00321 long uves_round_double(double x);
00322 double uves_max_double(double x, double y);
00323 int uves_max_int(int x, int y);
00324 double uves_min_double(double x, double y);
00325 int uves_min_int(int x, int y);
00326 double uves_error_fraction(double x, double y, double dx, double dy);
00327 const char *uves_get_license(void);
00328 cpl_error_code uves_get_version(int *major, int *minor, int *micro);
00329 int uves_get_version_binary(void);
00330
00331 char * uves_initialize(cpl_frameset *frames, const cpl_parameterlist *parlist,
00332 const char *recipe_id, const char *short_descr);
00333 cpl_error_code uves_end(const char *recipe_id, const cpl_frameset *frames);
00334
00335 uves_propertylist *uves_initialize_image_header(const char *ctype1, const char *ctype2,
00336 const char *bunit,
00337 double crval1 , double crval2,
00338 double crpix1 , double crpix2,
00339 double crdelt1, double crdelt2);
00340
00341 cpl_parameterlist*
00342 uves_parameterlist_duplicate(const cpl_parameterlist* pin);
00343
00344 cpl_image *uves_define_noise(const cpl_image *image, const uves_propertylist *image_header,
00345 int ncom, enum uves_chip);
00346 cpl_image *uves_average_images(const cpl_image *image1, const cpl_image *noise1,
00347 const cpl_image *image2, const cpl_image *noise2,
00348 cpl_image **noise);
00349
00350
00351 cpl_error_code uves_subtract_bias(cpl_image *image, const cpl_image *master_bias);
00352 cpl_error_code uves_subtract_dark(cpl_image *image, const uves_propertylist *image_header,
00353 const cpl_image *master_dark,
00354 const uves_propertylist *mdark_header);
00355
00356 polynomial *
00357 uves_polynomial_regression_2d_autodegree(cpl_table *t,
00358 const char *X1, const char *X2, const char *Y,
00359 const char *sigmaY,
00360 const char *polynomial_fit,
00361 const char *residual_square,
00362 const char *variance_fit,
00363 double *mean_squared_error, double *red_chisq,
00364 polynomial **variance, double kappa,
00365 int maxdeg1, int maxdeg2, double min_rms,
00366 double min_reject,
00367 bool verbose,
00368 const double *min_val,
00369 const double *max_val,
00370 int npos, double positions[][2]);
00371
00372 polynomial *
00373 uves_polynomial_regression_2d(cpl_table *t,
00374 const char *X1, const char *X2, const char *Y,
00375 const char *sigmaY,
00376 int degree1, int degree2,
00377 const char *polynomial_fit, const char *residual_square,
00378 const char *variance_fit,
00379 double *mse, double *red_chisq,
00380 polynomial **variance, double kappa,
00381 double min_reject);
00382
00383 polynomial *uves_polynomial_regression_1d(cpl_table *t,
00384 const char *X, const char *Y, const char *sigmaY,
00385 int degree,
00386 const char *polynomial_fit, const char *residual_square,
00387 double *mean_squared_error, const double kappa);
00388
00389 const char *uves_remove_string_prefix(const char *s, const char *prefix);
00390
00391 double uves_spline_hermite_table( double xp, const cpl_table *t, const char *column_x,
00392 const char *column_y, int *istart );
00393
00394 double uves_spline_hermite( double xp, const double *x, const double *y, int n, int *istart );
00395
00396 double uves_spline_cubic(double xp, double *x, float *y, float *y2, int n, int *kstart );
00397
00398 int uves_absolute_order(int first_abs_order, int last_abs_order, int relative_order);
00399
00400 double uves_average_reject(cpl_table *t,
00401 const char *column,
00402 const char *residual2,
00403 double kappa);
00404
00405
00406 cpl_table *uves_ordertable_traces_new(void);
00407 cpl_error_code uves_ordertable_traces_add(cpl_table *traces,
00408 int fibre_ID, double fibre_offset, int fibre_mask);
00409 bool uves_table_is_sorted_double(const cpl_table *t, const char *column, const bool reverse);
00410
00411 int uves_moffat(const double x[], const double a[], double *result);
00412 int uves_moffat_derivative(const double x[], const double a[], double result[]);
00413 int uves_gauss(const double x[], const double a[], double *result);
00414 int uves_gauss_derivative(const double x[], const double a[], double result[]);
00415 int uves_gauss_linear(const double x[], const double a[], double *result);
00416 int uves_gauss_linear_derivative(const double x[], const double a[], double result[]);
00417 void uves_check_version(void);
00418 void uves_frameset_dump(cpl_frameset* set);
00419 cpl_error_code
00420 uves_rcosmic(cpl_image* ima,
00421 cpl_image** flt,
00422 cpl_image** out,
00423 cpl_image** msk,
00424 const double sky,
00425 const double ron,
00426 const double gain,
00427 const int ns,
00428 const double rc);
00429
00430 cpl_image *
00431 uves_image_smooth_x(cpl_image * inp, const int r);
00432 cpl_image *
00433 uves_image_smooth_y(cpl_image * inp, const int r);
00434
00435 cpl_image *
00436 uves_image_smooth_mean_x(cpl_image * inp, const int r);
00437
00438 cpl_image *
00439 uves_image_smooth_median_x(cpl_image * inp, const int r);
00440 cpl_image *
00441 uves_image_smooth_fft(cpl_image * inp, const int fx);
00442
00443 cpl_image *
00444 uves_ksigma_stack(const cpl_imagelist *imlist, double klow, double khigh, int kiter);
00445
00446
00447 cpl_image *
00448 uves_flat_create_normalized_master(cpl_imagelist * flats,
00449 const cpl_table *ordertable,
00450 const polynomial* order_locations,
00451 const cpl_vector* gain_vals,
00452 double* fnoise);
00453
00454 cpl_image *
00455 uves_flat_create_normalized_master2(cpl_imagelist * flats,
00456 const cpl_table *ordertable,
00457 const polynomial* order_locations,
00458 const cpl_image* mflat,
00459 const cpl_vector* exptimes);
00460
00461 cpl_vector *
00462 uves_imagelist_get_clean_mean_levels(cpl_imagelist* iml, double kappa);
00463 cpl_error_code
00464 uves_imagelist_subtract_values(cpl_imagelist** iml, cpl_vector* values);
00465 cpl_image *
00466 uves_get_wave_map(cpl_image * ima_sci,
00467 const char *context,
00468 const cpl_parameterlist *parameters,
00469 const cpl_table *ordertable,
00470 const cpl_table *linetable,
00471 const polynomial* order_locations,
00472 const polynomial *dispersion_relation,
00473 const int first_abs_order,
00474 const int last_abs_order,
00475 const int slit_size);
00476
00477 cpl_image*
00478 uves_image_mflat_detect_blemishes(const cpl_image* flat,
00479 const uves_propertylist* head);
00480
00481
00482 cpl_error_code
00483 uves_table_remove_units(cpl_table **table);
00484 cpl_error_code
00485 uves_table_unify_units(cpl_table **table2, cpl_table **table1);
00486 cpl_error_code
00487 uves_tablenames_unify_units(const char* tname2, const char* tname1);
00488 cpl_error_code
00489 uves_tablename_remove_units(const char* tname);
00490
00491 #endif