irplib_detmon-test.c

00001 /*                                                                              *
00002  *   This file is part of the ESO IRPLIB package                                *
00003  *   Copyright (C) 2004,2005 European Southern Observatory                      *
00004  *                                                                              *
00005  *   This library is free software; you can redistribute it and/or modify       *
00006  *   it under the terms of the GNU General Public License as published by       *
00007  *   the Free Software Foundation; either version 2 of the License, or          *
00008  *   (at your option) any later version.                                        *
00009  *                                                                              *
00010  *   This program is distributed in the hope that it will be useful,            *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
00013  *   GNU General Public License for more details.                               *
00014  *                                                                              *
00015  *   You should have received a copy of the GNU General Public License          *
00016  *   along with this program; if not, write to the Free Software                *
00017  *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA       *
00018  *                                                                              */
00019 
00020 #ifdef HAVE_CONFIG_H
00021 #include <config.h>
00022 #endif
00023 
00024 /*----------------------------------------------------------------------------
00025                                 Includes
00026  ----------------------------------------------------------------------------*/
00027 
00028 
00029 #include <irplib_detmon.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       128
00046 #endif
00047 
00048 #define IMAGELISTSIZE   10
00049 
00050 #define NBADPIXS        10
00051 
00052 #undef REGEXP
00053 #define REGEXP                            "^(ARCFILE|MJD-OBS|ESO TPL ID|" \
00054                                           "DATE-OBS|ESO DET DIT|ESO DET NDIT|"\
00055                                           "ESO DET NCORRS|"\
00056                                           "ESO DET MODE NAME)$"
00057 
00058 /*----------------------------------------------------------------------------
00059                             Private Function prototypes
00060  ----------------------------------------------------------------------------*/
00061 
00062 static void irplib_detmon_tests(void);
00063 
00064 
00065 cpl_frameset * irplib_detmon_pernoise_tests_fill_frameset(cpl_boolean,
00066                                                           int);
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 static cpl_error_code
00075 irplib_ksigma_clip_bf(cpl_image * img,
00076               const int llx,
00077               const int lly,
00078               const int urx, int ury,
00079               const int kappa,
00080               const int nclip,
00081               double *clean_mean, double *clean_stdev);
00082 
00083 /*---------------------------------------------------------------------------*/
00084 /*
00085  * @brief   Unit tests of fit module
00086  */
00087 /*---------------------------------------------------------------------------*/
00088 
00089 int main(void)
00090 {
00091     /* Initialize CPL + IRPLIB */
00092     cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
00093 
00094     irplib_detmon_tests();
00095 
00096     return cpl_test_end(0);
00097 }
00098 
00099 static void irplib_detmon_tests(void)
00100 {
00101 
00102     cpl_parameterlist   * parlist;
00103     cpl_frameset        * frameset;
00104     cpl_frameset        * set;
00105 
00106     const char * tag = "RAW";
00107     cpl_error_code error;
00108 
00109     cpl_propertylist * prolist;
00110     /* HIGH LEVEL FUNCTION FOR RON/BIAS RECIPE */
00111 
00112     frameset = irplib_detmon_tests_fill_frameset(tag, tag, 3, TRUE, FALSE, 0);
00113     cpl_test(frameset != NULL);
00114     set = cpl_frameset_duplicate(frameset);
00115     cpl_test(set != NULL);
00116     parlist = cpl_parameterlist_new();
00117     cpl_test(parlist != NULL);
00118     cpl_test_error(CPL_ERROR_NONE);
00119     prolist = irplib_detmon_fill_prolist("PROCATG", "TYPE", "TECH", CPL_TRUE);
00120 
00121     irplib_detmon_ronbias_fill_parlist_default(parlist, "detmon_ronbias", "detmon");
00122 
00123 
00124     irplib_detmon_ronbias(set, parlist, tag, "detmon_ronbias", "detmon",
00125               REGEXP, prolist, NULL, NULL, prolist, prolist,
00126               prolist, prolist,  "DETMON / 1.0", NULL, OPT);
00127 
00128     cpl_test_error(CPL_ERROR_NONE);
00129     cpl_error_reset();
00130 
00131     cpl_parameterlist_delete(parlist);
00132     cpl_frameset_delete(set);
00133 
00134     /* 2. test with extensions */
00135     set = irplib_detmon_tests_fill_frameset(tag, tag, 3, TRUE, TRUE, 4);
00136     parlist = cpl_parameterlist_new();
00137     irplib_detmon_ronbias_fill_parlist(parlist, "detmon_ronbias", "detmon",
00138                        "ALL", /* --method */
00139                        "NORM",/* --pmethod */
00140                        1,     /* --preoverscan_degree */
00141                        -1,    /* --random_nsamples */
00142                        -1,    /* --random_sizex */
00143                        -1,    /* --random_sizey */
00144                        0,     /* --criteria     */
00145                        -1,    /* --ref_llx     */
00146                        -1,    /* --ref_lly */
00147                        -1,    /* --ref_urx */
00148                        -1,    /* --ref_ury */
00149                        "MEAN",/* --stacking_method */
00150                        3,     /* --stacking_ks_low */
00151                        10000, /* --stacking_ks_high */
00152                        25,    /* --stacking_ks_iter */
00153                        0,     /* --master_shift_x */
00154                        0,     /* --master_shift_y */
00155                        -1,    /* --ron_llx */
00156                        -1,    /* --ron_lly */
00157                        -1,    /* --ron_urx */
00158                        -1,    /* --ron_ury */
00159                        -1,    /* --exts */
00160                        OPT);
00161 
00162     error =irplib_detmon_ronbias(set, parlist, tag, "detmon_ronbias", "detmon",
00163                  REGEXP, prolist, NULL, NULL, prolist, prolist,
00164                  prolist, prolist,  "DETMON / 1.0", NULL, OPT);
00165 
00166     /* Move the NULLs away when X and Y structure built */
00167 
00168     cpl_test_eq(error, CPL_ERROR_NONE);
00169     cpl_test_error(CPL_ERROR_NONE);
00170 
00171     cpl_parameterlist_delete(parlist);
00172     cpl_frameset_delete(set);
00173 
00174     cpl_frameset_delete(frameset);
00175     cpl_propertylist_delete(prolist);
00176 
00177 
00178 #ifdef HAVE_FFTW
00179     /* Tests for Periodic Noise Characterisation */
00180 
00181     frameset = irplib_detmon_pernoise_tests_fill_frameset(0,0);
00182 
00183     parlist = cpl_parameterlist_new();
00184     irplib_detmon_fill_pernoise_params_default(parlist,
00185                                                "detmon_pernoise", "detmon");
00186 
00187     irplib_detmon_pernoise(frameset, parlist, "RAW", "detmon_pernoise", "detmon", "PRO-1.15", "DETMON / 1.0", NULL);
00188 
00189     cpl_parameterlist_delete(parlist);
00190     cpl_frameset_delete(frameset);
00191 
00192 #endif
00193 
00194     /* Test for DARK recipe */
00195 
00196     frameset = irplib_detmon_tests_fill_frameset("DARK", "DARK", 20,FALSE, FALSE, 0);
00197     parlist = cpl_parameterlist_new();
00198     error = irplib_detmon_fill_dark_params_default(parlist,
00199                                                "detmon_dark", "detmon");
00200     cpl_test_zero(error);
00201 
00202     irplib_detmon_dark(frameset, parlist, "DARK", "detmon_dark", "detmon",
00203                        "MASTER", "DSNU", "DSNU_TABLE", "DETMON / 1.0", NULL);
00204 
00205     cpl_parameterlist_delete(parlist);
00206     cpl_frameset_delete(frameset);
00207 
00208     /* New test for irplib_imagelist_collapse_stdev_create() */
00209     {
00210     cpl_imagelist * mylist = cpl_imagelist_new();
00211     cpl_image     * image  = cpl_image_new(IMAGESIZE, IMAGESIZE,
00212                            CPL_TYPE_FLOAT);
00213     cpl_image     * collapsed;
00214     double          mean, stdev;
00215 
00216     int i;
00217     for (i = 1; i <= 5; i++) {
00218         cpl_image * to_list =
00219         cpl_image_add_scalar_create(image, 10.0 * i);
00220         cpl_imagelist_set(mylist, to_list, i - 1);
00221     }
00222 
00223     collapsed = irplib_imagelist_collapse_stdev_create(mylist);
00224     mean  = cpl_image_get_mean(collapsed);
00225     stdev = cpl_image_get_stdev(collapsed);
00226 
00227     cpl_test_rel(mean, 15.81138, 1e-4);
00228     cpl_test_zero(stdev);
00229 
00230     cpl_imagelist_delete(mylist);
00231     cpl_image_delete(image);
00232     cpl_image_delete(collapsed);
00233     }
00234 
00235     /* Tests for ksigma_clip() */
00236     {
00237     cpl_image     * image  = cpl_image_new(IMAGESIZE, IMAGESIZE,
00238                            CPL_TYPE_FLOAT);
00239     double mean=0;
00240         double stdev=0;
00241     double mean_bf=0;
00242         double stdev_bf=0;
00243 
00244     cpl_image_fill_noise_uniform(image, 300, 350);
00245 
00246     cpl_image_set(image, 50, 50, 0.0);
00247     cpl_image_set(image, 15, 1, 0.0);
00248     cpl_image_set(image, 76, 32, 0.0);
00249     cpl_image_set(image, 10, 19, 0.0);
00250 
00251     cpl_image_set(image, 30, 10, 6000.0);
00252     cpl_image_set(image, 31, 11, 6020.0);
00253     cpl_image_set(image, 30, 20, 6030.0);
00254     cpl_image_set(image, 30, 40, 6040.0);
00255 
00256     error = irplib_ksigma_clip(image, 1, 1, IMAGESIZE, IMAGESIZE,
00257                    3.0, 10, 1e-5, &mean, &stdev);
00258     cpl_test(error == CPL_ERROR_NONE);
00259     cpl_test(mean  > 320.0 && mean  < 330.0);
00260     cpl_test(stdev > 12.0  && stdev < 18.0 );
00261 
00262 
00263     error = irplib_ksigma_clip_bf(image, 1, 1, IMAGESIZE, IMAGESIZE,
00264                       3.0, 10, &mean_bf, &stdev_bf);
00265 
00266     cpl_test(abs(mean  - mean_bf)  < FLT_EPSILON);
00267     cpl_test(abs(stdev - stdev_bf) < FLT_EPSILON);
00268 
00269     cpl_image_delete(image);
00270     }
00271 
00272     cpl_test_zero(system("rm *.paf *.fits"));
00273 }
00274 
00275 
00276 cpl_frameset * irplib_detmon_pernoise_tests_fill_frameset(cpl_boolean with_exts,
00277                                                           int nexts)
00278 {
00279 
00280     cpl_frameset                * frameset = cpl_frameset_new();
00281     cpl_frame                   * frame;
00282     cpl_propertylist            * plist;
00283 
00284     /* Create dummy image(s) */
00285 
00286     cpl_image * raw1 = cpl_image_new(512, 512, CPL_TYPE_FLOAT);
00287     cpl_image * raw2 = cpl_image_new(512, 512, CPL_TYPE_FLOAT);
00288     int i, j, k = 0;
00289 
00290     cpl_image_fill_noise_uniform(raw1, -2, 2);
00291 
00292     cpl_image_add_scalar(raw1, 100);
00293 
00294 
00295     for(i = 1; i <= 512; i++){
00296         for(j = 1; j <= 512; j++){
00297             int rejected;
00298             double value = cpl_image_get(raw1, j, i, &rejected);
00299             cpl_image_set(raw1, j, i, 4*sin((double)i/16*CPL_MATH_2PI) + value);
00300             if(rejected < 0) {
00301                cpl_msg_error(cpl_func, "Error adding test noise");
00302                k++;
00303             }
00304         }
00305     }
00306 
00307     cpl_image_fill_noise_uniform(raw2, -3, 3);
00308 
00309     frame = cpl_frame_new();
00310     cpl_frame_set_filename(frame, "pertest1.fits");
00311     cpl_frame_set_tag(frame, "RAW");
00312     cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
00313     cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
00314 
00315     cpl_frameset_insert(frameset, frame);
00316 
00317     plist = cpl_propertylist_new();
00318 
00319     cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(3));
00320     cpl_propertylist_append_double(plist, "EXPTIME", (double)(3));
00321     cpl_propertylist_append_double(plist, "MJD-OBS", 0);
00322 
00323 
00324     if(with_exts == TRUE) {
00325         cpl_image_save(NULL, "pertest1.fits", CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
00326         for(j = 0; j < nexts; j++) {
00327             cpl_image_save(raw1, "pertest1.fits", CPL_BPP_IEEE_FLOAT, plist, CPL_IO_EXTEND);
00328         }
00329     } else {
00330         cpl_image_save(raw1, "pertest1.fits", CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
00331     }
00332 
00333 
00334     frame = cpl_frame_new();
00335     cpl_frame_set_filename(frame, "pertest2.fits");
00336     cpl_frame_set_tag(frame, "RAW");
00337     cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
00338     cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
00339 
00340     cpl_frameset_insert(frameset, frame);
00341 
00342     if(with_exts == TRUE) {
00343         cpl_image_save(NULL, "pertest2.fits", CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
00344         for(j = 0; j < nexts; j++) {
00345             cpl_image_save(raw2, "pertest2.fits", CPL_BPP_IEEE_FLOAT, plist, CPL_IO_EXTEND);
00346         }
00347     } else {
00348         cpl_image_save(raw2, "pertest2.fits", CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
00349     }
00350     cpl_propertylist_delete(plist);
00351     cpl_image_delete(raw2);
00352     cpl_image_delete(raw1);
00353 
00354     return frameset;
00355 }
00356 
00357 /*---------------------------------------------------------------------------*/
00358 /*
00359  * @brief  Detect bad pixels of a selected type
00360  * @param  in           Input image
00361  * @param  mean         Mean level of the image - used to compute threshold
00362  * @param  sigma        Stdev level of the image - used to compute threshold
00363  * @param  flag         Flag - represents selected type of bad pixels (see enum)
00364  * @return The detected bad pixels in a cpl_mask.
00365  */
00366 /*---------------------------------------------------------------------------*/
00367 
00368 cpl_frameset * irplib_detmon_tests_fill_frameset(const char     * tag_on,
00369                                                  const char     * tag_off,
00370                                                  int              non,
00371                                                  cpl_boolean      opt_nir,
00372                                                  cpl_boolean      with_exts,
00373                                                  int              nexts)
00374 {
00375     cpl_frameset                * frameset;
00376     cpl_frame                   * frame;
00377     int i;
00378     char                        frame_name[20];
00379     cpl_propertylist            * plist;
00380     cpl_image                   * image;
00381     frameset = cpl_frameset_new();
00382 
00383     for (i=0; i<non; i++) {
00384         frame = cpl_frame_new();
00385         sprintf(frame_name, "dummyon%d.fits",i);
00386         cpl_frame_set_filename(frame, frame_name);
00387         cpl_frame_set_tag(frame, tag_on);
00388         cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
00389         cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
00390 
00391         cpl_frameset_insert(frameset, frame);
00392 
00393         plist = cpl_propertylist_new();
00394         if(opt_nir == TRUE) {
00395             cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(i/2+1));
00396             cpl_propertylist_append_double(plist, "EXPTIME", (double)(i/2+1));
00397             cpl_propertylist_append_double(plist, "MJD-OBS", 100);
00398 
00399         cpl_propertylist_append_int(plist, "NAXIS1", IMAGESIZE);
00400         cpl_propertylist_append_int(plist, "NAXIS2", IMAGESIZE);
00401         cpl_propertylist_append_int(plist, "ESO DET OUT1 NX", IMAGESIZE + 10 );
00402         cpl_propertylist_append_int(plist, "ESO DET OUT1 NY", IMAGESIZE);
00403         cpl_propertylist_append_int(plist, "ESO DET OUT1 PRSCX", 5);
00404         cpl_propertylist_append_int(plist, "ESO DET OUT1 OVSCX", 5);
00405         } else {
00406             cpl_propertylist_append_double(plist, "ESO DET DIT", (double)((i+1)/2));
00407             cpl_propertylist_append_double(plist, "EXPTIME", (double)((i+1)/2));
00408             cpl_propertylist_append_double(plist, "MJD-OBS",100);
00409 
00410         cpl_propertylist_append_int(plist, "NAXIS1", IMAGESIZE);
00411         cpl_propertylist_append_int(plist, "NAXIS2", IMAGESIZE);
00412         cpl_propertylist_append_int(plist, "ESO DET OUT1 NX", IMAGESIZE + 10 );
00413         cpl_propertylist_append_int(plist, "ESO DET OUT1 NY", IMAGESIZE);
00414         cpl_propertylist_append_int(plist, "ESO DET OUT1 PRSCX", 5);
00415         cpl_propertylist_append_int(plist, "ESO DET OUT1 OVSCX", 5);
00416 
00417         }
00418 
00419         if(with_exts == TRUE) {
00420           int j;
00421           cpl_image_save(NULL, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
00422           for(j = 0; j < nexts; j++) {
00423             image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00424             cpl_image_fill_noise_uniform(image, 25, 50);
00425             cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
00426         cpl_image_add_scalar(image, 300);
00427 
00428         cpl_image_set(image, 10, 10, 0.0);
00429         cpl_image_set(image, 11, 11, 0.0);
00430         cpl_image_set(image, 20, 20, 0.0);
00431         cpl_image_set(image, 10, 40, 0.0);
00432         cpl_image_set(image, 40, 10, 0.0);
00433         cpl_image_set(image, 12, 32, 0.0);
00434         cpl_image_set(image, 50, 50, 0.0);
00435         cpl_image_set(image, 15, 1, 0.0);
00436         cpl_image_set(image, 76, 32, 0.0);
00437         cpl_image_set(image, 10, 19, 0.0);
00438 
00439         cpl_image_set(image, 30, 10, 6000.0);
00440         cpl_image_set(image, 31, 11, 6020.0);
00441         cpl_image_set(image, 30, 20, 6030.0);
00442         cpl_image_set(image, 30, 40, 6040.0);
00443         cpl_image_set(image, 30, 10, 6070.0);
00444         cpl_image_set(image, 52, 32, 6300.0);
00445         cpl_image_set(image, 60, 50, 6500.0);
00446         cpl_image_set(image, 85, 1, 6100.0);
00447         cpl_image_set(image, 86, 32, 6040.0);
00448         cpl_image_set(image, 90, 19, 6020.0);
00449 
00450             cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_EXTEND);
00451             cpl_image_delete(image);
00452           }
00453         } else {
00454             image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00455             cpl_image_fill_noise_uniform(image, 25, 50);
00456             cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
00457         cpl_image_add_scalar(image, 300);
00458         cpl_image_set(image, 10, 10, 0.0);
00459         cpl_image_set(image, 11, 11, 0.0);
00460         cpl_image_set(image, 20, 20, 0.0);
00461         cpl_image_set(image, 10, 40, 0.0);
00462         cpl_image_set(image, 40, 10, 0.0);
00463         cpl_image_set(image, 12, 32, 0.0);
00464         cpl_image_set(image, 50, 50, 0.0);
00465         cpl_image_set(image, 15, 1, 0.0);
00466         cpl_image_set(image, 76, 32, 0.0);
00467         cpl_image_set(image, 10, 19, 0.0);
00468 
00469         cpl_image_set(image, 30, 10, 6000.0);
00470         cpl_image_set(image, 31, 11, 6020.0);
00471         cpl_image_set(image, 30, 20, 6030.0);
00472         cpl_image_set(image, 30, 40, 6040.0);
00473         cpl_image_set(image, 30, 10, 6070.0);
00474         cpl_image_set(image, 52, 32, 6300.0);
00475         cpl_image_set(image, 60, 50, 6500.0);
00476         cpl_image_set(image, 85, 1, 6100.0);
00477         cpl_image_set(image, 86, 32, 6040.0);
00478         cpl_image_set(image, 90, 19, 6020.0);
00479 
00480             cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
00481 
00482 
00483             cpl_image_delete(image);
00484         }
00485         cpl_propertylist_delete(plist);
00486 
00487 
00488         frame = cpl_frame_new();
00489         sprintf(frame_name, "dummyoff%d.fits",i);
00490         cpl_frame_set_filename(frame, frame_name);
00491         cpl_frame_set_tag(frame, tag_off);
00492         cpl_frame_set_type(frame, CPL_FRAME_TYPE_IMAGE);
00493         cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
00494 
00495         cpl_frameset_insert(frameset, frame);
00496 
00497         plist = cpl_propertylist_new();
00498         if(opt_nir == TRUE) {
00499             cpl_propertylist_append_double(plist, "ESO DET DIT", (double)(i/2+1));
00500             cpl_propertylist_append_double(plist, "EXPTIME", (double)(i/2+1));
00501             cpl_propertylist_append_double(plist, "MJD-OBS", 100);
00502 
00503         cpl_propertylist_append_int(plist, "NAXIS1", IMAGESIZE);
00504         cpl_propertylist_append_int(plist, "NAXIS2", IMAGESIZE);
00505         cpl_propertylist_append_int(plist, "ESO DET OUT1 NX", IMAGESIZE + 10 );
00506         cpl_propertylist_append_int(plist, "ESO DET OUT1 NY", IMAGESIZE);
00507         cpl_propertylist_append_int(plist, "ESO DET OUT1 PRSCX", 5);
00508         cpl_propertylist_append_int(plist, "ESO DET OUT1 OVSCX", 5);
00509         } else {
00510             cpl_propertylist_append_double(plist, "ESO DET DIT", (double)((i+1)/2));
00511             cpl_propertylist_append_double(plist, "EXPTIME", (double)((i+1)/2));
00512             cpl_propertylist_append_double(plist, "MJD-OBS", 100);
00513 
00514         cpl_propertylist_append_int(plist, "NAXIS1", IMAGESIZE);
00515         cpl_propertylist_append_int(plist, "NAXIS2", IMAGESIZE);
00516         cpl_propertylist_append_int(plist, "ESO DET OUT1 NX", IMAGESIZE + 10 );
00517         cpl_propertylist_append_int(plist, "ESO DET OUT1 NY", IMAGESIZE);
00518         cpl_propertylist_append_int(plist, "ESO DET OUT1 PRSCX", 5);
00519         cpl_propertylist_append_int(plist, "ESO DET OUT1 OVSCX", 5);
00520         }
00521 
00522         if(with_exts == TRUE) {
00523           int j;
00524           cpl_image_save(NULL, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
00525           for(j = 0; j < nexts; j++) {
00526             image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00527             cpl_image_fill_noise_uniform(image, 25, 50);
00528             cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
00529         cpl_image_add_scalar(image, 300);
00530         cpl_image_set(image, 10, 10, 0.0);
00531         cpl_image_set(image, 11, 11, 0.0);
00532         cpl_image_set(image, 20, 20, 0.0);
00533         cpl_image_set(image, 10, 40, 0.0);
00534         cpl_image_set(image, 40, 10, 0.0);
00535         cpl_image_set(image, 12, 32, 0.0);
00536         cpl_image_set(image, 50, 50, 0.0);
00537         cpl_image_set(image, 15, 1, 0.0);
00538         cpl_image_set(image, 76, 32, 0.0);
00539         cpl_image_set(image, 10, 19, 0.0);
00540 
00541         cpl_image_set(image, 30, 10, 6000.0);
00542         cpl_image_set(image, 31, 11, 6020.0);
00543         cpl_image_set(image, 30, 20, 6030.0);
00544         cpl_image_set(image, 30, 40, 6040.0);
00545         cpl_image_set(image, 30, 10, 6070.0);
00546         cpl_image_set(image, 52, 32, 6300.0);
00547         cpl_image_set(image, 60, 50, 6500.0);
00548         cpl_image_set(image, 85, 1, 6100.0);
00549         cpl_image_set(image, 86, 32, 6040.0);
00550         cpl_image_set(image, 90, 19, 6020.0);
00551 
00552             cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_EXTEND);
00553             cpl_image_delete(image);
00554           }
00555         } else {
00556             image = cpl_image_new(IMAGESIZE, IMAGESIZE, CPL_TYPE_FLOAT);
00557             cpl_image_fill_noise_uniform(image, 25, 50);
00558             cpl_ensure(cpl_error_get_code()== CPL_ERROR_NONE, CPL_ERROR_NULL_INPUT, NULL);
00559         cpl_image_add_scalar(image, 300);
00560         cpl_image_set(image, 10, 10, 0.0);
00561         cpl_image_set(image, 11, 11, 0.0);
00562         cpl_image_set(image, 20, 20, 0.0);
00563         cpl_image_set(image, 10, 40, 0.0);
00564         cpl_image_set(image, 40, 10, 0.0);
00565         cpl_image_set(image, 12, 32, 0.0);
00566         cpl_image_set(image, 50, 50, 0.0);
00567         cpl_image_set(image, 15, 1, 0.0);
00568         cpl_image_set(image, 76, 32, 0.0);
00569         cpl_image_set(image, 10, 19, 0.0);
00570 
00571         cpl_image_set(image, 30, 10, 6000.0);
00572         cpl_image_set(image, 31, 11, 6020.0);
00573         cpl_image_set(image, 30, 20, 6030.0);
00574         cpl_image_set(image, 30, 40, 6040.0);
00575         cpl_image_set(image, 30, 10, 6070.0);
00576         cpl_image_set(image, 52, 32, 6300.0);
00577         cpl_image_set(image, 60, 50, 6500.0);
00578         cpl_image_set(image, 85, 1, 6100.0);
00579         cpl_image_set(image, 86, 32, 6040.0);
00580         cpl_image_set(image, 90, 19, 6020.0);
00581 
00582             cpl_image_save(image, frame_name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
00583 
00584 
00585             cpl_image_delete(image);
00586         }
00587         cpl_propertylist_delete(plist);
00588     }
00589 
00590     return frameset;
00591 }
00592 
00607 static cpl_error_code
00608 irplib_ksigma_clip_bf(cpl_image * img,
00609               const int llx,
00610               const int lly,
00611               const int urx, int ury,
00612               const int kappa,
00613               const int nclip,
00614               double *clean_mean, double *clean_stdev)
00615 {
00616 
00617 
00618     double                  mean = 0;
00619     double                  stdev = 0;
00620     double                  threshold = 0;
00621     double                  lo_cut = 0;
00622     double                  hi_cut = 0;
00623     double                  lo_cut_p = 0;
00624     double                  hi_cut_p = 0;
00625 
00626     cpl_mask               *mask = NULL;
00627     cpl_image              *tmp = NULL;
00628     cpl_stats              *stats = NULL;
00629     int                     i = 0;
00630 
00631     if((tmp = cpl_image_extract(img, llx, lly, urx, ury)) == NULL) {
00632         cpl_msg_error(cpl_func, "Error extracting window");
00633         return -1;
00634     }
00635     cpl_image_accept_all(tmp);
00636     for(i = 0; i < nclip; i++) {
00637 
00638 
00639         cpl_stats_delete(stats);
00640         stats =
00641             cpl_stats_new_from_image(tmp, CPL_STATS_MEAN | CPL_STATS_STDEV);
00642         mean = cpl_stats_get_mean(stats);
00643         stdev = cpl_stats_get_stdev(stats);
00644 
00645         threshold = kappa * stdev;
00646         lo_cut = mean - threshold;
00647         hi_cut = mean + threshold;
00648 
00649         cpl_image_accept_all(tmp);
00650         mask = cpl_mask_threshold_image_create(tmp, lo_cut, hi_cut);
00651 
00652         cpl_mask_not(mask);
00653         cpl_image_reject_from_mask(tmp, mask);
00654         cpl_mask_delete(mask);
00655         if(lo_cut_p == lo_cut && hi_cut_p == hi_cut)
00656             break;
00657         else {
00658             lo_cut_p = lo_cut;
00659             hi_cut_p = hi_cut;
00660         }
00661 
00662     }
00663     *clean_mean = mean;
00664     *clean_stdev = stdev;
00665     cpl_image_delete(tmp);
00666     cpl_stats_delete(stats);
00667 
00668     return cpl_error_get_code();
00669 
00670 
00671 }
00672 

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