GIRAFFE Pipeline Reference Manual

gisutils.c
1 /* $Id$
2  *
3  * This file is part of the GIRAFFE Pipeline
4  * Copyright (C) 2002-2006 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /*
22  * $Author$
23  * $Date$
24  * $Revision$
25  * $Name$
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31 
32 #include <math.h>
33 
34 #include "gialias.h"
35 #include "gisutils.h"
36 
37 
46 GiImage *
47 giraffe_integrate_flux(GiImage *spectrum, GiRange *limits)
48 {
49 
50  cxint i = 0;
51  cxint k = 0;
52  cxint first = 0;
53  cxint last = 0;
54  cxint nx = 0;
55  cxint status = 0;
56 
57  cxdouble wmin = 0.;
58  cxdouble wmax = 0.;
59  cxdouble wstep = 0.;
60  cxdouble fstart = 0.;
61  cxdouble fend = 0.;
62 
63  cpl_propertylist *properties = giraffe_image_get_properties(spectrum);
64 
65  cpl_image *_spectrum = giraffe_image_get(spectrum);
66  cpl_image *_flux = NULL;
67 
68  GiImage *flux = NULL;
69 
70 
71  if (properties == NULL || _spectrum == NULL) {
72  return NULL;
73  }
74 
75 
76  if (!cpl_propertylist_has(properties, GIALIAS_BINWLMIN)) {
77  return NULL;
78  }
79 
80  wmin = cpl_propertylist_get_double(properties, GIALIAS_BINWLMIN);
81 
82 
83  if (!cpl_propertylist_has(properties, GIALIAS_BINWLMAX)) {
84  return NULL;
85  }
86 
87  wmax = cpl_propertylist_get_double(properties, GIALIAS_BINWLMAX);
88 
89 
90  if (!cpl_propertylist_has(properties, GIALIAS_BINSTEP)) {
91  return NULL;
92  }
93 
94  wstep = cpl_propertylist_get_double(properties, GIALIAS_BINSTEP);
95 
96 
97  /*
98  * Determine the pixel limits for the integration from the
99  * given wavelength range.
100  */
101 
102  last = cpl_image_get_size_y(_spectrum) - 1;
103 
104  if (giraffe_range_get_min(limits) > wmin) {
105 
106  cxdouble pixel = (giraffe_range_get_min(limits) - wmin) / wstep;
107 
108  first = ceil(pixel);
109  fstart = pixel - first;
110  }
111 
112  if (giraffe_range_get_max(limits) < wmax) {
113 
114  cxdouble pixel = (giraffe_range_get_max(limits) - wmin) / wstep;
115 
116  last = floor(pixel);
117  fend = pixel - last;
118  }
119 
120 
121  /*
122  * Sum fluxes along the dispersion direction (image y-axis) for
123  * the defined window.
124  */
125 
126  nx = cpl_image_get_size_x(_spectrum);
127 
128  _flux = cpl_image_new(nx, 1, CPL_TYPE_DOUBLE);
129 
130  if (_flux == NULL) {
131  return NULL;
132  }
133  else {
134 
135  cxdouble *data = cpl_image_get_data(_spectrum);
136  cxdouble *fx = cpl_image_get_data(_flux);
137 
138  for (k = first; k < last; ++k) {
139 
140  for (i = 0; i < nx; i++) {
141  fx[i] += data[k * nx + i];
142  }
143 
144  }
145 
146  }
147 
148 
149  /*
150  * Add fluxes for the pixel fractions at the beginning and the end of
151  * the image window.
152  */
153 
154  if ((first - 1) >= 0) {
155 
156  cxint j = (first - 1) * nx;
157 
158  cxdouble *data = cpl_image_get_data(_spectrum);
159  cxdouble *fx = cpl_image_get_data(_flux);
160 
161 
162  for (i = 0; i < nx; i++) {
163  fx[i] += data[j + i] * fstart;
164  }
165  }
166 
167 
168  if ((last + 1 ) < cpl_image_get_size_y(_spectrum)) {
169 
170  cxint j = last * nx;
171 
172  cxdouble *data = cpl_image_get_data(_spectrum);
173  cxdouble *fx = cpl_image_get_data(_flux);
174 
175 
176  for (i = 0; i < nx; i++) {
177  fx[i] += data[j + i] * fend;
178  }
179  }
180 
181  flux = giraffe_image_new(CPL_TYPE_DOUBLE);
182 
183  status = giraffe_image_set(flux, _flux);
184  cpl_image_delete(_flux);
185 
186  if (status != 0) {
187  giraffe_image_delete(flux);
188  return NULL;
189  }
190 
191  status = giraffe_image_set_properties(flux, properties);
192 
193  if (status != 0) {
194  giraffe_image_delete(flux);
195  return NULL;
196  }
197 
198  return flux;
199 
200 }

This file is part of the GIRAFFE Pipeline Reference Manual 2.12.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Mon Mar 24 2014 11:43:53 by doxygen 1.8.2 written by Dimitri van Heesch, © 1997-2004