GIRAFFE Pipeline Reference Manual

giastrometry.c

00001 /* $Id: giastrometry.c,v 1.1 2008/03/17 13:59:52 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: 2008/03/17 13:59:52 $
00024  * $Revision: 1.1 $
00025  * $Name: giraffe-2_8_8 $
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      * Get time related information
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          * Compute julian date of mid exposure. 2400000.5 is the offset
00115          * between JD and MJD and corresponds to November 17th 1858 0:00 UT.
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      * Get telescope location and elevation.
00133      */
00134 
00135     if (cpl_propertylist_has(properties, GIALIAS_TEL_LON) == FALSE) {
00136         return 2;
00137     }
00138     else {
00139 
00140         /*
00141          * The sign of the property TEL.GEOLON is defined as east = positive
00142          * For the computation we need west = positive.
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      * Get observed objects right ascension and declination
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              * The right ascension must be in hours
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 }

This file is part of the GIRAFFE Pipeline Reference Manual 2.8.8.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Fri Mar 4 10:50:26 2011 by doxygen 1.6.3 written by Dimitri van Heesch, © 1997-2004