sinfo_new_dark.c

00001 /*
00002  * This file is part of the ESO SINFONI Pipeline
00003  * Copyright (C) 2004,2005 European Southern Observatory
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
00018  */
00019 /*----------------------------------------------------------------------------
00020    
00021    File name    :       sinfo_new_dark.c
00022    Author       :    A. Modigliani
00023    Created on   :    Sep 17, 2003
00024    Description  :    Master sinfo_dark creation 
00025 
00026  ---------------------------------------------------------------------------*/
00027 #ifdef HAVE_CONFIG_H
00028 #  include <config.h>
00029 #endif
00030 
00031 /*----------------------------------------------------------------------------
00032                                 Includes
00033  ---------------------------------------------------------------------------*/
00034 #include "sinfo_new_dark.h"
00035 #include "sinfo_utilities.h"
00036 #include "sinfo_pro_save.h"
00037 #include "sinfo_dark_ini_by_cpl.h"
00038 #include "sinfo_dfs.h"
00039 #include "sinfo_pfits.h"
00040 #include "sinfo_error.h"
00041 #include "sinfo_utils_wrappers.h"
00042 /*----------------------------------------------------------------------------
00043                                 Defines
00044  ---------------------------------------------------------------------------*/
00045 static int sinfo_dark_ron_reduce(cpl_frameset * framelist,
00046                             dark_config* cfg,
00047                             cpl_table* qclog);
00048 
00049 
00050 static int 
00051 sinfo_dark_compare(const cpl_frame * frame1, const cpl_frame * frame2);
00052 
00062 /*----------------------------------------------------------------------------
00063                              Function Definitions
00064  ---------------------------------------------------------------------------*/
00065 
00066 /*----------------------------------------------------------------------------
00067    @name  sinfo_new_dark()
00068    @param  plugin_id recipe id
00069    @param  config input parameterlist
00070    @param  sof    input set of frames
00071    @return integer (0 if it worked, -1 if it doesn't) 
00072    @doc 
00073                   1) Sorts frames according to integration time
00074                   2) Take the clean mean of a stack of frames with the 
00075                   same integration time
00076 
00077  ---------------------------------------------------------------------------*/
00078 
00079 int sinfo_new_dark (const char* plugin_id, cpl_parameterlist* config, 
00080           cpl_frameset* sof, char* dark_name)
00081 {
00082     
00083     dark_config * cfg=NULL ;
00084     cpl_imagelist * image_list=NULL ;
00085     cpl_imagelist * object_list=NULL ;
00086 
00087    
00088     cpl_image * image=NULL ;
00089     cpl_image * eclipse_image=NULL ;
00090 
00091     cpl_image* dark_img=NULL;
00092     cpl_frame* first_frame=NULL;
00093     cpl_vector* qc_dark_median=NULL;
00094     cpl_frameset* raw=NULL;
00095     cpl_table* qclog_tbl=NULL;
00096     cpl_propertylist* rplist=NULL;
00097     cpl_frameset* f_one=NULL;
00098     int no=0;
00099     float lo_cut=0.;
00100     float hi_cut=0.;
00101 
00102     int i = 0;
00103     int j = 0;
00104     int n = 0;
00105     int count = 0;
00106     int* n_times=NULL;
00107     double exp_time = 0.;    
00108     float* int_time=NULL;   
00109     float time_val = 0.; 
00110 
00111     char   ref_file[MAX_NAME_SIZE];
00112     int zone_def[4];
00113     double qc_ron_val=0;
00114     double qc_ron_err=0;
00115     double qc_darkmed_ave=0;
00116     double qc_darkmed_stdev=0;
00117     double fpn=0;
00118     int zone[4];
00119     int naxis1=0;
00120     int naxis2=0;
00121 
00122     int* selection=NULL;
00123     int nsets=0;
00124     /* 
00125        -----------------------------------------------------------------
00126        1) parse the file names and parameters to the dark_config data 
00127           structure cfg 
00128        -----------------------------------------------------------------
00129      */
00130  
00131     check_nomsg(raw=cpl_frameset_new());
00132     cknull(cfg = sinfo_parse_cpl_input_dark(config,sof,&raw),
00133            "could not parse cpl input!") ;
00134 
00135     /* 
00136        -----------------------------------------------------------------
00137        2) GET FRAMES AND SORT ACCORDING TO EXPOSURE TIME 
00138        -----------------------------------------------------------------
00139      */
00140      
00141     /* 
00142        2.1) get the total integration time from the fits header and 
00143             store it in an array
00144      */
00145 
00146     /* 2.1.1) get a data cube to stack darks */
00147     sinfo_msg("Build data cube");
00148     /* take a clean mean of the frames */
00149     check_nomsg(image_list = cpl_imagelist_new());
00150     int_time = (float*) cpl_calloc(cfg -> nframes, sizeof(float)) ;
00151     sinfo_check_rec_status(0);
00152  
00153     for ( i = 0 ; i < cfg->nframes ; i++ )
00154     {
00155         if (sinfo_is_fits_file (cfg->inFrameList[i]) != 1) {
00156        sinfo_msg_error("Input file %s is not FITS",cfg->inFrameList[i]);
00157            goto cleanup;
00158         }
00159 
00160     check_nomsg(cpl_imagelist_set(image_list,
00161                     cpl_image_load(cfg->inFrameList[i],CPL_TYPE_FLOAT,0,0),i));
00162 
00163         exp_time = sinfo_pfits_get_exptime(cfg->inFrameList[i]);
00164     if(cpl_error_get_code() != CPL_ERROR_NONE) {
00165        sinfo_msg_error("could not get exposure time from fits header!\n");
00166            goto cleanup;
00167     }
00168         sinfo_new_array_set_value(int_time, (float)exp_time, i);
00169     }
00170     no=cfg->nframes;
00171 
00172 
00173     /*
00174        2.2) find the number of frames with the same integration time
00175      */
00176     sinfo_msg("Find frames with same tint");
00177     n = 0;
00178 
00179     n_times = (int*) cpl_calloc(cfg -> nframes, sizeof(int));
00180     sinfo_msg("Sort frames with same tint");
00181 
00182     for ( i = 0 ; i < cfg->nframes-1 ; i++ )
00183     {
00184          if ( sinfo_new_array_get_value(int_time, i+1) != 
00185               sinfo_new_array_get_value(int_time, i)
00186         ) {
00187 
00188     n_times[n] = i+1;
00189         n = n+1;
00190     }
00191     
00192     }
00193 
00194     /* 
00195        2.3) store the images with the same tint in data cubes and take 
00196             clean means
00197      */
00198     sinfo_msg("Do clean mean");
00199     if ( n == 0 ) {
00200 
00201       sinfo_msg("n == 0 ");
00202        time_val = sinfo_new_array_get_value(int_time, 0);
00203 
00204       cknull(object_list = cpl_imagelist_new(),
00205          "could not allocate memory for object_list");
00206 
00207        /* here we have a leak of 80 bytes */
00208 
00209 
00210        count = 0;
00211        /* do also QC log */
00212        check_nomsg(qc_dark_median=cpl_vector_new(cfg->nframes));
00213 
00214        /* AMo here there is a leak */
00215        for ( j = 0 ; j < cfg->nframes ; j++ ) {
00216      check_nomsg(cpl_imagelist_set(object_list,
00217                      cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
00218                      count));
00219      check_nomsg(cpl_vector_set(qc_dark_median,j,
00220                      cpl_image_get_median(cpl_imagelist_get(image_list,j))));
00221          count = count + 1;
00222        }
00223 
00224 
00225  
00226        check_nomsg(qc_darkmed_ave=cpl_vector_get_mean(qc_dark_median));
00227        if (cfg->nframes > 1) {
00228           check_nomsg(qc_darkmed_stdev=cpl_vector_get_stdev(qc_dark_median));
00229        }
00230        /* 
00231         rms   = stdev * sqrt(1-1/(double)cpl_vector_get_size(myvector)); 
00232        qc_darkmed_stdev = qc_darkmed_stdev * 
00233                        sqrt(1-1/(double)cpl_vector_get_size(qc_dark_median));
00234         */  
00235 
00236        check_nomsg(no=cpl_imagelist_get_size(object_list));
00237        lo_cut=(floor)(cfg->lo_reject*no+0.5);
00238        hi_cut=(floor)(cfg->hi_reject*no+0.5);
00239 
00240  
00241   
00242        cknull(image=cpl_imagelist_collapse_minmax_create(object_list,
00243                                                          lo_cut,hi_cut),
00244           "sinfo_average_with_rejection failed");
00245 
00246        sinfo_free_imagelist(&object_list);
00247 
00248        sinfo_msg("dark_name=%s\n",dark_name);
00249        
00250        check_nomsg(first_frame = cpl_frameset_get_frame(raw, 0)) ;
00251    
00252        strcpy(ref_file,cpl_frame_get_filename(first_frame)) ;
00253        cknull_nomsg(rplist = cpl_propertylist_load(ref_file, 0));
00254 
00255        check_nomsg(naxis1=cpl_propertylist_get_int(rplist,"NAXIS1"));
00256        check_nomsg(naxis2=cpl_propertylist_get_int(rplist,"NAXIS1"));
00257        sinfo_free_propertylist(&rplist);
00258 
00259        if(cfg->qc_ron_xmin < 1) {
00260      sinfo_msg_error("qc_ron_xmin %d < 1",cfg->qc_ron_xmin);
00261          goto cleanup;
00262        }
00263 
00264        if(cfg->qc_ron_xmax > naxis1) {
00265      sinfo_msg_error("qc_ron_xmax %d > %d",cfg->qc_ron_xmax,naxis1);
00266          goto cleanup;
00267        }
00268 
00269        if(cfg->qc_ron_ymin < 1) {
00270      sinfo_msg_error("qc_ron_ymin %d < 1",cfg->qc_ron_ymin);
00271          goto cleanup;
00272        }
00273 
00274        if(cfg->qc_ron_ymax > naxis2) {
00275      sinfo_msg_error("qc_ron_ymax %d > %d",cfg->qc_ron_ymax,naxis2);
00276          goto cleanup;
00277        }
00278 
00279        zone_def[0]=cfg->qc_ron_xmin;
00280        zone_def[1]=cfg->qc_ron_xmax;
00281        zone_def[2]=cfg->qc_ron_ymin;
00282        zone_def[3]=cfg->qc_ron_ymax;
00283 
00284 
00285 
00286        check(cpl_flux_get_noise_window(image,
00287                        zone_def,
00288                        cfg->qc_ron_hsize,
00289                        cfg->qc_ron_nsamp,
00290                        &qc_ron_val,
00291                        &qc_ron_err),
00292          "In computation RON on image %s",dark_name);
00293       
00294  
00295 
00296        if(cfg->qc_fpn_xmin < 1) {
00297      sinfo_msg_error("qc_fpn_xmin %d < 1",cfg->qc_fpn_xmin);
00298          goto cleanup;
00299        }
00300 
00301        if(cfg->qc_fpn_xmax > naxis1) {
00302      sinfo_msg_error("qc_fpn_xmax %d > %d",cfg->qc_fpn_xmax,naxis1);
00303          goto cleanup;
00304        }
00305 
00306        if(cfg->qc_fpn_ymin < 1) {
00307      sinfo_msg_error("qc_fpn_ymin %d < 1",cfg->qc_fpn_ymin);
00308          goto cleanup;
00309        }
00310 
00311        if(cfg->qc_fpn_ymax > naxis2) {
00312      sinfo_msg_error("qc_fpn_ymax %d > %d",cfg->qc_fpn_ymax,naxis2);
00313          goto cleanup;
00314        }
00315 
00316        zone[0]=cfg->qc_fpn_xmin;
00317        zone[1]=cfg->qc_fpn_xmax;
00318        zone[2]=cfg->qc_fpn_ymin;
00319        zone[3]=cfg->qc_fpn_ymax;
00320        check(cpl_flux_get_noise_window(image, zone, cfg->qc_fpn_hsize,
00321                        cfg->qc_fpn_nsamp, &fpn, NULL),
00322          "Error computing noise in a window");
00323 
00324        /* QC LOG */
00325        cknull_nomsg(qclog_tbl = sinfo_qclog_init());
00326 
00327        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC DARKMED AVE",
00328              qc_darkmed_ave,"Average of raw darks medians","%f"));
00329 
00330        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC DARKMED STDEV",
00331                      qc_darkmed_stdev,"STDEV of raw darks medians","%f"));
00332 
00333        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC RON",
00334                      qc_ron_val,"Read Out Noise","%f"));
00335        
00336        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC RONRMS",
00337                      qc_ron_err,"RMS on Read Out Noise","%f"));
00338 
00339        ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC DARKFPN",
00340                      fpn,"Fixed Pattern Noise of combined frames","%g"));
00341 
00342  
00343        /* special way to calculate RON: for each couple */
00344        
00345        check(selection = cpl_frameset_labelise(raw,sinfo_dark_compare,&nsets),
00346          "Error labelizing");
00347 
00348 
00349 
00350        for ( i = 0 ; i < nsets ; i++ ) {
00351          sinfo_msg("Reduce data set no %d out of %d", i+1, nsets);
00352          cpl_msg_indent_more();
00353      check_nomsg(f_one = cpl_frameset_extract(raw,selection,i));
00354          if (cpl_frameset_get_size(f_one) < 2) {
00355            sinfo_msg_warning("Skip %d set. One frame, not enough "
00356                              "to get ron",i+1);
00357      } else {
00358            if (sinfo_dark_ron_reduce(f_one,cfg,qclog_tbl) ) {
00359          sinfo_msg_warning( "Cannot reduce set number %d", i+1) ;
00360        }
00361      }
00362          sinfo_free_frameset(&f_one);
00363          cpl_msg_indent_less();
00364 
00365        }
00366        sinfo_free_int(&selection);
00367 
00368 
00369        /* generate a dummy_set with the master dark and a dummy 
00370               dark=2*master_dark */
00371 
00372        ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
00373                  PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
00374                            "cannot save ima %s", dark_name);
00375        sinfo_free_table(&qclog_tbl);
00376        sinfo_free_image(&image);
00377  
00378     } else if (n == 1) {
00379 
00380        sinfo_msg("n == 1");
00381        time_val = sinfo_new_array_get_value(int_time, 0);
00382        cknull(object_list = cpl_imagelist_new(),
00383            "could not allocate memory");
00384 
00385        count = 0;
00386 
00387        for (j =0; j < n_times[0]; j++) {
00388 
00389      check_nomsg(cpl_imagelist_set(object_list,
00390                      cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
00391                      count));
00392      count = count + 1;
00393        }
00394 
00395 
00396        check_nomsg(no=cpl_imagelist_get_size(object_list));
00397        lo_cut=(floor)(cfg->lo_reject*no+0.5);
00398        hi_cut=(floor)(cfg->hi_reject*no+0.5);
00399        check(image=cpl_imagelist_collapse_minmax_create(object_list,
00400                                                         lo_cut,hi_cut),
00401                                  "sinfo_average_with_rejection failed!");
00402 
00403        sinfo_free_imagelist(&object_list);
00404 
00405        cknull_nomsg(qclog_tbl = sinfo_qclog_init());
00406        ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
00407                                      "A description","%d"));
00408 
00409        ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
00410                   PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
00411                           "cannot save ima %s", dark_name);
00412 
00413 
00414        sinfo_free_image(&image);
00415        sinfo_free_table(&qclog_tbl);
00416 
00417        time_val = sinfo_new_array_get_value(int_time, n_times[0]);
00418        cknull(object_list = cpl_imagelist_new(),
00419           "could not allocate memory");
00420        count = 0;
00421 
00422 
00423        for (j = n_times[0]; j < cfg->nframes; j++) {
00424 
00425      check_nomsg(cpl_imagelist_set(object_list,
00426                      cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
00427                      count));
00428          count = count + 1;
00429        }
00430 
00431 
00432        check_nomsg(no=cpl_imagelist_get_size(object_list));
00433        lo_cut=(floor)(cfg->lo_reject*no+0.5);
00434        hi_cut=(floor)(cfg->hi_reject*no+0.5);
00435        cknull(eclipse_image=cpl_imagelist_collapse_minmax_create(object_list,
00436                                                                  lo_cut,hi_cut),
00437           "sinfo_average_with_rejection failed!");
00438 
00439        sinfo_free_imagelist(&object_list);
00440 
00441 
00442        cknull_nomsg(qclog_tbl = sinfo_qclog_init());
00443        ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
00444                                      "A description","%d"));
00445 
00446        ck0(sinfo_pro_save_ima(eclipse_image,raw,sof,dark_name,
00447                   PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
00448                           "cannot save ima %s", dark_name);
00449 
00450        sinfo_free_image(&eclipse_image);
00451        sinfo_free_table(&qclog_tbl);
00452 
00453     } else {
00454 
00455        sinfo_msg("n==else\n");
00456 
00457        for (i= 0; i < n+1; i++) {
00458          if ( i == 0 ) {
00459            time_val = sinfo_new_array_get_value(int_time, 0);
00460         check(object_list = cpl_imagelist_new(),
00461                "could not allocate memory");
00462 
00463             count = 0;
00464             for (j = 0; j < n_times[0]; j++) {
00465           check_nomsg(cpl_imagelist_set(object_list,
00466                           cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
00467                           count));
00468           count = count + 1;
00469         }
00470         check_nomsg(no=cpl_imagelist_get_size(object_list));
00471         lo_cut=(floor)(cfg->lo_reject*no+0.5);
00472         hi_cut=(floor)(cfg->hi_reject*no+0.5);
00473             check(image=cpl_imagelist_collapse_minmax_create(object_list,
00474                                                              lo_cut,hi_cut),
00475                                     "Error computing average with rejection");
00476             sinfo_free_imagelist(&object_list);
00477 
00478             sinfo_msg("dark_name-%s\n",dark_name);
00479             cknull_nomsg(qclog_tbl = sinfo_qclog_init());
00480             ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
00481                                           "A description","%d"));
00482 
00483             ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
00484                    PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
00485               "cannot save ima %s", dark_name);
00486 
00487 
00488             sinfo_free_table(&qclog_tbl);
00489             sinfo_free_image(&image);
00490      } else if ( i == n ) {
00491             time_val = sinfo_new_array_get_value(int_time, n_times[n-1]);
00492             cknull(object_list = cpl_imagelist_new(), 
00493                "could not allocate memory");
00494 
00495             count = 0;
00496             for (j = n_times[n-1]; j < cfg->nframes; j++) {
00497           check_nomsg(cpl_imagelist_set(object_list,
00498                           cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
00499                           count));
00500           count = count + 1;
00501         }
00502         check_nomsg(no=cpl_imagelist_get_size(object_list));
00503         lo_cut=(floor)(cfg->lo_reject*no+0.5);
00504         hi_cut=(floor)(cfg->hi_reject*no+0.5);
00505             check(image=cpl_imagelist_collapse_minmax_create(object_list,
00506                                                              lo_cut,hi_cut),
00507                   "Error computing average with rejection");
00508 
00509             sinfo_free_imagelist(&object_list);
00510 
00511             cknull_nomsg(qclog_tbl = sinfo_qclog_init());
00512             ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
00513                                           "A description","%d"));
00514 
00515             ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
00516                    PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
00517         "cannot save ima %s", dark_name);
00518             sinfo_free_table(&qclog_tbl);
00519             sinfo_free_image(&image);
00520     } else {
00521         time_val = sinfo_new_array_get_value(int_time, n_times[i-1]);
00522         cknull(object_list = cpl_imagelist_new(), 
00523                    "could not allocate memory");
00524 
00525             count = 0;
00526             for (j = n_times[i-1]; j < n_times[i]; j++) {
00527           check_nomsg(cpl_imagelist_set(object_list,
00528                           cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
00529                           count));
00530           count = count + 1;
00531         }
00532         check_nomsg(no=cpl_imagelist_get_size(object_list));
00533         lo_cut=(floor)(cfg->lo_reject*no+0.5);
00534         hi_cut=(floor)(cfg->hi_reject*no+0.5);
00535             cknull(image=cpl_imagelist_collapse_minmax_create(object_list,
00536                                                               lo_cut,hi_cut),
00537                                      "Error computing average with rejection");
00538 
00539             sinfo_free_imagelist(&object_list);
00540 
00541             cknull_nomsg(qclog_tbl = sinfo_qclog_init());
00542             ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
00543                                           "A description","%d"));
00544 
00545             ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
00546                    PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
00547                                    "cannot save ima %s", dark_name);
00548 
00549             sinfo_free_image(&image);
00550             sinfo_free_table(&qclog_tbl);
00551     }
00552        
00553        } /* end for loop */
00554     } /* end else over n */
00555 
00556  
00557 
00558        sinfo_free_imagelist(&image_list);
00559        sinfo_free_my_vector(&qc_dark_median);
00560        sinfo_free_int(&n_times);
00561        sinfo_free_float(&int_time);
00562        sinfo_dark_free(&cfg);
00563        sinfo_free_frameset(&raw);
00564 
00565       return 0;
00566 
00567  cleanup:
00568        sinfo_free_frameset(&f_one);
00569        sinfo_free_int(&selection);
00570        sinfo_free_image(&eclipse_image);
00571        sinfo_free_table(&qclog_tbl);
00572        sinfo_free_image(&dark_img);
00573        sinfo_free_image(&image);
00574        sinfo_free_propertylist(&rplist);
00575        sinfo_free_my_vector(&qc_dark_median);
00576        sinfo_free_imagelist(&object_list);
00577        sinfo_free_int(&n_times);
00578        sinfo_free_float(&int_time);
00579        sinfo_free_imagelist(&image_list);
00580        sinfo_dark_free(&cfg);
00581        sinfo_free_frameset(&raw);
00582 
00583        return -1;
00584 
00585 }
00586 
00587 
00588 
00589 
00590 
00591 
00592 /*--------------------------------------------------------------------*/
00599 /*--------------------------------------------------------------------*/
00600  static int 
00601 sinfo_dark_ron_reduce(cpl_frameset    *   framelist,
00602               dark_config     *   cfg,
00603               cpl_table       *   qclog_tbl)
00604 {
00605   cpl_imagelist   *   iset =NULL;
00606   int                 i =0;
00607   double* ron=NULL;
00608   int nraw=0;
00609   int niset=0;
00610   char key_name[MAX_NAME_SIZE];
00611   /* Test entries */
00612 
00613   cknull_nomsg(framelist);
00614 
00615   /* Load the current set */
00616   if ((iset = sinfo_new_frameset_to_iset(framelist)) == NULL) {
00617     sinfo_msg_error( "Cannot load the data") ;
00618     return -1 ;
00619   }
00620   /* Loop on all pairs */
00621   nraw = cpl_table_get_nrow(qclog_tbl);
00622   niset=cpl_imagelist_get_size(iset);
00623 
00624   ron = cpl_calloc(niset,sizeof(double));
00625 
00626   sinfo_get_ron(framelist,
00627                 cfg->qc_ron_xmin,cfg->qc_ron_xmax,
00628                 cfg->qc_ron_ymin,cfg->qc_ron_ymax,
00629                 cfg->qc_ron_hsize,cfg->qc_ron_nsamp,
00630                 &ron);
00631 
00632   for (i=0 ; i<niset-1 ; i++) {
00633 
00634     /* Write the paf file on disk */
00635     /* Write QC LOG */
00636 
00637     snprintf(key_name,MAX_NAME_SIZE-1,"%s%d","QC RON",i+1);
00638     sinfo_qclog_add_double(qclog_tbl,key_name,ron[i],
00639                "Read Out Noise","%f");
00640 
00641   }
00642 
00643   cpl_free(ron);
00644   sinfo_free_imagelist(&iset) ;
00645 
00646   return 0 ;
00647  cleanup:
00648   cpl_free(ron);
00649   ron=NULL;
00650   sinfo_free_imagelist(&iset) ;
00651 
00652   return -1;
00653 
00654 }
00655 
00656 
00657 /*---------------------------------------------------------------------------*/
00664 /*---------------------------------------------------------------------------*/
00665 static int sinfo_dark_compare(
00666         const cpl_frame   *   frame1,
00667         const cpl_frame   *   frame2)
00668 {
00669     int                 comparison=0 ;
00670     cpl_propertylist *  plist1=NULL;
00671     cpl_propertylist *  plist2=NULL;
00672 
00673     char            *   sval ;
00674     char                mode1[512] ;
00675     char                mode2[512] ;
00676     double              dval1=0;
00677     double              dval2=0;
00678     int                 ival1=0;
00679     int                 ival2=0;
00680 
00681     /* Test entries */
00682     if (frame1==NULL || frame2==NULL) return -1 ;
00683 
00684     /* Get property lists */
00685     cknull(plist1=cpl_propertylist_load(cpl_frame_get_filename(frame1),0),
00686         "getting header from reference frame");
00687 
00688     cknull(plist2=cpl_propertylist_load(cpl_frame_get_filename(frame2),0),
00689         "getting header from reference frame");
00690      
00691     /* Compare exposure time */
00692     comparison = 1 ;
00693     check(dval1=sinfo_pfits_get_exp_time(plist1),"To get exptime");
00694     check(dval2=sinfo_pfits_get_exp_time(plist2),"To get exptime");
00695 
00696     if (fabs(dval1-dval2) > 1e-5) comparison = 0 ;
00697 
00698     /* Compare the readout mode */
00699     check(ival1=sinfo_pfits_get_rom(plist1),"to get read out mode");
00700     check(ival2=sinfo_pfits_get_rom(plist2),"to get read out mode");
00701     if (ival1 != ival2) comparison = 0 ;
00702 
00703 
00704     /* Compare the detector mode */
00705     cknull(sval=sinfo_pfits_get_mode(plist1),"to get detector mode");
00706     strcpy(mode1, sval) ;
00707 
00708     cknull(sval=sinfo_pfits_get_mode(plist2),"to get detector mode");
00709     strcpy(mode2, sval) ;
00710 
00711 
00712     if (strcmp(mode1, mode2)) comparison = 0 ;
00713 
00714     /* Files have to be consequtive */
00715     /*
00716     check(ival1 = sinfo_pfits_get_expno(plist1),"to get exposure number");
00717     check(ival2 = sinfo_pfits_get_expno(plist1),"to get exposure number");
00718     if (ival1 != ival2) comparison = 0 ;
00719     */
00720     sinfo_free_propertylist(&plist1);
00721     sinfo_free_propertylist(&plist2);
00722 
00723     return comparison ;
00724  cleanup:
00725     sinfo_free_propertylist(&plist1);
00726     sinfo_free_propertylist(&plist2);
00727     return -1 ;
00728 
00729 
00730 }

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