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 #ifndef UVES_UTILS_H
00142 #define UVES_UTILS_H
00143
00144
00145 #ifdef HAVE_CONFIG_H
00146 # include <config.h>
00147 #endif
00148
00149
00150
00151
00152
00153 #include <uves_utils_polynomial.h>
00154 #include <uves_extract_iterate.h>
00155 #include <uves_extract_profile.h>
00156 #include <uves_chip.h>
00157
00158 #include <cpl.h>
00159 #include <math.h>
00160
00161
00162
00163
00164
00165
00166 #if defined HAVE_DECL___FUNC__ && !HAVE_DECL___FUNC__
00167
00168 #ifndef __func__
00169 #define __func__ "<fct.id>"
00170 #endif
00171 #endif
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 #ifndef WANT_BIG_LOGFILE
00185 #define WANT_BIG_LOGFILE 0
00186 #endif
00187
00188
00189
00190
00191
00192 #ifndef WANT_TIME_MEASURE
00193 #define WANT_TIME_MEASURE 0
00194 #endif
00195
00196
00197 #if WANT_TIME_MEASURE
00198 #define UVES_TIME_START(what) uves_msg("Timing (%s, l%d) %s start", \
00199 __FILE__, __LINE__, what)
00200 #define UVES_TIME_END uves_msg("Timing (%s, l%d) end", \
00201 __FILE__, __LINE__)
00202 #else
00203 #define UVES_TIME_START(what) uves_msg_debug("Timing (%s, l%d) %s start", \
00204 __FILE__, __LINE__, what)
00205 #define UVES_TIME_END uves_msg_debug("Timing (%s, l%d) end", \
00206 __FILE__, __LINE__)
00207 #endif
00208
00209
00210 #ifndef stringify
00211 #ifndef make_str
00212 #define stringify(X) #X
00213 #define make_str(X) stringify(X)
00214 #endif
00215 #endif
00216
00217 #define TWOSQRT2LN2 2.35482004503095
00218
00219 #ifndef M_PI
00220 #define M_PI 3.1415926535897932384626433832795
00221 #endif
00222
00223 #define SPEED_OF_LIGHT 299792458
00224
00225 #define COS_DEG(x) cos(((x)/180)*M_PI)
00226 #define SIN_DEG(x) sin(((x)/180)*M_PI)
00227 #define ACOS_DEG(x) (acos(x)*180/M_PI)
00228
00229
00230
00231
00232
00233 cpl_image *
00234 uves_create_image(uves_iterate_position *pos, enum uves_chip chip,
00235 const cpl_image *spectrum, const cpl_image *sky,
00236 const cpl_image *cosmic_image,
00237 const uves_extract_profile *profile,
00238 cpl_image **image_noise, uves_propertylist **image_header);
00239
00240 double uves_gaussrand(void);
00241 double uves_pow_int(double x, int y);
00242 long uves_round_double(double x);
00243 double uves_max_double(double x, double y);
00244 int uves_max_int(int x, int y);
00245 double uves_min_double(double x, double y);
00246 int uves_min_int(int x, int y);
00247 double uves_error_fraction(double x, double y, double dx, double dy);
00248 const char *uves_get_license(void);
00249 cpl_error_code uves_get_version(int *major, int *minor, int *micro);
00250 int uves_get_version_binary(void);
00251
00252 char * uves_initialize(cpl_frameset *frames, const cpl_parameterlist *parlist,
00253 const char *recipe_id, const char *short_descr);
00254 cpl_error_code uves_end(const char *recipe_id, const cpl_frameset *frames);
00255
00256 uves_propertylist *uves_initialize_image_header(const char *ctype1, const char *ctype2,
00257 const char *bunit,
00258 double crval1 , double crval2,
00259 double crpix1 , double crpix2,
00260 double crdelt1, double crdelt2);
00261
00262 cpl_image *uves_define_noise(const cpl_image *image, const uves_propertylist *image_header,
00263 int ncom, enum uves_chip);
00264 cpl_image *uves_average_images(const cpl_image *image1, const cpl_image *noise1,
00265 const cpl_image *image2, const cpl_image *noise2,
00266 cpl_image **noise);
00267
00268
00269 cpl_error_code uves_subtract_bias(cpl_image *image, const cpl_image *master_bias);
00270 cpl_error_code uves_subtract_dark(cpl_image *image, const uves_propertylist *image_header,
00271 const cpl_image *master_dark,
00272 const uves_propertylist *mdark_header);
00273
00274 polynomial *
00275 uves_polynomial_regression_2d_autodegree(cpl_table *t,
00276 const char *X1, const char *X2, const char *Y,
00277 const char *sigmaY,
00278 const char *polynomial_fit,
00279 const char *residual_square,
00280 const char *variance_fit,
00281 double *mean_squared_error, double *red_chisq,
00282 polynomial **variance, double kappa,
00283 int maxdeg1, int maxdeg2, double min_rms,
00284 double min_reject,
00285 bool verbose,
00286 const double *min_val,
00287 const double *max_val,
00288 int npos, double positions[][2]);
00289
00290 polynomial *
00291 uves_polynomial_regression_2d(cpl_table *t,
00292 const char *X1, const char *X2, const char *Y,
00293 const char *sigmaY,
00294 int degree1, int degree2,
00295 const char *polynomial_fit, const char *residual_square,
00296 const char *variance_fit,
00297 double *mse, double *red_chisq,
00298 polynomial **variance, double kappa,
00299 double min_reject);
00300
00301 polynomial *uves_polynomial_regression_1d(cpl_table *t,
00302 const char *X, const char *Y, const char *sigmaY,
00303 int degree,
00304 const char *polynomial_fit, const char *residual_square,
00305 double *mean_squared_error, const double kappa);
00306
00307 const char *uves_remove_string_prefix(const char *s, const char *prefix);
00308
00309 double uves_spline_hermite_table( double xp, const cpl_table *t, const char *column_x,
00310 const char *column_y, int *istart );
00311
00312 double uves_spline_hermite( double xp, const double *x, const double *y, int n, int *istart );
00313
00314 double uves_spline_cubic(double xp, double *x, float *y, float *y2, int n, int *kstart );
00315
00316 int uves_absolute_order(int first_abs_order, int last_abs_order, int relative_order);
00317
00318 double uves_average_reject(cpl_table *t,
00319 const char *column,
00320 const char *residual2,
00321 double kappa);
00322
00323
00324 cpl_table *uves_ordertable_traces_new(void);
00325 cpl_error_code uves_ordertable_traces_add(cpl_table *traces,
00326 int fibre_ID, double fibre_offset, int fibre_mask);
00327 bool uves_table_is_sorted_double(const cpl_table *t, const char *column, const bool reverse);
00328
00329 int uves_moffat(const double x[], const double a[], double *result);
00330 int uves_moffat_derivative(const double x[], const double a[], double result[]);
00331 int uves_gauss(const double x[], const double a[], double *result);
00332 int uves_gauss_derivative(const double x[], const double a[], double result[]);
00333 int uves_gauss_linear(const double x[], const double a[], double *result);
00334 int uves_gauss_linear_derivative(const double x[], const double a[], double result[]);
00335 void uves_check_version(void);
00336
00337 #endif