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: amodigli $
00022  * $Date: 2010/09/24 09:31:49 $
00023  * $Revision: 1.7 $
00024  * $Name: uves-4_9_1 $
00025  * $Log: uves_corrbadpix-test.c,v $
00026  * Revision 1.7  2010/09/24 09:31:49  amodigli
00027  * put back QFITS dependency to fix problem spot by NRI on FIBER mode (with MIDAS calibs) data
00028  *
00029  * Revision 1.5  2009/11/04 06:58:26  amodigli
00030  * fixed API error
00031  *
00032  * Revision 1.4  2009/06/05 05:49:02  amodigli
00033  * updated init/end to cpl5
00034  *
00035  * Revision 1.3  2007/05/23 06:43:23  jmlarsen
00036  * Removed unused variables
00037  *
00038  * Revision 1.2  2007/04/24 12:50:29  jmlarsen
00039  * Replaced cpl_propertylist -> uves_propertylist which is much faster
00040  *
00041  * Revision 1.1  2007/03/15 12:27:18  jmlarsen
00042  * Moved unit tests to ./uves/tests and ./flames/tests
00043  *
00044  * Revision 1.3  2007/02/27 14:04:14  jmlarsen
00045  * Move unit test infrastructure to IRPLIB
00046  *
00047  * Revision 1.2  2007/01/29 12:17:54  jmlarsen
00048  * Support setting verbosity from command line
00049  *
00050  * Revision 1.1  2007/01/16 10:25:11  jmlarsen
00051  * Added test of bad pixel correction
00052  *
00053  * Revision 1.1  2006/11/28 08:26:35  jmlarsen
00054  * Added QC log unit test
00055  *
00056  */
00057 
00058 /*-----------------------------------------------------------------------------
00059                                 Includes
00060  -----------------------------------------------------------------------------*/
00061 
00062 #ifdef HAVE_CONFIG_H
00063 #  include <config.h>
00064 #endif
00065 
00066 #include <uves_corrbadpix.h>
00067 #include <uves_chip.h>
00068 #include <uves_utils_wrappers.h>
00069 #include <uves_error.h>
00070 #include <cpl_test.h>
00071 
00072 #include <cpl.h>
00073 /*-----------------------------------------------------------------------------
00074                                 Defines
00075  -----------------------------------------------------------------------------*/
00076 
00077 /*-----------------------------------------------------------------------------
00078                             Functions prototypes
00079  -----------------------------------------------------------------------------*/
00080 
00081 
00082 /*----------------------------------------------------------------------------*/
00086 /*----------------------------------------------------------------------------*/
00089 /*----------------------------------------------------------------------------*/
00093 /*----------------------------------------------------------------------------*/
00094 static void
00095 test_bad_corr(void)
00096 {
00097     cpl_image *master_bias = NULL;
00098     uves_propertylist *header = uves_propertylist_new();
00099     int **map = NULL;
00100     int mark_bad;
00101     int blue, binx, biny;
00102     
00103     /* Empty map */
00104     map = cpl_calloc(1, sizeof(int*));
00105     map[0] = cpl_calloc(4, sizeof(int));
00106     map[0][0] = -1;
00107     map[0][1] = -1;
00108     map[0][2] = -1;
00109     map[0][3] = -1;
00110     uves_badmap_free(&map);
00111     
00112     /* 2 row map */
00113     map = cpl_calloc(3, sizeof(int*));
00114     map[0] = cpl_calloc(4, sizeof(int));
00115     map[0][0] = 1;
00116     map[0][1] = 2;
00117     map[0][2] = 3;
00118     map[0][3] = 4;
00119     map[1] = cpl_calloc(4, sizeof(int));
00120     map[1][0] = 5;
00121     map[1][1] = 6;
00122     map[1][2] = 7;
00123     map[1][3] = 8;
00124     map[2] = cpl_calloc(4, sizeof(int));
00125     map[2][0] = -1;
00126     map[2][1] = -1;
00127     map[2][2] = -1;
00128     map[2][3] = -1;
00129     uves_badmap_free(&map);
00130 
00131     for (blue = 0; blue <= 1; blue++)
00132     for (binx = 1; binx <= 3; binx++)
00133     for (biny = 1; biny <= 3; biny++)
00134     if (!(
00135         (binx == 1 && biny == 3) ||
00136         (binx == 2 && biny == 1) ||
00137         (binx == 3 && biny == 1) ||
00138         (binx == 3 && biny == 2) ||
00139         (binx == 3 && biny == 3)
00140         )){
00141         enum uves_chip chip;
00142         for (chip = uves_chip_get_first(blue);
00143          chip != UVES_CHIP_INVALID;
00144          chip = uves_chip_get_next(chip))
00145         {
00146             uves_free_image(&master_bias);
00147             master_bias = cpl_image_new(4096/biny, 2048/binx, CPL_TYPE_DOUBLE);
00148             assure_mem( master_bias );
00149 
00150             for (mark_bad = 0; mark_bad <= 1; mark_bad++)
00151             {
00152                 int expected_size;
00153 
00154                 /* Call low level function */
00155                 check( map = uves_get_badpix(chip, binx, biny, mark_bad,0),
00156                    "Error getting bad pixel map");
00157                 uves_badmap_free(&map);    
00158                 
00159                 /* Call higher level wrapper */
00160                 uves_propertylist_empty(header);
00161                 check( uves_correct_badpix_all(master_bias, header,
00162                                chip,
00163                                binx, biny, mark_bad,0),
00164                    "Error in bad pixel correction");
00165                 
00166                 /* Should write one key:  correct = true   (or something like that) */
00167                 if (chip == UVES_CHIP_BLUE)
00168                 {
00169                     expected_size = 0;
00170                 }
00171                 else
00172                 {
00173                     expected_size = 1;
00174                 }
00175                 assure( uves_propertylist_get_size(header) == expected_size,
00176                     CPL_ERROR_ILLEGAL_OUTPUT, "Wrong output header size: %ld "
00177                     "(%d expected)",
00178                     uves_propertylist_get_size(header), expected_size);
00179             }
00180 
00181         }
00182     }
00183 
00184   cleanup:
00185     uves_badmap_free(&map);
00186     uves_free_propertylist(&header);
00187     uves_free_image(&master_bias);
00188     return;
00189 }
00190 
00191    
00192 /*----------------------------------------------------------------------------*/
00196 /*----------------------------------------------------------------------------*/
00197 
00198 int main(void)
00199 {
00200     /* Initialize CPL + UVES messaging */
00201     cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
00202 
00203     check( test_bad_corr(),
00204        "Test failed");
00205 
00206   cleanup:
00207     return cpl_test_end(0);
00208 }
00209 
00210 

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