GIRAFFE Pipeline Reference Manual

giastroutils.c

00001 /* $Id: giastroutils.c,v 1.1 2008/03/17 13:59:32 rpalsa Exp $
00002  *
00003  * This file is part of the GIRAFFE Pipeline
00004  * Copyright (C) 2002-2006 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:32 $
00024  * $Revision: 1.1 $
00025  * $Name: giraffe-2_10 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #  include <config.h>
00030 #endif
00031 
00032 #include <math.h>
00033 
00034 #include <cxtypes.h>
00035 
00036 #include <cpl_msg.h>
00037 
00038 #include <giastroutils.h>
00039 
00040 
00041 
00050 static const cxdouble TINY = 1.e-12;
00051 
00052 static const cxdouble RV_DPI  =
00053     3.1415926535897932384626433832795028841971693993751;       /* pi      */
00054 
00055 static const cxdouble DEG_TO_RAD =
00056         0.017453292519943295769236907684886127134428718885417; /* pi/180  */
00057 
00058 static const cxdouble SEC_TO_DEG = 15. / 3600.;
00059 
00060 
00061 
00062 /*
00063  * @brief
00064  *  Compute the zenith distance of a point in the sky
00065  *
00066  * @param hourangle  Hour angle in radians
00067  * @param delta      Declination in radians
00068  * @param latitude   Latitude of the observatory in radians
00069  *
00070  * @return
00071  *  The secant of the zenith distance, or @c 0. if na error occurred.
00072  *
00073  * The function computes the secans of the zenith distance of a point
00074  * in the sky, given by the angle @em hourangle from the meridian and the
00075  * declination @em delta. The latitude of the observing site is given by
00076  * @em latitude.
00077  *
00078  * The domain of the hour angle, declination and the latitude of the
00079  * observing site are [$-\pi$, \pi$], [$-0.5\pi, 0.5\pi$] and [$0, 2\pi$]
00080  * respectively.
00081  */
00082 
00083 inline static cxdouble
00084 _giraffe_compute_zdistance(cxdouble hourangle, cxdouble delta,
00085                            cxdouble latitude)
00086 {
00087 
00088     cxdouble p0 = sin(latitude) * sin(delta);
00089     cxdouble p1 = cos(latitude) * cos(delta);
00090     cxdouble z  = p0 + cos(hourangle) * p1;
00091 
00092     if (fabs(z) < TINY) {
00093         z = z < 0. ? -TINY : TINY;
00094     }
00095 
00096     return 1. / z;
00097 
00098 }
00099 
00100 
00101 /*
00102  * @brief
00103  *  Compute approximated airmass value.
00104  *
00105  * @param secz  Secant of the zenith distance.
00106  *
00107  * @return
00108  *  The function returns the approximated airmass value.
00109  *
00110  * The function uses the approximation given by Young and Irvine
00111  * (Young A. T., Irvine W. M., 1967, Astron. J. 72, 945) to compute
00112  * the airmass for a given sec(z) @em secz. This approximation
00113  * takes into account atmosphere refraction and curvature, but is in
00114  * principle only valid at sea level.
00115  */
00116 
00117 inline static cxdouble
00118 _giraffe_compute_airmass_young_irvine(cxdouble secz)
00119 {
00120 
00121     return secz * (1. - 0.0012 * (pow(secz, 2.) - 1.));
00122 
00123 }
00124 
00125 
00126 /*
00127  * @brief
00128  *  Compute approximated airmass value.
00129  *
00130  * @param secz  Secant of the zenith distance.
00131  *
00132  * @return
00133  *  The function returns the approximated airmass value.
00134  *
00135  * The function uses the approximation given by Young (Young A. T.,
00136  * 1994, "Air mass and refraction", Applied Optics, 33, 1108-1110) to
00137  * compute the airmass for a given sec(z) @em secz, where z is the true
00138  * zenith angle.
00139  */
00140 
00141 inline static cxdouble
00142 _giraffe_compute_airmass_young(cxdouble secz)
00143 {
00144 
00145     cxdouble z = 1. / secz;    /* cos(zt) cosine of the true zenith angle */
00146     cxdouble x = 0.;
00147     cxdouble y = 0.;
00148 
00149     x = 1.002432 * z * z + 0.148386 * z + 0.0096467;
00150     y = z * z * z + 0.149864 * z * z + 0.0102963 * z + 0.000303978;
00151 
00152     return x / y;
00153 
00154 }
00155 
00156 
00184 cxdouble
00185 giraffe_compute_airmass(cxdouble alpha, cxdouble delta, cxdouble lst,
00186                         cxdouble exptime, cxdouble latitude)
00187 {
00188 
00189     const cxchar* const fctid = "giraffe_compute_airmass";
00190 
00191 
00192     /* Weights for Stetson's formula */
00193 
00194     const cxdouble weights[] = {1. / 6., 2. / 3., 1. / 6.};
00195 
00196 
00197    /*
00198     * Accuracy limit for airmass approximation (cf. Young A. T., Irvine W. M.,
00199     * 1967, Astron. J. 72, 945).
00200     */
00201 
00202     const cxdouble airmass_upper_limit = 10.;
00203 
00204 
00205     cxdouble z = 0.;
00206     cxdouble hourangle = 0.;
00207     cxdouble airmass = 0.;
00208 
00209 
00210    /*
00211     * Compute hour angle of the observation in degrees.
00212     */
00213 
00214     hourangle = lst * SEC_TO_DEG - alpha;
00215 
00216 
00217    /*
00218     * Range adjustments. Angle between line of sight and the meridian
00219     * is needed.
00220     */
00221 
00222     if (hourangle < -180.) {
00223         hourangle += 360.;
00224     }
00225 
00226     if (hourangle > 180.) {
00227         hourangle -= 360.;
00228     }
00229 
00230 
00231    /*
00232     * Convert angles from degrees to radians
00233     */
00234 
00235     delta *= DEG_TO_RAD;
00236     latitude *= DEG_TO_RAD;
00237     hourangle *= DEG_TO_RAD;
00238 
00239 
00240    /*
00241     * Calculate airmass of the observation using the approximation given
00242     * by Young (Young A. T., 1994, "Air mass and refraction", Applied
00243     * Optics, 33, 1108-1110)for the individual airmass values. For finite
00244     * exposure times these airmass values are averaged using the weights
00245     * given by Stetson (Stetson P., 1987, PASP 99, 191)
00246     */
00247 
00248     z = _giraffe_compute_zdistance(hourangle, delta, latitude);
00249 
00250     if (fabs(z) < TINY) {
00251         cpl_msg_debug(fctid, "Airmass computation failed. Object is "
00252                       "below the horizon.");
00253         return -1.;
00254     }
00255 
00256     airmass = _giraffe_compute_airmass_young(z);
00257 
00258     if (exptime > 0.) {
00259 
00260         const cxint nweights = CX_N_ELEMENTS(weights);
00261 
00262         cxint i = 0;
00263 
00264         cxdouble timestep = exptime / (nweights - 1) * SEC_TO_DEG *
00265                 DEG_TO_RAD;
00266 
00267 
00268         airmass *= weights[0];
00269 
00270         for (i = 1; i < nweights; i++) {
00271 
00272             z = _giraffe_compute_zdistance(hourangle + i * timestep,
00273                                            delta, latitude);
00274 
00275             if (fabs(z) < TINY) {
00276 
00277                 cpl_msg_debug(fctid, "Airmass computation failed. Object "
00278                               "is below the horizon.");
00279                 return -1.;
00280 
00281             }
00282 
00283             airmass += weights[i] * _giraffe_compute_airmass_young(z);
00284 
00285         }
00286 
00287     }
00288 
00289 
00290     if (airmass > airmass_upper_limit) {
00291         cpl_msg_debug(fctid, "Airmass larger than %f", airmass_upper_limit);
00292     }
00293 
00294     return airmass;
00295 
00296 }

This file is part of the GIRAFFE Pipeline Reference Manual 2.10.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Thu Mar 7 14:11:02 2013 by doxygen 1.4.7 written by Dimitri van Heesch, © 1997-2004