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
00211
00212
00213 #ifndef UVES_UTILS_H
00214 #define UVES_UTILS_H
00215
00216
00217 #ifdef HAVE_CONFIG_H
00218 # include <config.h>
00219 #endif
00220 #include <uves_cpl_size.h>
00221
00222
00223
00224
00225 #include <uves_utils_polynomial.h>
00226 #include <uves_extract_iterate.h>
00227 #include <uves_extract_profile.h>
00228 #include <uves_chip.h>
00229
00230 #include <cpl.h>
00231 #include <math.h>
00232
00233
00234
00235
00236
00237
00238 #if defined HAVE_DECL___FUNC__ && !HAVE_DECL___FUNC__
00239
00240 #ifndef __func__
00241 #define __func__ "<fct.id>"
00242 #endif
00243 #endif
00244
00245 #ifndef inline
00246 #define inline
00247 #endif
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 #ifndef WANT_BIG_LOGFILE
00260 #define WANT_BIG_LOGFILE 0
00261 #endif
00262
00263
00264
00265
00266
00267 #ifndef WANT_TIME_MEASURE
00268 #define WANT_TIME_MEASURE 0
00269 #endif
00270
00271
00272 #if WANT_TIME_MEASURE
00273 #define UVES_TIME_START(what) uves_msg("Timing (%s, l%d) %s start", \
00274 __FILE__, __LINE__, what)
00275 #define UVES_TIME_END uves_msg("Timing (%s, l%d) end", \
00276 __FILE__, __LINE__)
00277 #else
00278 #define UVES_TIME_START(what) uves_msg_debug("Timing (%s, l%d) %s start", \
00279 __FILE__, __LINE__, what)
00280 #define UVES_TIME_END uves_msg_debug("Timing (%s, l%d) end", \
00281 __FILE__, __LINE__)
00282 #endif
00283
00284
00285 #ifndef stringify
00286 #ifndef make_str
00287 #define stringify(X) #X
00288 #define make_str(X) stringify(X)
00289 #endif
00290 #endif
00291
00292 #define TWOSQRT2LN2 2.35482004503095
00293
00294 #ifndef M_PI
00295 #define M_PI 3.1415926535897932384626433832795
00296 #endif
00297
00298 #define SPEED_OF_LIGHT 299792458
00299
00300 #define COS_DEG(x) cos(((x)/180)*M_PI)
00301 #define SIN_DEG(x) sin(((x)/180)*M_PI)
00302 #define ACOS_DEG(x) (acos(x)*180/M_PI)
00303
00304
00305
00306
00307
00308 cpl_image *
00309 uves_create_image(uves_iterate_position *pos, enum uves_chip chip,
00310 const cpl_image *spectrum, const cpl_image *sky,
00311 const cpl_image *cosmic_image,
00312 const uves_extract_profile *profile,
00313 cpl_image **image_noise, uves_propertylist **image_header);
00314 cpl_frameset *
00315 uves_frameset_extract(const cpl_frameset *frames,const char *tag);
00316
00317 const char*
00318 uves_string_tolower(char* s);
00319 const char*
00320 uves_string_toupper(char* s);
00321
00322 double uves_gaussrand(void);
00323 double uves_pow_int(double x, int y);
00324 long uves_round_double(double x);
00325 double uves_max_double(double x, double y);
00326 int uves_max_int(int x, int y);
00327 double uves_min_double(double x, double y);
00328 int uves_min_int(int x, int y);
00329 double uves_error_fraction(double x, double y, double dx, double dy);
00330 const char *uves_get_license(void);
00331 cpl_error_code uves_get_version(int *major, int *minor, int *micro);
00332 int uves_get_version_binary(void);
00333
00334 char * uves_initialize(cpl_frameset *frames, const cpl_parameterlist *parlist,
00335 const char *recipe_id, const char *short_descr);
00336 cpl_error_code uves_end(const char *recipe_id, const cpl_frameset *frames);
00337
00338 uves_propertylist *uves_initialize_image_header(const char *ctype1, const char *ctype2,
00339 const char *bunit,
00340 double crval1 , double crval2,
00341 double crpix1 , double crpix2,
00342 double crdelt1, double crdelt2);
00343
00344 cpl_parameterlist*
00345 uves_parameterlist_duplicate(const cpl_parameterlist* pin);
00346
00347 cpl_image *uves_define_noise(const cpl_image *image, const uves_propertylist *image_header,
00348 int ncom, enum uves_chip);
00349 cpl_image *uves_average_images(const cpl_image *image1, const cpl_image *noise1,
00350 const cpl_image *image2, const cpl_image *noise2,
00351 cpl_image **noise);
00352
00353
00354 cpl_error_code uves_subtract_bias(cpl_image *image, const cpl_image *master_bias);
00355 cpl_error_code uves_subtract_dark(cpl_image *image, const uves_propertylist *image_header,
00356 const cpl_image *master_dark,
00357 const uves_propertylist *mdark_header);
00358
00359 polynomial *
00360 uves_polynomial_regression_2d_autodegree(cpl_table *t,
00361 const char *X1, const char *X2, const char *Y,
00362 const char *sigmaY,
00363 const char *polynomial_fit,
00364 const char *residual_square,
00365 const char *variance_fit,
00366 double *mean_squared_error, double *red_chisq,
00367 polynomial **variance, double kappa,
00368 int maxdeg1, int maxdeg2, double min_rms,
00369 double min_reject,
00370 bool verbose,
00371 const double *min_val,
00372 const double *max_val,
00373 int npos, double positions[][2]);
00374
00375 polynomial *
00376 uves_polynomial_regression_2d(cpl_table *t,
00377 const char *X1, const char *X2, const char *Y,
00378 const char *sigmaY,
00379 int degree1, int degree2,
00380 const char *polynomial_fit, const char *residual_square,
00381 const char *variance_fit,
00382 double *mse, double *red_chisq,
00383 polynomial **variance, double kappa,
00384 double min_reject);
00385
00386 polynomial *uves_polynomial_regression_1d(cpl_table *t,
00387 const char *X, const char *Y, const char *sigmaY,
00388 int degree,
00389 const char *polynomial_fit, const char *residual_square,
00390 double *mean_squared_error, const double kappa);
00391
00392 const char *uves_remove_string_prefix(const char *s, const char *prefix);
00393
00394 double uves_spline_hermite_table( double xp, const cpl_table *t, const char *column_x,
00395 const char *column_y, int *istart );
00396
00397 double uves_spline_hermite( double xp, const double *x, const double *y, int n, int *istart );
00398
00399 double uves_spline_cubic(double xp, double *x, float *y, float *y2, int n, int *kstart );
00400
00401 int uves_absolute_order(int first_abs_order, int last_abs_order, int relative_order);
00402
00403 double uves_average_reject(cpl_table *t,
00404 const char *column,
00405 const char *residual2,
00406 double kappa);
00407
00408
00409 cpl_table *uves_ordertable_traces_new(void);
00410 cpl_error_code uves_ordertable_traces_add(cpl_table *traces,
00411 int fibre_ID, double fibre_offset, int fibre_mask);
00412 bool uves_table_is_sorted_double(const cpl_table *t, const char *column, const bool reverse);
00413
00414 int uves_moffat(const double x[], const double a[], double *result);
00415 int uves_moffat_derivative(const double x[], const double a[], double result[]);
00416 int uves_gauss(const double x[], const double a[], double *result);
00417 int uves_gauss_derivative(const double x[], const double a[], double result[]);
00418 int uves_gauss_linear(const double x[], const double a[], double *result);
00419 int uves_gauss_linear_derivative(const double x[], const double a[], double result[]);
00420 void uves_check_version(void);
00421 void uves_frameset_dump(cpl_frameset* set);
00422 cpl_error_code
00423 uves_rcosmic(cpl_image* ima,
00424 cpl_image** flt,
00425 cpl_image** out,
00426 cpl_image** msk,
00427 const double sky,
00428 const double ron,
00429 const double gain,
00430 const int ns,
00431 const double rc);
00432
00433 cpl_image *
00434 uves_image_smooth_x(cpl_image * inp, const int r);
00435 cpl_image *
00436 uves_image_smooth_y(cpl_image * inp, const int r);
00437
00438 cpl_image *
00439 uves_image_smooth_mean_x(cpl_image * inp, const int r);
00440
00441 cpl_image *
00442 uves_image_smooth_median_x(cpl_image * inp, const int r);
00443 cpl_image *
00444 uves_image_smooth_fft(cpl_image * inp, const int fx);
00445
00446 cpl_image *
00447 uves_ksigma_stack(const cpl_imagelist *imlist, double klow, double khigh, int kiter);
00448
00449
00450 cpl_image *
00451 uves_flat_create_normalized_master(cpl_imagelist * flats,
00452 const cpl_table *ordertable,
00453 const polynomial* order_locations,
00454 const cpl_vector* gain_vals,
00455 double* fnoise);
00456
00457 cpl_image *
00458 uves_flat_create_normalized_master2(cpl_imagelist * flats,
00459 const cpl_table *ordertable,
00460 const polynomial* order_locations,
00461 const cpl_image* mflat,
00462 const cpl_vector* exptimes);
00463
00464 cpl_vector *
00465 uves_imagelist_get_clean_mean_levels(cpl_imagelist* iml, double kappa);
00466 cpl_error_code
00467 uves_imagelist_subtract_values(cpl_imagelist** iml, cpl_vector* values);
00468 cpl_image *
00469 uves_get_wave_map(cpl_image * ima_sci,
00470 const char *context,
00471 const cpl_parameterlist *parameters,
00472 const cpl_table *ordertable,
00473 const cpl_table *linetable,
00474 const polynomial* order_locations,
00475 const polynomial *dispersion_relation,
00476 const int first_abs_order,
00477 const int last_abs_order,
00478 const int slit_size);
00479
00480 cpl_image*
00481 uves_image_mflat_detect_blemishes(const cpl_image* flat,
00482 const uves_propertylist* head);
00483
00484
00485 cpl_error_code
00486 uves_table_remove_units(cpl_table **table);
00487 cpl_error_code
00488 uves_table_unify_units(cpl_table **table2, cpl_table **table1);
00489 cpl_error_code
00490 uves_tablenames_unify_units(const char* tname2, const char* tname1);
00491 cpl_error_code
00492 uves_tablename_remove_units(const char* tname);
00493
00494 #endif