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
00070 cxint
00071 giraffe_add_rvcorrection(GiTable* fibers, const GiImage* spectra)
00072 {
00073
00074 cxint fiber = 0;
00075 cxint nr = 0;
00076
00077 cxdouble exptime = 0.;
00078 cxdouble jd = 0.;
00079 cxdouble equinox = 2000.;
00080 cxdouble longitude = 0.;
00081 cxdouble latitude = 0.;
00082 cxdouble elevation = 0.;
00083
00084 const cpl_propertylist* properties = NULL;
00085
00086 cpl_table* _fibers = NULL;
00087
00088
00089 if ((fibers == NULL) || (spectra == NULL)) {
00090 return -1;
00091 }
00092
00093 properties = giraffe_image_get_properties(spectra);
00094 cx_assert(properties != NULL);
00095
00096
00097
00098
00099
00100
00101 if (cpl_propertylist_has(properties, GIALIAS_EXPTIME) == FALSE) {
00102 return 1;
00103 }
00104 else {
00105 exptime = cpl_propertylist_get_double(properties, GIALIAS_EXPTIME);
00106 }
00107
00108 if (cpl_propertylist_has(properties, GIALIAS_MJDOBS) == FALSE) {
00109 return 1;
00110 }
00111 else {
00112
00113
00114
00115
00116
00117
00118 jd = cpl_propertylist_get_double(properties, GIALIAS_MJDOBS);
00119 jd += 2400000.5 + 0.5 * exptime / (24. * 3600.);
00120
00121 }
00122
00123 if (cpl_propertylist_has(properties, GIALIAS_EQUINOX) == FALSE) {
00124 return 1;
00125 }
00126 else {
00127 equinox = cpl_propertylist_get_double(properties, GIALIAS_EQUINOX);
00128 }
00129
00130
00131
00132
00133
00134
00135 if (cpl_propertylist_has(properties, GIALIAS_TEL_LON) == FALSE) {
00136 return 2;
00137 }
00138 else {
00139
00140
00141
00142
00143
00144
00145 longitude = -cpl_propertylist_get_double(properties, GIALIAS_TEL_LON);
00146
00147 }
00148
00149 if (cpl_propertylist_has(properties, GIALIAS_TEL_LAT) == FALSE) {
00150 return 2;
00151 }
00152 else {
00153 latitude = cpl_propertylist_get_double(properties, GIALIAS_TEL_LAT);
00154 }
00155
00156 if (cpl_propertylist_has(properties, GIALIAS_TEL_ELEV) == FALSE) {
00157 return 2;
00158 }
00159 else {
00160 elevation = cpl_propertylist_get_double(properties, GIALIAS_TEL_ELEV);
00161 }
00162
00163 properties = NULL;
00164
00165
00166
00167
00168
00169
00170 _fibers = giraffe_table_get(fibers);
00171
00172 if ((cpl_table_has_column(_fibers, "RA") == FALSE) ||
00173 (cpl_table_has_column(_fibers, "DEC") == FALSE)) {
00174 return 3;
00175 }
00176
00177 if (cpl_table_has_column(_fibers, "RP") == FALSE) {
00178 return -1;
00179 }
00180
00181
00182 giraffe_error_push();
00183
00184 if (cpl_table_has_column(_fibers, "GCORR") == FALSE) {
00185 cpl_table_new_column(_fibers, "GCORR", CPL_TYPE_DOUBLE);
00186 }
00187
00188 if (cpl_table_has_column(_fibers, "HCORR") == FALSE) {
00189 cpl_table_new_column(_fibers, "HCORR", CPL_TYPE_DOUBLE);
00190 }
00191
00192 if (cpl_table_has_column(_fibers, "BCORR") == FALSE) {
00193 cpl_table_new_column(_fibers, "BCORR", CPL_TYPE_DOUBLE);
00194 }
00195
00196 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00197 return -2;
00198 }
00199
00200 giraffe_error_pop();
00201
00202
00203 nr = cpl_table_get_nrow(_fibers);
00204
00205 for (fiber = 0; fiber < nr; ++fiber) {
00206
00207 cxint rp = cpl_table_get_int(_fibers, "RP", fiber, NULL);
00208
00209 GiRvCorrection rv = {0., 0., 0.};
00210
00211
00212 if (rp != -1) {
00213
00214
00215 cxdouble ra = cpl_table_get_double(_fibers, "RA", fiber, NULL);
00216 cxdouble dec = cpl_table_get_double(_fibers, "DEC", fiber, NULL);
00217
00218
00219
00220
00221
00222
00223 ra /= 15.;
00224
00225 giraffe_rvcorrection_compute(&rv, jd, longitude, latitude,
00226 elevation, ra, dec, equinox);
00227
00228
00229 }
00230
00231 cpl_table_set_double(_fibers, "GCORR", fiber, rv.gc);
00232 cpl_table_set_double(_fibers, "HCORR", fiber, rv.hc);
00233 cpl_table_set_double(_fibers, "BCORR", fiber, rv.bc);
00234
00235 }
00236
00237 return 0;
00238 }