GIRAFFE Pipeline Reference Manual

giflat.c

00001 /* $Id: giflat.c,v 1.9 2006/07/12 15:25:57 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: 2006/07/12 15:25:57 $
00024  * $Revision: 1.9 $
00025  * $Name: giraffe-2_5_1 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #  include <config.h>
00030 #endif
00031 
00032 #include <cxmemory.h>
00033 #include <cxmessages.h>
00034 #include <cxstrutils.h>
00035 
00036 #include <cpl_msg.h>
00037 #include <cpl_parameterlist.h>
00038 
00039 #include "gifiberutils.h"
00040 #include "giflat.h"
00041 #include "gimessages.h"
00042 
00043 
00052 /*
00053  * For each extracted spectra look up the corresponding flat field
00054  * spectrum and devide the extracted flux value by the flat field
00055  * flux value for each individual pixel along the dispersion axis.
00056  */
00057 
00058 inline static cxint
00059 _giraffe_flat_apply(GiImage *spectra, GiTable *fibers, GiImage *flat)
00060 {
00061 
00062     const cxchar *fctid = "giraffe_flat_apply";
00063 
00064     const cxchar *idx = NULL;
00065 
00066     cxint nf;
00067     cxint nfibers = 0;
00068     cxint nbins = 0;
00069 
00070     cpl_image *_spectra = giraffe_image_get(spectra);
00071     cpl_image *_flat = giraffe_image_get(flat);
00072 
00073     cpl_table *_fibers = giraffe_table_get(fibers);
00074 
00075 
00076     idx = giraffe_fiberlist_query_index(_fibers);
00077 
00078     if (idx == NULL) {
00079         cpl_error_set(fctid, CPL_ERROR_DATA_NOT_FOUND);
00080         return -1;
00081     }
00082 
00083 
00084     /*
00085      * The number of fibers to be process must be less or equal to the
00086      * number of spectra available in the flat field.
00087      */
00088 
00089     nfibers = cpl_table_get_nrow(_fibers);
00090 
00091     if (nfibers > cpl_image_get_size_x(_spectra)) {
00092         cpl_error_set(fctid, CPL_ERROR_INCOMPATIBLE_INPUT);
00093         return -2;
00094     }
00095 
00096     nbins = cpl_image_get_size_y(_spectra);
00097 
00098     if (nbins != cpl_image_get_size_y(_flat)) {
00099         cpl_error_set(fctid, CPL_ERROR_INCOMPATIBLE_INPUT);
00100         return -3;
00101     }
00102 
00103     for (nf = 0; nf < nfibers; ++nf) {
00104 
00105         register cxint y;
00106         register cxint ns = cpl_table_get_int(_fibers, idx, nf, NULL) - 1;
00107 
00108         cxdouble *s = cpl_image_get_data(_spectra);
00109         cxdouble *f = cpl_image_get_data(_flat);
00110 
00111         for (y = 0; y < nbins ; ++y) {
00112 
00113             cxint ls = y * cpl_image_get_size_x(_spectra) + nf;
00114             cxint lf = y * cpl_image_get_size_x(_flat) + ns;
00115 
00116             s[ls] /= f[lf];
00117 
00118         }
00119 
00120     }
00121 
00122     return 0;
00123 
00124 }
00125 
00126 
00141 cxint
00142 giraffe_flat_apply(GiExtraction *extraction, GiTable *fibers, GiImage *flat,
00143                    GiFlatConfig *config)
00144 {
00145 
00146     cxint status = 0;
00147 
00148 
00149     if (extraction == NULL || extraction->spectra == NULL) {
00150         return -1;
00151     }
00152 
00153     if (fibers == NULL) {
00154         return -2;
00155     }
00156 
00157     if (flat == NULL) {
00158         return -3;
00159     }
00160 
00161     if (config == NULL) {
00162         return -4;
00163     }
00164 
00165 
00166     status = _giraffe_flat_apply(extraction->spectra, fibers, flat);
00167 
00168     if (status) {
00169         return 1;
00170     }
00171 
00172     if (extraction->error != NULL) {
00173 
00174         status = _giraffe_flat_apply(extraction->error, fibers, flat);
00175 
00176         if (status) {
00177             return 1;
00178         }
00179 
00180     }
00181 
00182     return 0;
00183 
00184 }
00185 
00186 
00199 GiFlatConfig *
00200 giraffe_flat_config_create(cpl_parameterlist *list)
00201 {
00202 
00203     cpl_parameter *p;
00204 
00205     GiFlatConfig *config = NULL;
00206 
00207 
00208     if (!list) {
00209         return NULL;
00210     }
00211 
00212     config = cx_calloc(1, sizeof *config);
00213 
00214 
00215     /*
00216      * Some defaults
00217      */
00218 
00219     config->apply = FALSE;
00220     config->transmission = TRUE;
00221 
00222 
00223     p = cpl_parameterlist_find(list, "giraffe.flat.apply");
00224     config->apply = cpl_parameter_get_bool(p);
00225 
00226     p = cpl_parameterlist_find(list, "giraffe.flat.transmission");
00227     config->transmission = cpl_parameter_get_bool(p);
00228 
00229     config->load = config->apply || config->transmission;
00230 
00231     return config;
00232 
00233 }
00234 
00235 
00250 void
00251 giraffe_flat_config_destroy(GiFlatConfig *config)
00252 {
00253 
00254     if (config) {
00255         cx_free(config);
00256     }
00257 
00258     return;
00259 }
00260 
00261 
00273 void
00274 giraffe_flat_config_add(cpl_parameterlist *list)
00275 {
00276 
00277     cpl_parameter *p;
00278 
00279 
00280     if (!list) {
00281         return;
00282     }
00283 
00284     p = cpl_parameter_new_value("giraffe.flat.apply",
00285                                 CPL_TYPE_BOOL,
00286                                 "Controls the flat field correction.",
00287                                 "giraffe.flat",
00288                                 TRUE);
00289     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "flat-apply");
00290     cpl_parameterlist_append(list, p);
00291 
00292 
00293     p = cpl_parameter_new_value("giraffe.flat.transmission",
00294                                 CPL_TYPE_BOOL,
00295                                 "Controls the fiber to fiber transmission "
00296                                 "correction.",
00297                                 "giraffe.flat",
00298                                 FALSE);
00299     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "transmission-apply");
00300     cpl_parameterlist_append(list, p);
00301 
00302     return;
00303 
00304 }

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