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

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