irplib_detmon-test.c

00001 /*                                                                              *
00002  *   This file is part of the ESO IRPLIB package                                *
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 #ifdef HAVE_CONFIG_H
00021 #include <config.h>
00022 #endif
00023 
00024 /*----------------------------------------------------------------------------
00025                                 Includes
00026  ----------------------------------------------------------------------------*/
00027 
00028 #include <irplib_test.h>
00029 
00030 #include <irplib_detmon.h>
00031 
00032 #ifdef HAVE_FFTW
00033 #include <complex.h>
00034 #include <fftw3.h>
00035 #endif
00036 
00037 /*---------------------------------------------------------------------------*/
00038 /*
00039  * @defgroup irplib_detmon_test   Testing of the IRPLIB utilities
00040  */
00041 /*---------------------------------------------------------------------------*/
00042 
00043 /*----------------------------------------------------------------------------
00044                 Defines
00045  ----------------------------------------------------------------------------*/
00046 
00047 #ifndef IMAGESIZE
00048 #define IMAGESIZE   256
00049 #endif
00050 
00051 #define IMAGELISTSIZE   10
00052 
00053 #define NBADPIXS    10
00054 
00055 
00056 /*----------------------------------------------------------------------------
00057                             Private Function prototypes
00058  ----------------------------------------------------------------------------*/
00059 
00060 static void irplib_detmon_tests(void);
00061 
00062 cpl_frameset * irplib_detmon_tests_fill_frameset(const char     * tag_on,
00063                          const char * tag_off,
00064                          int          non,
00065                                                  cpl_boolean      opt_nir);
00066 
00067 /*---------------------------------------------------------------------------*/
00068 /*
00069  * @brief   Unit tests of fit module
00070  */
00071 /*---------------------------------------------------------------------------*/
00072 
00073 int main(void)
00074 {
00075     /* Initialize CPL + IRPLIB */
00076     IRPLIB_TEST_INIT;
00077 
00078     irplib_detmon_tests();
00079 
00080     IRPLIB_TEST_END;
00081 }
00082 
00083 static void irplib_detmon_tests(void)
00084 {
00085 #ifdef HAVE_FFTW
00086     /* Variables used for correlation function */
00087     int           px, py ;
00088     cpl_image       * image1 ;
00089     cpl_image       * image2 ;
00090     cpl_image       * result ;
00091 #endif
00092 
00093 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(3, 1, 90)
00094     /* Variables used for detmon_ir_lg function */
00095     cpl_parameterlist   * parlist;
00096     cpl_frameset        * frameset;
00097     const char                * tag_on;
00098     const char                * tag_off;
00099 #else
00100 //    cpl_ensure_code(0, CPL_ERROR_UNSUPPORTED_MODE);
00101 #endif
00102 
00103 #ifdef HAVE_FFTW
00104     /* CORRELATION */
00105 
00106     /* 1. trial: all inputs illegal, NULL pointers */
00107     result = irplib_detmon_image_correlate(NULL, NULL, 0, 0) ;
00108     irplib_test(cpl_error_get_code() == CPL_ERROR_NULL_INPUT) ;
00109     cpl_error_reset() ;
00110     irplib_test(result == NULL) ;
00111     cpl_image_delete(result) ;
00112 
00113     /* 2. trial: 2 equal and symmetrical images */
00114     image1 = cpl_image_new(1024, 1024, CPL_TYPE_FLOAT) ;
00115     cpl_image_fill_gaussian(image1, (1024 + 1)/2, (1024 + 1)/2, 25, 40, 40) ;
00116 
00117     image2 = cpl_image_new(1024, 1024, CPL_TYPE_FLOAT) ;
00118     cpl_image_fill_gaussian(image2, (1024 + 1)/2, (1024 + 1)/2, 25, 40, 40) ;
00119 
00120     px = -1 ;
00121     py = -1 ;
00122 
00123     result = irplib_detmon_image_correlate(image1, image2, 13, 13) ;
00124 
00125     cpl_image_get_maxpos(result, &px, &py) ;
00126     irplib_test(px == 13+1 && py == 13+1) ;
00127 
00128     cpl_image_delete(image1) ;
00129     cpl_image_delete(image2) ;
00130     cpl_image_delete(result) ;
00131 
00132     /* 3. trial: 2 equal but not symmetrical images */
00133     image1 = cpl_image_new(1024, 1024, CPL_TYPE_FLOAT) ;
00134     cpl_image_fill_gaussian(image1, (1024 + 1)/2+30, (1024 + 1)/2+30, 25, 40, 40) ;
00135 
00136     image2 = cpl_image_new(1024, 1024, CPL_TYPE_FLOAT) ;
00137     cpl_image_fill_gaussian(image2, (1024 + 1)/2+30, (1024 + 1)/2+30, 25, 40, 40) ;
00138 
00139     px = -1 ;
00140     py = -1 ;
00141 
00142     result = irplib_detmon_image_correlate(image1, image2, 13, 13) ;
00143 
00144     cpl_image_get_maxpos(result, &px, &py) ;
00145     irplib_test(px == 13+1 && py == 13+1) ;
00146 
00147     cpl_image_delete(image1) ;
00148     cpl_image_delete(image2) ;
00149     cpl_image_delete(result) ;
00150 
00151     /* 4. trial: 2 different images */
00152     image1 = cpl_image_new(1024, 1024, CPL_TYPE_FLOAT) ;
00153     cpl_image_fill_gaussian(image1, (1024 + 1)/2+30, (1024 + 1)/2+30, 25, 40, 40) ;
00154 
00155     image2 = cpl_image_new(1024, 1024, CPL_TYPE_FLOAT) ;
00156     cpl_image_fill_gaussian(image2, (1024 + 1)/2+40, (1024 + 1)/2+40, 25, 40, 40) ;
00157 
00158     px = -1 ;
00159     py = -1 ;
00160  
00161     result = irplib_detmon_image_correlate(image1, image2, 13, 13) ;
00162 
00163     cpl_image_get_maxpos(result, &px, &py) ;
00164     irplib_test(px == 13+11 && py == 13+11) ;
00165     
00166     cpl_image_delete(image1) ;
00167     cpl_image_delete(image2) ;
00168     cpl_image_delete(result) ;
00169 
00170 #endif
00171 
00172     /* HIGH LEVEL FUNCTION FOR LINEARITY/GAIN RECIPE */
00173 
00174     /* 1. trial: All inputs illegal, NULL pointers */
00175     irplib_detmon_lg(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, TRUE) ;
00176     irplib_test(cpl_error_get_code() == CPL_ERROR_NULL_INPUT) ;
00177     cpl_error_reset() ;
00178 
00179     /* Remove this ifdef once CPL 3.1 is no longer supported */
00180 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(3, 1, 90)
00181 
00182     /* 2. trial: Different nb of ON and OFF frames */
00183     tag_on = "FRAME_ON" ;
00184     tag_off = "FRAME_OFF" ;
00185 
00186     /* Fill the parameter list */
00187     parlist = cpl_parameterlist_new() ;
00188     irplib_detmon_fill_params(parlist, "detmon_ir_lg", "detmon") ;
00189 
00190     /* Fill a frameset */
00191     frameset = irplib_detmon_tests_fill_frameset(tag_on, tag_off, 20, TRUE) ;
00192 
00193     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg", "detmon",
00194                         "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0", NULL, TRUE) ;
00195     irplib_test(cpl_error_get_code() == CPL_ERROR_NONE ||
00196                 cpl_error_get_code() == CPL_ERROR_UNSUPPORTED_MODE);
00197     cpl_error_reset();
00198     cpl_frameset_delete(frameset);
00199     cpl_parameterlist_delete(parlist);
00200 
00201 
00202     parlist = cpl_parameterlist_new() ;
00203     irplib_detmon_fill_params(parlist, "detmon_opt_lg", "detmon") ;
00204 
00205     frameset = irplib_detmon_tests_fill_frameset(tag_on, tag_off, 21, FALSE) ;
00206 
00207     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_opt_lg", "detmon",
00208                         "PRO-1.15", "PRO-1.15", "PRO-1.15", "PRO-1.15", "DETMON / 1.0", NULL, FALSE) ;
00209     irplib_test(cpl_error_get_code() == CPL_ERROR_NONE ||
00210                 cpl_error_get_code() == CPL_ERROR_UNSUPPORTED_MODE);
00211     cpl_error_reset();
00212 
00213     cpl_parameterlist_delete(parlist);
00214     cpl_frameset_delete(frameset);
00215 #else
00216    // cpl_ensure_code(0, CPL_ERROR_UNSUPPORTED_MODE);
00217 #endif
00218 
00219 }
00220 
00221 /*---------------------------------------------------------------------------*/
00222 /*
00223  * @brief  Detect bad pixels of a selected type
00224  * @param  in       Input image
00225  * @param  mean     Mean level of the image - used to compute threshold
00226  * @param  sigma    Stdev level of the image - used to compute threshold
00227  * @param  flag     Flag - represents selected type of bad pixels (see enum)
00228  * @return The detected bad pixels in a cpl_mask.
00229  */
00230 /*---------------------------------------------------------------------------*/
00231 
00232 cpl_frameset * irplib_detmon_tests_fill_frameset(const char     * tag_on,
00233                          const char * tag_off,
00234                          int          non,
00235                                                  cpl_boolean      opt_nir)
00236 {
00237     cpl_frameset        * frameset ;
00238     cpl_frame           * frame ;
00239     int i ;
00240     char            frame_name[20] ;
00241     cpl_propertylist        * plist ;
00242     cpl_image           * image ;
00243     frameset = cpl_frameset_new() ;
00244 
00245     for (i=0 ; i<non ; i++) {
00246     frame = cpl_frame_new() ;
00247     sprintf(frame_name, "dummyon%d.fits",i) ;
00248     cpl_frame_set_filename(frame, frame_name);
00249     cpl_frame_set_tag(frame, tag_on) ;
00250     cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
00251     cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
00252 
00253     cpl_frameset_insert(frameset, frame) ;
00254 
00255     plist = cpl_propertylist_new() ;
00256         if(opt_nir == TRUE) {
00257         cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(i/2+1)) ;
00258         cpl_propertylist_append_double(plist, "EXPTIME", (double)(i/2+1)) ;
00259         } else {
00260         cpl_propertylist_append_double(plist, "ESO DET DIT", (double)((i+1)/2)) ;
00261         cpl_propertylist_append_double(plist, "EXPTIME", (double)((i+1)/2)) ;
00262         }
00263     image = cpl_image_new(1024, 1024, CPL_TYPE_FLOAT) ;
00264     cpl_image_fill_noise_uniform(image, 25, 50);
00265     cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL) ;
00266 
00267     cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT) ;
00268     cpl_propertylist_delete(plist) ;
00269     cpl_image_delete(image) ;
00270 
00271     frame = cpl_frame_new() ;
00272     sprintf(frame_name, "dummyoff%d.fits",i) ;
00273     cpl_frame_set_filename(frame, frame_name);
00274     cpl_frame_set_tag(frame, tag_off) ;
00275     cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
00276     cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
00277 
00278     cpl_frameset_insert(frameset, frame) ;
00279 
00280     plist = cpl_propertylist_new() ;
00281         if(opt_nir == TRUE) {
00282         cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(i/2+1)) ;
00283         cpl_propertylist_append_double(plist, "EXPTIME", (double)(i/2+1)) ;
00284         } else {
00285         cpl_propertylist_append_double(plist, "ESO DET DIT", (double)((i+1)/2)) ;
00286         cpl_propertylist_append_double(plist, "EXPTIME", (double)((i+1)/2)) ;
00287         }
00288 
00289     image = cpl_image_new(1024, 1024, CPL_TYPE_FLOAT) ;
00290     cpl_image_fill_noise_uniform(image, 25, 50);
00291     cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL) ;
00292 
00293     cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT) ;
00294 
00295     cpl_propertylist_delete(plist) ;
00296     cpl_image_delete(image) ;
00297     }
00298 
00299     return frameset ;
00300 }

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