uves_corrbadpix-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.3 $
00024  * $Name: uves-4_2_2 $
00025  * $Log: uves_corrbadpix-test.c,v $
00026  * Revision 1.3  2007/05/23 06:43:23  jmlarsen
00027  * Removed unused variables
00028  *
00029  * Revision 1.2  2007/04/24 12:50:29  jmlarsen
00030  * Replaced cpl_propertylist -> uves_propertylist which is much faster
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.3  2007/02/27 14:04:14  jmlarsen
00036  * Move unit test infrastructure to IRPLIB
00037  *
00038  * Revision 1.2  2007/01/29 12:17:54  jmlarsen
00039  * Support setting verbosity from command line
00040  *
00041  * Revision 1.1  2007/01/16 10:25:11  jmlarsen
00042  * Added test of bad pixel correction
00043  *
00044  * Revision 1.1  2006/11/28 08:26:35  jmlarsen
00045  * Added QC log unit test
00046  *
00047  */
00048 
00049 /*-----------------------------------------------------------------------------
00050                                 Includes
00051  -----------------------------------------------------------------------------*/
00052 
00053 #ifdef HAVE_CONFIG_H
00054 #  include <config.h>
00055 #endif
00056 
00057 #include <uves_corrbadpix.h>
00058 #include <uves_chip.h>
00059 #include <uves_utils_wrappers.h>
00060 #include <uves_error.h>
00061 #include <irplib_test.h>
00062 
00063 #include <cpl.h>
00064 /*-----------------------------------------------------------------------------
00065                                 Defines
00066  -----------------------------------------------------------------------------*/
00067 
00068 /*-----------------------------------------------------------------------------
00069                             Functions prototypes
00070  -----------------------------------------------------------------------------*/
00071 
00072 
00073 /*----------------------------------------------------------------------------*/
00077 /*----------------------------------------------------------------------------*/
00080 /*----------------------------------------------------------------------------*/
00084 /*----------------------------------------------------------------------------*/
00085 static void
00086 test_bad_corr(void)
00087 {
00088     cpl_image *master_bias = NULL;
00089     uves_propertylist *header = uves_propertylist_new();
00090     int **map = NULL;
00091     int mark_bad;
00092     int blue, binx, biny;
00093     
00094     /* Empty map */
00095     map = cpl_calloc(1, sizeof(int*));
00096     map[0] = cpl_calloc(4, sizeof(int));
00097     map[0][0] = -1;
00098     map[0][1] = -1;
00099     map[0][2] = -1;
00100     map[0][3] = -1;
00101     uves_badmap_free(&map);
00102     
00103     /* 2 row map */
00104     map = cpl_calloc(3, sizeof(int*));
00105     map[0] = cpl_calloc(4, sizeof(int));
00106     map[0][0] = 1;
00107     map[0][1] = 2;
00108     map[0][2] = 3;
00109     map[0][3] = 4;
00110     map[1] = cpl_calloc(4, sizeof(int));
00111     map[1][0] = 5;
00112     map[1][1] = 6;
00113     map[1][2] = 7;
00114     map[1][3] = 8;
00115     map[2] = cpl_calloc(4, sizeof(int));
00116     map[2][0] = -1;
00117     map[2][1] = -1;
00118     map[2][2] = -1;
00119     map[2][3] = -1;
00120     uves_badmap_free(&map);
00121 
00122     for (blue = 0; blue <= 1; blue++)
00123     for (binx = 1; binx <= 3; binx++)
00124     for (biny = 1; biny <= 3; biny++)
00125     if (!(
00126         (binx == 1 && biny == 3) ||
00127         (binx == 2 && biny == 1) ||
00128         (binx == 3 && biny == 1) ||
00129         (binx == 3 && biny == 2) ||
00130         (binx == 3 && biny == 3)
00131         )){
00132         enum uves_chip chip;
00133         for (chip = uves_chip_get_first(blue);
00134          chip != UVES_CHIP_INVALID;
00135          chip = uves_chip_get_next(chip))
00136         {
00137             uves_free_image(&master_bias);
00138             master_bias = cpl_image_new(4096/biny, 2048/binx, CPL_TYPE_DOUBLE);
00139             assure_mem( master_bias );
00140 
00141             for (mark_bad = 0; mark_bad <= 1; mark_bad++)
00142             {
00143                 int expected_size;
00144 
00145                 /* Call low level function */
00146                 check( map = uves_get_badpix(chip, binx, biny, mark_bad),
00147                    "Error getting bad pixel map");
00148                 uves_badmap_free(&map);    
00149                 
00150                 /* Call higher level wrapper */
00151                 uves_propertylist_empty(header);
00152                 check( uves_correct_badpix_all(master_bias, header,
00153                                chip,
00154                                binx, biny, mark_bad),
00155                    "Error in bad pixel correction");
00156                 
00157                 /* Should write one key:  correct = true   (or something like that) */
00158                 if (chip == UVES_CHIP_BLUE)
00159                 {
00160                     expected_size = 0;
00161                 }
00162                 else
00163                 {
00164                     expected_size = 1;
00165                 }
00166                 assure( uves_propertylist_get_size(header) == expected_size,
00167                     CPL_ERROR_ILLEGAL_OUTPUT, "Wrong output header size: %ld "
00168                     "(%d expected)",
00169                     uves_propertylist_get_size(header), expected_size);
00170             }
00171 
00172         }
00173     }
00174 
00175   cleanup:
00176     uves_badmap_free(&map);
00177     uves_free_propertylist(&header);
00178     uves_free_image(&master_bias);
00179     return;
00180 }
00181 
00182    
00183 /*----------------------------------------------------------------------------*/
00187 /*----------------------------------------------------------------------------*/
00188 
00189 int main(void)
00190 {
00191     /* Initialize CPL + UVES messaging */
00192     IRPLIB_TEST_INIT;
00193 
00194     check( test_bad_corr(),
00195        "Test failed");
00196 
00197   cleanup:
00198     IRPLIB_TEST_END;
00199 }
00200 
00201 

Generated on Mon Apr 21 10:56:54 2008 for UVES Pipeline Reference Manual by  doxygen 1.5.1