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