GIRAFFE Pipeline Reference Manual

gimasterdark.c

00001 /* $Id: gimasterdark.c,v 1.9 2008/07/10 12:19:12 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/07/10 12:19:12 $
00024  * $Revision: 1.9 $
00025  * $Name: giraffe-2_8_8 $
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 (bias_config->method == GIBIAS_METHOD_MASTER ||
00363         bias_config->method == GIBIAS_METHOD_ZMASTER) {
00364 
00365         if (mbias_frame == NULL) {
00366             cpl_msg_error(_id, "Missing master bias frame! Selected bias "
00367                           "removal method requires a master bias frame!");
00368 
00369             giraffe_bias_config_destroy(bias_config);
00370             bias_config = NULL;
00371 
00372             cx_list_destroy(darks, (cx_free_func)giraffe_image_delete);
00373             darks = NULL;
00374 
00375             return 1;
00376         }
00377         else {
00378 
00379             const cxchar* filename = cpl_frame_get_filename(mbias_frame);
00380 
00381 
00382             mbias = giraffe_image_new(CPL_TYPE_DOUBLE);
00383             status = giraffe_image_load(mbias, filename, 0);
00384 
00385             if (status != 0) {
00386                 cpl_msg_error(_id, "Cannot load master bias from '%s'. "
00387                               "Aborting ...", filename);
00388 
00389                 giraffe_image_delete(mbias);
00390                 mbias = NULL;
00391 
00392                 giraffe_bias_config_destroy(bias_config);
00393                 bias_config = NULL;
00394 
00395                 cx_list_destroy(darks, (cx_free_func)giraffe_image_delete);
00396                 darks = NULL;
00397 
00398                 return 1;
00399             }
00400 
00401         }
00402     }
00403 
00404 
00405     /*
00406      * Load bad pixel map if it is present in the frame set.
00407      */
00408 
00409      if (bpixel_frame) {
00410 
00411         const cxchar* filename = cpl_frame_get_filename(bpixel_frame);
00412 
00413 
00414         bpixel = giraffe_image_new(CPL_TYPE_INT);
00415         status = giraffe_image_load(bpixel, filename, 0);
00416 
00417         if (status != 0) {
00418             cpl_msg_error(_id, "Cannot load bad pixel map from '%s'. "
00419                           "Aborting ...", filename);
00420 
00421             if (mbias != NULL) {
00422                 giraffe_image_delete(mbias);
00423                 mbias = NULL;
00424             }
00425 
00426             giraffe_bias_config_destroy(bias_config);
00427             bias_config = NULL;
00428 
00429             cx_list_destroy(darks, (cx_free_func)giraffe_image_delete);
00430             darks = NULL;
00431 
00432             return 1;
00433         }
00434 
00435     }
00436 
00437 
00438     /*
00439      * Subtract the bias from each dark.
00440      */
00441 
00442     for (i = 0; i < count; i++) {
00443 
00444         GiImage* dark = cx_list_pop_front(darks);
00445         GiImage* rdark = giraffe_image_new(CPL_TYPE_DOUBLE);
00446 
00447 
00448         status = giraffe_bias_remove(rdark, dark, mbias, bpixel, bias_areas,
00449                                      bias_config);
00450 
00451         if (status != 0) {
00452 
00453             cx_list_push_front(darks, dark);
00454 
00455             giraffe_image_delete(rdark);
00456             rdark = NULL;
00457 
00458             if (mbias != NULL) {
00459                 giraffe_image_delete(mbias);
00460                 mbias = NULL;
00461             }
00462 
00463             giraffe_bias_config_destroy(bias_config);
00464             bias_config = NULL;
00465 
00466             cx_list_destroy(darks, (cx_free_func)giraffe_image_delete);
00467             darks = NULL;
00468 
00469             return 1;
00470 
00471         }
00472 
00473         giraffe_image_delete(dark);
00474         dark = NULL;
00475 
00476         cx_list_push_back(darks, rdark);
00477 
00478     }
00479 
00480     if (mbias != NULL) {
00481         giraffe_image_delete(mbias);
00482         mbias = NULL;
00483     }
00484 
00485     giraffe_bias_config_destroy(bias_config);
00486     bias_config = NULL;
00487 
00488 
00489     /*
00490      * Scale each bias subtracted dark to 1 second exposure time.
00491      * Compute total exposure time.
00492      */
00493 
00494     position = cx_list_begin(darks);
00495 
00496     while (position != cx_list_end(darks)) {
00497 
00498         cxdouble exptime = 0.;
00499 
00500         GiImage* dark = cx_list_get(darks, position);
00501 
00502         properties = giraffe_image_get_properties(dark);
00503         exptime = cpl_propertylist_get_double(properties, GIALIAS_EXPTIME);
00504 
00505         cpl_image_divide_scalar(giraffe_image_get(dark), exptime);
00506         exptotal += exptime;
00507 
00508         cpl_propertylist_update_double(properties, GIALIAS_EXPTIME, 1.);
00509 
00510         position = cx_list_next(darks, position);
00511 
00512     }
00513 
00514 
00515     /*
00516      * Check that enough raw frames are present in the frameset
00517      * for the selected frame combination method.
00518      */
00519 
00520     stack_config = giraffe_stacking_config_create(config);
00521 
00522     count = cx_list_size(darks);
00523 
00524     if (count < stack_config->min_nr_frames) {
00525 
00526         cpl_msg_error(_id, "Not enough frames (%d). Stacking method '%d' "
00527                       "requires at least %d frames! Aborting...", count,
00528                       stack_config->stackmethod, stack_config->min_nr_frames);
00529 
00530         giraffe_stacking_config_destroy(stack_config);
00531         stack_config = NULL;
00532 
00533         return 1;
00534 
00535     }
00536 
00537 
00538     /*
00539      * Combine the raw dark frames
00540      */
00541 
00542     cpl_msg_info(_id, "Combining %d of %d dark frames.", i, count);
00543 
00544     stack = cx_calloc(count + 1, sizeof(GiImage*));
00545 
00546     i = 0;
00547     position = cx_list_begin(darks);
00548 
00549     while (position != cx_list_end(darks)) {
00550         stack[i] = cx_list_get(darks, position);
00551         position = cx_list_next(darks, position);
00552         ++i;
00553     }
00554 
00555     result = giraffe_stacking_stack_images(stack, stack_config);
00556 
00557     if (result == NULL) {
00558 
00559         cpl_msg_error(_id, "Frame combination failed! Aborting ...");
00560 
00561         cx_free(stack);
00562         stack = NULL;
00563 
00564         cx_list_destroy(darks, (cx_free_func)giraffe_image_delete);
00565         darks = NULL;
00566 
00567         giraffe_stacking_config_destroy(stack_config);
00568         stack_config = NULL;
00569 
00570         return 1;
00571 
00572     }
00573 
00574     properties = giraffe_image_get_properties(stack[0]);
00575     giraffe_image_set_properties(result, properties);
00576 
00577     cx_free(stack);
00578     stack = NULL;
00579 
00580     giraffe_stacking_config_destroy(stack_config);
00581     stack_config = NULL;
00582 
00583     cx_list_destroy(darks, (cx_free_func)giraffe_image_delete);
00584     darks = NULL;
00585 
00586 
00587     /*
00588      * Clean the bad pixels if a bad pixel map is present. The flux of
00589      * bad pixels is simply set to 0.
00590      */
00591 
00592     if (bpixel) {
00593 
00594         status = _giraffe_clean_badpixels(result, bpixel);
00595 
00596         if (status != 0) {
00597 
00598             cpl_msg_error(_id, "Bad pixel cleaning on master dark frame "
00599                           "failed!");
00600 
00601             giraffe_image_delete(result);
00602             result = NULL;
00603 
00604             giraffe_image_delete(bpixel);
00605             bpixel = NULL;
00606 
00607             return 1;
00608 
00609         }
00610 
00611     }
00612 
00613     giraffe_image_delete(bpixel);
00614     bpixel = NULL;
00615 
00616 
00617     /*
00618      * Update master dark properties.
00619      */
00620 
00621     cpl_msg_info(_id, "Writing master dark image ...");
00622 
00623     properties = giraffe_image_get_properties(result);
00624     cx_assert(properties != NULL);
00625 
00626     cpl_propertylist_update_double(properties, GIALIAS_CRPIX1, 1.);
00627 
00628     cpl_propertylist_update_double(properties, GIALIAS_EXPTTOT, exptotal);
00629     cpl_propertylist_update_int(properties, GIALIAS_DATANCOM, count);
00630 
00631     _dark = giraffe_image_get(result);
00632 
00633     cpl_propertylist_update_double(properties, GIALIAS_DARKVALUE,
00634                                    cpl_image_get_mean(_dark));
00635     cpl_propertylist_set_comment(properties, GIALIAS_DARKVALUE,
00636                                  "Dark current in ADU/s");
00637 
00638     cpl_propertylist_erase(properties, GIALIAS_TPLEXPNO);
00639 
00640 
00641     giraffe_image_add_info(result, &info, set);
00642 
00643     mdark_frame = giraffe_frame_create_image(result,
00644                                              GIFRAME_DARK_MASTER,
00645                                              CPL_FRAME_LEVEL_FINAL,
00646                                              TRUE, TRUE);
00647 
00648     if (mdark_frame == NULL) {
00649 
00650         cpl_msg_error(_id, "Cannot create local file! Aborting ...");
00651 
00652         if (result != NULL) {
00653             giraffe_image_delete(result);
00654         }
00655 
00656         return 1;
00657 
00658     }
00659 
00660     cpl_frameset_insert(set, mdark_frame);
00661 
00662 
00663     if (result != NULL) {
00664         giraffe_image_delete(result);
00665     }
00666 
00667     return 0;
00668 
00669 }
00670 
00671 
00672 /*
00673  * The quality control task starts here.
00674  */
00675 
00676 static cxint
00677 giqcmasterdark(cpl_frameset* set)
00678 {
00679 
00680     const cxchar* const fctid = "giqcmasterdark";
00681 
00682     cxint status = 0;
00683     cxint gpx = 0;
00684     cxint gpy = 0;
00685 
00686     cxdouble mean = 0.;
00687     cxdouble exptime = 1.;
00688     cxdouble gflux = 0.;
00689 
00690     cpl_propertylist* properties = NULL;
00691     cpl_propertylist* qclog = NULL;
00692 
00693 
00694     cpl_image* _mdark = NULL;
00695 
00696     cpl_frame* rframe = NULL;
00697     cpl_frame* pframe = NULL;
00698 
00699     GiPaf* qc = NULL;
00700 
00701     GiImage* mdark = NULL;
00702     GiImage* dark = NULL;
00703 
00704     GiWindow w = {10, 200, 2038, 3000};
00705 
00706 
00707     cpl_msg_info(fctid, "Computing QC1 parameters ...");
00708 
00709     qc = giraffe_qclog_open(0);
00710 
00711     if (qc == NULL) {
00712         cpl_msg_error(fctid, "Cannot create QC1 log!");
00713         return 1;
00714     }
00715 
00716     qclog = giraffe_paf_get_properties(qc);
00717     cx_assert(qclog != NULL);
00718 
00719 
00720     /*
00721      * Process master dark
00722      */
00723 
00724     pframe = giraffe_get_frame(set, GIFRAME_DARK_MASTER,
00725                                CPL_FRAME_GROUP_PRODUCT);
00726 
00727     if (pframe == NULL) {
00728         cpl_msg_error(fctid, "Missing product frame (%s)",
00729                       GIFRAME_DARK_MASTER);
00730 
00731         giraffe_paf_delete(qc);
00732         qc = NULL;
00733 
00734         return 1;
00735     }
00736 
00737     cpl_msg_info(fctid, "Processing product frame '%s' (%s)",
00738                  cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
00739 
00740     mdark = giraffe_image_new(CPL_TYPE_DOUBLE);
00741     status = giraffe_image_load(mdark, cpl_frame_get_filename(pframe), 0);
00742 
00743     if (status != 0) {
00744         cpl_msg_error(fctid, "Could not load master dark '%s'! Aborting ...",
00745                       cpl_frame_get_filename(pframe));
00746 
00747         giraffe_image_delete(mdark);
00748         mdark = NULL;
00749 
00750         giraffe_paf_delete(qc);
00751         qc = NULL;
00752 
00753         return 1;
00754     }
00755 
00756 
00757     /*
00758      * Load first raw image as reference
00759      */
00760 
00761     rframe = cpl_frameset_find(set, GIFRAME_DARK);
00762 
00763     if (rframe == NULL) {
00764         cpl_msg_error(fctid, "Missing raw frame (%s)", GIFRAME_DARK);
00765 
00766         giraffe_image_delete(mdark);
00767         mdark = NULL;
00768 
00769         giraffe_paf_delete(qc);
00770         qc = NULL;
00771 
00772         return 1;
00773     }
00774 
00775     dark = giraffe_image_new(CPL_TYPE_DOUBLE);
00776     status = giraffe_image_load(dark, cpl_frame_get_filename(rframe), 0);
00777 
00778     if (status != 0) {
00779         cpl_msg_error(fctid, "Could not load dark '%s'!",
00780                       cpl_frame_get_filename(rframe));
00781 
00782         giraffe_image_delete(dark);
00783         dark = NULL;
00784 
00785         giraffe_image_delete(mdark);
00786         mdark = NULL;
00787 
00788         giraffe_paf_delete(qc);
00789         qc = NULL;
00790 
00791         return 1;
00792 
00793     }
00794 
00795     properties = giraffe_image_get_properties(dark);
00796     cx_assert(properties != NULL);
00797 
00798     giraffe_propertylist_copy(qclog, "ARCFILE", properties, GIALIAS_ARCFILE);
00799     giraffe_propertylist_copy(qclog, "TPL.ID", properties, GIALIAS_TPLID);
00800 
00801     cpl_propertylist_update_string(qclog, "PRO.CATG",
00802                                    cpl_frame_get_tag(pframe));
00803     cpl_propertylist_set_comment(qclog, "PRO.CATG",
00804                                  "Pipeline product category");
00805 
00806     properties = giraffe_image_get_properties(mdark);
00807     cx_assert(properties != NULL);
00808 
00809     giraffe_propertylist_copy(qclog, "PRO.DATAAVG", properties,
00810                               GIALIAS_DATAMEAN);
00811     giraffe_propertylist_copy(qclog, "PRO.DATARMS", properties,
00812                               GIALIAS_DATASIG);
00813     giraffe_propertylist_copy(qclog, "PRO.DATAMED", properties,
00814                               GIALIAS_DATAMEDI);
00815     giraffe_propertylist_copy(qclog, "PRO.DATANCOM", properties,
00816                               GIALIAS_DATANCOM);
00817 
00818 
00819     /*
00820      * Get 1 over exposure time in hours from the master dark frame
00821      */
00822 
00823     if (cpl_propertylist_has(properties, GIALIAS_EXPTIME) == TRUE) {
00824 
00825         exptime = cpl_propertylist_get_double(properties, GIALIAS_EXPTIME);
00826 
00827     }
00828 
00829     exptime = 3600. / exptime;
00830 
00831 
00832     /*
00833      * Compute average dark value on a central window of the
00834      * master dark frame. The window is used to exclude the
00835      * glow feature in the upper part of the CCD.
00836      */
00837 
00838     _mdark = giraffe_image_get(mdark);
00839 
00840     mean = cpl_image_get_mean_window(_mdark, w.x0, w.y0, w.x1, w.y1);
00841 
00842 
00843     cpl_propertylist_update_double(properties, GIALIAS_QCMDARKAVG,
00844                                    mean * exptime);
00845     cpl_propertylist_set_comment(properties, GIALIAS_QCMDARKAVG,
00846                                  "Mean master dark current (ADU/hr)");
00847 
00848     giraffe_propertylist_copy(qclog, "QC.DARK.CURRENT", properties,
00849                               GIALIAS_QCMDARKAVG);
00850 
00851     /*
00852      * Monitoring the glow in the upper right part of the CCD
00853      */
00854 
00855     w.x0 = 1350;
00856     w.x1 = 2048;
00857     w.y0 = 3800;
00858     w.y1 = 4095;
00859 
00860     gflux = cpl_image_get_flux_window(_mdark, w.x0, w.y0, w.x1, w.y1);
00861 
00862     cpl_image_get_maxpos_window(_mdark, w.x0, w.y0, w.x1, w.y1, &gpx, &gpy);
00863 
00864 
00865     cpl_propertylist_update_double(properties, GIALIAS_QCGLOWFLX, gflux);
00866     cpl_propertylist_set_comment(properties, GIALIAS_QCGLOWFLX,
00867                                  "Total flux of glow feature (ADU/s)");
00868 
00869     cpl_propertylist_update_int(properties, GIALIAS_QCGLOWX, gpx);
00870     cpl_propertylist_set_comment(properties, GIALIAS_QCGLOWX,
00871                                  "X position of glow feature (pxl)");
00872 
00873     cpl_propertylist_update_int(properties, GIALIAS_QCGLOWY, gpy);
00874     cpl_propertylist_set_comment(properties, GIALIAS_QCGLOWY,
00875                                  "X position of glow feature (pxl)");
00876 
00877     giraffe_propertylist_copy(qclog, "QC.GLOW.LEVEL", properties,
00878                               GIALIAS_QCGLOWFLX);
00879     giraffe_propertylist_copy(qclog, "QC.GLOW.POSX", properties,
00880                               GIALIAS_QCGLOWX);
00881     giraffe_propertylist_copy(qclog, "QC.GLOW.POSY", properties,
00882                               GIALIAS_QCGLOWY);
00883 
00884     /*
00885      * Write QC1 log and save updated master dark.
00886      */
00887 
00888     giraffe_image_save(mdark, cpl_frame_get_filename(pframe));
00889 
00890     giraffe_image_delete(mdark);
00891     mdark = NULL;
00892 
00893     giraffe_qclog_close(qc);
00894     qc = NULL;
00895 
00896     return 0;
00897 
00898 }
00899 
00900 
00901 /*
00902  * Build table of contents, i.e. the list of available plugins, for
00903  * this module. This function is exported.
00904  */
00905 
00906 int
00907 cpl_plugin_get_info(cpl_pluginlist* list)
00908 {
00909 
00910     cpl_recipe* recipe = cx_calloc(1, sizeof *recipe);
00911     cpl_plugin* plugin = &recipe->interface;
00912 
00913 
00914     cpl_plugin_init(plugin,
00915                     CPL_PLUGIN_API,
00916                     GIRAFFE_BINARY_VERSION,
00917                     CPL_PLUGIN_TYPE_RECIPE,
00918                     "gimasterdark",
00919                     "Creates a master dark image from a set of raw dark "
00920                     "frames.",
00921                     "For detailed information please refer to the "
00922                     "GIRAFFE pipeline user manual.\nIt is available at "
00923                     "http://www.eso.org/pipelines.",
00924                     "Giraffe Pipeline",
00925                     PACKAGE_BUGREPORT,
00926                     giraffe_get_license(),
00927                     gimasterdark_create,
00928                     gimasterdark_exec,
00929                     gimasterdark_destroy);
00930 
00931     cpl_pluginlist_append(list, plugin);
00932 
00933     return 0;
00934 
00935 }

This file is part of the GIRAFFE Pipeline Reference Manual 2.8.8.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Fri Mar 4 10:50:27 2011 by doxygen 1.6.3 written by Dimitri van Heesch, © 1997-2004