GIRAFFE Pipeline Reference Manual

gimasterdark.c

00001 /* $Id: gimasterdark.c,v 1.7.2.1 2008/02/21 11:02:11 rpalsa Exp $
00002  *
00003  * This file is part of the GIRAFFE Pipeline
00004  * Copyright (C) 2002-2006 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 /*
00022  * $Author: rpalsa $
00023  * $Date: 2008/02/21 11:02:11 $
00024  * $Revision: 1.7.2.1 $
00025  * $Name: giraffe-2_5_1 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #  include <config.h>
00030 #endif
00031 
00032 #include <math.h>
00033 
00034 #include <cxmessages.h>
00035 #include <cxmemory.h>
00036 #include <cxlist.h>
00037 
00038 #include <cpl_recipe.h>
00039 #include <cpl_plugininfo.h>
00040 #include <cpl_parameterlist.h>
00041 #include <cpl_frameset.h>
00042 #include <cpl_propertylist.h>
00043 #include <cpl_vector.h>
00044 #include <cpl_msg.h>
00045 
00046 #include "gialias.h"
00047 #include "gierror.h"
00048 #include "giframe.h"
00049 #include "giimage.h"
00050 #include "giwindow.h"
00051 #include "gifibers.h"
00052 #include "gibias.h"
00053 #include "gimath.h"
00054 #include "gistacking.h"
00055 #include "giqclog.h"
00056 #include "giutils.h"
00057 
00058 
00059 static cxint gimasterdark(cpl_parameterlist*, cpl_frameset*);
00060 static cxint giqcmasterdark(cpl_frameset*);
00061 
00062 
00063 static cxint
00064 _giraffe_clean_badpixels(GiImage* image, GiImage* bpixel)
00065 {
00066 
00067     cxint i = 0;
00068 
00069     cxint nx_image = 0;
00070     cxint ny_image = 0;
00071     cxint ny_mask = 0;
00072     cxint shift = 0;
00073     cxint* _bpixel = NULL;
00074 
00075     cxdouble* _image = NULL;
00076 
00077     cpl_propertylist* properties = NULL;
00078 
00079 
00080     cx_assert(image != NULL);
00081     cx_assert(bpixel != NULL);
00082 
00083     nx_image = cpl_image_get_size_y(giraffe_image_get(image));
00084     ny_image = cpl_image_get_size_x(giraffe_image_get(image));
00085 
00086     ny_mask = cpl_image_get_size_x(giraffe_image_get(bpixel));
00087 
00088     properties = giraffe_image_get_properties(bpixel);
00089     shift = cpl_propertylist_get_int(properties, GIALIAS_PRSCX);
00090 
00091     _image = cpl_image_get_data_double(giraffe_image_get(image));
00092     _bpixel = cpl_image_get_data_int(giraffe_image_get(bpixel));
00093 
00094     for (i = 0; i < nx_image; i++) {
00095 
00096         cxint j = 0;
00097 
00098         for (j = 0; j < ny_image; j++) {
00099 
00100             if (_bpixel[i * ny_mask + j + shift] != 0) {
00101                 _image[i * ny_image + j] = 0.;
00102             }
00103 
00104         }
00105 
00106     }
00107 
00108     return 0;
00109 
00110 }
00111 
00112 
00113 /*
00114  * Create the recipe instance, i.e. setup the parameter list for this
00115  * recipe and make it availble to the application using the interface.
00116  */
00117 
00118 static cxint
00119 gimasterdark_create(cpl_plugin* plugin)
00120 {
00121 
00122     cpl_parameter* p = NULL;
00123 
00124     cpl_recipe* recipe = (cpl_recipe*)plugin;
00125 
00126 
00127     giraffe_error_init();
00128 
00129 
00130     /*
00131      * We have to provide the option we accept to the application. We
00132      * need to setup our parameter list and hook it into the recipe
00133      * interface.
00134      */
00135 
00136     recipe->parameters = cpl_parameterlist_new();
00137     cx_assert(recipe->parameters != NULL);
00138 
00139     /*
00140      * Fill the parameter list.
00141      */
00142 
00143     /* Frame combination */
00144 
00145     giraffe_stacking_config_add(recipe->parameters);
00146     p = cpl_parameterlist_find(recipe->parameters, "giraffe.stacking.method");
00147 
00148     if ( p != NULL) {
00149         cpl_parameter_set_default_string(p, "median");
00150     }
00151 
00152     /* Bias removal */
00153 
00154     giraffe_bias_config_add(recipe->parameters);
00155 
00156     return 0;
00157 
00158 }
00159 
00160 /*
00161  * Execute the plugin instance given by the interface.
00162  */
00163 
00164 static cxint
00165 gimasterdark_exec(cpl_plugin* plugin)
00166 {
00167 
00168     cpl_recipe* recipe = (cpl_recipe*)plugin;
00169 
00170     cxint status = 0;
00171 
00172 
00173     if (recipe->parameters == NULL || recipe->frames == NULL) {
00174         return 1;
00175     }
00176 
00177     status = gimasterdark(recipe->parameters, recipe->frames);
00178 
00179     if (status != 0) {
00180         return 1;
00181     }
00182 
00183     status = giqcmasterdark(recipe->frames);
00184 
00185     if (status != 0) {
00186         return 1;
00187     }
00188 
00189     return 0;
00190 
00191 }
00192 
00193 
00194 static cxint
00195 gimasterdark_destroy(cpl_plugin* plugin)
00196 {
00197 
00198     cpl_recipe* recipe = (cpl_recipe*)plugin;
00199 
00200 
00201     /*
00202      * We just destroy what was created during the plugin initialization
00203      * phase, i.e. the parameter list. The frame set is managed by the
00204      * application which called us, so we must not touch it,
00205      */
00206 
00207     cpl_parameterlist_delete(recipe->parameters);
00208 
00209     giraffe_error_clear();
00210 
00211     return 0;
00212 
00213 }
00214 
00215 
00216 /*
00217  * The actual recipe starts here.
00218  */
00219 
00220 static cxint
00221 gimasterdark(cpl_parameterlist* config, cpl_frameset* set)
00222 {
00223 
00224     const cxchar* const _id = "gimasterdark";
00225 
00226     cxint i = 0;
00227     cxint status = 0;
00228     cxint count = 0;
00229 
00230     cxdouble exptotal = 0.;
00231 
00232     cx_list* darks = NULL;
00233 
00234     cx_list_const_iterator position = NULL;
00235 
00236     cpl_matrix* bias_areas = NULL;
00237 
00238     cpl_frame* dark_frame = NULL;
00239     cpl_frame* mbias_frame = NULL;
00240     cpl_frame* bpixel_frame = NULL;
00241     cpl_frame* mdark_frame = NULL;
00242 
00243     cpl_image* _dark = NULL;
00244 
00245     cpl_propertylist* properties = NULL;
00246 
00247 
00248     GiImage* result = NULL;
00249     GiImage* mbias = NULL;
00250     GiImage* bpixel = NULL;
00251     GiImage** stack = NULL;
00252 
00253     GiBiasConfig* bias_config = NULL;
00254 
00255     GiStackingConfig* stack_config = NULL;
00256 
00257     GiRecipeInfo info = {(cxchar*)_id, 1, NULL};
00258 
00259     GiGroupInfo groups[] = {
00260         {GIFRAME_DARK, CPL_FRAME_GROUP_RAW},
00261         {GIFRAME_BIAS_MASTER, CPL_FRAME_GROUP_CALIB},
00262         {GIFRAME_BADPIXEL_MAP, CPL_FRAME_GROUP_CALIB},
00263         {NULL, CPL_FRAME_GROUP_NONE}
00264     };
00265 
00266 
00267 
00268     /*
00269      * Set frame group information
00270      */
00271 
00272     status = giraffe_frameset_set_groups(set, groups);
00273 
00274     if (status != 0) {
00275         cpl_msg_error(_id, "Setting frame group information failed!");
00276         return 1;
00277     }
00278 
00279 
00280     /*
00281      * Count the number of available raw frames
00282      */
00283 
00284     count = cpl_frameset_count_tags(set, GIFRAME_DARK);
00285 
00286     if (count == 0) {
00287         cpl_msg_error(_id, "No raw dark frames found in frameset! "
00288                 "Aborting ...");
00289         return 1;
00290     }
00291 
00292 
00293     /*
00294      * Verify frameset contents
00295      */
00296 
00297     mbias_frame = cpl_frameset_find(set, GIFRAME_BIAS_MASTER);
00298 
00299     if (!mbias_frame) {
00300         cpl_msg_error(_id, "No master bias present in frame set. "
00301                       "Aborting ...");
00302         return 1;
00303     }
00304 
00305     bpixel_frame = cpl_frameset_find(set, GIFRAME_BADPIXEL_MAP);
00306 
00307     if (!bpixel_frame) {
00308         cpl_msg_info(_id, "No bad pixel map present in frame set.");
00309     }
00310 
00311 
00312     /*
00313      * Load the raw data frames
00314      */
00315 
00316     cpl_msg_info(_id, "Loading dark frames ...");
00317 
00318     darks = cx_list_new();
00319     dark_frame = cpl_frameset_find(set, GIFRAME_DARK);
00320 
00321     i = 0;
00322 
00323     while ((dark_frame != NULL ) && (i < count)) {
00324 
00325         const cxchar* const filename = cpl_frame_get_filename(dark_frame);
00326 
00327         GiImage* dark = giraffe_image_new(CPL_TYPE_DOUBLE);
00328 
00329 
00330         status = giraffe_image_load(dark, filename, 0);
00331 
00332         if (status != 0) {
00333             cpl_msg_error(_id, "Cannot load dark from '%s'. Aborting ...",
00334                           filename);
00335 
00336             cx_list_destroy(darks, (cx_free_func)giraffe_image_delete);
00337             darks = NULL;
00338 
00339             return 1;
00340         }
00341 
00342         cx_list_push_back(darks, dark);
00343 
00344         dark_frame = cpl_frameset_find(set, NULL);
00345         ++i;
00346 
00347     }
00348 
00349     cx_assert(i == count);
00350 
00351 
00352     /*
00353      * Prepare for bias subtraction
00354      */
00355 
00356     bias_config = giraffe_bias_config_create(config);
00357 
00358     /*
00359      * Setup user defined areas to use for the bias computation
00360      */
00361 
00362     if (strcmp(bias_config->areas, "None") != 0) {
00363 
00364         cpl_msg_warning(_id, "User defined bias areas are not yet "
00365                 "supported. Using image pre- and overscan areas!");
00366 
00367         bias_areas = NULL;
00368 
00369     }
00370 
00371 
00372     if (bias_config->method == GIBIAS_METHOD_MASTER ||
00373         bias_config->method == GIBIAS_METHOD_ZMASTER) {
00374 
00375         if (mbias_frame == NULL) {
00376             cpl_msg_error(_id, "Missing master bias frame! Selected bias "
00377                           "removal method requires a master bias frame!");
00378 
00379             if (bias_areas != NULL) {
00380                 cpl_matrix_delete(bias_areas);
00381                 bias_areas = NULL;
00382             }
00383 
00384             giraffe_bias_config_destroy(bias_config);
00385             bias_config = NULL;
00386 
00387             cx_list_destroy(darks, (cx_free_func)giraffe_image_delete);
00388             darks = NULL;
00389 
00390             return 1;
00391         }
00392         else {
00393 
00394             const cxchar* filename = cpl_frame_get_filename(mbias_frame);
00395 
00396 
00397             mbias = giraffe_image_new(CPL_TYPE_DOUBLE);
00398             status = giraffe_image_load(mbias, filename, 0);
00399 
00400             if (status != 0) {
00401                 cpl_msg_error(_id, "Cannot load master bias from '%s'. "
00402                               "Aborting ...", filename);
00403 
00404                 giraffe_image_delete(mbias);
00405                 mbias = NULL;
00406 
00407                 if (bias_areas) {
00408                     cpl_matrix_delete(bias_areas);
00409                     bias_areas = NULL;
00410                 }
00411 
00412                 giraffe_bias_config_destroy(bias_config);
00413                 bias_config = NULL;
00414 
00415                 cx_list_destroy(darks, (cx_free_func)giraffe_image_delete);
00416                 darks = NULL;
00417 
00418                 return 1;
00419             }
00420 
00421         }
00422     }
00423 
00424 
00425     /*
00426      * Load bad pixel map if it is present in the frame set.
00427      */
00428 
00429      if (bpixel_frame) {
00430 
00431         const cxchar* filename = cpl_frame_get_filename(bpixel_frame);
00432 
00433 
00434         bpixel = giraffe_image_new(CPL_TYPE_INT);
00435         status = giraffe_image_load(bpixel, filename, 0);
00436 
00437         if (status != 0) {
00438             cpl_msg_error(_id, "Cannot load bad pixel map from '%s'. "
00439                           "Aborting ...", filename);
00440 
00441             if (mbias != NULL) {
00442                 giraffe_image_delete(mbias);
00443                 mbias = NULL;
00444             }
00445 
00446             if (bias_areas != NULL) {
00447                 cpl_matrix_delete(bias_areas);
00448                 bias_areas = NULL;
00449             }
00450 
00451             giraffe_bias_config_destroy(bias_config);
00452             bias_config = NULL;
00453 
00454             cx_list_destroy(darks, (cx_free_func)giraffe_image_delete);
00455             darks = NULL;
00456 
00457             return 1;
00458         }
00459 
00460     }
00461 
00462 
00463     /*
00464      * Subtract the bias from each dark.
00465      */
00466 
00467     for (i = 0; i < count; i++) {
00468 
00469         GiImage* dark = cx_list_pop_front(darks);
00470         GiImage* rdark = giraffe_image_new(CPL_TYPE_DOUBLE);
00471 
00472 
00473         status = giraffe_bias_remove(rdark, dark, mbias, bpixel, bias_areas,
00474                                      bias_config);
00475 
00476         if (status != 0) {
00477 
00478             cx_list_push_front(darks, dark);
00479 
00480             giraffe_image_delete(rdark);
00481             rdark = NULL;
00482 
00483             if (mbias != NULL) {
00484                 giraffe_image_delete(mbias);
00485                 mbias = NULL;
00486             }
00487 
00488             if (bias_areas != NULL) {
00489                 cpl_matrix_delete(bias_areas);
00490                 bias_areas = NULL;
00491             }
00492 
00493             giraffe_bias_config_destroy(bias_config);
00494             bias_config = NULL;
00495 
00496             cx_list_destroy(darks, (cx_free_func)giraffe_image_delete);
00497             darks = NULL;
00498 
00499             return 1;
00500 
00501         }
00502 
00503         giraffe_image_delete(dark);
00504         dark = NULL;
00505 
00506         cx_list_push_back(darks, rdark);
00507 
00508     }
00509 
00510     if (mbias != NULL) {
00511         giraffe_image_delete(mbias);
00512         mbias = NULL;
00513     }
00514 
00515     if (bias_areas != NULL) {
00516         cpl_matrix_delete(bias_areas);
00517         bias_areas = NULL;
00518     }
00519 
00520     giraffe_bias_config_destroy(bias_config);
00521     bias_config = NULL;
00522 
00523 
00524     /*
00525      * Scale each bias subtracted dark to 1 second exposure time.
00526      * Compute total exposure time.
00527      */
00528 
00529     position = cx_list_begin(darks);
00530 
00531     while (position != cx_list_end(darks)) {
00532 
00533         cxdouble exptime = 0.;
00534 
00535         GiImage* dark = cx_list_get(darks, position);
00536 
00537         properties = giraffe_image_get_properties(dark);
00538         exptime = cpl_propertylist_get_double(properties, GIALIAS_EXPTIME);
00539 
00540         cpl_image_divide_scalar(giraffe_image_get(dark), exptime);
00541         exptotal += exptime;
00542 
00543         cpl_propertylist_update_double(properties, GIALIAS_EXPTIME, 1.);
00544 
00545         position = cx_list_next(darks, position);
00546 
00547     }
00548 
00549 
00550     /*
00551      * Check that enough raw frames are present in the frameset
00552      * for the selected frame combination method.
00553      */
00554 
00555     stack_config = giraffe_stacking_config_create(config);
00556 
00557     count = cx_list_size(darks);
00558 
00559     if (count < stack_config->min_nr_frames) {
00560 
00561         cpl_msg_error(_id, "Not enough frames (%d). Stacking method '%d' "
00562                       "requires at least %d frames! Aborting...", count,
00563                       stack_config->stackmethod, stack_config->min_nr_frames);
00564 
00565         giraffe_stacking_config_destroy(stack_config);
00566         stack_config = NULL;
00567 
00568         return 1;
00569 
00570     }
00571 
00572 
00573     /*
00574      * Combine the raw dark frames
00575      */
00576 
00577     cpl_msg_info(_id, "Combining %d of %d dark frames.", i, count);
00578 
00579     stack = cx_calloc(count + 1, sizeof(GiImage*));
00580 
00581     i = 0;
00582     position = cx_list_begin(darks);
00583 
00584     while (position != cx_list_end(darks)) {
00585         stack[i] = cx_list_get(darks, position);
00586         position = cx_list_next(darks, position);
00587         ++i;
00588     }
00589 
00590     result = giraffe_stacking_stack_images(stack, stack_config);
00591 
00592     if (result == NULL) {
00593 
00594         cpl_msg_error(_id, "Frame combination failed! Aborting ...");
00595 
00596         cx_free(stack);
00597         stack = NULL;
00598 
00599         cx_list_destroy(darks, (cx_free_func)giraffe_image_delete);
00600         darks = NULL;
00601 
00602         giraffe_stacking_config_destroy(stack_config);
00603         stack_config = NULL;
00604 
00605         return 1;
00606 
00607     }
00608 
00609     properties = giraffe_image_get_properties(stack[0]);
00610     giraffe_image_set_properties(result, properties);
00611 
00612     cx_free(stack);
00613     stack = NULL;
00614 
00615     giraffe_stacking_config_destroy(stack_config);
00616     stack_config = NULL;
00617 
00618     cx_list_destroy(darks, (cx_free_func)giraffe_image_delete);
00619     darks = NULL;
00620 
00621 
00622     /*
00623      * Clean the bad pixels if a bad pixel map is present. The flux of
00624      * bad pixels is simply set to 0.
00625      */
00626 
00627     if (bpixel) {
00628 
00629         status = _giraffe_clean_badpixels(result, bpixel);
00630 
00631         if (status != 0) {
00632 
00633             cpl_msg_error(_id, "Bad pixel cleaning on master dark frame "
00634                           "failed!");
00635 
00636             giraffe_image_delete(result);
00637             result = NULL;
00638 
00639             giraffe_image_delete(bpixel);
00640             bpixel = NULL;
00641 
00642             return 1;
00643 
00644         }
00645 
00646     }
00647 
00648     giraffe_image_delete(bpixel);
00649     bpixel = NULL;
00650 
00651 
00652     /*
00653      * Update master dark properties.
00654      */
00655 
00656     cpl_msg_info(_id, "Writing master dark image ...");
00657 
00658     properties = giraffe_image_get_properties(result);
00659     cx_assert(properties != NULL);
00660 
00661     cpl_propertylist_update_double(properties, GIALIAS_CRPIX1, 1.);
00662 
00663     cpl_propertylist_update_double(properties, GIALIAS_EXPTTOT, exptotal);
00664     cpl_propertylist_update_int(properties, GIALIAS_DATANCOM, count);
00665 
00666     _dark = giraffe_image_get(result);
00667 
00668     cpl_propertylist_update_double(properties, GIALIAS_DARKVALUE,
00669                                    cpl_image_get_mean(_dark));
00670     cpl_propertylist_set_comment(properties, GIALIAS_DARKVALUE,
00671                                  "Dark current in ADU/s");
00672 
00673     cpl_propertylist_erase(properties, GIALIAS_TPLEXPNO);
00674 
00675 
00676     giraffe_image_add_info(result, &info, set);
00677 
00678     mdark_frame = giraffe_frame_create_image(result,
00679                                              GIFRAME_DARK_MASTER,
00680                                              CPL_FRAME_LEVEL_FINAL,
00681                                              TRUE, TRUE);
00682 
00683     if (mdark_frame == NULL) {
00684 
00685         cpl_msg_error(_id, "Cannot create local file! Aborting ...");
00686 
00687         if (result != NULL) {
00688             giraffe_image_delete(result);
00689         }
00690 
00691         return 1;
00692 
00693     }
00694 
00695     cpl_frameset_insert(set, mdark_frame);
00696 
00697 
00698     if (result != NULL) {
00699         giraffe_image_delete(result);
00700     }
00701 
00702     return 0;
00703 
00704 }
00705 
00706 
00707 /*
00708  * The quality control task starts here.
00709  */
00710 
00711 static cxint
00712 giqcmasterdark(cpl_frameset* set)
00713 {
00714 
00715     const cxchar* const fctid = "giqcmasterdark";
00716 
00717     cxint status = 0;
00718     cxint gpx = 0;
00719     cxint gpy = 0;
00720 
00721     cxdouble mean = 0.;
00722     cxdouble exptime = 1.;
00723     cxdouble gflux = 0.;
00724 
00725     cpl_propertylist* properties = NULL;
00726     cpl_propertylist* qclog = NULL;
00727 
00728 
00729     cpl_image* _mdark = NULL;
00730 
00731     cpl_frame* rframe = NULL;
00732     cpl_frame* pframe = NULL;
00733 
00734     GiPaf* qc = NULL;
00735 
00736     GiImage* mdark = NULL;
00737     GiImage* dark = NULL;
00738 
00739     GiWindow w = {10, 200, 2038, 3000};
00740 
00741 
00742     cpl_msg_info(fctid, "Computing QC1 parameters ...");
00743 
00744     qc = giraffe_qclog_open(0);
00745 
00746     if (qc == NULL) {
00747         cpl_msg_error(fctid, "Cannot create QC1 log!");
00748         return 1;
00749     }
00750 
00751     qclog = giraffe_paf_get_properties(qc);
00752     cx_assert(qclog != NULL);
00753 
00754 
00755     /*
00756      * Process master dark
00757      */
00758 
00759     pframe = giraffe_get_frame(set, GIFRAME_DARK_MASTER,
00760                                CPL_FRAME_GROUP_PRODUCT);
00761 
00762     if (pframe == NULL) {
00763         cpl_msg_error(fctid, "Missing product frame (%s)",
00764                       GIFRAME_DARK_MASTER);
00765 
00766         giraffe_paf_delete(qc);
00767         qc = NULL;
00768 
00769         return 1;
00770     }
00771 
00772     cpl_msg_info(fctid, "Processing product frame '%s' (%s)",
00773                  cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
00774 
00775     mdark = giraffe_image_new(CPL_TYPE_DOUBLE);
00776     status = giraffe_image_load(mdark, cpl_frame_get_filename(pframe), 0);
00777 
00778     if (status != 0) {
00779         cpl_msg_error(fctid, "Could not load master dark '%s'! Aborting ...",
00780                       cpl_frame_get_filename(pframe));
00781 
00782         giraffe_image_delete(mdark);
00783         mdark = NULL;
00784 
00785         giraffe_paf_delete(qc);
00786         qc = NULL;
00787 
00788         return 1;
00789     }
00790 
00791 
00792     /*
00793      * Load first raw image as reference
00794      */
00795 
00796     rframe = cpl_frameset_find(set, GIFRAME_DARK);
00797 
00798     if (rframe == NULL) {
00799         cpl_msg_error(fctid, "Missing raw frame (%s)", GIFRAME_DARK);
00800 
00801         giraffe_image_delete(mdark);
00802         mdark = NULL;
00803 
00804         giraffe_paf_delete(qc);
00805         qc = NULL;
00806 
00807         return 1;
00808     }
00809 
00810     dark = giraffe_image_new(CPL_TYPE_DOUBLE);
00811     status = giraffe_image_load(dark, cpl_frame_get_filename(rframe), 0);
00812 
00813     if (status != 0) {
00814         cpl_msg_error(fctid, "Could not load dark '%s'!",
00815                       cpl_frame_get_filename(rframe));
00816 
00817         giraffe_image_delete(dark);
00818         dark = NULL;
00819 
00820         giraffe_image_delete(mdark);
00821         mdark = NULL;
00822 
00823         giraffe_paf_delete(qc);
00824         qc = NULL;
00825 
00826         return 1;
00827 
00828     }
00829 
00830     properties = giraffe_image_get_properties(dark);
00831     cx_assert(properties != NULL);
00832 
00833     giraffe_propertylist_copy(qclog, "ARCFILE", properties, GIALIAS_ARCFILE);
00834     giraffe_propertylist_copy(qclog, "TPL.ID", properties, GIALIAS_TPLID);
00835 
00836     cpl_propertylist_update_string(qclog, "PRO.CATG",
00837                                    cpl_frame_get_tag(pframe));
00838     cpl_propertylist_set_comment(qclog, "PRO.CATG",
00839                                  "Pipeline product category");
00840 
00841     properties = giraffe_image_get_properties(mdark);
00842     cx_assert(properties != NULL);
00843 
00844     giraffe_propertylist_copy(qclog, "PRO.DATAAVG", properties,
00845                               GIALIAS_DATAMEAN);
00846     giraffe_propertylist_copy(qclog, "PRO.DATARMS", properties,
00847                               GIALIAS_DATASIG);
00848     giraffe_propertylist_copy(qclog, "PRO.DATAMED", properties,
00849                               GIALIAS_DATAMEDI);
00850     giraffe_propertylist_copy(qclog, "PRO.DATANCOM", properties,
00851                               GIALIAS_DATANCOM);
00852 
00853 
00854     /*
00855      * Get 1 over exposure time in hours from the master dark frame
00856      */
00857 
00858     if (cpl_propertylist_has(properties, GIALIAS_EXPTIME) == TRUE) {
00859 
00860         exptime = cpl_propertylist_get_double(properties, GIALIAS_EXPTIME);
00861 
00862     }
00863 
00864     exptime = 3600. / exptime;
00865 
00866 
00867     /*
00868      * Compute average dark value on a central window of the
00869      * master dark frame. The window is used to exclude the
00870      * glow feature in the upper part of the CCD.
00871      */
00872 
00873     _mdark = giraffe_image_get(mdark);
00874 
00875     mean = cpl_image_get_mean_window(_mdark, w.x0, w.y0, w.x1, w.y1);
00876 
00877 
00878     cpl_propertylist_update_double(properties, GIALIAS_QCMDARKAVG,
00879                                    mean * exptime);
00880     cpl_propertylist_set_comment(properties, GIALIAS_QCMDARKAVG,
00881                                  "Mean master dark current (ADU/hr)");
00882 
00883     giraffe_propertylist_copy(qclog, "QC.DARK.CURRENT", properties,
00884                               GIALIAS_QCMDARKAVG);
00885 
00886     /*
00887      * Monitoring the glow in the upper right part of the CCD
00888      */
00889 
00890     w.x0 = 1350;
00891     w.x1 = 2048;
00892     w.y0 = 3800;
00893     w.y1 = 4095;
00894 
00895     gflux = cpl_image_get_flux_window(_mdark, w.x0, w.y0, w.x1, w.y1);
00896 
00897     cpl_image_get_maxpos_window(_mdark, w.x0, w.y0, w.x1, w.y1, &gpx, &gpy);
00898 
00899 
00900     cpl_propertylist_update_double(properties, GIALIAS_QCGLOWFLX, gflux);
00901     cpl_propertylist_set_comment(properties, GIALIAS_QCGLOWFLX,
00902                                  "Total flux of glow feature (ADU/s)");
00903 
00904     cpl_propertylist_update_int(properties, GIALIAS_QCGLOWX, gpx);
00905     cpl_propertylist_set_comment(properties, GIALIAS_QCGLOWX,
00906                                  "X position of glow feature (pxl)");
00907 
00908     cpl_propertylist_update_int(properties, GIALIAS_QCGLOWY, gpy);
00909     cpl_propertylist_set_comment(properties, GIALIAS_QCGLOWY,
00910                                  "X position of glow feature (pxl)");
00911 
00912     giraffe_propertylist_copy(qclog, "QC.GLOW.LEVEL", properties,
00913                               GIALIAS_QCGLOWFLX);
00914     giraffe_propertylist_copy(qclog, "QC.GLOW.POSX", properties,
00915                               GIALIAS_QCGLOWX);
00916     giraffe_propertylist_copy(qclog, "QC.GLOW.POSY", properties,
00917                               GIALIAS_QCGLOWY);
00918 
00919     /*
00920      * Write QC1 log and save updated master dark.
00921      */
00922 
00923     giraffe_image_save(mdark, cpl_frame_get_filename(pframe));
00924 
00925     giraffe_image_delete(mdark);
00926     mdark = NULL;
00927 
00928     giraffe_qclog_close(qc);
00929     qc = NULL;
00930 
00931     return 0;
00932 
00933 }
00934 
00935 
00936 /*
00937  * Build table of contents, i.e. the list of available plugins, for
00938  * this module. This function is exported.
00939  */
00940 
00941 int
00942 cpl_plugin_get_info(cpl_pluginlist* list)
00943 {
00944 
00945     cpl_recipe* recipe = cx_calloc(1, sizeof *recipe);
00946     cpl_plugin* plugin = &recipe->interface;
00947 
00948 
00949     cpl_plugin_init(plugin,
00950                     CPL_PLUGIN_API,
00951                     GIRAFFE_BINARY_VERSION,
00952                     CPL_PLUGIN_TYPE_RECIPE,
00953                     "gimasterdark",
00954                     "Creates a master dark image from a set of raw dark "
00955                     "frames.",
00956                     "For detailed information please refer to the "
00957                     "GIRAFFE pipeline user manual.\nIt is available at "
00958                     "http://www.eso.org/pipelines.",
00959                     "Giraffe Pipeline",
00960                     PACKAGE_BUGREPORT,
00961                     giraffe_get_license(),
00962                     gimasterdark_create,
00963                     gimasterdark_exec,
00964                     gimasterdark_destroy);
00965 
00966     cpl_pluginlist_append(list, plugin);
00967 
00968     return 0;
00969 
00970 }

This file is part of the GIRAFFE Pipeline Reference Manual 2.5.1.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Tue Mar 18 10:47:42 2008 by doxygen 1.4.6 written by Dimitri van Heesch, © 1997-2004