00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 # include <config.h>
00030 #endif
00031
00032
00033 #include "gialias.h"
00034 #include "gierror.h"
00035 #include "girvcorrection.h"
00036 #include "giastrometry.h"
00037
00038
00075 cxint
00076 giraffe_add_rvcorrection(GiTable* fibers, const GiImage* spectra)
00077 {
00078
00079 cxint fiber = 0;
00080 cxint nr = 0;
00081
00082 cxdouble exptime = 0.;
00083 cxdouble jd = 0.;
00084 cxdouble equinox = 2000.;
00085 cxdouble longitude = 0.;
00086 cxdouble latitude = 0.;
00087 cxdouble elevation = 0.;
00088 cxdouble tel_ra = 0.;
00089 cxdouble tel_dec = 0.;
00090
00091 const cpl_propertylist* properties = NULL;
00092
00093 cpl_table* _fibers = NULL;
00094
00095
00096 if ((fibers == NULL) || (spectra == NULL)) {
00097 return -1;
00098 }
00099
00100 properties = giraffe_image_get_properties(spectra);
00101 cx_assert(properties != NULL);
00102
00103
00104
00105
00106
00107
00108 if (cpl_propertylist_has(properties, GIALIAS_EXPTIME) == FALSE) {
00109 return 1;
00110 }
00111 else {
00112 exptime = cpl_propertylist_get_double(properties, GIALIAS_EXPTIME);
00113 }
00114
00115 if (cpl_propertylist_has(properties, GIALIAS_MJDOBS) == FALSE) {
00116 return 1;
00117 }
00118 else {
00119
00120
00121
00122
00123
00124
00125 jd = cpl_propertylist_get_double(properties, GIALIAS_MJDOBS);
00126 jd += 2400000.5 + 0.5 * exptime / (24. * 3600.);
00127
00128 }
00129
00130 if (cpl_propertylist_has(properties, GIALIAS_EQUINOX) == FALSE) {
00131 return 1;
00132 }
00133 else {
00134 equinox = cpl_propertylist_get_double(properties, GIALIAS_EQUINOX);
00135 }
00136
00137
00138
00139
00140
00141
00142 if (cpl_propertylist_has(properties, GIALIAS_TEL_LON) == FALSE) {
00143 return 2;
00144 }
00145 else {
00146
00147
00148
00149
00150
00151
00152 longitude = -cpl_propertylist_get_double(properties, GIALIAS_TEL_LON);
00153
00154 }
00155
00156 if (cpl_propertylist_has(properties, GIALIAS_TEL_LAT) == FALSE) {
00157 return 2;
00158 }
00159 else {
00160 latitude = cpl_propertylist_get_double(properties, GIALIAS_TEL_LAT);
00161 }
00162
00163 if (cpl_propertylist_has(properties, GIALIAS_TEL_ELEV) == FALSE) {
00164 return 2;
00165 }
00166 else {
00167 elevation = cpl_propertylist_get_double(properties, GIALIAS_TEL_ELEV);
00168 }
00169
00170
00171
00172
00173
00174
00175 if (cpl_propertylist_has(properties, GIALIAS_RADEG) == FALSE) {
00176 return 4;
00177 }
00178 else {
00179 tel_ra = cpl_propertylist_get_double(properties, GIALIAS_RADEG);
00180 }
00181
00182 if (cpl_propertylist_has(properties, GIALIAS_DECDEG) == FALSE) {
00183 return 4;
00184 }
00185 else {
00186 tel_dec = cpl_propertylist_get_double(properties, GIALIAS_DECDEG);
00187 }
00188
00189 properties = NULL;
00190
00191
00192
00193
00194
00195
00196 _fibers = giraffe_table_get(fibers);
00197
00198 if ((cpl_table_has_column(_fibers, "RA") == FALSE) ||
00199 (cpl_table_has_column(_fibers, "DEC") == FALSE)) {
00200 return 3;
00201 }
00202
00203 if (cpl_table_has_column(_fibers, "RP") == FALSE) {
00204 return -1;
00205 }
00206
00207
00208 giraffe_error_push();
00209
00210 if (cpl_table_has_column(_fibers, "GCORR") == FALSE) {
00211 cpl_table_new_column(_fibers, "GCORR", CPL_TYPE_DOUBLE);
00212 }
00213
00214 if (cpl_table_has_column(_fibers, "HCORR") == FALSE) {
00215 cpl_table_new_column(_fibers, "HCORR", CPL_TYPE_DOUBLE);
00216 }
00217
00218 if (cpl_table_has_column(_fibers, "BCORR") == FALSE) {
00219 cpl_table_new_column(_fibers, "BCORR", CPL_TYPE_DOUBLE);
00220 }
00221
00222 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00223 return -2;
00224 }
00225
00226 giraffe_error_pop();
00227
00228
00229 nr = cpl_table_get_nrow(_fibers);
00230
00231 for (fiber = 0; fiber < nr; ++fiber) {
00232
00233 cxint rp = cpl_table_get_int(_fibers, "RP", fiber, NULL);
00234
00235 GiRvCorrection rv = {0., 0., 0.};
00236
00237
00238 if (rp != -1) {
00239
00240 register cxdouble ra = 0.;
00241 register cxdouble dec = 0.;
00242
00243
00244
00245
00246
00247
00248
00249
00250 if (rp == 0) {
00251
00252 ra = tel_ra;
00253 dec = tel_dec;
00254
00255 }
00256 else {
00257
00258 ra = cpl_table_get_double(_fibers, "RA", fiber, NULL);
00259 dec = cpl_table_get_double(_fibers, "DEC", fiber, NULL);
00260
00261 }
00262
00263
00264
00265
00266
00267
00268 ra /= 15.;
00269
00270 giraffe_rvcorrection_compute(&rv, jd, longitude, latitude,
00271 elevation, ra, dec, equinox);
00272
00273
00274 }
00275
00276 cpl_table_set_double(_fibers, "GCORR", fiber, rv.gc);
00277 cpl_table_set_double(_fibers, "HCORR", fiber, rv.hc);
00278 cpl_table_set_double(_fibers, "BCORR", fiber, rv.bc);
00279
00280 }
00281
00282 return 0;
00283 }