GIRAFFE Pipeline Reference Manual

giastrometry.c

00001 /* $Id: giastrometry.c,v 1.2 2011/04/04 13:40:30 rpalsa Exp $
00002  *
00003  * This file is part of the GIRAFFE Pipeline
00004  * Copyright (C) 2002-2008 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 /*
00022  * $Author: rpalsa $
00023  * $Date: 2011/04/04 13:40:30 $
00024  * $Revision: 1.2 $
00025  * $Name: giraffe-2_9 $
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      * Get time related information
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          * Compute julian date of mid exposure. 2400000.5 is the offset
00122          * between JD and MJD and corresponds to November 17th 1858 0:00 UT.
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      * Get telescope location and elevation.
00140      */
00141 
00142     if (cpl_propertylist_has(properties, GIALIAS_TEL_LON) == FALSE) {
00143         return 2;
00144     }
00145     else {
00146 
00147         /*
00148          * The sign of the property TEL.GEOLON is defined as east = positive
00149          * For the computation we need west = positive.
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      * Get telescope pointing
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      * Get observed objects right ascension and declination
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              * Argus fibers have no associated position. In this case use
00246              * the telescope pointing to compute the correction. Argus object
00247              * fibers have rp set to 0.
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              * The right ascension must be in hours
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 }

This file is part of the GIRAFFE Pipeline Reference Manual 2.9.0.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Thu Jan 26 14:20:27 2012 by doxygen 1.6.3 written by Dimitri van Heesch, © 1997-2004