GIRAFFE Pipeline Reference Manual

gisutils.c

00001 /* $Id: gisutils.c,v 1.6 2007/08/23 08:39:06 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: 2007/08/23 08:39:06 $
00024  * $Revision: 1.6 $
00025  * $Name: giraffe-2_5_2 $
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;
00051     cxint first;
00052     cxint last;
00053     cxint nx;
00054     cxint status = 0;
00055 
00056     cxdouble wmin;
00057     cxdouble wmax;
00058     cxdouble wstep;
00059     cxdouble fstart;
00060     cxdouble fend;
00061 
00062     cpl_propertylist *properties = giraffe_image_get_properties(spectrum);
00063 
00064     cpl_image *_spectrum = giraffe_image_get(spectrum);
00065     cpl_image *_flux = NULL;
00066 
00067     GiImage *flux = NULL;
00068 
00069 
00070     if (properties == NULL || _spectrum == NULL) {
00071         return NULL;
00072     }
00073 
00074 
00075     if (!cpl_propertylist_has(properties, GIALIAS_BINWLMIN)) {
00076         return NULL;
00077     }
00078 
00079     wmin = cpl_propertylist_get_double(properties, GIALIAS_BINWLMIN);
00080 
00081 
00082     if (!cpl_propertylist_has(properties, GIALIAS_BINWLMAX)) {
00083         return NULL;
00084     }
00085 
00086     wmax = cpl_propertylist_get_double(properties, GIALIAS_BINWLMAX);
00087 
00088 
00089     if (!cpl_propertylist_has(properties, GIALIAS_BINSTEP)) {
00090         return NULL;
00091     }
00092 
00093     wstep = cpl_propertylist_get_double(properties, GIALIAS_BINSTEP);
00094 
00095 
00096     /*
00097      * Determine the pixel limits for the integration from the
00098      * given wavelength range.
00099      */
00100 
00101     first = 0;
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 = last - (wmax - giraffe_range_get_max(limits)) / 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_collapse_window_create(_spectrum, 1, first + 1, nx,
00129                                              last + 1, 0);
00130 
00131     if (_flux == NULL) {
00132         return NULL;
00133     }
00134 
00135 
00136     /*
00137      * Add fluxes for the pixel fractions at the beginning and the end of
00138      * the image window.
00139      */
00140 
00141     if ((first - 1) >= 0) {
00142 
00143         cxint j = (first - 1) * nx;
00144 
00145         cxdouble *data = cpl_image_get_data(_spectrum);
00146         cxdouble *fx = cpl_image_get_data(_flux);
00147 
00148 
00149         for (i = 0; i < nx; i++) {
00150             fx[i] += data[j + i] * fstart;
00151         }
00152     }
00153 
00154 
00155     if ((last + 1 ) < cpl_image_get_size_y(_spectrum)) {
00156 
00157         cxint j = (last + 1) * nx;
00158 
00159         cxdouble *data = cpl_image_get_data(_spectrum);
00160         cxdouble *fx = cpl_image_get_data(_flux);
00161 
00162 
00163         for (i = 0; i < nx; i++) {
00164             fx[i] += data[j + i] * fend;
00165         }
00166     }
00167 
00168     flux = giraffe_image_new(CPL_TYPE_DOUBLE);
00169 
00170     status = giraffe_image_set(flux, _flux);
00171     cpl_image_delete(_flux);
00172 
00173     if (status != 0) {
00174         giraffe_image_delete(flux);
00175         return NULL;
00176     }
00177 
00178     status = giraffe_image_set_properties(flux, properties);
00179 
00180     if (status != 0) {
00181         giraffe_image_delete(flux);
00182         return NULL;
00183     }
00184 
00185     return flux;
00186 
00187 }

This file is part of the GIRAFFE Pipeline Reference Manual 2.5.2.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Fri Jun 13 14:36:24 2008 by doxygen 1.4.6 written by Dimitri van Heesch, © 1997-2004