GIRAFFE Pipeline Reference Manual

giastrometry.c
1 /* $Id$
2  *
3  * This file is part of the GIRAFFE Pipeline
4  * Copyright (C) 2002-2008 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 
33 #include "gialias.h"
34 #include "gierror.h"
35 #include "girvcorrection.h"
36 #include "giastrometry.h"
37 
38 
75 cxint
76 giraffe_add_rvcorrection(GiTable* fibers, const GiImage* spectra)
77 {
78 
79  cxint fiber = 0;
80  cxint nr = 0;
81 
82  cxdouble exptime = 0.;
83  cxdouble jd = 0.;
84  cxdouble equinox = 2000.;
85  cxdouble longitude = 0.;
86  cxdouble latitude = 0.;
87  cxdouble elevation = 0.;
88  cxdouble tel_ra = 0.;
89  cxdouble tel_dec = 0.;
90 
91  const cpl_propertylist* properties = NULL;
92 
93  cpl_table* _fibers = NULL;
94 
95 
96  if ((fibers == NULL) || (spectra == NULL)) {
97  return -1;
98  }
99 
100  properties = giraffe_image_get_properties(spectra);
101  cx_assert(properties != NULL);
102 
103 
104  /*
105  * Get time related information
106  */
107 
108  if (cpl_propertylist_has(properties, GIALIAS_EXPTIME) == FALSE) {
109  return 1;
110  }
111  else {
112  exptime = cpl_propertylist_get_double(properties, GIALIAS_EXPTIME);
113  }
114 
115  if (cpl_propertylist_has(properties, GIALIAS_MJDOBS) == FALSE) {
116  return 1;
117  }
118  else {
119 
120  /*
121  * Compute julian date of mid exposure. 2400000.5 is the offset
122  * between JD and MJD and corresponds to November 17th 1858 0:00 UT.
123  */
124 
125  jd = cpl_propertylist_get_double(properties, GIALIAS_MJDOBS);
126  jd += 2400000.5 + 0.5 * exptime / (24. * 3600.);
127 
128  }
129 
130  if (cpl_propertylist_has(properties, GIALIAS_EQUINOX) == FALSE) {
131  return 1;
132  }
133  else {
134  equinox = cpl_propertylist_get_double(properties, GIALIAS_EQUINOX);
135  }
136 
137 
138  /*
139  * Get telescope location and elevation.
140  */
141 
142  if (cpl_propertylist_has(properties, GIALIAS_TEL_LON) == FALSE) {
143  return 2;
144  }
145  else {
146 
147  /*
148  * The sign of the property TEL.GEOLON is defined as east = positive
149  * For the computation we need west = positive.
150  */
151 
152  longitude = -cpl_propertylist_get_double(properties, GIALIAS_TEL_LON);
153 
154  }
155 
156  if (cpl_propertylist_has(properties, GIALIAS_TEL_LAT) == FALSE) {
157  return 2;
158  }
159  else {
160  latitude = cpl_propertylist_get_double(properties, GIALIAS_TEL_LAT);
161  }
162 
163  if (cpl_propertylist_has(properties, GIALIAS_TEL_ELEV) == FALSE) {
164  return 2;
165  }
166  else {
167  elevation = cpl_propertylist_get_double(properties, GIALIAS_TEL_ELEV);
168  }
169 
170 
171  /*
172  * Get telescope pointing
173  */
174 
175  if (cpl_propertylist_has(properties, GIALIAS_RADEG) == FALSE) {
176  return 4;
177  }
178  else {
179  tel_ra = cpl_propertylist_get_double(properties, GIALIAS_RADEG);
180  }
181 
182  if (cpl_propertylist_has(properties, GIALIAS_DECDEG) == FALSE) {
183  return 4;
184  }
185  else {
186  tel_dec = cpl_propertylist_get_double(properties, GIALIAS_DECDEG);
187  }
188 
189  properties = NULL;
190 
191 
192  /*
193  * Get observed objects right ascension and declination
194  */
195 
196  _fibers = giraffe_table_get(fibers);
197 
198  if ((cpl_table_has_column(_fibers, "RA") == FALSE) ||
199  (cpl_table_has_column(_fibers, "DEC") == FALSE)) {
200  return 3;
201  }
202 
203  if (cpl_table_has_column(_fibers, "RP") == FALSE) {
204  return -1;
205  }
206 
207 
208  giraffe_error_push();
209 
210  if (cpl_table_has_column(_fibers, "GCORR") == FALSE) {
211  cpl_table_new_column(_fibers, "GCORR", CPL_TYPE_DOUBLE);
212  }
213 
214  if (cpl_table_has_column(_fibers, "HCORR") == FALSE) {
215  cpl_table_new_column(_fibers, "HCORR", CPL_TYPE_DOUBLE);
216  }
217 
218  if (cpl_table_has_column(_fibers, "BCORR") == FALSE) {
219  cpl_table_new_column(_fibers, "BCORR", CPL_TYPE_DOUBLE);
220  }
221 
222  if (cpl_error_get_code() != CPL_ERROR_NONE) {
223  return -2;
224  }
225 
226  giraffe_error_pop();
227 
228 
229  nr = cpl_table_get_nrow(_fibers);
230 
231  for (fiber = 0; fiber < nr; ++fiber) {
232 
233  cxint rp = cpl_table_get_int(_fibers, "RP", fiber, NULL);
234 
235  GiRvCorrection rv = {0., 0., 0.};
236 
237 
238  if (rp != -1) {
239 
240  register cxdouble ra = 0.;
241  register cxdouble dec = 0.;
242 
243 
244  /*
245  * Argus fibers have no associated position. In this case use
246  * the telescope pointing to compute the correction. Argus object
247  * fibers have rp set to 0.
248  */
249 
250  if (rp == 0) {
251 
252  ra = tel_ra;
253  dec = tel_dec;
254 
255  }
256  else {
257 
258  ra = cpl_table_get_double(_fibers, "RA", fiber, NULL);
259  dec = cpl_table_get_double(_fibers, "DEC", fiber, NULL);
260 
261  }
262 
263 
264  /*
265  * The right ascension must be in hours
266  */
267 
268  ra /= 15.;
269 
270  giraffe_rvcorrection_compute(&rv, jd, longitude, latitude,
271  elevation, ra, dec, equinox);
272 
273 
274  }
275 
276  cpl_table_set_double(_fibers, "GCORR", fiber, rv.gc);
277  cpl_table_set_double(_fibers, "HCORR", fiber, rv.hc);
278  cpl_table_set_double(_fibers, "BCORR", fiber, rv.bc);
279 
280  }
281 
282  return 0;
283 }

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:51 by doxygen 1.8.2 written by Dimitri van Heesch, © 1997-2004