uves_tflat_impl.c

00001 /*                                                                              *
00002  *   This file is part of the ESO UVES Pipeline                                 *
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 /*
00021  * $Author: amodigli $
00022  * $Date: 2008/03/28 08:54:45 $
00023  * $Revision: 1.22 $
00024  * $Name: uves-3_9_0 $
00025  * $Log: uves_tflat_impl.c,v $
00026  * Revision 1.22  2008/03/28 08:54:45  amodigli
00027  * IRPLIB_CONCAT2X-->UVES_CONCAT2X
00028  *
00029  * Revision 1.21  2008/03/04 15:24:22  amodigli
00030  * fixed redchain problem with clean_traps parameter
00031  *
00032  * Revision 1.20  2008/03/04 07:36:17  amodigli
00033  * add parameter clean_traps
00034  *
00035  * Revision 1.19  2008/02/15 12:43:49  amodigli
00036  * allow lower/upper chip for parameter process_chip
00037  *
00038  * Revision 1.18  2007/10/05 16:01:45  amodigli
00039  * using proces_chip parameter to process or not a given RED chip
00040  *
00041  * Revision 1.17  2007/08/21 13:08:26  jmlarsen
00042  * Removed irplib_access module, largely deprecated by CPL-4
00043  *
00044  * Revision 1.16  2007/06/11 13:28:26  jmlarsen
00045  * Changed recipe contact address to cpl at eso.org
00046  *
00047  * Revision 1.15  2007/06/08 13:06:16  jmlarsen
00048  * Send bug reports to Andrea
00049  *
00050  * Revision 1.14  2007/06/06 08:17:33  amodigli
00051  * replace tab with 4 spaces
00052  *
00053  * Revision 1.13  2007/05/14 08:09:48  amodigli
00054  * updated input frames and tag description in recipe man page
00055  *
00056  * Revision 1.12  2007/02/09 13:44:30  jmlarsen
00057  * Use defines for recipe id
00058  *
00059  * Revision 1.11  2007/02/09 09:00:06  jmlarsen
00060  * Use defines rather than hard-coded recipe names
00061  *
00062  * Revision 1.10  2006/11/15 15:02:15  jmlarsen
00063  * Implemented const safe workarounds for CPL functions
00064  *
00065  * Revision 1.8  2006/11/15 14:04:08  jmlarsen
00066  * Removed non-const version of parameterlist_get_first/last/next which is
00067  * already in CPL, added const-safe wrapper, unwrapper and deallocator functions
00068  *
00069  * Revision 1.7  2006/11/13 12:48:35  jmlarsen
00070  * Changed interface of uves_reduce_mflat to support FLAMES
00071  *
00072  * Revision 1.6  2006/11/06 15:19:42  jmlarsen
00073  * Removed unused include directives
00074  *
00075  * Revision 1.5  2006/10/17 12:33:02  jmlarsen
00076  * Added semicolon at UVES_RECIPE_DEFINE invocation
00077  *
00078  * Revision 1.4  2006/10/09 13:01:13  jmlarsen
00079  * Use macro to define recipe interface functions
00080  *
00081  * Revision 1.3  2006/10/02 08:33:36  jmlarsen
00082  * Re-tag MASTER_TFLAT as product after the science reduction
00083  *
00084  * Revision 1.2  2006/09/27 15:08:45  jmlarsen
00085  * Fixed doc. bug
00086  *
00087  * Revision 1.1  2006/09/27 13:23:38  jmlarsen
00088  * Added tflat recipe
00089  *
00090  */
00091 #ifdef HAVE_CONFIG_H
00092 #  include <config.h>
00093 #endif
00094 
00095 /*----------------------------------------------------------------------------*/
00101 /*----------------------------------------------------------------------------*/
00102 
00103 /*-----------------------------------------------------------------------------
00104                                 Includes
00105  -----------------------------------------------------------------------------*/
00106 
00107 #include <uves_reduce_mflat.h>
00108 #include <uves_reduce_scired.h>
00109 #include <uves_parameters.h>
00110 #include <uves_utils_wrappers.h>
00111 #include <uves_dfs.h>
00112 #include <uves_recipe.h>
00113 #include <uves.h>
00114 #include <uves_error.h>
00115 #include <uves_msg.h>
00116 
00117 #include <cpl.h>
00118 
00119 /*-----------------------------------------------------------------------------
00120                             Functions prototypes
00121  -----------------------------------------------------------------------------*/
00122 static int
00123 uves_tflat_define_parameters(cpl_parameterlist *parameters);
00124 
00125 /*-----------------------------------------------------------------------------
00126                             Recipe standard code
00127  -----------------------------------------------------------------------------*/
00128 #define cpl_plugin_get_info uves_tflat_get_info
00129 UVES_RECIPE_DEFINE(
00130     UVES_TFLAT_ID, UVES_TFLAT_DOM, uves_tflat_define_parameters,
00131     "Jonas M. Larsen", "cpl@eso.org",
00132     "Reduces a TFLAT frame",
00133     "This recipe reduces a TFLAT_xxx frame (xxx = BLUE,RED). This is\n"
00134     "achieved by\n"
00135     "1) combining all provided TFLAT frames to a MASTER_TFLAT frame, then\n"
00136     "2) doing a normal science reduction on the first input TFLAT frame\n"
00137     "Input frames are raw TFLAT_xxx  frames, and: \n"
00138     "order table(s) for each chip, ORDER_TABLE_xxxx (where xxxx=BLUE, REDL, REDU),\n"
00139     "line table(s) for each chip, LINE_TABLE_xxxx, a master bias frame,\n"
00140     "MASTER_BIAS_xxxx, a master flat, MASTER_FLAT_xxxx, \n");
00141 
00143 /*-----------------------------------------------------------------------------
00144                               Functions code
00145  -----------------------------------------------------------------------------*/
00146 /*----------------------------------------------------------------------------*/
00152 /*----------------------------------------------------------------------------*/
00153 static int
00154 uves_tflat_define_parameters(cpl_parameterlist *parameters)
00155 {
00156 
00157 
00158     /*****************
00159      *    General    *
00160      *****************/
00161     if (uves_define_global_parameters(parameters) != CPL_ERROR_NONE)
00162         {
00163             return -1;
00164         }
00165 
00166     if (uves_corr_traps_define_parameters(parameters,"uves_cal_tflat") 
00167         != CPL_ERROR_NONE)
00168         {
00169             return -1;
00170         }
00171 
00172 
00173 
00174     /***********************************
00175      *  Spline back.sub. (master flat) *
00176      ***********************************/
00177     
00178     if (uves_propagate_parameters_step(UVES_BACKSUB_ID, parameters, 
00179                        make_str(UVES_TFLAT_ID), NULL) != 0)
00180     {
00181         return -1;
00182     }
00183 
00184     /*******************
00185      *  Reduce.        *
00186      ******************/
00187     if (uves_propagate_parameters_step(UVES_REDUCE_ID, parameters,
00188                                        make_str(UVES_TFLAT_ID), NULL) != 0)
00189         {
00190             return -1;
00191         }
00192 
00193     /* For TFLAT reduction: average extraction, no sky subtraction */
00194     {
00195     const char *param = "average";
00196     bool bool_param;
00197 
00198     if (uves_set_parameter_default(parameters, 
00199                        make_str(UVES_TFLAT_ID), "reduce.extract.method",
00200                        CPL_TYPE_STRING, &param) != CPL_ERROR_NONE)
00201         {
00202         return -1;
00203         }
00204 
00205     bool_param = false;
00206     if (uves_set_parameter_default(parameters, 
00207                        make_str(UVES_TFLAT_ID), "reduce.skysub",
00208                        CPL_TYPE_BOOL, &bool_param) != CPL_ERROR_NONE)
00209         {
00210         return -1;
00211         }
00212     }
00213     
00214     return (cpl_error_get_code() != CPL_ERROR_NONE);
00215 }
00216 
00217 /*----------------------------------------------------------------------------*/
00224 /*----------------------------------------------------------------------------*/
00225 static void
00226 UVES_CONCAT2X(UVES_TFLAT_ID,exe)(cpl_frameset *frames,
00227                    const cpl_parameterlist *parameters, 
00228                    const char *starttime)
00229 {
00230     uves_msg("Creating master tflat");
00231     check_nomsg( uves_mflat_exe_body(frames, parameters, 
00232                      starttime,
00233                      make_str(UVES_TFLAT_ID)) );
00234 
00235     uves_msg("Reducing first raw tflat");
00236     check_nomsg( uves_reduce_scired(frames, parameters, make_str(UVES_TFLAT_ID), starttime) );
00237 
00238     /* The MASTER_TFLAT was reclassified as CALIB by the reduction step.
00239        But it is actually a product of this recipe, so retag it */
00240     {
00241       enum uves_chip chip;
00242       int blue;
00243       const char* PROCESS_CHIP=NULL;
00244       check( uves_get_parameter(parameters, NULL, "uves", "process_chip", CPL_TYPE_STRING, &PROCESS_CHIP),
00245          "Could not read parameter");
00246     uves_string_toupper((char*)PROCESS_CHIP);
00247 
00248       /* Loop over all possible MASTER_TFLATs */
00249       for (blue = 0; blue <= 1; blue++)
00250         {
00251       for (chip = uves_chip_get_first(blue);
00252            chip != UVES_CHIP_INVALID;
00253            chip = uves_chip_get_next(chip))
00254             {
00255 
00256           if(strcmp(PROCESS_CHIP,"REDU") == 0) {
00257         chip = uves_chip_get_next(chip);
00258           }
00259 
00260           cpl_frame *f = cpl_frameset_find(frames, UVES_MASTER_TFLAT(chip));
00261           if (f != NULL)
00262                 {
00263           cpl_frame_set_group(f, CPL_FRAME_GROUP_PRODUCT);
00264                 }
00265             
00266           f = cpl_frameset_find(frames, UVES_BKG_FLAT(chip));
00267           if (f != NULL)
00268                 {
00269           cpl_frame_set_group(f, CPL_FRAME_GROUP_PRODUCT);
00270                 }
00271             }
00272 
00273       if(strcmp(PROCESS_CHIP,"REDL") == 0) {
00274         chip = uves_chip_get_next(chip);
00275       }
00276 
00277         }
00278     }
00279 
00280   cleanup:
00281     return;
00282 }
00283 

Generated on Fri Apr 18 14:11:43 2008 for UVES Pipeline Reference Manual by  doxygen 1.5.1