fors_dark_impl.c

00001 /* $Id: fors_dark_impl.c,v 1.15 2010/09/14 07:49:30 cizzo Exp $
00002  *
00003  * This file is part of the FORS Library
00004  * Copyright (C) 2002-2010 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: cizzo $
00023  * $Date: 2010/09/14 07:49:30 $
00024  * $Revision: 1.15 $
00025  * $Name: fors-4_8_6 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 #include <fors_dark_impl.h>
00033 
00034 #include <fors_stack.h>
00035 #include <fors_dfs.h>
00036 #include <fors_utils.h>
00037 
00038 #include <cpl.h>
00039 
00046 const char *const fors_dark_name = "fors_dark";
00047 const char *const fors_dark_description_short = "Compute master dark frame";
00048 const char *const fors_dark_author = "Jonas M. Larsen";
00049 const char *const fors_dark_email = PACKAGE_BUGREPORT;
00050 const char *const fors_dark_description =
00051 "This recipe is used to combine input raw DARK frames into a master dark\n"
00052 "frame by subtracing the master bias and using the given stacking method.\n"
00053 "The overscan regions, if present, are removed from the result.\n"
00054 "\n"
00055 "Input files:\n"
00056 "\n"
00057 "  DO category:               Type:       Explanation:         Required:\n"
00058 "  DARK                       Raw         Dark frame              Y\n"
00059 "  MASTER_BIAS                FITS image  Master bias             Y\n"
00060 "\n"
00061 "Output files:\n"
00062 "\n"
00063 "  DO category:               Data type:  Explanation:\n"
00064 "  MASTER_DARK                FITS image  Master dark frame\n"
00065 "\n";
00066 
00071 void fors_dark_define_parameters(cpl_parameterlist *parameters)
00072 {
00073     const char *context = cpl_sprintf("fors.%s", fors_dark_name);
00074     
00075     fors_stack_define_parameters(parameters, context, "median");
00076 
00077     cpl_free((void *)context);
00078 
00079     return;
00080 }
00081 
00082 #undef cleanup
00083 #define cleanup \
00084 do { \
00085     cpl_frameset_delete(dark_frames); \
00086     cpl_frameset_delete(master_bias_frame); \
00087     fors_image_delete_const(&master_bias); \
00088     fors_stack_method_delete(&sm); \
00089     fors_image_delete(&master_dark); \
00090     fors_image_list_delete_const(&darks, fors_image_delete); \
00091     fors_setting_delete(&setting); \
00092     cpl_free((void *)context); \
00093 } while (0)
00094 
00103 void fors_dark(cpl_frameset *frames, const cpl_parameterlist *parameters)
00104 {
00105     /* Raw */
00106     cpl_frameset *dark_frames      = NULL;
00107     const fors_image_list *darks   = NULL;
00108 
00109     /* Calibration */
00110     cpl_frameset *master_bias_frame = NULL;
00111     const fors_image *master_bias   = NULL; 
00112 
00113     /* Product */
00114     fors_image *master_dark = NULL;
00115 
00116     /* Parameters */
00117     stack_method *sm    = NULL;
00118 
00119     /* Other */
00120     fors_setting *setting = NULL;
00121     const char *context = cpl_sprintf("fors.%s", fors_dark_name);
00122 
00123     /* Get parameters */
00124     sm = fors_stack_method_new(parameters, context);
00125     assure( !cpl_error_get_code(), return, "Could not get stacking method");
00126     
00127     /* Find raw */
00128     dark_frames = fors_frameset_extract(frames, DARK);
00129     assure( cpl_frameset_get_size(dark_frames) > 0, return, 
00130             "No %s provided", DARK);
00131 
00132     /* Find calibration */
00133     master_bias_frame = fors_frameset_extract(frames, MASTER_BIAS);
00134     assure( cpl_frameset_get_size(master_bias_frame) == 1, return, 
00135             "One %s required. %d found", 
00136             MASTER_BIAS, cpl_frameset_get_size(master_bias_frame));
00137 
00138     /* Get instrument setting */
00139     setting = fors_setting_new(cpl_frameset_get_first(dark_frames));
00140     assure( !cpl_error_get_code(), return, "Could not get instrument setting" );
00141 
00142     master_bias = fors_image_load(cpl_frameset_get_first(master_bias_frame), 
00143                                   NULL, setting,
00144                                   NULL);
00145     assure( !cpl_error_get_code(), return, 
00146             "Could not load master bias");
00147     
00148     /* Load dark, subtract bias */
00149     darks = fors_image_load_list_const(dark_frames, master_bias, setting, NULL);
00150     assure( !cpl_error_get_code(), return, "Could not load dark images");
00151 
00152     /* Stack */
00153     master_dark = fors_stack_const(darks, sm);
00154     assure( !cpl_error_get_code(), return, "Dark stacking failed");
00155     
00156     /* Save product */
00157     fors_dfs_save_image(frames, master_dark, MASTER_DARK,
00158                         NULL, parameters, fors_dark_name, 
00159                         cpl_frameset_get_first(dark_frames));
00160     assure( !cpl_error_get_code(), return, "Saving %s failed",
00161             MASTER_DARK);
00162     
00163     cleanup;
00164     return;
00165 }
00166 

Generated on Fri Mar 4 09:46:00 2011 for FORS Pipeline Reference Manual by  doxygen 1.4.7