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: 2013/02/12 10:52:38 $
00023  * $Revision: 1.119 $
00024  * $Name: HEAD $
00025  * $Log: uves_utils.h,v $
00026  * Revision 1.119  2013/02/12 10:52:38  amodigli
00027  * removed scaling by exptime as requested by Daniel PIPE-4020
00028  *
00029  * Revision 1.118  2011/12/08 13:54:40  amodigli
00030  * include uves_cpl_size.h for CPL6
00031  *
00032  * Revision 1.117  2011/01/11 18:00:16  amodigli
00033  * fixed compiler warnings (DFS09815)
00034  *
00035  * Revision 1.116  2010/12/20 16:35:57  amodigli
00036  * added uves_table_remove_units(), uves_table_unify_units(), uves_tablenames_unify_units(), uves_tablename_remove_units(), useful in flames/uves to fix a problem on raw order fibre table generated by flames_cal_prep_sff_ofpos that has in an instance units filled by a string like '   ' and is being merged with a table with empty units. CPL5.3 makes a check on table column units consistency
00037  *
00038  * Revision 1.115  2010/12/16 16:57:40  amodigli
00039  * fixed compiler warnings
00040  *
00041  * Revision 1.114  2010/12/01 11:32:22  amodigli
00042  * add uves_image_mflat_detect_blemishes()
00043  *
00044  * Revision 1.113  2010/11/26 07:43:11  amodigli
00045  * added uves_get_wave_map()
00046  *
00047  * Revision 1.112  2010/11/25 10:37:59  amodigli
00048  * changed interface uves_flat_create_normalized_master()
00049  *
00050  * Revision 1.111  2010/10/06 07:52:13  amodigli
00051  * changed interface uves_flat_create_normalized_master2()
00052  *
00053  * Revision 1.110  2010/09/29 09:40:05  amodigli
00054  * fixed compiler warnings (changed function interface)
00055  *
00056  * Revision 1.109  2010/09/24 09:32:08  amodigli
00057  * put back QFITS dependency to fix problem spot by NRI on FIBER mode (with MIDAS calibs) data
00058  *
00059  * Revision 1.107  2010/06/02 09:19:01  amodigli
00060  * removed chip param from uves_imagelist_get_clean_mean_levels()
00061  *
00062  * Revision 1.106  2010/05/18 11:37:44  amodigli
00063  * added uves_imagelist_get_clean_mean_levels
00064  *
00065  * Revision 1.105  2010/05/04 17:21:14  amodigli
00066  * added uves_flat_create_normalized_master2
00067  *
00068  * Revision 1.104  2010/04/07 06:29:19  amodigli
00069  * fixed compiler warnings
00070  *
00071  * Revision 1.103  2010/04/06 17:39:39  amodigli
00072  * added uves_flat_create_normalized_master()
00073  *
00074  * Revision 1.102  2010/03/22 15:56:15  amodigli
00075  * added uves_ksigma_stack
00076  *
00077  * Revision 1.101  2009/08/03 12:46:44  amodigli
00078  * added uves_image_smooth_y
00079  *
00080  * Revision 1.100  2009/07/28 13:48:52  amodigli
00081  * added smoothing functions
00082  *
00083  * Revision 1.99  2008/03/25 08:55:21  amodigli
00084  * check if inline is defined to remove possible compilation warnings
00085  *
00086  * Revision 1.98  2008/02/29 10:26:08  amodigli
00087  * added uves_rcosmic
00088  *
00089  * Revision 1.97  2008/02/15 12:43:21  amodigli
00090  * added uves_string_tolower uves_string_toupper
00091  *
00092  * Revision 1.96  2008/02/04 14:08:58  amodigli
00093  * added uves_parameterlist_duplicate
00094  *
00095  * Revision 1.95  2007/09/11 12:11:49  amodigli
00096  * added uves_frameset_extract
00097  *
00098  * Revision 1.94  2007/08/02 15:18:44  amodigli
00099  * added uves_frameset_dump
00100  *
00101  * Revision 1.93  2007/06/06 08:17:33  amodigli
00102  * replace tab with 4 spaces
00103  *
00104  * Revision 1.92  2007/05/22 11:30:57  jmlarsen
00105  * Removed MIDAS flag for good
00106  *
00107  * Revision 1.91  2007/05/02 13:18:52  jmlarsen
00108  * Added function to simulate reconstruct raw image
00109  *
00110  * Revision 1.90  2007/04/24 12:50:29  jmlarsen
00111  * Replaced cpl_propertylist -> uves_propertylist which is much faster
00112  *
00113  * Revision 1.89  2007/04/12 11:58:07  jmlarsen
00114  * Check compile time CPL version number
00115  *
00116  * Revision 1.88  2007/04/10 07:10:50  jmlarsen
00117  * uves_spline_hermite(): maintain current array position (for efficiency)
00118  *
00119  * Revision 1.87  2007/03/28 11:39:38  jmlarsen
00120  * Removed MIDAS flag from uves_define_noise
00121  *
00122  * Revision 1.86  2007/03/13 15:34:07  jmlarsen
00123  * Parametrize verbosity of autodegree fitting function
00124  *
00125  * Revision 1.85  2007/03/05 10:19:54  jmlarsen
00126  * Define SPEED_OF_LIGHT
00127  *
00128  * Revision 1.84  2007/02/22 15:34:48  jmlarsen
00129  * Implement gaussian function with linear background
00130  *
00131  * Revision 1.83  2006/11/13 12:49:38  jmlarsen
00132  * Removed re-definition of cpl_table_erase_selected
00133  *
00134  * Revision 1.82  2006/11/07 14:05:35  jmlarsen
00135  * Removed flag to enable/disable FLAMES code generation
00136  *
00137  * Revision 1.81  2006/11/06 15:19:42  jmlarsen
00138  * Removed unused include directives
00139  *
00140  * Revision 1.80  2006/11/03 15:01:21  jmlarsen
00141  * Killed UVES 3d table module and use CPL 3d tables
00142  *
00143  * Revision 1.79  2006/10/19 08:23:09  jmlarsen
00144  * Enabled FLAMES code
00145  *
00146  * Revision 1.78  2006/10/12 11:37:28  jmlarsen
00147  * Temporarily disabled FLAMES code generation
00148  *
00149  * Revision 1.77  2006/10/09 13:04:22  jmlarsen
00150  * Removed message domain parameter of uves_initialize
00151  *
00152  * Revision 1.76  2006/09/20 12:53:57  jmlarsen
00153  * Replaced stringcat functions with uves_sprintf()
00154  *
00155  * Revision 1.75  2006/09/08 14:05:39  jmlarsen
00156  * Added max/min allowed values in autodegree fitting
00157  *
00158  * Revision 1.74  2006/08/24 11:43:49  jmlarsen
00159  * Write recipe start/stop time to header
00160  *
00161  * Revision 1.73  2006/08/17 13:56:53  jmlarsen
00162  * Reduced max line length
00163  *
00164  * Revision 1.72  2006/08/11 14:37:30  jmlarsen
00165  * Implemented workaround for slow cpl_table_erase_selected
00166  *
00167  * Revision 1.71  2006/08/11 11:29:11  jmlarsen
00168  * uves_get_version_binary
00169  *
00170  * Revision 1.70  2006/08/08 11:27:18  amodigli
00171  * upgrade to CPL3
00172  *
00173  * Revision 1.69  2006/07/14 12:42:42  jmlarsen
00174  * Added function uves_strincat_4
00175  *
00176  * Revision 1.68  2006/06/22 09:44:02  jmlarsen
00177  * Added function to remove string prefix
00178  *
00179  * Revision 1.67  2006/06/01 14:43:17  jmlarsen
00180  * Added missing documentation
00181  *
00182  * Revision 1.66  2006/05/12 15:12:11  jmlarsen
00183  * Support minimum RMS in auto-degree fitting
00184  *
00185  * Revision 1.65  2006/05/05 13:58:09  jmlarsen
00186  * Added uves_polynomial_regression_2d_autodegree
00187  *
00188  * Revision 1.64  2006/04/24 09:26:37  jmlarsen
00189  * Added code to compute Moffat profile
00190  *
00191  * Revision 1.63  2006/04/06 08:51:43  jmlarsen
00192  * Allow setting WANT_TIME_MEASURE when ./configure'ing
00193  *
00194  * Revision 1.62  2006/03/24 13:48:09  jmlarsen
00195  * Macro to turn on/off timing info
00196  *
00197  * Revision 1.61  2006/03/09 10:55:50  jmlarsen
00198  * Added timing macros
00199  *
00200  * Revision 1.60  2006/02/28 09:15:23  jmlarsen
00201  * Minor update
00202  *
00203  * Revision 1.59  2006/02/21 14:26:54  jmlarsen
00204  * Minor changes
00205  *
00206  * Revision 1.58  2006/02/15 13:19:15  jmlarsen
00207  * Reduced source code max. line length
00208  *
00209  * Revision 1.57  2006/01/12 15:41:14  jmlarsen
00210  * Moved gauss. fitting to irplib
00211  *
00212  * Revision 1.56  2005/12/20 08:11:44  jmlarsen
00213  * Added CVS  entry
00214  *
00215  */
00216 #ifndef UVES_UTILS_H
00217 #define UVES_UTILS_H
00218 
00219 
00220 #ifdef HAVE_CONFIG_H
00221 #  include <config.h>
00222 #endif
00223 #include <uves_cpl_size.h>
00224 /*-----------------------------------------------------------------------------
00225                     Includes
00226  -----------------------------------------------------------------------------*/
00227 
00228 #include <uves_utils_polynomial.h>
00229 #include <uves_extract_iterate.h>
00230 #include <uves_extract_profile.h>
00231 #include <uves_chip.h>
00232 
00233 #include <cpl.h>
00234 #include <math.h>
00235 
00236 /*-----------------------------------------------------------------------------
00237                              Defines
00238  -----------------------------------------------------------------------------*/
00239 
00240 /* If __func__ is not declared, use a default function name */
00241 #if defined HAVE_DECL___FUNC__ && !HAVE_DECL___FUNC__
00242 //static const char __func__[] = "<fctid>";
00243 #ifndef __func__
00244 #define __func__ "<fct.id>"
00245 #endif
00246 #endif
00247 
00248 #ifndef inline
00249 #define inline /* inline */
00250 #endif
00251 
00252 /*
00253  * The purpose of this target is to
00254  * decrease the amount of messages
00255  * printed at the debug level.
00256  *
00257  * If set to non-zero, even more messages
00258  * are printed at the debug level
00259  * (sometimes 50 - 100 MB)
00260  *
00261  */
00262 #ifndef WANT_BIG_LOGFILE
00263 #define WANT_BIG_LOGFILE 0
00264 #endif
00265 
00266 /*
00267  * Set to 1 to show timing
00268  * information on msg-level = info
00269  */
00270 #ifndef WANT_TIME_MEASURE
00271 #define WANT_TIME_MEASURE 0
00272 #endif
00273 
00274 
00275 #if WANT_TIME_MEASURE
00276 #define UVES_TIME_START(what) uves_msg("Timing (%s, l%d) %s start", \
00277                        __FILE__, __LINE__, what)
00278 #define UVES_TIME_END         uves_msg("Timing (%s, l%d) end", \
00279                        __FILE__, __LINE__)
00280 #else
00281 #define UVES_TIME_START(what) uves_msg_debug("Timing (%s, l%d) %s start", \
00282                          __FILE__, __LINE__, what)
00283 #define UVES_TIME_END         uves_msg_debug("Timing (%s, l%d) end", \
00284                          __FILE__, __LINE__)
00285 #endif
00286 
00287 
00288 #ifndef stringify
00289 #ifndef make_str
00290 #define stringify(X) #X
00291 #define make_str(X) stringify(X)
00292 #endif
00293 #endif
00294 
00295 #define TWOSQRT2LN2 2.35482004503095
00296 
00297 #ifndef M_PI 
00298 #define M_PI 3.1415926535897932384626433832795
00299 #endif
00300 
00301 #define SPEED_OF_LIGHT  299792458    /* SI-units */
00302 
00303 #define COS_DEG(x) cos(((x)/180)*M_PI)
00304 #define SIN_DEG(x) sin(((x)/180)*M_PI)
00305 #define ACOS_DEG(x) (acos(x)*180/M_PI)
00306 
00307 /*-----------------------------------------------------------------------------
00308                                    Prototypes
00309  -----------------------------------------------------------------------------*/
00310 
00311 cpl_image *
00312 uves_create_image(uves_iterate_position *pos, enum uves_chip chip,
00313                   const cpl_image *spectrum, const cpl_image *sky,
00314                   const cpl_image *cosmic_image,
00315                   const uves_extract_profile *profile,
00316                   cpl_image **image_noise, uves_propertylist **image_header);
00317 cpl_frameset *
00318 uves_frameset_extract(const cpl_frameset *frames,const char *tag);
00319 
00320 const char*
00321 uves_string_tolower(char* s);
00322 const char*
00323 uves_string_toupper(char* s);
00324 
00325 double uves_gaussrand(void);
00326 double uves_pow_int(double x, int y);
00327 long uves_round_double(double x);
00328 double uves_max_double(double x, double y);
00329 int uves_max_int(int x, int y);
00330 double uves_min_double(double x, double y);
00331 int uves_min_int(int x, int y);
00332 double uves_error_fraction(double x, double y, double dx, double dy);
00333 const char *uves_get_license(void);
00334 cpl_error_code uves_get_version(int *major, int *minor, int *micro);
00335 int uves_get_version_binary(void);
00336 
00337 char * uves_initialize(cpl_frameset *frames, const cpl_parameterlist *parlist, 
00338                const char *recipe_id, const char *short_descr);
00339 cpl_error_code uves_end(const char *recipe_id, const cpl_frameset *frames);
00340 
00341 uves_propertylist *uves_initialize_image_header(const char *ctype1, const char *ctype2, 
00342                            const char *bunit,
00343                            double crval1 , double crval2,
00344                            double crpix1 , double crpix2,
00345                            double crdelt1, double crdelt2);
00346 
00347 cpl_parameterlist* 
00348 uves_parameterlist_duplicate(const cpl_parameterlist* pin);
00349 
00350 cpl_image *uves_define_noise(const cpl_image *image, const uves_propertylist *image_header,
00351                  int ncom, enum uves_chip);
00352 cpl_image *uves_average_images(const cpl_image *image1, const cpl_image *noise1,
00353                    const cpl_image *image2, const cpl_image *noise2,
00354                    cpl_image **noise);
00355 
00356 
00357 cpl_error_code uves_subtract_bias(cpl_image *image, const cpl_image *master_bias);
00358 cpl_error_code uves_subtract_dark(cpl_image *image, const uves_propertylist *image_header,
00359                   const cpl_image *master_dark, 
00360                   const uves_propertylist *mdark_header);
00361 
00362 polynomial *
00363 uves_polynomial_regression_2d_autodegree(cpl_table *t,
00364                      const char *X1, const char *X2, const char *Y,
00365                      const char *sigmaY,
00366                      const char *polynomial_fit,
00367                      const char *residual_square, 
00368                      const char *variance_fit,
00369                      double *mean_squared_error, double *red_chisq,
00370                      polynomial **variance, double kappa,
00371                      int maxdeg1, int maxdeg2, double min_rms,
00372                                          double min_reject,
00373                                          bool verbose,
00374                      const double *min_val,
00375                      const double *max_val,
00376                      int npos, double positions[][2]);
00377 
00378 polynomial *
00379 uves_polynomial_regression_2d(cpl_table *t,
00380                   const char *X1, const char *X2, const char *Y, 
00381                   const char *sigmaY,
00382                   int degree1, int degree2,
00383                   const char *polynomial_fit, const char *residual_square, 
00384                   const char *variance_fit,
00385                   double *mse, double *red_chisq,
00386                   polynomial **variance, double kappa,
00387                               double min_reject);
00388 
00389 polynomial *uves_polynomial_regression_1d(cpl_table *t, 
00390                       const char *X, const char *Y, const char *sigmaY, 
00391                       int degree, 
00392                       const char *polynomial_fit, const char *residual_square,
00393                       double *mean_squared_error, const double kappa);
00394 
00395 const char *uves_remove_string_prefix(const char *s, const char *prefix);
00396 
00397 double uves_spline_hermite_table( double xp, const cpl_table *t, const char *column_x, 
00398                   const char *column_y, int *istart );
00399 
00400 double uves_spline_hermite( double xp, const double *x, const double *y, int n, int *istart );
00401 
00402 double uves_spline_cubic(double xp, double *x, float *y, float *y2, int n, int *kstart );
00403 
00404 int uves_absolute_order(int first_abs_order, int last_abs_order, int relative_order);
00405 
00406 double uves_average_reject(cpl_table *t,
00407                const char *column,
00408                const char *residual2,
00409                double kappa);
00410 
00411 
00412 cpl_table *uves_ordertable_traces_new(void);
00413 cpl_error_code uves_ordertable_traces_add(cpl_table *traces, 
00414                       int fibre_ID, double fibre_offset, int fibre_mask);
00415 bool uves_table_is_sorted_double(const cpl_table *t, const char *column, const bool reverse);
00416 
00417 int uves_moffat(const double x[], const double a[], double *result);
00418 int uves_moffat_derivative(const double x[], const double a[], double result[]);
00419 int uves_gauss(const double x[], const double a[], double *result);
00420 int uves_gauss_derivative(const double x[], const double a[], double result[]);
00421 int uves_gauss_linear(const double x[], const double a[], double *result);
00422 int uves_gauss_linear_derivative(const double x[], const double a[], double result[]);
00423 void uves_check_version(void);
00424 void uves_frameset_dump(cpl_frameset* set);
00425 cpl_error_code
00426 uves_rcosmic(cpl_image* ima,
00427              cpl_image** flt,
00428              cpl_image** out,
00429              cpl_image** msk,
00430              const double sky,
00431              const double ron,
00432              const double gain,
00433              const int ns,
00434              const double rc);
00435 
00436 cpl_image *
00437 uves_image_smooth_x(cpl_image * inp, const int r);
00438 cpl_image *
00439 uves_image_smooth_y(cpl_image * inp, const int r);
00440 
00441 cpl_image *
00442 uves_image_smooth_mean_x(cpl_image * inp, const int r);
00443 
00444 cpl_image *
00445 uves_image_smooth_median_x(cpl_image * inp, const int r);
00446 cpl_image *
00447 uves_image_smooth_fft(cpl_image * inp, const int fx);
00448 
00449 cpl_image *
00450 uves_ksigma_stack(const cpl_imagelist *imlist, double klow, double khigh, int kiter);
00451 
00452 
00453 cpl_image *
00454 uves_flat_create_normalized_master(cpl_imagelist * flats,
00455                    const cpl_table *ordertable,
00456                                    const polynomial* order_locations,
00457                    const cpl_vector* gain_vals,
00458                    double* fnoise);
00459 
00460 cpl_image *
00461 uves_flat_create_normalized_master2(cpl_imagelist * flats,
00462                                    const cpl_table *ordertable,
00463                                    const polynomial* order_locations,
00464                                     const cpl_image* mflat);
00465 
00466 cpl_vector * 
00467 uves_imagelist_get_clean_mean_levels(cpl_imagelist* iml, double kappa);
00468 cpl_error_code
00469 uves_imagelist_subtract_values(cpl_imagelist** iml, cpl_vector* values);
00470 cpl_image *
00471 uves_get_wave_map(cpl_image * ima_sci,
00472           const char *context,
00473                   const cpl_parameterlist *parameters,
00474           const cpl_table *ordertable,
00475           const cpl_table *linetable,
00476           const polynomial* order_locations,
00477           const polynomial *dispersion_relation,
00478           const int first_abs_order,
00479           const int last_abs_order,
00480           const int slit_size);
00481 
00482 cpl_image*
00483 uves_image_mflat_detect_blemishes(const cpl_image* flat, 
00484                                   const uves_propertylist* head);
00485 
00486 
00487 cpl_error_code
00488 uves_table_remove_units(cpl_table **table);
00489 cpl_error_code
00490 uves_table_unify_units(cpl_table **table2,  cpl_table **table1);
00491 cpl_error_code
00492 uves_tablenames_unify_units(const char* tname2, const char* tname1);
00493 cpl_error_code
00494 uves_tablename_remove_units(const char* tname);
00495 
00496 #endif

Generated on 3 Mar 2013 for UVES Pipeline Reference Manual by  doxygen 1.6.1