uves_utils.h

00001 /*
00002  * This file is part of the ESO UVES Pipeline
00003  * Copyright (C) 2004,2005 European Southern Observatory
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
00018  */
00019 
00020 /*
00021  * $Author: amodigli $
00022  * $Date: 2007/09/11 12:11:49 $
00023  * $Revision: 1.95 $
00024  * $Name: uves-3_4_5 $
00025  * $Log: uves_utils.h,v $
00026  * Revision 1.95  2007/09/11 12:11:49  amodigli
00027  * added uves_frameset_extract
00028  *
00029  * Revision 1.94  2007/08/02 15:18:44  amodigli
00030  * added uves_frameset_dump
00031  *
00032  * Revision 1.93  2007/06/06 08:17:33  amodigli
00033  * replace tab with 4 spaces
00034  *
00035  * Revision 1.92  2007/05/22 11:30:57  jmlarsen
00036  * Removed MIDAS flag for good
00037  *
00038  * Revision 1.91  2007/05/02 13:18:52  jmlarsen
00039  * Added function to simulate reconstruct raw image
00040  *
00041  * Revision 1.90  2007/04/24 12:50:29  jmlarsen
00042  * Replaced cpl_propertylist -> uves_propertylist which is much faster
00043  *
00044  * Revision 1.89  2007/04/12 11:58:07  jmlarsen
00045  * Check compile time CPL version number
00046  *
00047  * Revision 1.88  2007/04/10 07:10:50  jmlarsen
00048  * uves_spline_hermite(): maintain current array position (for efficiency)
00049  *
00050  * Revision 1.87  2007/03/28 11:39:38  jmlarsen
00051  * Removed MIDAS flag from uves_define_noise
00052  *
00053  * Revision 1.86  2007/03/13 15:34:07  jmlarsen
00054  * Parametrize verbosity of autodegree fitting function
00055  *
00056  * Revision 1.85  2007/03/05 10:19:54  jmlarsen
00057  * Define SPEED_OF_LIGHT
00058  *
00059  * Revision 1.84  2007/02/22 15:34:48  jmlarsen
00060  * Implement gaussian function with linear background
00061  *
00062  * Revision 1.83  2006/11/13 12:49:38  jmlarsen
00063  * Removed re-definition of cpl_table_erase_selected
00064  *
00065  * Revision 1.82  2006/11/07 14:05:35  jmlarsen
00066  * Removed flag to enable/disable FLAMES code generation
00067  *
00068  * Revision 1.81  2006/11/06 15:19:42  jmlarsen
00069  * Removed unused include directives
00070  *
00071  * Revision 1.80  2006/11/03 15:01:21  jmlarsen
00072  * Killed UVES 3d table module and use CPL 3d tables
00073  *
00074  * Revision 1.79  2006/10/19 08:23:09  jmlarsen
00075  * Enabled FLAMES code
00076  *
00077  * Revision 1.78  2006/10/12 11:37:28  jmlarsen
00078  * Temporarily disabled FLAMES code generation
00079  *
00080  * Revision 1.77  2006/10/09 13:04:22  jmlarsen
00081  * Removed message domain parameter of uves_initialize
00082  *
00083  * Revision 1.76  2006/09/20 12:53:57  jmlarsen
00084  * Replaced stringcat functions with uves_sprintf()
00085  *
00086  * Revision 1.75  2006/09/08 14:05:39  jmlarsen
00087  * Added max/min allowed values in autodegree fitting
00088  *
00089  * Revision 1.74  2006/08/24 11:43:49  jmlarsen
00090  * Write recipe start/stop time to header
00091  *
00092  * Revision 1.73  2006/08/17 13:56:53  jmlarsen
00093  * Reduced max line length
00094  *
00095  * Revision 1.72  2006/08/11 14:37:30  jmlarsen
00096  * Implemented workaround for slow cpl_table_erase_selected
00097  *
00098  * Revision 1.71  2006/08/11 11:29:11  jmlarsen
00099  * uves_get_version_binary
00100  *
00101  * Revision 1.70  2006/08/08 11:27:18  amodigli
00102  * upgrade to CPL3
00103  *
00104  * Revision 1.69  2006/07/14 12:42:42  jmlarsen
00105  * Added function uves_strincat_4
00106  *
00107  * Revision 1.68  2006/06/22 09:44:02  jmlarsen
00108  * Added function to remove string prefix
00109  *
00110  * Revision 1.67  2006/06/01 14:43:17  jmlarsen
00111  * Added missing documentation
00112  *
00113  * Revision 1.66  2006/05/12 15:12:11  jmlarsen
00114  * Support minimum RMS in auto-degree fitting
00115  *
00116  * Revision 1.65  2006/05/05 13:58:09  jmlarsen
00117  * Added uves_polynomial_regression_2d_autodegree
00118  *
00119  * Revision 1.64  2006/04/24 09:26:37  jmlarsen
00120  * Added code to compute Moffat profile
00121  *
00122  * Revision 1.63  2006/04/06 08:51:43  jmlarsen
00123  * Allow setting WANT_TIME_MEASURE when ./configure'ing
00124  *
00125  * Revision 1.62  2006/03/24 13:48:09  jmlarsen
00126  * Macro to turn on/off timing info
00127  *
00128  * Revision 1.61  2006/03/09 10:55:50  jmlarsen
00129  * Added timing macros
00130  *
00131  * Revision 1.60  2006/02/28 09:15:23  jmlarsen
00132  * Minor update
00133  *
00134  * Revision 1.59  2006/02/21 14:26:54  jmlarsen
00135  * Minor changes
00136  *
00137  * Revision 1.58  2006/02/15 13:19:15  jmlarsen
00138  * Reduced source code max. line length
00139  *
00140  * Revision 1.57  2006/01/12 15:41:14  jmlarsen
00141  * Moved gauss. fitting to irplib
00142  *
00143  * Revision 1.56  2005/12/20 08:11:44  jmlarsen
00144  * Added CVS  entry
00145  *
00146  */
00147 #ifndef UVES_UTILS_H
00148 #define UVES_UTILS_H
00149 
00150 
00151 #ifdef HAVE_CONFIG_H
00152 #  include <config.h>
00153 #endif
00154 
00155 /*-----------------------------------------------------------------------------
00156                     Includes
00157  -----------------------------------------------------------------------------*/
00158 
00159 #include <uves_utils_polynomial.h>
00160 #include <uves_extract_iterate.h>
00161 #include <uves_extract_profile.h>
00162 #include <uves_chip.h>
00163 
00164 #include <cpl.h>
00165 #include <math.h>
00166 
00167 /*-----------------------------------------------------------------------------
00168                              Defines
00169  -----------------------------------------------------------------------------*/
00170 
00171 /* If __func__ is not declared, use a default function name */
00172 #if defined HAVE_DECL___FUNC__ && !HAVE_DECL___FUNC__
00173 //static const char __func__[] = "<fctid>";
00174 #ifndef __func__
00175 #define __func__ "<fct.id>"
00176 #endif
00177 #endif
00178 
00179 
00180 /*
00181  * The purpose of this target is to
00182  * decrease the amount of messages
00183  * printed at the debug level.
00184  *
00185  * If set to non-zero, even more messages
00186  * are printed at the debug level
00187  * (sometimes 50 - 100 MB)
00188  *
00189  */
00190 #ifndef WANT_BIG_LOGFILE
00191 #define WANT_BIG_LOGFILE 0
00192 #endif
00193 
00194 /*
00195  * Set to 1 to show timing
00196  * information on msg-level = info
00197  */
00198 #ifndef WANT_TIME_MEASURE
00199 #define WANT_TIME_MEASURE 0
00200 #endif
00201 
00202 
00203 #if WANT_TIME_MEASURE
00204 #define UVES_TIME_START(what) uves_msg("Timing (%s, l%d) %s start", \
00205                        __FILE__, __LINE__, what)
00206 #define UVES_TIME_END         uves_msg("Timing (%s, l%d) end", \
00207                        __FILE__, __LINE__)
00208 #else
00209 #define UVES_TIME_START(what) uves_msg_debug("Timing (%s, l%d) %s start", \
00210                          __FILE__, __LINE__, what)
00211 #define UVES_TIME_END         uves_msg_debug("Timing (%s, l%d) end", \
00212                          __FILE__, __LINE__)
00213 #endif
00214 
00215 
00216 #ifndef stringify
00217 #ifndef make_str
00218 #define stringify(X) #X
00219 #define make_str(X) stringify(X)
00220 #endif
00221 #endif
00222 
00223 #define TWOSQRT2LN2 2.35482004503095
00224 
00225 #ifndef M_PI 
00226 #define M_PI 3.1415926535897932384626433832795
00227 #endif
00228 
00229 #define SPEED_OF_LIGHT  299792458    /* SI-units */
00230 
00231 #define COS_DEG(x) cos(((x)/180)*M_PI)
00232 #define SIN_DEG(x) sin(((x)/180)*M_PI)
00233 #define ACOS_DEG(x) (acos(x)*180/M_PI)
00234 
00235 /*-----------------------------------------------------------------------------
00236                                    Prototypes
00237  -----------------------------------------------------------------------------*/
00238 
00239 cpl_image *
00240 uves_create_image(uves_iterate_position *pos, enum uves_chip chip,
00241                   const cpl_image *spectrum, const cpl_image *sky,
00242                   const cpl_image *cosmic_image,
00243                   const uves_extract_profile *profile,
00244                   cpl_image **image_noise, uves_propertylist **image_header);
00245 cpl_frameset *
00246 uves_frameset_extract(const cpl_frameset *frames,const char *tag);
00247 
00248 double uves_gaussrand(void);
00249 double uves_pow_int(double x, int y);
00250 long uves_round_double(double x);
00251 double uves_max_double(double x, double y);
00252 int uves_max_int(int x, int y);
00253 double uves_min_double(double x, double y);
00254 int uves_min_int(int x, int y);
00255 double uves_error_fraction(double x, double y, double dx, double dy);
00256 const char *uves_get_license(void);
00257 cpl_error_code uves_get_version(int *major, int *minor, int *micro);
00258 int uves_get_version_binary(void);
00259 
00260 char * uves_initialize(cpl_frameset *frames, const cpl_parameterlist *parlist, 
00261                const char *recipe_id, const char *short_descr);
00262 cpl_error_code uves_end(const char *recipe_id, const cpl_frameset *frames);
00263 
00264 uves_propertylist *uves_initialize_image_header(const char *ctype1, const char *ctype2, 
00265                            const char *bunit,
00266                            double crval1 , double crval2,
00267                            double crpix1 , double crpix2,
00268                            double crdelt1, double crdelt2);
00269 
00270 cpl_image *uves_define_noise(const cpl_image *image, const uves_propertylist *image_header,
00271                  int ncom, enum uves_chip);
00272 cpl_image *uves_average_images(const cpl_image *image1, const cpl_image *noise1,
00273                    const cpl_image *image2, const cpl_image *noise2,
00274                    cpl_image **noise);
00275 
00276 
00277 cpl_error_code uves_subtract_bias(cpl_image *image, const cpl_image *master_bias);
00278 cpl_error_code uves_subtract_dark(cpl_image *image, const uves_propertylist *image_header,
00279                   const cpl_image *master_dark, 
00280                   const uves_propertylist *mdark_header);
00281 
00282 polynomial *
00283 uves_polynomial_regression_2d_autodegree(cpl_table *t,
00284                      const char *X1, const char *X2, const char *Y,
00285                      const char *sigmaY,
00286                      const char *polynomial_fit,
00287                      const char *residual_square, 
00288                      const char *variance_fit,
00289                      double *mean_squared_error, double *red_chisq,
00290                      polynomial **variance, double kappa,
00291                      int maxdeg1, int maxdeg2, double min_rms,
00292                                          double min_reject,
00293                                          bool verbose,
00294                      const double *min_val,
00295                      const double *max_val,
00296                      int npos, double positions[][2]);
00297 
00298 polynomial *
00299 uves_polynomial_regression_2d(cpl_table *t,
00300                   const char *X1, const char *X2, const char *Y, 
00301                   const char *sigmaY,
00302                   int degree1, int degree2,
00303                   const char *polynomial_fit, const char *residual_square, 
00304                   const char *variance_fit,
00305                   double *mse, double *red_chisq,
00306                   polynomial **variance, double kappa,
00307                               double min_reject);
00308 
00309 polynomial *uves_polynomial_regression_1d(cpl_table *t, 
00310                       const char *X, const char *Y, const char *sigmaY, 
00311                       int degree, 
00312                       const char *polynomial_fit, const char *residual_square,
00313                       double *mean_squared_error, const double kappa);
00314 
00315 const char *uves_remove_string_prefix(const char *s, const char *prefix);
00316 
00317 double uves_spline_hermite_table( double xp, const cpl_table *t, const char *column_x, 
00318                   const char *column_y, int *istart );
00319 
00320 double uves_spline_hermite( double xp, const double *x, const double *y, int n, int *istart );
00321 
00322 double uves_spline_cubic(double xp, double *x, float *y, float *y2, int n, int *kstart );
00323 
00324 int uves_absolute_order(int first_abs_order, int last_abs_order, int relative_order);
00325 
00326 double uves_average_reject(cpl_table *t,
00327                const char *column,
00328                const char *residual2,
00329                double kappa);
00330 
00331 
00332 cpl_table *uves_ordertable_traces_new(void);
00333 cpl_error_code uves_ordertable_traces_add(cpl_table *traces, 
00334                       int fibre_ID, double fibre_offset, int fibre_mask);
00335 bool uves_table_is_sorted_double(const cpl_table *t, const char *column, const bool reverse);
00336 
00337 int uves_moffat(const double x[], const double a[], double *result);
00338 int uves_moffat_derivative(const double x[], const double a[], double result[]);
00339 int uves_gauss(const double x[], const double a[], double *result);
00340 int uves_gauss_derivative(const double x[], const double a[], double result[]);
00341 int uves_gauss_linear(const double x[], const double a[], double *result);
00342 int uves_gauss_linear_derivative(const double x[], const double a[], double result[]);
00343 void uves_check_version(void);
00344 void uves_frameset_dump(cpl_frameset* set);
00345 
00346 #endif

Generated on Thu Nov 15 14:32:31 2007 for UVES Pipeline Reference Manual by  doxygen 1.5.1