GIRAFFE Pipeline Reference Manual

gisutils.c

00001 /* $Id: gisutils.c,v 1.7 2009/05/29 12:46:08 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: 2009/05/29 12:46:08 $
00024  * $Revision: 1.7 $
00025  * $Name: giraffe-2_10 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #  include <config.h>
00030 #endif
00031 
00032 #include <math.h>
00033 
00034 #include "gialias.h"
00035 #include "gisutils.h"
00036 
00037 
00046 GiImage *
00047 giraffe_integrate_flux(GiImage *spectrum, GiRange *limits)
00048 {
00049 
00050     cxint i = 0;
00051     cxint k = 0;
00052     cxint first = 0;
00053     cxint last = 0;
00054     cxint nx = 0;
00055     cxint status = 0;
00056 
00057     cxdouble wmin = 0.;
00058     cxdouble wmax = 0.;
00059     cxdouble wstep = 0.;
00060     cxdouble fstart = 0.;
00061     cxdouble fend = 0.;
00062 
00063     cpl_propertylist *properties = giraffe_image_get_properties(spectrum);
00064 
00065     cpl_image *_spectrum = giraffe_image_get(spectrum);
00066     cpl_image *_flux = NULL;
00067 
00068     GiImage *flux = NULL;
00069 
00070 
00071     if (properties == NULL || _spectrum == NULL) {
00072         return NULL;
00073     }
00074 
00075 
00076     if (!cpl_propertylist_has(properties, GIALIAS_BINWLMIN)) {
00077         return NULL;
00078     }
00079 
00080     wmin = cpl_propertylist_get_double(properties, GIALIAS_BINWLMIN);
00081 
00082 
00083     if (!cpl_propertylist_has(properties, GIALIAS_BINWLMAX)) {
00084         return NULL;
00085     }
00086 
00087     wmax = cpl_propertylist_get_double(properties, GIALIAS_BINWLMAX);
00088 
00089 
00090     if (!cpl_propertylist_has(properties, GIALIAS_BINSTEP)) {
00091         return NULL;
00092     }
00093 
00094     wstep = cpl_propertylist_get_double(properties, GIALIAS_BINSTEP);
00095 
00096 
00097     /*
00098      * Determine the pixel limits for the integration from the
00099      * given wavelength range.
00100      */
00101 
00102     last = cpl_image_get_size_y(_spectrum) - 1;
00103 
00104     if (giraffe_range_get_min(limits) > wmin) {
00105 
00106         cxdouble pixel = (giraffe_range_get_min(limits) - wmin) / wstep;
00107 
00108         first  = ceil(pixel);
00109         fstart = pixel - first;
00110     }
00111 
00112     if (giraffe_range_get_max(limits) < wmax) {
00113 
00114         cxdouble pixel = (giraffe_range_get_max(limits) - wmin) / wstep;
00115 
00116         last = floor(pixel);
00117         fend = pixel - last;
00118     }
00119 
00120 
00121     /*
00122      * Sum fluxes along the dispersion direction (image y-axis) for
00123      * the defined window.
00124      */
00125 
00126     nx = cpl_image_get_size_x(_spectrum);
00127 
00128     _flux = cpl_image_new(nx, 1, CPL_TYPE_DOUBLE);
00129 
00130     if (_flux == NULL) {
00131         return NULL;
00132     }
00133     else {
00134 
00135         cxdouble *data = cpl_image_get_data(_spectrum);
00136         cxdouble *fx = cpl_image_get_data(_flux);
00137 
00138         for (k = first; k < last; ++k) {
00139 
00140             for (i = 0; i < nx; i++) {
00141                 fx[i] += data[k * nx + i];
00142             }
00143 
00144         }
00145 
00146     }
00147 
00148 
00149     /*
00150      * Add fluxes for the pixel fractions at the beginning and the end of
00151      * the image window.
00152      */
00153 
00154     if ((first - 1) >= 0) {
00155 
00156         cxint j = (first - 1) * nx;
00157 
00158         cxdouble *data = cpl_image_get_data(_spectrum);
00159         cxdouble *fx = cpl_image_get_data(_flux);
00160 
00161 
00162         for (i = 0; i < nx; i++) {
00163             fx[i] += data[j + i] * fstart;
00164         }
00165     }
00166 
00167 
00168     if ((last + 1 ) < cpl_image_get_size_y(_spectrum)) {
00169 
00170         cxint j = last * nx;
00171 
00172         cxdouble *data = cpl_image_get_data(_spectrum);
00173         cxdouble *fx = cpl_image_get_data(_flux);
00174 
00175 
00176         for (i = 0; i < nx; i++) {
00177             fx[i] += data[j + i] * fend;
00178         }
00179     }
00180 
00181     flux = giraffe_image_new(CPL_TYPE_DOUBLE);
00182 
00183     status = giraffe_image_set(flux, _flux);
00184     cpl_image_delete(_flux);
00185 
00186     if (status != 0) {
00187         giraffe_image_delete(flux);
00188         return NULL;
00189     }
00190 
00191     status = giraffe_image_set_properties(flux, properties);
00192 
00193     if (status != 0) {
00194         giraffe_image_delete(flux);
00195         return NULL;
00196     }
00197 
00198     return flux;
00199 
00200 }

This file is part of the GIRAFFE Pipeline Reference Manual 2.10.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Thu Mar 7 14:11:03 2013 by doxygen 1.4.7 written by Dimitri van Heesch, © 1997-2004