GIRAFFE Pipeline Reference Manual

giastrometry.c
1/*
2 * This file is part of the GIRAFFE Pipeline
3 * Copyright (C) 2002-2019 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21# include <config.h>
22#endif
23
24
25#include "gialias.h"
26#include "gierror.h"
27#include "girvcorrection.h"
28#include "giastrometry.h"
29
30
67cxint
68giraffe_add_rvcorrection(GiTable* fibers, const GiImage* spectra)
69{
70
71 cxint fiber = 0;
72 cxint nr = 0;
73
74 cxdouble exptime = 0.;
75 cxdouble jd = 0.;
76 cxdouble equinox = 2000.;
77 cxdouble longitude = 0.;
78 cxdouble latitude = 0.;
79 cxdouble elevation = 0.;
80 cxdouble tel_ra = 0.;
81 cxdouble tel_dec = 0.;
82
83 const cpl_propertylist* properties = NULL;
84
85 cpl_table* _fibers = NULL;
86
87
88 if ((fibers == NULL) || (spectra == NULL)) {
89 return -1;
90 }
91
92 properties = giraffe_image_get_properties(spectra);
93 cx_assert(properties != NULL);
94
95
96 /*
97 * Get time related information
98 */
99
100 if (cpl_propertylist_has(properties, GIALIAS_EXPTIME) == FALSE) {
101 return 1;
102 }
103 else {
104 exptime = cpl_propertylist_get_double(properties, GIALIAS_EXPTIME);
105 }
106
107 if (cpl_propertylist_has(properties, GIALIAS_MJDOBS) == FALSE) {
108 return 1;
109 }
110 else {
111
112 /*
113 * Compute julian date of mid exposure. 2400000.5 is the offset
114 * between JD and MJD and corresponds to November 17th 1858 0:00 UT.
115 */
116
117 jd = cpl_propertylist_get_double(properties, GIALIAS_MJDOBS);
118 jd += 2400000.5 + 0.5 * exptime / (24. * 3600.);
119
120 }
121
122 if (cpl_propertylist_has(properties, GIALIAS_EQUINOX) == FALSE) {
123 return 1;
124 }
125 else {
126 equinox = cpl_propertylist_get_double(properties, GIALIAS_EQUINOX);
127 }
128
129
130 /*
131 * Get telescope location and elevation.
132 */
133
134 if (cpl_propertylist_has(properties, GIALIAS_TEL_LON) == FALSE) {
135 return 2;
136 }
137 else {
138
139 /*
140 * The sign of the property TEL.GEOLON is defined as east = positive
141 * For the computation we need west = positive.
142 */
143
144 longitude = -cpl_propertylist_get_double(properties, GIALIAS_TEL_LON);
145
146 }
147
148 if (cpl_propertylist_has(properties, GIALIAS_TEL_LAT) == FALSE) {
149 return 2;
150 }
151 else {
152 latitude = cpl_propertylist_get_double(properties, GIALIAS_TEL_LAT);
153 }
154
155 if (cpl_propertylist_has(properties, GIALIAS_TEL_ELEV) == FALSE) {
156 return 2;
157 }
158 else {
159 elevation = cpl_propertylist_get_double(properties, GIALIAS_TEL_ELEV);
160 }
161
162
163 /*
164 * Get telescope pointing
165 */
166
167 if (cpl_propertylist_has(properties, GIALIAS_RADEG) == FALSE) {
168 return 4;
169 }
170 else {
171 tel_ra = cpl_propertylist_get_double(properties, GIALIAS_RADEG);
172 }
173
174 if (cpl_propertylist_has(properties, GIALIAS_DECDEG) == FALSE) {
175 return 4;
176 }
177 else {
178 tel_dec = cpl_propertylist_get_double(properties, GIALIAS_DECDEG);
179 }
180
181 properties = NULL;
182
183
184 /*
185 * Get observed objects right ascension and declination
186 */
187
188 _fibers = giraffe_table_get(fibers);
189
190 if ((cpl_table_has_column(_fibers, "RA") == FALSE) ||
191 (cpl_table_has_column(_fibers, "DEC") == FALSE)) {
192 return 3;
193 }
194
195 if (cpl_table_has_column(_fibers, "RP") == FALSE) {
196 return -1;
197 }
198
199
200 giraffe_error_push();
201
202 if (cpl_table_has_column(_fibers, "GCORR") == FALSE) {
203 cpl_table_new_column(_fibers, "GCORR", CPL_TYPE_DOUBLE);
204 }
205
206 if (cpl_table_has_column(_fibers, "HCORR") == FALSE) {
207 cpl_table_new_column(_fibers, "HCORR", CPL_TYPE_DOUBLE);
208 }
209
210 if (cpl_table_has_column(_fibers, "BCORR") == FALSE) {
211 cpl_table_new_column(_fibers, "BCORR", CPL_TYPE_DOUBLE);
212 }
213
214 if (cpl_error_get_code() != CPL_ERROR_NONE) {
215 return -2;
216 }
217
218 giraffe_error_pop();
219
220
221 nr = cpl_table_get_nrow(_fibers);
222
223 for (fiber = 0; fiber < nr; ++fiber) {
224
225 cxint rp = cpl_table_get_int(_fibers, "RP", fiber, NULL);
226
227 GiRvCorrection rv = {0., 0., 0.};
228
229
230 if (rp != -1) {
231
232 register cxdouble ra = 0.;
233 register cxdouble dec = 0.;
234
235
236 /*
237 * Argus fibers have no associated position. In this case use
238 * the telescope pointing to compute the correction. Argus object
239 * fibers have rp set to 0.
240 */
241
242 if (rp == 0) {
243
244 ra = tel_ra;
245 dec = tel_dec;
246
247 }
248 else {
249
250 ra = cpl_table_get_double(_fibers, "RA", fiber, NULL);
251 dec = cpl_table_get_double(_fibers, "DEC", fiber, NULL);
252
253 }
254
255
256 /*
257 * The right ascension must be in hours
258 */
259
260 ra /= 15.;
261
262 giraffe_rvcorrection_compute(&rv, jd, longitude, latitude,
263 elevation, ra, dec, equinox);
264
265
266 }
267
268 cpl_table_set_double(_fibers, "GCORR", fiber, rv.gc);
269 cpl_table_set_double(_fibers, "HCORR", fiber, rv.hc);
270 cpl_table_set_double(_fibers, "BCORR", fiber, rv.bc);
271
272 }
273
274 return 0;
275}
cxint giraffe_add_rvcorrection(GiTable *fibers, const GiImage *spectra)
Add the barycentric and heliocentric corrections to the given fiber setup.
Definition: giastrometry.c:68
cpl_propertylist * giraffe_image_get_properties(const GiImage *self)
Get the properties of an image.
Definition: giimage.c:282
void giraffe_rvcorrection_compute(GiRvCorrection *rv, cxdouble jdate, cxdouble longitude, cxdouble latitude, cxdouble elevation, cxdouble ra, cxdouble dec, cxdouble equinox)
Compute heliocentric, barycentric and geocentric correction.
cpl_table * giraffe_table_get(const GiTable *self)
Get the table data from a Giraffe table.
Definition: gitable.c:433

This file is part of the GIRAFFE Pipeline Reference Manual 2.17.1.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Fri Feb 21 2025 02:35:06 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2004