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

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