uves_test_simulate.c

00001 /*                                                                              *
00002  *   This file is part of the ESO UVES Pipeline                                 *
00003  *   Copyright (C) 2004,2005 European Southern Observatory                      *
00004  *                                                                              *
00005  *   This library 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: jmlarsen $
00022  * $Date: 2007/05/22 11:28:14 $
00023  * $Revision: 1.6 $
00024  * $Name: uves-3_3_1 $
00025  * $Log: uves_test_simulate.c,v $
00026  * Revision 1.6  2007/05/22 11:28:14  jmlarsen
00027  * Removed unused variables
00028  *
00029  * Revision 1.5  2007/04/24 12:50:29  jmlarsen
00030  * Replaced cpl_propertylist -> uves_propertylist which is much faster
00031  *
00032  * Revision 1.4  2007/04/10 11:34:48  jmlarsen
00033  * More points per order in order table
00034  *
00035  * Revision 1.3  2007/04/10 07:22:07  jmlarsen
00036  * Changed interface of polynomial_regression_2d()
00037  *
00038  * Revision 1.2  2007/03/15 14:44:51  jmlarsen
00039  * Removed debugging dump
00040  *
00041  * Revision 1.1  2007/03/15 12:47:32  jmlarsen
00042  * Imported sources
00043  *
00044  *
00045  */
00046 
00047 #ifdef HAVE_CONFIG_H
00048 #  include <config.h>
00049 #endif
00050 
00051 /*----------------------------------------------------------------------------*/
00055 /*----------------------------------------------------------------------------*/
00058 /*-----------------------------------------------------------------------------
00059                                 Includes
00060  -----------------------------------------------------------------------------*/
00061 
00062 #include <uves_test_simulate.h>
00063 #include <uves_utils_polynomial.h>
00064 #include <uves_utils_wrappers.h>
00065 #include <uves_wavecal_utils.h>
00066 #include <uves_error.h>
00067 
00068 #include <cpl.h>
00069 
00070 /*-----------------------------------------------------------------------------
00071                             Functions prototypes
00072  -----------------------------------------------------------------------------*/
00073 
00074 /*-----------------------------------------------------------------------------
00075                             Implementation
00076  -----------------------------------------------------------------------------*/
00077 
00078 /*----------------------------------------------------------------------------*/
00087 /*----------------------------------------------------------------------------*/
00088 void
00089 create_order_table(cpl_table **ordertable, polynomial **order_locations, cpl_table **tracetable,
00090                    int minorder, int maxorder, int nx)
00091 {
00092     uves_propertylist *header = NULL;
00093     
00094     /* Create polynomial */
00095     assure_nomsg(order_locations != NULL, CPL_ERROR_NULL_INPUT);
00096     
00097     {
00098         const char *data[] = {"",
00099                               "'COEFFI','I*4',1,7,'7I10'",
00100                               "     53889         2         3         2         1         4         5",
00101                               "",
00102                               "'COEFFR','R*4',1,5,'5E14.7'",
00103                               " 4.3300000E+02 4.0880000E+03 1.0000000E+00 2.1000000E+01 0.0000000E+00",
00104                               "",
00105                               "'COEFFD','R*8',1,30,'3E23.15'",
00106                               " -7.097005629698889E+01  4.050908371864904E-02 -2.886756545398909E-06",
00107                               "  5.504345508879626E-10 -5.583004967206025E-14  7.624532125635992E+01",
00108                               " -2.428213567964009E-03  1.819158447566360E-06 -5.090366383338846E-10",
00109                               "  5.198098506055602E-14  3.513177145982783E-01  5.570332137951829E-04",
00110                               " -3.876157463910250E-07  1.113253735718822E-10 -1.132455173423791E-14",
00111                               "  2.977232589499959E-02 -5.389240622889887E-05  3.777456726044612E-08",
00112                               " -1.083863050648735E-11  1.098450510939580E-15 -1.093309039442914E-03",          
00113                               "  2.402609262989674E-06 -1.688416547941747E-09  4.839101712729582E-13",
00114                               " -4.884504488944702E-17  1.919853952642526E-05 -4.004133160220927E-08",
00115                               "  2.816206503824200E-11 -8.051313882805877E-15  8.090579180112579E-19",
00116                               " ",
00117                               "'TAB_IN_OUT_YSHIFT','R*8',1,1,'3E23.15'",
00118                               "  4.180818583555659E+01          ",
00119                               " "};
00120             
00121         header = uves_propertylist_new();
00122         {
00123             unsigned i;
00124             for (i = 0; i < sizeof(data)/sizeof(char *); i++)
00125                 {
00126                     uves_propertylist_append_string(header, "HISTORY",
00127                                                    data[i]);
00128                 }
00129         }
00130             
00131         check_nomsg( *order_locations = uves_polynomial_convert_from_plist_midas(header, 
00132                                                                                  "COEFF"));
00133     }
00134 
00135     /* Fill order table */
00136     if (ordertable != NULL)
00137         {
00138             int order;
00139             int row = 0;
00140 
00141             *ordertable = cpl_table_new(5*(maxorder - minorder + 1));
00142             cpl_table_new_column(*ordertable, "Order", CPL_TYPE_INT);
00143             cpl_table_new_column(*ordertable, "X", CPL_TYPE_INT);
00144             cpl_table_new_column(*ordertable, "Yfit", CPL_TYPE_DOUBLE);
00145 
00146             for (order = minorder; order <= maxorder; order++)
00147                 {
00148                     int x[5];
00149                     int i;
00150                     x[0] = (1*nx)/6+1;
00151                     x[1] = (2*nx)/6+1;
00152                     x[2] = (3*nx)/6+1;
00153                     x[3] = (4*nx)/6+1;
00154                     x[4] = (5*nx)/6+1;
00155                     
00156                     for (i = 0; i < 5; i++)
00157                         {
00158                             cpl_table_set_int(*ordertable, "Order", row, order);
00159                             cpl_table_set_int(*ordertable, "X", row, x[i]);
00160                             cpl_table_set_double(*ordertable, "Yfit", row, 
00161                                                  uves_polynomial_evaluate_2d(*order_locations,
00162                                                                              x[i], order));
00163                             row++;
00164                         }
00165                 }
00166         }
00167   
00168   /* Not implemented: */
00169   /* Fill tracetable */
00170     tracetable = tracetable; /* suppress warnings */
00171   
00172  cleanup:
00173   uves_free_propertylist(&header);
00174   return;
00175 }
00176 
00177 /*----------------------------------------------------------------------------*/
00184 /*----------------------------------------------------------------------------*/
00185 void
00186 create_line_table(cpl_table **linetable, polynomial **dispersion, polynomial **abs_orders,
00187                   int minorder, int maxorder, int nx)
00188 {
00189     polynomial *order_locations = NULL;
00190     cpl_table *ordertable = NULL;
00191     cpl_table *tracetable = NULL;
00192 
00193     create_order_table(&ordertable, &order_locations, &tracetable,
00194                        minorder, maxorder, nx);
00195 
00196     assure_nomsg(linetable != NULL, CPL_ERROR_NULL_INPUT);
00197     
00198     {
00199         int row = 0;
00200         *linetable = cpl_table_new(cpl_table_get_nrow(ordertable));
00201         cpl_table_new_column(*linetable, "X", CPL_TYPE_DOUBLE);
00202         cpl_table_new_column(*linetable, "Ynew", CPL_TYPE_DOUBLE);
00203         cpl_table_new_column(*linetable, "Y", CPL_TYPE_INT);
00204         cpl_table_new_column(*linetable, "Order", CPL_TYPE_INT);
00205         cpl_table_new_column(*linetable, LINETAB_LAMBDAC, CPL_TYPE_DOUBLE);
00206         cpl_table_new_column(*linetable, "Ident", CPL_TYPE_DOUBLE);
00207         cpl_table_new_column(*linetable, "Aux", CPL_TYPE_DOUBLE);
00208         for (row = 0; row < cpl_table_get_nrow(ordertable); row++)
00209             {
00210                 int order = cpl_table_get_int(ordertable, "Order", row, NULL);
00211                 double x  = cpl_table_get_int(ordertable, "X", row, NULL);
00212                 double y  = cpl_table_get_double(ordertable, "Yfit", row, NULL);
00213                 int m = 120 - order; /* absolute order number */
00214                 double lambda = 3000 + 50*(order - minorder) + 80*(x*1.0/nx);
00215                 
00216                 cpl_table_set_double(*linetable, "X", row, x);
00217                 cpl_table_set_double(*linetable, "Ynew", row, y);
00218                 cpl_table_set_int(*linetable, "Y", row, order);   /* it's correct! */
00219                 cpl_table_set_int(*linetable, "Order", row, m);
00220                 cpl_table_set_double(*linetable, LINETAB_LAMBDAC, row, lambda);
00221                 cpl_table_set_double(*linetable, "Ident", row, lambda); /* exact! */
00222                 cpl_table_set_double(*linetable, "Aux", row, lambda*m);
00223             }
00224     }
00225     
00226     if (abs_orders != NULL)
00227         {
00228             /* Create polynomial
00229                absorders(x, y) = m
00230             */
00231             int degree = 2;
00232             check_nomsg(
00233             *abs_orders = uves_polynomial_regression_2d(*linetable,
00234                                                         "X", "Ynew", "Order", NULL,
00235                                                         degree, degree,
00236                                                         NULL, NULL, NULL, /* new columns */
00237                                                         NULL, NULL, /* mse, red_chisq */
00238                                                         NULL, -1, -1)); /* variance, kappa */
00239         }
00240 
00241     if (dispersion != NULL)
00242         {
00243             /* Create polynomial of this form
00244                f(x, m) = lambda m
00245             */
00246             int degree = 2;
00247             check_nomsg(
00248             *dispersion = uves_polynomial_regression_2d(*linetable,
00249                                                         "X", "Order", "Aux", NULL,
00250                                                         degree, degree,
00251                                                         NULL, NULL, NULL, /* new columns */
00252                                                         NULL, NULL, /* mse, red_chisq */
00253                                                         NULL, -1, -1)); /* variance, kappa */
00254         }
00255     
00256  cleanup:
00257     uves_polynomial_delete(&order_locations);
00258     uves_free_table(&ordertable);
00259     uves_free_table(&tracetable);
00260     return;
00261 }

Generated on Tue Jun 19 14:39:17 2007 for UVES Pipeline Reference Manual by  doxygen 1.4.6