uves_cd_align-test.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: amodigli $
00022  * $Date: 2009/06/05 05:49:02 $
00023  * $Revision: 1.4 $
00024  * $Name: uves-4_9_1 $
00025  * $Log: uves_cd_align-test.c,v $
00026  * Revision 1.4  2009/06/05 05:49:02  amodigli
00027  * updated init/end to cpl5
00028  *
00029  * Revision 1.3  2007/08/30 07:56:05  amodigli
00030  * fixed some doxygen warnings
00031  *
00032  * Revision 1.2  2007/05/23 06:43:23  jmlarsen
00033  * Removed unused variables
00034  *
00035  * Revision 1.1  2007/03/15 12:27:18  jmlarsen
00036  * Moved unit tests to ./uves/tests and ./flames/tests
00037  *
00038  * Revision 1.2  2007/02/27 14:04:14  jmlarsen
00039  * Move unit test infrastructure to IRPLIB
00040  *
00041  * Revision 1.1  2007/02/08 11:38:56  jmlarsen
00042  * Added cd_align recipe
00043  *
00044  * Revision 1.5  2007/01/31 15:11:09  jmlarsen
00045  * Test of inf+nan when saving FITS files
00046  */
00047 
00048 /*-----------------------------------------------------------------------------
00049                                 Includes
00050  -----------------------------------------------------------------------------*/
00051 
00052 #ifdef HAVE_CONFIG_H
00053 #  include <config.h>
00054 #endif
00055 
00056 #include <uves_cd_align_impl.h>
00057 #include <uves_utils_wrappers.h>
00058 #include <uves_error.h>
00059 #include <cpl_test.h>
00060 
00061 #include <cpl.h>
00062 
00063 #include <float.h>
00064 /*-----------------------------------------------------------------------------
00065                                 Defines
00066  -----------------------------------------------------------------------------*/
00067 
00068 /*-----------------------------------------------------------------------------
00069                             Functions prototypes
00070  -----------------------------------------------------------------------------*/
00071 
00072 
00073 /*----------------------------------------------------------------------------*/
00077 /*----------------------------------------------------------------------------*/
00080 /*----------------------------------------------------------------------------*/
00089 /*----------------------------------------------------------------------------*/
00090 static double eval_gauss(double x, double my, double sigma, double norm, double back)
00091 {
00092     double result;
00093     double a[5];
00094     double xa[1];
00095 
00096     xa[0] = x;
00097 
00098     a[0] = my;
00099     a[1] = sigma;
00100     a[2] = norm;
00101     a[3] = back;
00102     a[4] = 0.01;  /* linear background term */
00103 
00104     /* Use moffat, to have something that is not perfectly Gaussian  */
00105     assure( uves_moffat(xa, a, &result) == 0,
00106         CPL_ERROR_ILLEGAL_OUTPUT,
00107         "Moffat evalutation failed");
00108     
00109   cleanup:
00110     return result;
00111 }
00112 
00113 
00114 /*----------------------------------------------------------------------------*/
00118 /*----------------------------------------------------------------------------*/
00119 static void
00120 test_process(void)
00121 {
00122     const int nx = 100;
00123     const int ny = 100;
00124     const double maxrow = 61.1;
00125     const double sigma = 2;
00126     const double norm = 6000;
00127     const double background = 200;
00128     cpl_image *im[2] = {NULL, NULL};
00129     cpl_table *cd_align = NULL;
00130     double shift;
00131 
00132     /* Create data */
00133     im[0] = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
00134     im[1] = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
00135 
00136     assure_mem( im[0] );
00137     assure_mem( im[1] );
00138 
00139 
00140 
00141     for (shift = -20; shift < 5; shift = (shift < -5) ? shift/1.5 : shift + 0.7)
00142     {
00143         int x, y;
00144         for (y = 1; y <= ny; y++)
00145         {
00146             for (x = 1; x <= nx; x++)
00147             {
00148                 cpl_image_set(im[0], x, y,
00149                       eval_gauss(y, maxrow, sigma, norm, background));
00150                 cpl_image_set(im[1], x, y,
00151                       eval_gauss(y, maxrow+shift, sigma, norm, background));
00152             }
00153         }
00154         
00155         /* Call function */
00156         {
00157         int steps = 10;
00158         int xborder = 0;
00159         int window = 20;
00160         
00161         bool DEBUG = false;
00162         enum uves_chip chip = UVES_CHIP_BLUE;   /* not used */
00163         
00164         uves_free_table(&cd_align);
00165         check( cd_align = uves_cd_align_process(
00166                im[0],
00167                im[1],
00168                NULL, NULL,
00169                steps, xborder, window, DEBUG, chip),
00170                "Processing failed");
00171         }
00172 
00173         /* Check results */
00174         assure_nomsg( cpl_table_has_column(cd_align, "X"    ), CPL_ERROR_ILLEGAL_OUTPUT);
00175         assure_nomsg( cpl_table_has_column(cd_align, "YCEN1"), CPL_ERROR_ILLEGAL_OUTPUT);
00176         assure_nomsg( cpl_table_has_column(cd_align, "YCEN2"), CPL_ERROR_ILLEGAL_OUTPUT);
00177         assure_nomsg( cpl_table_has_column(cd_align, "SIGMA1"), CPL_ERROR_ILLEGAL_OUTPUT);
00178         assure_nomsg( cpl_table_has_column(cd_align, "SIGMA2"), CPL_ERROR_ILLEGAL_OUTPUT);
00179         assure_nomsg( cpl_table_has_column(cd_align, "BACK1"), CPL_ERROR_ILLEGAL_OUTPUT);
00180         assure_nomsg( cpl_table_has_column(cd_align, "BACK2"), CPL_ERROR_ILLEGAL_OUTPUT);
00181         assure_nomsg( cpl_table_has_column(cd_align, "NORM1"), CPL_ERROR_ILLEGAL_OUTPUT);
00182         assure_nomsg( cpl_table_has_column(cd_align, "NORM2"), CPL_ERROR_ILLEGAL_OUTPUT);
00183         assure_nomsg( cpl_table_has_column(cd_align, "YDIFF"), CPL_ERROR_ILLEGAL_OUTPUT);
00184         
00185         uves_msg("Shift: %f pixels. Measured shift: %f pixels",
00186              shift, cpl_table_get_column_mean(cd_align, "YDIFF"));
00187 
00188         {
00189         double abs_tolerance = 0.1; /* pixels */
00190 
00191                 cpl_test_rel(cpl_table_get_column_mean(cd_align, "YDIFF"), 
00192                                 shift, abs_tolerance);
00193         }
00194     
00195     } /* for shift */
00196 
00197   cleanup:
00198     uves_free_image(&im[0]);
00199     uves_free_image(&im[1]);
00200     uves_free_table(&cd_align);
00201 
00202     return;
00203 }
00204 
00205 /*----------------------------------------------------------------------------*/
00209 /*----------------------------------------------------------------------------*/
00210 
00211 int main(void)
00212 {
00213     /* Initialize CPL + UVES messaging */
00214     cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
00215 
00216     check( test_process(),
00217        "Test of CD align failed");
00218 
00219   cleanup:
00220     return cpl_test_end(0);
00221 }
00222 
00223 

Generated on 8 Mar 2011 for UVES Pipeline Reference Manual by  doxygen 1.6.1