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

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