GIRAFFE Pipeline Reference Manual

giastroutils.c
1 /* $Id$
2  *
3  * This file is part of the GIRAFFE Pipeline
4  * Copyright (C) 2002-2006 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /*
22  * $Author$
23  * $Date$
24  * $Revision$
25  * $Name$
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31 
32 #include <math.h>
33 
34 #include <cxtypes.h>
35 
36 #include <cpl_msg.h>
37 
38 #include <giastroutils.h>
39 
40 
41 
50 static const cxdouble TINY = 1.e-12;
51 
52 static const cxdouble RV_DPI =
53  3.1415926535897932384626433832795028841971693993751; /* pi */
54 
55 static const cxdouble DEG_TO_RAD =
56  0.017453292519943295769236907684886127134428718885417; /* pi/180 */
57 
58 static const cxdouble SEC_TO_DEG = 15. / 3600.;
59 
60 
61 
62 /*
63  * @brief
64  * Compute the zenith distance of a point in the sky
65  *
66  * @param hourangle Hour angle in radians
67  * @param delta Declination in radians
68  * @param latitude Latitude of the observatory in radians
69  *
70  * @return
71  * The secant of the zenith distance, or @c 0. if na error occurred.
72  *
73  * The function computes the secans of the zenith distance of a point
74  * in the sky, given by the angle @em hourangle from the meridian and the
75  * declination @em delta. The latitude of the observing site is given by
76  * @em latitude.
77  *
78  * The domain of the hour angle, declination and the latitude of the
79  * observing site are [$-\pi$, \pi$], [$-0.5\pi, 0.5\pi$] and [$0, 2\pi$]
80  * respectively.
81  */
82 
83 inline static cxdouble
84 _giraffe_compute_zdistance(cxdouble hourangle, cxdouble delta,
85  cxdouble latitude)
86 {
87 
88  cxdouble p0 = sin(latitude) * sin(delta);
89  cxdouble p1 = cos(latitude) * cos(delta);
90  cxdouble z = p0 + cos(hourangle) * p1;
91 
92  if (fabs(z) < TINY) {
93  z = z < 0. ? -TINY : TINY;
94  }
95 
96  return 1. / z;
97 
98 }
99 
100 
101 /*
102  * @brief
103  * Compute approximated airmass value.
104  *
105  * @param secz Secant of the zenith distance.
106  *
107  * @return
108  * The function returns the approximated airmass value.
109  *
110  * The function uses the approximation given by Young and Irvine
111  * (Young A. T., Irvine W. M., 1967, Astron. J. 72, 945) to compute
112  * the airmass for a given sec(z) @em secz. This approximation
113  * takes into account atmosphere refraction and curvature, but is in
114  * principle only valid at sea level.
115  */
116 
117 inline static cxdouble
118 _giraffe_compute_airmass_young_irvine(cxdouble secz)
119 {
120 
121  return secz * (1. - 0.0012 * (pow(secz, 2.) - 1.));
122 
123 }
124 
125 
126 /*
127  * @brief
128  * Compute approximated airmass value.
129  *
130  * @param secz Secant of the zenith distance.
131  *
132  * @return
133  * The function returns the approximated airmass value.
134  *
135  * The function uses the approximation given by Young (Young A. T.,
136  * 1994, "Air mass and refraction", Applied Optics, 33, 1108-1110) to
137  * compute the airmass for a given sec(z) @em secz, where z is the true
138  * zenith angle.
139  */
140 
141 inline static cxdouble
142 _giraffe_compute_airmass_young(cxdouble secz)
143 {
144 
145  cxdouble z = 1. / secz; /* cos(zt) cosine of the true zenith angle */
146  cxdouble x = 0.;
147  cxdouble y = 0.;
148 
149  x = 1.002432 * z * z + 0.148386 * z + 0.0096467;
150  y = z * z * z + 0.149864 * z * z + 0.0102963 * z + 0.000303978;
151 
152  return x / y;
153 
154 }
155 
156 
184 cxdouble
185 giraffe_compute_airmass(cxdouble alpha, cxdouble delta, cxdouble lst,
186  cxdouble exptime, cxdouble latitude)
187 {
188 
189  const cxchar* const fctid = "giraffe_compute_airmass";
190 
191 
192  /* Weights for Stetson's formula */
193 
194  const cxdouble weights[] = {1. / 6., 2. / 3., 1. / 6.};
195 
196 
197  /*
198  * Accuracy limit for airmass approximation (cf. Young A. T., Irvine W. M.,
199  * 1967, Astron. J. 72, 945).
200  */
201 
202  const cxdouble airmass_upper_limit = 10.;
203 
204 
205  cxdouble z = 0.;
206  cxdouble hourangle = 0.;
207  cxdouble airmass = 0.;
208 
209 
210  /*
211  * Compute hour angle of the observation in degrees.
212  */
213 
214  hourangle = lst * SEC_TO_DEG - alpha;
215 
216 
217  /*
218  * Range adjustments. Angle between line of sight and the meridian
219  * is needed.
220  */
221 
222  if (hourangle < -180.) {
223  hourangle += 360.;
224  }
225 
226  if (hourangle > 180.) {
227  hourangle -= 360.;
228  }
229 
230 
231  /*
232  * Convert angles from degrees to radians
233  */
234 
235  delta *= DEG_TO_RAD;
236  latitude *= DEG_TO_RAD;
237  hourangle *= DEG_TO_RAD;
238 
239 
240  /*
241  * Calculate airmass of the observation using the approximation given
242  * by Young (Young A. T., 1994, "Air mass and refraction", Applied
243  * Optics, 33, 1108-1110)for the individual airmass values. For finite
244  * exposure times these airmass values are averaged using the weights
245  * given by Stetson (Stetson P., 1987, PASP 99, 191)
246  */
247 
248  z = _giraffe_compute_zdistance(hourangle, delta, latitude);
249 
250  if (fabs(z) < TINY) {
251  cpl_msg_debug(fctid, "Airmass computation failed. Object is "
252  "below the horizon.");
253  return -1.;
254  }
255 
256  airmass = _giraffe_compute_airmass_young(z);
257 
258  if (exptime > 0.) {
259 
260  const cxint nweights = CX_N_ELEMENTS(weights);
261 
262  cxint i = 0;
263 
264  cxdouble timestep = exptime / (nweights - 1) * SEC_TO_DEG *
265  DEG_TO_RAD;
266 
267 
268  airmass *= weights[0];
269 
270  for (i = 1; i < nweights; i++) {
271 
272  z = _giraffe_compute_zdistance(hourangle + i * timestep,
273  delta, latitude);
274 
275  if (fabs(z) < TINY) {
276 
277  cpl_msg_debug(fctid, "Airmass computation failed. Object "
278  "is below the horizon.");
279  return -1.;
280 
281  }
282 
283  airmass += weights[i] * _giraffe_compute_airmass_young(z);
284 
285  }
286 
287  }
288 
289 
290  if (airmass > airmass_upper_limit) {
291  cpl_msg_debug(fctid, "Airmass larger than %f", airmass_upper_limit);
292  }
293 
294  return airmass;
295 
296 }
cxdouble giraffe_compute_airmass(cxdouble alpha, cxdouble delta, cxdouble lst, cxdouble exptime, cxdouble latitude)
Compute the airmass for a given pointing direction and observing site.
Definition: giastroutils.c:185

This file is part of the GIRAFFE Pipeline Reference Manual 2.14.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Wed Mar 11 2015 13:19:41 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2004