irplib_detmon_lg-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_detmon.h>
00029 #include <irplib_detmon_lg.h>
00030 
00031 
00032 #include <math.h>
00033 /*---------------------------------------------------------------------------*/
00034 /*
00035  * @defgroup irplib_detmon_test   Testing of the IRPLIB utilities
00036  */
00037 /*---------------------------------------------------------------------------*/
00038 
00039 #define PI 3.141592653
00040 /*----------------------------------------------------------------------------
00041                                 Defines
00042  ----------------------------------------------------------------------------*/
00043 
00044 #ifndef IMAGESIZE
00045 #define IMAGESIZE       64
00046 #endif
00047 
00048 #define IMAGELISTSIZE   10
00049 
00050 #define NBADPIXS        10
00051 
00052 #define ON_LEVEL        300.0
00053 #define OFF_LEVEL       100.0
00054 
00055 #define NOISE_MIN       10.0
00056 #define NOISE_MAX       40.0
00057 
00058 #define ON TRUE
00059 #define OFF FALSE
00060 
00061 
00062 /*----------------------------------------------------------------------------
00063                             Private Function prototypes
00064  ----------------------------------------------------------------------------*/
00065 
00066 static void irplib_detmon_lg_tests(void);
00067 
00068 cpl_frameset * irplib_detmon_tests_fill_frameset(const char     * tag_on,
00069                                                  const char     * tag_off,
00070                                                  int              non,
00071                                                  cpl_boolean      opt_nir,
00072                                                  cpl_boolean      with_exts,
00073                                                  int              nexts,
00074                                                  int              nsettings);
00075 
00076 cpl_frameset * irplib_detmon_tests_fill_frameset_oct(const char         * tag_on,
00077                                                  const char     * tag_off,
00078                                                  int              non,
00079                                                  cpl_boolean      opt_nir,
00080                                                  cpl_boolean      with_exts,
00081                                                      int              nexts);
00082 
00083 int compare_settings(const cpl_frame * frame1, const cpl_frame * frame2);
00084 
00085 cpl_imagelist * irplib_detmon_tests_imlist(int ndits, cpl_boolean onoff);
00086 
00087 /*---------------------------------------------------------------------------*/
00088 /*
00089  * @brief   Unit tests of fit module
00090  */
00091 /*---------------------------------------------------------------------------*/
00092 
00093 int main(void)
00094 {
00095     /* Initialize CPL + IRPLIB */
00096     cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
00097 
00098     irplib_detmon_lg_tests();
00099 
00100     return cpl_test_end(0);
00101 }
00102 
00103 static void irplib_detmon_lg_tests(void)
00104 {
00105 
00106     /* Variables used for correlation function */
00107     int                   px, py;
00108     cpl_image           * image1;
00109 #ifdef HAVE_FFTW
00110     cpl_image           * image2;
00111 #endif
00112     cpl_image           * result;
00113 
00114     cpl_parameterlist   * parlist;
00115     cpl_frameset        * frameset;
00116     cpl_frameset        * set;
00117     cpl_propertylist    * prolist;
00118 
00119     /* Variables used for detmon_ir_lg function */
00120     const char                * tag_on;
00121     const char                * tag_off;
00122 
00123 
00124 #ifdef HAVE_FFTW
00125     /* CORRELATION */
00126 
00127     /* 1. trial: all inputs illegal, NULL pointers */
00128     result = irplib_detmon_image_correlate(NULL, NULL, 0, 0);
00129     cpl_test_error(CPL_ERROR_NULL_INPUT);
00130     cpl_error_reset();
00131     cpl_test_null(result);
00132     cpl_image_delete(result);
00133 
00134     /* 2. trial: 2 equal and symmetrical images */
00135     image1 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00136     cpl_image_fill_gaussian(image1, (IMAGESIZE + 1)/2, (IMAGESIZE + 1)/2, 25, 40, 40);
00137 
00138     image2 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00139     cpl_image_fill_gaussian(image2, (IMAGESIZE + 1)/2, (IMAGESIZE + 1)/2, 25, 40, 40);
00140 
00141     px = -1;
00142     py = -1;
00143 
00144     result = irplib_detmon_image_correlate(image1, image2, 13, 13);
00145 
00146     cpl_image_get_maxpos(result, &px, &py);
00147     cpl_test(px == 13+1 && py == 13+1);
00148 
00149     cpl_image_delete(image1);
00150     cpl_image_delete(image2);
00151     cpl_image_delete(result);
00152 
00153     /* 3. trial: 2 equal but not symmetrical images */
00154     image1 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00155     cpl_image_fill_gaussian(image1, (IMAGESIZE + 1)/2+30, (IMAGESIZE + 1)/2+30, 25, 40, 40);
00156 
00157     image2 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00158     cpl_image_fill_gaussian(image2, (IMAGESIZE + 1)/2+30, (IMAGESIZE + 1)/2+30, 25, 40, 40);
00159 
00160     px = -1;
00161     py = -1;
00162 
00163     result = irplib_detmon_image_correlate(image1, image2, 13, 13);
00164 
00165     cpl_image_get_maxpos(result, &px, &py);
00166     cpl_test(px == 13+1 && py == 13+1);
00167 
00168     cpl_image_delete(image1);
00169     cpl_image_delete(image2);
00170     cpl_image_delete(result);
00171 
00172     /* 4. trial: 2 different images */
00173     image1 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00174     cpl_image_fill_gaussian(image1, (IMAGESIZE + 1)/2+30, (IMAGESIZE + 1)/2+30, 25, 40, 40);
00175 
00176     image2 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00177     cpl_image_fill_gaussian(image2, (IMAGESIZE + 1)/2+40, (IMAGESIZE + 1)/2+40, 25, 40, 40);
00178 
00179     px = -1;
00180     py = -1;
00181  
00182     result = irplib_detmon_image_correlate(image1, image2, 13, 13);
00183 
00184     cpl_image_get_maxpos(result, &px, &py);
00185 
00186     /*
00187      * FIXME:
00188      * cpl_test(px == 13+11 && py == 13+11);
00189      */
00190     cpl_image_delete(image1);
00191     cpl_image_delete(image2);
00192     cpl_image_delete(result);
00193 #else
00194     /* CORRELATION with cpl_image_fft() */
00195 
00196     /* 1. trial: all inputs illegal, NULL pointers */
00197     result = irplib_detmon_autocorrelate(NULL, 0, 0);
00198     cpl_test_error(CPL_ERROR_NULL_INPUT);
00199     cpl_error_reset();
00200     cpl_test_null(result);
00201     cpl_image_delete(result);
00202 
00203     /* 2. trial: 2 equal and symmetrical images */
00204     image1 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00205     cpl_image_fill_gaussian(image1, (IMAGESIZE + 1)/2, (IMAGESIZE + 1)/2, 25, 40, 40);
00206 
00207     px = -1;
00208     py = -1;
00209 
00210     result = irplib_detmon_autocorrelate(image1, 13, 13);
00211 
00212     cpl_image_get_maxpos(result, &px, &py);
00213     cpl_test(px == 13+1 && py == 13+1);
00214 
00215     cpl_image_delete(image1);
00216     cpl_image_delete(result);
00217 
00218 #endif
00219 
00220     /* HIGH LEVEL FUNCTION FOR LINEARITY/GAIN RECIPE */
00221 
00222     tag_on  = "FRAME_ON";
00223     tag_off = "FRAME_OFF";
00224 
00225     set = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00226                         20, TRUE, FALSE, 0, 1);
00227     
00228     prolist = irplib_detmon_fill_prolist("PROCATG", "TYPE", "TECH", CPL_TRUE);
00229 
00230     /* 1. test: All inputs illegal, NULL pointers */
00231     irplib_detmon_lg(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
00232              NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, TRUE);
00233     cpl_test_error(CPL_ERROR_NULL_INPUT);
00234     cpl_error_reset();
00235 
00236 
00237     /* 2. test: Default use, NIR case */
00238     parlist = cpl_parameterlist_new();
00239     irplib_detmon_lg_fill_parlist_nir_default(parlist,
00240                           "detmon_ir_lg", "detmon");
00241 
00242     frameset = cpl_frameset_duplicate(set);
00243 
00244     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00245              "detmon", REGEXP, prolist, prolist, prolist,
00246              prolist, prolist, prolist, "DETMON / 1.0",
00247              NULL, NULL, TRUE);
00248     cpl_test_error(CPL_ERROR_NONE);
00249     cpl_error_reset();
00250 
00251     cpl_frameset_delete(frameset);
00252     cpl_parameterlist_delete(parlist);
00253 
00254 
00255     /* 3. test: NIR case, with different llx, lly, urx, ury */
00256     parlist = cpl_parameterlist_new();
00257     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00258                   "PTC",
00259                             3,                /* --order         */
00260                             3,                /* --kappa         */
00261                             25,               /* --niter         */
00262                             8,               /* --llx           */
00263                             8,               /* --lly           */    
00264                             56,               /* --urx           */
00265                             56,               /* --ury           */
00266                             10000,            /* --ref_level     */
00267                             "CPL_FALSE",      /* --intermediate  */
00268                             "CPL_FALSE",      /* --autocorr      */
00269                             "CPL_FALSE",      /* --collapse      */
00270                             "CPL_TRUE",       /* --rescale       */
00271                             "CPL_TRUE",       /* --pix2pix       */
00272                             "CPL_FALSE",       /* --bpmbin       */
00273                               -1,             /* --filter        */
00274                             26,               /* --m             */
00275                             26,               /* --n             */
00276                   1e-3,
00277                   "detmon_ir_lg",
00278                             -1,               /* --llx1          */
00279                             -1,               /* --lly1          */
00280                             -1,               /* --urx1          */
00281                             -1,               /* --ury1          */
00282                             -1,               /* --llx2          */
00283                             -1,               /* --lly2          */
00284                             -1,               /* --urx2          */
00285                             -1,               /* --ury2          */
00286                             -1,               /* --llx3          */
00287                             -1,               /* --lly3          */
00288                             -1,               /* --urx3          */
00289                             -1,               /* --ury3          */
00290                             -1,               /* --llx4          */
00291                             -1,               /* --lly4          */
00292                             -1,               /* --urx4          */
00293                             -1,               /* --ury4          */
00294                             -1,               /* --llx5          */
00295                             -1,               /* --lly5          */
00296                             -1,               /* --urx5          */
00297                             -1,               /* --ury5          */
00298                   0,               /* --exts          */
00299     NIR);
00300 
00301     frameset = cpl_frameset_duplicate(set);
00302 
00303     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00304              "detmon", REGEXP, prolist, prolist, prolist,
00305              prolist, prolist, prolist, "DETMON / 1.0",
00306              NULL, NULL, TRUE);
00307     cpl_test_error(CPL_ERROR_NONE);
00308     cpl_error_reset();
00309 
00310     cpl_frameset_delete(frameset);
00311     cpl_parameterlist_delete(parlist);
00312 
00313     /* 3. test: NIR case, MED method applied for GAIN */
00314     parlist = cpl_parameterlist_new();
00315     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00316                   "MED",
00317                             3,                /* --order         */
00318                             3,                /* --kappa         */
00319                             25,               /* --niter         */
00320                             -1,               /* --llx           */
00321                             -1,               /* --lly           */    
00322                             -1,               /* --urx           */
00323                             -1,               /* --ury           */
00324                             10000,            /* --ref_level     */
00325                             "CPL_FALSE",      /* --intermediate  */
00326                             "CPL_FALSE",      /* --autocorr      */
00327                             "CPL_FALSE",      /* --collapse      */
00328                             "CPL_TRUE",       /* --rescale       */
00329                             "CPL_TRUE",       /* --pix2pix       */
00330                             "CPL_FALSE",       /* --bpmbin       */
00331                               -1,             /* --filter        */
00332                             26,               /* --m             */
00333                             26,               /* --n             */
00334                   1e-3,
00335                   "detmon_ir_lg",
00336                             -1,               /* --llx1          */
00337                             -1,               /* --lly1          */
00338                             -1,               /* --urx1          */
00339                             -1,               /* --ury1          */
00340                             -1,               /* --llx2          */
00341                             -1,               /* --lly2          */
00342                             -1,               /* --urx2          */
00343                             -1,               /* --ury2          */
00344                             -1,               /* --llx3          */
00345                             -1,               /* --lly3          */
00346                             -1,               /* --urx3          */
00347                             -1,               /* --ury3          */
00348                             -1,               /* --llx4          */
00349                             -1,               /* --lly4          */
00350                             -1,               /* --urx4          */
00351                             -1,               /* --ury4          */
00352                             -1,               /* --llx5          */
00353                             -1,               /* --lly5          */
00354                             -1,               /* --urx5          */
00355                             -1,               /* --ury5          */
00356                   0,               /* --exts          */
00357     NIR);
00358 
00359     frameset = cpl_frameset_duplicate(set);
00360 
00361     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00362              "detmon", REGEXP, prolist, prolist, prolist,
00363              prolist, prolist, prolist, "DETMON / 1.0",
00364              NULL, NULL, TRUE);
00365     cpl_test_error(CPL_ERROR_NONE);
00366     cpl_error_reset();
00367 
00368     cpl_frameset_delete(frameset);
00369     cpl_parameterlist_delete(parlist);
00370 
00371     /*FIXME: The products should be checked to see that MED has been in fact
00372       applied (not only that it finished without errors) */
00373 
00374     /* 4. test: NIR case, --intermediate activated */
00375     parlist = cpl_parameterlist_new();
00376     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00377                   "PTC",
00378                             3,                /* --order         */
00379                             3,                /* --kappa         */
00380                             25,               /* --niter         */
00381                             -1,               /* --llx           */
00382                             -1,               /* --lly           */    
00383                             -1,               /* --urx           */
00384                             -1,               /* --ury           */
00385                             10000,            /* --ref_level     */
00386                             "CPL_TRUE",      /* --intermediate  */
00387                             "CPL_FALSE",      /* --autocorr      */
00388                             "CPL_FALSE",      /* --collapse      */
00389                             "CPL_TRUE",       /* --rescale       */
00390                             "CPL_TRUE",       /* --pix2pix       */
00391                             "CPL_FALSE",       /* --bpmbin       */
00392                               -1,             /* --filter        */
00393                             26,               /* --m             */
00394                             26,               /* --n             */
00395                   1e-3,
00396                   "detmon_ir_lg",
00397                             -1,               /* --llx1          */
00398                             -1,               /* --lly1          */
00399                             -1,               /* --urx1          */
00400                             -1,               /* --ury1          */
00401                             -1,               /* --llx2          */
00402                             -1,               /* --lly2          */
00403                             -1,               /* --urx2          */
00404                             -1,               /* --ury2          */
00405                             -1,               /* --llx3          */
00406                             -1,               /* --lly3          */
00407                             -1,               /* --urx3          */
00408                             -1,               /* --ury3          */
00409                             -1,               /* --llx4          */
00410                             -1,               /* --lly4          */
00411                             -1,               /* --urx4          */
00412                             -1,               /* --ury4          */
00413                             -1,               /* --llx5          */
00414                             -1,               /* --lly5          */
00415                             -1,               /* --urx5          */
00416                             -1,               /* --ury5          */
00417                   0,               /* --exts          */
00418     NIR);
00419 
00420     frameset = cpl_frameset_duplicate(set);
00421 
00422     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00423              "detmon", REGEXP, prolist, prolist, prolist,
00424              prolist, prolist, prolist, "DETMON / 1.0",
00425              NULL, NULL, TRUE);
00426     cpl_test_error(CPL_ERROR_NONE);
00427     cpl_error_reset();
00428 
00429     cpl_frameset_delete(frameset);
00430     cpl_parameterlist_delete(parlist);
00431 
00432     /*FIXME: Check that the new intermediate have been in fact created */
00433 
00434     /* 5. test: NIR case, --rescale deactivated */
00435     parlist = cpl_parameterlist_new();
00436     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00437                   "PTC",
00438                             3,                /* --order         */
00439                             3,                /* --kappa         */
00440                             25,               /* --niter         */
00441                             -1,               /* --llx           */
00442                             -1,               /* --lly           */    
00443                             -1,               /* --urx           */
00444                             -1,               /* --ury           */
00445                             10000,            /* --ref_level     */
00446                             "CPL_FALSE",      /* --intermediate  */
00447                             "CPL_FALSE",      /* --autocorr      */
00448                             "CPL_FALSE",      /* --collapse      */
00449                             "CPL_FALSE",       /* --rescale       */
00450                             "CPL_TRUE",       /* --pix2pix       */
00451                             "CPL_FALSE",       /* --bpmbin       */
00452                               -1,             /* --filter        */
00453                             26,               /* --m             */
00454                             26,               /* --n             */
00455                   1e-3,
00456                   "detmon_ir_lg",
00457                             -1,               /* --llx1          */
00458                             -1,               /* --lly1          */
00459                             -1,               /* --urx1          */
00460                             -1,               /* --ury1          */
00461                             -1,               /* --llx2          */
00462                             -1,               /* --lly2          */
00463                             -1,               /* --urx2          */
00464                             -1,               /* --ury2          */
00465                             -1,               /* --llx3          */
00466                             -1,               /* --lly3          */
00467                             -1,               /* --urx3          */
00468                             -1,               /* --ury3          */
00469                             -1,               /* --llx4          */
00470                             -1,               /* --lly4          */
00471                             -1,               /* --urx4          */
00472                             -1,               /* --ury4          */
00473                             -1,               /* --llx5          */
00474                             -1,               /* --lly5          */
00475                             -1,               /* --urx5          */
00476                             -1,               /* --ury5          */
00477                   0,               /* --exts          */
00478     NIR);
00479 
00480     frameset = cpl_frameset_duplicate(set);
00481 
00482     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00483              "detmon", REGEXP, prolist, prolist, prolist,
00484              prolist, prolist, prolist, "DETMON / 1.0",
00485              NULL, NULL, TRUE);
00486     cpl_test_error(CPL_ERROR_NONE);
00487     cpl_error_reset();
00488 
00489     cpl_frameset_delete(frameset);
00490     cpl_parameterlist_delete(parlist);
00491 
00492     /* 5a. test: NIR case, --bpmbin activated */
00493     parlist = cpl_parameterlist_new();
00494     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00495                   "PTC",
00496                             3,                /* --order         */
00497                             3,                /* --kappa         */
00498                             25,               /* --niter         */
00499                             -1,               /* --llx           */
00500                             -1,               /* --lly           */    
00501                             -1,               /* --urx           */
00502                             -1,               /* --ury           */
00503                             10000,            /* --ref_level     */
00504                             "CPL_FALSE",      /* --intermediate  */
00505                             "CPL_FALSE",      /* --autocorr      */
00506                             "CPL_FALSE",      /* --collapse      */
00507                             "CPL_TRUE",       /* --rescale       */
00508                             "CPL_TRUE",       /* --pix2pix       */
00509                             "CPL_TRUE",       /* --bpmbin       */
00510                               -1,             /* --filter        */
00511                             26,               /* --m             */
00512                             26,               /* --n             */
00513                   1e-3,
00514                   "detmon_ir_lg",
00515                             -1,               /* --llx1          */
00516                             -1,               /* --lly1          */
00517                             -1,               /* --urx1          */
00518                             -1,               /* --ury1          */
00519                             -1,               /* --llx2          */
00520                             -1,               /* --lly2          */
00521                             -1,               /* --urx2          */
00522                             -1,               /* --ury2          */
00523                             -1,               /* --llx3          */
00524                             -1,               /* --lly3          */
00525                             -1,               /* --urx3          */
00526                             -1,               /* --ury3          */
00527                             -1,               /* --llx4          */
00528                             -1,               /* --lly4          */
00529                             -1,               /* --urx4          */
00530                             -1,               /* --ury4          */
00531                             -1,               /* --llx5          */
00532                             -1,               /* --lly5          */
00533                             -1,               /* --urx5          */
00534                             -1,               /* --ury5          */
00535                   0,               /* --exts          */
00536     NIR);
00537 
00538     frameset = cpl_frameset_duplicate(set);
00539 
00540     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00541              "detmon", REGEXP, prolist, prolist, prolist,
00542              prolist, prolist, prolist, "DETMON / 1.0",
00543              NULL, NULL, TRUE);
00544     cpl_test_error(CPL_ERROR_NONE);
00545     cpl_error_reset();
00546 
00547     {
00548     /* Check that the image is in fact binary */
00549     cpl_image * bpm = cpl_image_load("detmon_ir_lg_bpm.fits",
00550                      CPL_TYPE_INT, 0, 0);
00551 
00552     cpl_mask * mask = cpl_mask_threshold_image_create(bpm, 0.5, 1.5);
00553 
00554     int nbpixs = cpl_mask_count(mask);
00555 
00556     int flux = (int)cpl_image_get_flux(bpm);
00557 
00558     cpl_test_eq(flux, nbpixs);
00559 
00560     cpl_image_delete(bpm);
00561     cpl_mask_delete(mask);
00562     }
00563 
00564     cpl_frameset_delete(frameset);
00565     cpl_parameterlist_delete(parlist);
00566 
00567     /* Is there any way, looking into the products, to know if the --rescale
00568        has been in fact deactivated? Other health checkings should be done 
00569        here to prove that the deactivation doesn't compromise correctness */
00570 
00571     /* 6. test: NIR case, --pix2pix deactivated */
00572     parlist = cpl_parameterlist_new();
00573     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00574                   "PTC",
00575                             3,                /* --order         */
00576                             3,                /* --kappa         */
00577                             25,               /* --niter         */
00578                             -1,               /* --llx           */
00579                             -1,               /* --lly           */    
00580                             -1,               /* --urx           */
00581                             -1,               /* --ury           */
00582                             10000,            /* --ref_level     */
00583                             "CPL_FALSE",      /* --intermediate  */
00584                             "CPL_FALSE",      /* --autocorr      */
00585                             "CPL_FALSE",      /* --collapse      */
00586                             "CPL_TRUE",       /* --rescale       */
00587                             "CPL_FALSE",       /* --pix2pix       */
00588                             "CPL_FALSE",       /* --bpmbin       */
00589                               -1,             /* --filter        */
00590                             26,               /* --m             */
00591                             26,               /* --n             */
00592                   1e-3,
00593                   "detmon_ir_lg",
00594                             -1,               /* --llx1          */
00595                             -1,               /* --lly1          */
00596                             -1,               /* --urx1          */
00597                             -1,               /* --ury1          */
00598                             -1,               /* --llx2          */
00599                             -1,               /* --lly2          */
00600                             -1,               /* --urx2          */
00601                             -1,               /* --ury2          */
00602                             -1,               /* --llx3          */
00603                             -1,               /* --lly3          */
00604                             -1,               /* --urx3          */
00605                             -1,               /* --ury3          */
00606                             -1,               /* --llx4          */
00607                             -1,               /* --lly4          */
00608                             -1,               /* --urx4          */
00609                             -1,               /* --ury4          */
00610                             -1,               /* --llx5          */
00611                             -1,               /* --lly5          */
00612                             -1,               /* --urx5          */
00613                             -1,               /* --ury5          */
00614                   0,               /* --exts          */
00615     NIR);
00616 
00617     frameset = cpl_frameset_duplicate(set);
00618 
00619 /*    irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00620              "detmon", REGEXP, prolist, prolist, prolist,
00621              prolist, prolist, prolist, "DETMON / 1.0",
00622              NULL, NULL, TRUE);
00623     cpl_test_error(CPL_ERROR_NONE);
00624     cpl_error_reset();
00625 */
00626     cpl_frameset_delete(frameset);
00627     cpl_parameterlist_delete(parlist);
00628 
00629     /* Should check at least that there is no data cube */
00630 
00631     /* 7. test: NIR case, --filter activated (4000) */
00632     parlist = cpl_parameterlist_new();
00633     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00634                   "PTC",
00635                             3,                /* --order         */
00636                             3,                /* --kappa         */
00637                             25,               /* --niter         */
00638                             -1,               /* --llx           */
00639                             -1,               /* --lly           */    
00640                             -1,               /* --urx           */
00641                             -1,               /* --ury           */
00642                             10000,            /* --ref_level     */
00643                             "CPL_FALSE",      /* --intermediate  */
00644                             "CPL_FALSE",      /* --autocorr      */
00645                             "CPL_FALSE",      /* --collapse      */
00646                             "CPL_TRUE",       /* --rescale       */
00647                             "CPL_TRUE",       /* --pix2pix       */
00648                             "CPL_FALSE",       /* --bpmbin       */
00649                               4000,             /* --filter        */
00650                             26,               /* --m             */
00651                             26,               /* --n             */
00652                   1e-3,
00653                   "detmon_ir_lg",
00654                             -1,               /* --llx1          */
00655                             -1,               /* --lly1          */
00656                             -1,               /* --urx1          */
00657                             -1,               /* --ury1          */
00658                             -1,               /* --llx2          */
00659                             -1,               /* --lly2          */
00660                             -1,               /* --urx2          */
00661                             -1,               /* --ury2          */
00662                             -1,               /* --llx3          */
00663                             -1,               /* --lly3          */
00664                             -1,               /* --urx3          */
00665                             -1,               /* --ury3          */
00666                             -1,               /* --llx4          */
00667                             -1,               /* --lly4          */
00668                             -1,               /* --urx4          */
00669                             -1,               /* --ury4          */
00670                             -1,               /* --llx5          */
00671                             -1,               /* --lly5          */
00672                             -1,               /* --urx5          */
00673                             -1,               /* --ury5          */
00674                   0,               /* --exts          */
00675     NIR);
00676 
00677     frameset = cpl_frameset_duplicate(set);
00678 
00679     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00680              "detmon", REGEXP, prolist, prolist, prolist,
00681              prolist, prolist, prolist, "DETMON / 1.0",
00682              NULL, NULL, TRUE);
00683     cpl_test_error(CPL_ERROR_NONE);
00684     cpl_error_reset();
00685 
00686     cpl_frameset_delete(frameset);
00687     cpl_parameterlist_delete(parlist);
00688 
00689     /*FIXME: Move this deletion more to the end if standard set used
00690       for more tests */
00691     cpl_frameset_delete(set);
00692 
00693     /* Check that there are less entries into the table.
00694      We should know for sure how many entries are going to be!
00695     To avoid other errors as not having enough points for fitting!*/
00696 
00697     /* 8. test: Check that it fails when not enough frames for order-degree
00698        fitting */
00699     parlist = cpl_parameterlist_new();
00700     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00701                   "PTC",
00702                             3,                /* --order         */
00703                             3,                /* --kappa         */
00704                             25,               /* --niter         */
00705                             -1,               /* --llx           */
00706                             -1,               /* --lly           */    
00707                             -1,               /* --urx           */
00708                             -1,               /* --ury           */
00709                             10000,            /* --ref_level     */
00710                             "CPL_FALSE",      /* --intermediate  */
00711                             "CPL_FALSE",      /* --autocorr      */
00712                             "CPL_FALSE",      /* --collapse      */
00713                             "CPL_TRUE",       /* --rescale       */
00714                             "CPL_TRUE",       /* --pix2pix       */
00715                             "CPL_FALSE",       /* --bpmbin       */
00716                               -1,             /* --filter        */
00717                             26,               /* --m             */
00718                             26,               /* --n             */
00719                   1e-3,
00720                   "detmon_ir_lg",
00721                             -1,               /* --llx1          */
00722                             -1,               /* --lly1          */
00723                             -1,               /* --urx1          */
00724                             -1,               /* --ury1          */
00725                             -1,               /* --llx2          */
00726                             -1,               /* --lly2          */
00727                             -1,               /* --urx2          */
00728                             -1,               /* --ury2          */
00729                             -1,               /* --llx3          */
00730                             -1,               /* --lly3          */
00731                             -1,               /* --urx3          */
00732                             -1,               /* --ury3          */
00733                             -1,               /* --llx4          */
00734                             -1,               /* --lly4          */
00735                             -1,               /* --urx4          */
00736                             -1,               /* --ury4          */
00737                             -1,               /* --llx5          */
00738                             -1,               /* --lly5          */
00739                             -1,               /* --urx5          */
00740                             -1,               /* --ury5          */
00741                   0,               /* --exts          */
00742     NIR);
00743 
00744     frameset = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00745                          6, TRUE, FALSE, 0, 1);
00746 
00747 /*    irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg",
00748              "detmon", REGEXP, prolist, prolist, prolist,
00749              prolist, prolist, prolist, "DETMON / 1.0",
00750              NULL, NULL, TRUE);
00751     cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
00752     cpl_error_reset();
00753 */
00754     cpl_frameset_delete(frameset);
00755     cpl_parameterlist_delete(parlist);
00756 
00757 
00758     /* 9. test: Default use, OPT case */
00759     parlist = cpl_parameterlist_new();
00760     irplib_detmon_lg_fill_parlist_opt_default(parlist,
00761                           "detmon_opt_lg", "detmon");
00762 
00763     frameset = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00764                          20, FALSE, FALSE, 0, 1);
00765 
00766 /*    irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_opt_lg",
00767              "detmon", REGEXP, prolist, prolist, prolist,
00768              prolist, prolist, prolist, "DETMON / 1.0",
00769              NULL, NULL, FALSE);
00770     cpl_test_error(CPL_ERROR_NONE);
00771     cpl_error_reset();
00772 */
00773     cpl_frameset_delete(frameset);
00774     cpl_parameterlist_delete(parlist);
00775 
00776 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 1, 0)
00777     /* 4. test: Passing a frameset where frames have extensions */
00778     parlist = cpl_parameterlist_new();
00779     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00780                   "PTC",
00781                             3,                /* --order         */
00782                             3,                /* --kappa         */
00783                             25,               /* --niter         */
00784                             -1,               /* --llx           */
00785                             -1,               /* --lly           */    
00786                             -1,               /* --urx           */
00787                             -1,               /* --ury           */
00788                             10000,            /* --ref_level     */
00789                             "CPL_FALSE",      /* --intermediate  */
00790                             "CPL_FALSE",      /* --autocorr      */
00791                             "CPL_FALSE",      /* --collapse      */
00792                             "CPL_TRUE",       /* --rescale       */
00793                             "CPL_TRUE",       /* --pix2pix       */
00794                             "CPL_FALSE",       /* --bpmbin       */
00795                               -1,             /* --filter        */
00796                             26,               /* --m             */
00797                             26,               /* --n             */
00798                   1e-3,
00799                   "detmon_ir_lg",
00800                             -1,               /* --llx1          */
00801                             -1,               /* --lly1          */
00802                             -1,               /* --urx1          */
00803                             -1,               /* --ury1          */
00804                             -1,               /* --llx2          */
00805                             -1,               /* --lly2          */
00806                             -1,               /* --urx2          */
00807                             -1,               /* --ury2          */
00808                             -1,               /* --llx3          */
00809                             -1,               /* --lly3          */
00810                             -1,               /* --urx3          */
00811                             -1,               /* --ury3          */
00812                             -1,               /* --llx4          */
00813                             -1,               /* --lly4          */
00814                             -1,               /* --urx4          */
00815                             -1,               /* --ury4          */
00816                             -1,               /* --llx5          */
00817                             -1,               /* --lly5          */
00818                             -1,               /* --urx5          */
00819                             -1,               /* --ury5          */
00820                   -1,               /* --exts          */
00821     NIR);
00822     /*
00823                                     * Unique change of this call with
00824                                     * respect of the default call:
00825                                     * last parameter --exts = -1
00826                                     * to tell the recipe to compute on
00827                                     * all extensions.
00828                                     */
00829 
00830     frameset = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00831                                                  20, TRUE, TRUE, 8, 1);
00832     
00833     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg", "detmon", REGEXP,
00834                      prolist, prolist, prolist, prolist, prolist, prolist, "DETMON / 1.0", NULL, NULL, TRUE);
00835     cpl_test(cpl_error_get_code() == CPL_ERROR_NONE ||
00836                 cpl_error_get_code() == CPL_ERROR_UNSUPPORTED_MODE);
00837     cpl_error_reset();
00838     
00839     cpl_parameterlist_delete(parlist);
00840     cpl_frameset_delete(frameset);
00841 #endif
00842 
00843     /* 2 Trial: passing a frameset where frames have extensions,
00844        but computing on a single extension */
00845     parlist = cpl_parameterlist_new();
00846     irplib_detmon_lg_fill_parlist(parlist, "detmon_ir_lg", "detmon",
00847                   "PTC",
00848                             3,                /* --order         */
00849                             3,                /* --kappa         */
00850                             25,               /* --niter         */
00851                             -1,               /* --llx           */
00852                             -1,               /* --lly           */    
00853                             -1,               /* --urx           */
00854                             -1,               /* --ury           */
00855                             10000,            /* --ref_level     */
00856                             "CPL_FALSE",      /* --intermediate  */
00857                             "CPL_FALSE",      /* --autocorr      */
00858                             "CPL_FALSE",      /* --collapse      */
00859                             "CPL_TRUE",       /* --rescale       */
00860                             "CPL_TRUE",       /* --pix2pix       */
00861                             "CPL_FALSE",       /* --bpmbin       */
00862                               -1,             /* --filter        */
00863                             26,               /* --m             */
00864                             26,               /* --n             */
00865                   1e-3,
00866                   "detmon_ir_lg",
00867                             -1,               /* --llx1          */
00868                             -1,               /* --lly1          */
00869                             -1,               /* --urx1          */
00870                             -1,               /* --ury1          */
00871                             -1,               /* --llx2          */
00872                             -1,               /* --lly2          */
00873                             -1,               /* --urx2          */
00874                             -1,               /* --ury2          */
00875                             -1,               /* --llx3          */
00876                             -1,               /* --lly3          */
00877                             -1,               /* --urx3          */
00878                             -1,               /* --ury3          */
00879                             -1,               /* --llx4          */
00880                             -1,               /* --lly4          */
00881                             -1,               /* --urx4          */
00882                             -1,               /* --ury4          */
00883                             -1,               /* --llx5          */
00884                             -1,               /* --lly5          */
00885                             -1,               /* --urx5          */
00886                             -1,               /* --ury5          */
00887                   2,               /* --exts          */
00888     NIR);
00889     /*
00890                                     * Main change of this call with
00891                                     * respect of the default call:
00892                                     * last parameter --exts = 2
00893                                     * to tell the recipe to compute only on
00894                                     * the second extension.
00895                                     */
00896 
00897     frameset = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00898                                                  20, TRUE, TRUE, 8, 1);
00899     
00900     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg", "detmon", REGEXP,
00901                      prolist, prolist, prolist, prolist, prolist, prolist, "DETMON / 1.0", NULL, NULL, TRUE);
00902     cpl_test(cpl_error_get_code() == CPL_ERROR_NONE ||
00903                 cpl_error_get_code() == CPL_ERROR_UNSUPPORTED_MODE);
00904     cpl_error_reset();
00905     
00906     cpl_parameterlist_delete(parlist);
00907     cpl_frameset_delete(frameset);
00908 
00909 
00910     /* New trial. With a octatett instead of a quartett. */
00911     parlist = cpl_parameterlist_new();
00912     irplib_detmon_lg_fill_parlist_nir_default(parlist, "detmon_ir_lg", "detmon");
00913 
00914     frameset = irplib_detmon_tests_fill_frameset_oct(tag_on, tag_off, 20, TRUE, FALSE, 0);
00915 
00916 /*    irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg", "detmon", REGEXP,
00917                      prolist, prolist, prolist, prolist, prolist, prolist, "DETMON / 1.0", NULL, NULL, TRUE);
00918     cpl_test(cpl_error_get_code() == CPL_ERROR_NONE ||
00919                 cpl_error_get_code() == CPL_ERROR_UNSUPPORTED_MODE);
00920     cpl_error_reset();
00921 */
00922     cpl_parameterlist_delete(parlist);
00923     cpl_frameset_delete(frameset);
00924 
00925     /* Test with more than a single setting */
00926     parlist = cpl_parameterlist_new();
00927     irplib_detmon_lg_fill_parlist_nir_default(parlist, "detmon_ir_lg", "detmon");
00928 
00929     frameset = irplib_detmon_tests_fill_frameset(tag_on, tag_off,
00930                                                  20, TRUE, FALSE, 0, 3);
00931 
00932     irplib_detmon_lg(frameset, parlist, tag_on, tag_off, "detmon_ir_lg", "detmon", REGEXP, 
00933                      prolist, prolist, prolist, prolist, prolist, prolist, "DETMON / 1.0", compare_settings, NULL, TRUE);
00934 
00935     cpl_test_error(CPL_ERROR_NONE);
00936 
00937     cpl_parameterlist_delete(parlist);
00938     cpl_frameset_delete(frameset);
00939 
00940     cpl_propertylist_delete(prolist);
00941 
00942     cpl_test_zero(system("rm *.paf *.fits"));
00943 
00944     /* TESTS for irplib_detmon_gain() */
00945     {
00946     /* Variable used for irplib_detmon_gain() testing */
00947     cpl_table * gain_table;
00948     cpl_imagelist * imlist_on;
00949     cpl_imagelist * imlist_off;
00950     cpl_imagelist * diff;
00951     cpl_imagelist * corr;
00952     cpl_vector * exptimes;
00953     cpl_propertylist * qclist;
00954     int i;
00955     double gain;
00956 
00957     /* Test with NULL inputs */
00958     gain_table = irplib_detmon_gain(NULL, NULL, NULL, 0, 0, 0, 0, 0, 0.0,
00959                     0, 0, 0, NULL, 0, NULL, NULL);
00960     cpl_test_null(gain_table);
00961     cpl_test_error(CPL_ERROR_NULL_INPUT);
00962 
00963     imlist_on  = irplib_detmon_tests_imlist(8, ON);
00964     imlist_off = irplib_detmon_tests_imlist(8, OFF);
00965 
00966     exptimes = cpl_vector_new(16);
00967 
00968     for(i = 0; i < 16; i++) {
00969         cpl_vector_set(exptimes, i, (double)(i/2 + 1));
00970     }
00971 
00972     qclist = cpl_propertylist_new();
00973 
00974     gain_table = irplib_detmon_gain(imlist_on, imlist_off, exptimes, 0.0,
00975                     1, 1,
00976                     IMAGESIZE, IMAGESIZE, 3.0, 25, 26, 26,
00977                     qclist, IRPLIB_GAIN_NO_COLLAPSE |
00978                     IRPLIB_GAIN_NIR,
00979                     NULL, NULL);
00980     cpl_test_nonnull(gain_table);
00981     cpl_test_error(CPL_ERROR_NONE);
00982 
00983     /* Check correctness */
00984     gain = cpl_propertylist_get_double(qclist, DETMON_QC_GAIN);
00985     cpl_test(gain > 220.0 && gain < 240.0);
00986 
00987     cpl_table_delete(gain_table);
00988     cpl_propertylist_delete(qclist);
00989 
00990 
00991     qclist = cpl_propertylist_new();
00992 
00993     gain_table = irplib_detmon_gain(imlist_on, imlist_off, exptimes, 0.0, 
00994                     1, 1,
00995                     IMAGESIZE, IMAGESIZE, 3.0, 25, 26, 26,
00996                     qclist, IRPLIB_GAIN_NO_COLLAPSE |
00997                     IRPLIB_GAIN_NIR |
00998                     IRPLIB_GAIN_PTC,
00999                     NULL, NULL);
01000     cpl_test_nonnull(gain_table);
01001     cpl_test_error(CPL_ERROR_NONE);
01002 
01003     /* Check correctness */
01004     gain = cpl_propertylist_get_double(qclist, DETMON_QC_GAIN);
01005     cpl_test(gain > 160.0 && gain < 180.0);
01006 
01007     cpl_table_delete(gain_table);
01008     cpl_propertylist_delete(qclist);
01009 
01010     qclist = cpl_propertylist_new();
01011 
01012     diff = NULL;
01013     corr = NULL;
01014 
01015     gain_table = irplib_detmon_gain(imlist_on, imlist_off, exptimes, 0.0, 
01016                     1, 1,
01017                     IMAGESIZE, IMAGESIZE, 3.0, 25, 26, 26,
01018                     qclist, IRPLIB_GAIN_NO_COLLAPSE |
01019                     IRPLIB_GAIN_NIR |
01020                     IRPLIB_GAIN_WITH_AUTOCORR, &diff, &corr);
01021     cpl_test_nonnull(gain_table);
01022     cpl_test_nonnull(diff);
01023     cpl_test_nonnull(corr);
01024     cpl_test_error(CPL_ERROR_NONE);
01025 
01026     cpl_imagelist_delete(diff);
01027     cpl_imagelist_delete(corr);
01028     cpl_table_delete(gain_table);
01029     cpl_propertylist_delete(qclist);
01030 
01031     qclist = cpl_propertylist_new();
01032 
01033     gain_table = irplib_detmon_gain(imlist_on, imlist_off, exptimes, 0.0,
01034                     1, 1,
01035                     IMAGESIZE, IMAGESIZE, 3.0, 25, 26, 26,
01036                     qclist, IRPLIB_GAIN_NO_COLLAPSE |
01037                     IRPLIB_GAIN_NIR |
01038                     IRPLIB_GAIN_WITH_AUTOCORR, NULL, NULL);
01039     cpl_test_nonnull(gain_table);
01040     cpl_test_error(CPL_ERROR_NONE);
01041 
01042     cpl_imagelist_delete(imlist_on);
01043     cpl_imagelist_delete(imlist_off);
01044     cpl_propertylist_delete(qclist);
01045     cpl_vector_delete(exptimes);
01046     cpl_table_delete(gain_table);
01047     }
01048 
01049     /* TESTS for irplib_detmon_lin() */
01050     {
01051     cpl_table     * lin_table;
01052     cpl_imagelist * imlist_on;
01053     cpl_imagelist * imlist_off;
01054     cpl_vector    * exptimes;
01055     cpl_propertylist * qclist;
01056     cpl_imagelist * coeffs_cube =NULL;
01057     cpl_image     * bpm =NULL;
01058     double lincoeff1, lincoeff2, lincoeff3;
01059     int i;
01060     
01061     /* TESTS with NULL inputs */
01062     lin_table = irplib_detmon_lin(NULL, NULL, NULL, 0.0, 0, 0, 0, 0,
01063                                       0, 10000, 3, FALSE, NULL, 0, NULL, NULL);
01064 
01065     cpl_test_null(lin_table);
01066     cpl_test_error(CPL_ERROR_NULL_INPUT);
01067 
01068     /* Basic setting for testing */
01069     imlist_on  = irplib_detmon_tests_imlist(8, ON);
01070     imlist_off = irplib_detmon_tests_imlist(8, OFF);
01071 
01072     exptimes = cpl_vector_new(16);
01073 
01074     for(i = 0; i < 16; i++) {
01075         cpl_vector_set(exptimes, i, (double)(i/2 + 1));
01076     }
01077 
01078     qclist = cpl_propertylist_new();
01079 
01080     lin_table = irplib_detmon_lin(imlist_on, imlist_off, exptimes, 0.0,
01081                       1, 1, IMAGESIZE, IMAGESIZE,
01082                       3, 10000, 3, FALSE, qclist, 
01083                                       IRPLIB_LIN_NO_COLLAPSE |
01084                       IRPLIB_LIN_NIR,
01085                                   NULL, NULL);
01086 
01087     cpl_test_nonnull(lin_table);
01088     cpl_test_error(CPL_ERROR_NONE);
01089 
01090     /* Check correctness */
01091     lincoeff1 = cpl_propertylist_get_double(qclist, "ESO QC LIN COEF1");
01092     lincoeff2 = cpl_propertylist_get_double(qclist, "ESO QC LIN COEF2");
01093     lincoeff3 = cpl_propertylist_get_double(qclist, "ESO QC LIN COEF3");
01094 
01095     cpl_test(lincoeff1 > 195.0 && lincoeff1 < 205.0);
01096     cpl_test(abs(lincoeff2) < 1);
01097     cpl_test(abs(lincoeff3) < 1);
01098 
01099     cpl_table_delete(lin_table);
01100     
01101     lin_table = irplib_detmon_lin(imlist_on, imlist_off, exptimes, 0.0,
01102                       1, 1, IMAGESIZE, IMAGESIZE,
01103                       3, 10000, 3, FALSE, qclist, 
01104                                       IRPLIB_LIN_NO_COLLAPSE |
01105                       IRPLIB_LIN_NIR | IRPLIB_LIN_PIX2PIX,
01106                                   &coeffs_cube, &bpm);
01107 
01108     cpl_test_nonnull(lin_table);
01109     cpl_test_nonnull(coeffs_cube);
01110     cpl_test_nonnull(bpm);
01111     cpl_test_error(CPL_ERROR_NONE);
01112 
01113     cpl_table_delete(lin_table);
01114     cpl_imagelist_delete(coeffs_cube);
01115     cpl_image_delete(bpm);
01116     
01117     cpl_imagelist_delete(imlist_on);
01118     cpl_imagelist_delete(imlist_off);
01119     cpl_vector_delete(exptimes);
01120     cpl_propertylist_delete(qclist);
01121     }
01122 }
01123 
01124 /*---------------------------------------------------------------------------*/
01125 /*
01126  * @brief  Detect bad pixels of a selected type
01127  * @param  in           Input image
01128  * @param  mean         Mean level of the image - used to compute threshold
01129  * @param  sigma        Stdev level of the image - used to compute threshold
01130  * @param  flag         Flag - represents selected type of bad pixels (see enum)
01131  * @return The detected bad pixels in a cpl_mask.
01132  */
01133 /*---------------------------------------------------------------------------*/
01134 
01135 cpl_frameset * irplib_detmon_tests_fill_frameset(const char     * tag_on,
01136                                                  const char     * tag_off,
01137                                                  int              non,
01138                                                  cpl_boolean      opt_nir,
01139                                                  cpl_boolean      with_exts,
01140                                                  int              nexts,
01141                                                  int              nsettings)
01142 {
01143     cpl_frameset                * frameset;
01144     cpl_frame                   * frame;
01145     int i, h;
01146     char                        frame_name[20];
01147     cpl_propertylist            * plist;
01148     cpl_image                   * image;
01149     frameset = cpl_frameset_new();
01150 
01151     for (h = 0; h < nsettings; h++) {
01152     for (i=0; i<non; i++) {
01153         frame = cpl_frame_new();
01154         sprintf(frame_name, "dummyon%d%d.fits",i,h);
01155         cpl_frame_set_filename(frame, frame_name);
01156         cpl_frame_set_tag(frame, tag_on);
01157         cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
01158         cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
01159 
01160         cpl_frameset_insert(frameset, frame);
01161 
01162         plist = cpl_propertylist_new();
01163         if(opt_nir == TRUE) {
01164         cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(i/2+1));
01165         } else {
01166         cpl_propertylist_append_double(plist, "ESO DET WIN1 UIT1", (double)((i+1)/2));
01167         }
01168 
01169         cpl_propertylist_append_double(plist, "EXPTIME", (double)(i/2 + 1) );
01170         cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01171 
01172         cpl_propertylist_append_double(plist, "SETTING", h+1);
01173         if(with_exts == TRUE) {
01174         int j;
01175         cpl_image_save(NULL, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01176         for(j = 0; j < nexts; j++) {
01177             image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01178             cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01179             cpl_image_add_scalar(image,300* i);
01180             cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01181 
01182             cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_EXTEND);
01183             cpl_image_delete(image);
01184         }
01185         } else {
01186         image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01187         cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01188         cpl_image_add_scalar(image,300* i);
01189         cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01190 
01191         cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01192 
01193 
01194         cpl_image_delete(image);
01195         }
01196         cpl_propertylist_delete(plist);
01197     }
01198     for (i=0; i<non; i++) {
01199 
01200 
01201         frame = cpl_frame_new();
01202         sprintf(frame_name, "dummyoff%d%d.fits",i,h);
01203         cpl_frame_set_filename(frame, frame_name);
01204         cpl_frame_set_tag(frame, tag_off);
01205         cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
01206         cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
01207 
01208         cpl_frameset_insert(frameset, frame);
01209 
01210         plist = cpl_propertylist_new();
01211         if(opt_nir == TRUE) {
01212         cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(i/2+1));
01213         } else {
01214         cpl_propertylist_append_double(plist, "ESO DET WIN1 UIT1", (double)((i+1)/2));
01215         }
01216         cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01217         cpl_propertylist_append_double(plist, "EXPTIME", (double)(i/2 + 1));
01218         cpl_propertylist_append_double(plist, "SETTING", h+1);
01219 
01220         if(with_exts == TRUE) {
01221         int j;
01222         cpl_image_save(NULL, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01223         for(j = 0; j < nexts; j++) {
01224             image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01225             cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01226             cpl_image_add_scalar(image, i);
01227             cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01228 
01229             cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_EXTEND);
01230             cpl_image_delete(image);
01231         }
01232         } else {
01233         image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01234         cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01235         cpl_image_add_scalar(image, i);
01236         cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01237 
01238         cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01239 
01240 
01241         cpl_image_delete(image);
01242         }
01243         cpl_propertylist_delete(plist);
01244     }
01245     }
01246 
01247     return frameset;
01248 }
01249 
01250 
01251 cpl_frameset * irplib_detmon_tests_fill_frameset_oct(const char         * tag_on,
01252                                                  const char     * tag_off,
01253                                                  int              non,
01254                                                  cpl_boolean      opt_nir,
01255                                                  cpl_boolean      with_exts,
01256                                                  int              nexts)
01257 {
01258     cpl_frameset                * frameset;
01259     cpl_frame                   * frame;
01260     int i;
01261     char                        frame_name[20];
01262     cpl_propertylist            * plist;
01263     cpl_image                   * image;
01264     frameset = cpl_frameset_new();
01265 
01266     for (i=0; i<non; i++) {
01267         frame = cpl_frame_new();
01268         sprintf(frame_name, "dummyon%d.fits",i);
01269         cpl_frame_set_filename(frame, frame_name);
01270         cpl_frame_set_tag(frame, tag_on);
01271         cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
01272         cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
01273 
01274         cpl_frameset_insert(frameset, frame);
01275 
01276         plist = cpl_propertylist_new();
01277         if(opt_nir == TRUE) {
01278           if( i == 2 || i == 3) {
01279             cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(1));
01280             cpl_propertylist_append_double(plist, "EXPTIME", (double)(1));
01281             cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01282           } else {
01283             cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(i/2+1));
01284             cpl_propertylist_append_double(plist, "EXPTIME", (double)(i/2+1));
01285             cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01286           }
01287         } else {
01288             cpl_propertylist_append_double(plist, "ESO DET WIN1 UIT1", (double)((i+1)/2));
01289             cpl_propertylist_append_double(plist, "EXPTIME", (double)((i+1)/2));
01290             cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01291         }
01292 
01293         if(with_exts == TRUE) {
01294           int j;
01295           cpl_image_save(NULL, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01296           for(j = 0; j < nexts; j++) {
01297             image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01298             cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01299         if(i == 0 || i == 1 || i== 2 || i == 3) {
01300         cpl_image_add_scalar(image,300);
01301         } else
01302         cpl_image_add_scalar(image,300* i);
01303             cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01304 
01305             cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_EXTEND);
01306             cpl_image_delete(image);
01307           }
01308         } else {
01309             image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01310             cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01311         if(i == 0 || i == 1 || i== 2 || i == 3) {
01312         cpl_image_add_scalar(image,300);
01313         } else
01314         cpl_image_add_scalar(image,300* i);
01315 
01316             cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01317 
01318             cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01319 
01320 
01321             cpl_image_delete(image);
01322         }
01323         cpl_propertylist_delete(plist);
01324     }
01325 
01326     for (i=0; i<non; i++) {
01327 
01328 
01329         frame = cpl_frame_new();
01330         sprintf(frame_name, "dummyoff%d.fits",i);
01331         cpl_frame_set_filename(frame, frame_name);
01332         cpl_frame_set_tag(frame, tag_off);
01333         cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
01334         cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
01335 
01336         cpl_frameset_insert(frameset, frame);
01337 
01338         plist = cpl_propertylist_new();
01339         if(opt_nir == TRUE) {
01340           if( i == 2 || i == 3) {
01341             cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(1));
01342             cpl_propertylist_append_double(plist, "EXPTIME", (double)(1));
01343             cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01344           } else {
01345             cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(i/2+1));
01346             cpl_propertylist_append_double(plist, "EXPTIME", (double)(i/2+1));
01347             cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01348           }
01349         } else {
01350             cpl_propertylist_append_double(plist, "ESO DET WIN1 UIT1", (double)((i+1)/2));
01351             cpl_propertylist_append_double(plist, "EXPTIME", (double)((i+1)/2));
01352             cpl_propertylist_append_double(plist, "MJD-OBS", 0);
01353         }
01354 
01355         if(with_exts == TRUE) {
01356           int j;
01357           cpl_image_save(NULL, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01358           for(j = 0; j < nexts; j++) {
01359             image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01360             cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01361         if(i == 0 || i == 1 || i== 2 || i == 3) {
01362         cpl_image_add_scalar(image,300);
01363         } else
01364         cpl_image_add_scalar(image,300* i);
01365 
01366             cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01367 
01368             cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_EXTEND);
01369             cpl_image_delete(image);
01370           }
01371         } else {
01372             image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01373             cpl_image_fill_noise_uniform(image, 5 - i, 10 + i);
01374         if(i == 0 || i == 1 || i== 2 || i == 3) {
01375         cpl_image_add_scalar(image,300);
01376         } else
01377         cpl_image_add_scalar(image,300* i);
01378 
01379             cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
01380 
01381             cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
01382 
01383 
01384             cpl_image_delete(image);
01385         }
01386         cpl_propertylist_delete(plist);
01387     }
01388 
01389     return frameset;
01390 }
01391 
01392 
01393 int compare_settings(const cpl_frame * frame1, const cpl_frame * frame2)
01394 {
01395     int                     comparison;
01396     cpl_propertylist       *plist1;
01397     cpl_propertylist       *plist2;
01398     double                  dval1, dval2;
01399 
01400     /* Test entries */
01401     if(frame1 == NULL || frame2 == NULL)
01402         return -1;
01403 
01404     /* Get property lists */
01405     if((plist1 = cpl_propertylist_load(cpl_frame_get_filename(frame1),
01406                                        0)) == NULL) {
01407         cpl_msg_error(cpl_func, "getting header from reference frame");
01408         return -1;
01409     }
01410     if((plist2 = cpl_propertylist_load(cpl_frame_get_filename(frame2),
01411                                        0)) == NULL) {
01412         cpl_msg_error(cpl_func, "getting header from reference frame");
01413         cpl_propertylist_delete(plist1);
01414         return -1;
01415     }
01416 
01417     /* Test status */
01418     if(cpl_error_get_code()) {
01419         cpl_propertylist_delete(plist1);
01420         cpl_propertylist_delete(plist2);
01421         return -1;
01422     }
01423 
01424     /* Compare exposure time */
01425     comparison = 1;
01426     dval1 = cpl_propertylist_get_double(plist1, "SETTING");
01427     dval2 = cpl_propertylist_get_double(plist2, "SETTING");
01428     if(cpl_error_get_code()) {
01429         cpl_msg_error(cpl_func, "cannot get exposure time");
01430         cpl_propertylist_delete(plist1);
01431         cpl_propertylist_delete(plist2);
01432         return -1;
01433     }
01434     if( dval1 != dval2)
01435         comparison = 0;
01436 
01437     /* Free and return */
01438     cpl_propertylist_delete(plist1);
01439     cpl_propertylist_delete(plist2);
01440     return comparison;
01441 
01442 }
01443 
01444 cpl_imagelist * irplib_detmon_tests_imlist(int ndits, cpl_boolean onoff)
01445 {
01446   cpl_imagelist * imlist = cpl_imagelist_new();
01447   int i;
01448 
01449   double levelstep = onoff ? ON_LEVEL : OFF_LEVEL;
01450   double factor    = onoff ? 1.0 : 0.5;
01451 
01452   for (i = 1; i <= ndits; i++) {
01453     cpl_image * im1 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01454     cpl_image * im2 = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
01455     double noise_min = NOISE_MIN * sqrt(i) / (double) ndits * factor;
01456     double noise_max = NOISE_MAX * sqrt(i) / (double) ndits * factor;
01457     cpl_image_fill_noise_uniform(im1, noise_min, noise_max);
01458     cpl_image_fill_noise_uniform(im2, noise_min, noise_max);
01459     cpl_image_add_scalar(im1, levelstep * i);
01460     cpl_image_add_scalar(im2, levelstep * i);
01461     cpl_imagelist_set(imlist, im1, 2 * (i - 1));
01462     cpl_imagelist_set(imlist, im2, 2 * (i - 1) + 1);
01463   }
01464 
01465   return imlist;
01466 }
01467 

Generated on Fri Jul 3 11:23:56 2009 for NACO Pipeline Reference Manual by  doxygen 1.5.8