GIRAFFE Pipeline Reference Manual

giastroutils.c
1/*
2 * This file is part of the GIRAFFE Pipeline
3 * Copyright (C) 2002-2019 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21# include <config.h>
22#endif
23
24#include <math.h>
25
26#include <cxtypes.h>
27
28#include <cpl_msg.h>
29
30#include <giastroutils.h>
31
32
33
42static const cxdouble TINY = 1.e-12;
43
44static const cxdouble DEG_TO_RAD =
45 0.017453292519943295769236907684886127134428718885417; /* pi/180 */
46
47static const cxdouble SEC_TO_DEG = 15. / 3600.;
48
49
50
51/*
52 * @brief
53 * Compute the zenith distance of a point in the sky
54 *
55 * @param hourangle Hour angle in radians
56 * @param delta Declination in radians
57 * @param latitude Latitude of the observatory in radians
58 *
59 * @return
60 * The secant of the zenith distance, or @c 0. if na error occurred.
61 *
62 * The function computes the secans of the zenith distance of a point
63 * in the sky, given by the angle @em hourangle from the meridian and the
64 * declination @em delta. The latitude of the observing site is given by
65 * @em latitude.
66 *
67 * The domain of the hour angle, declination and the latitude of the
68 * observing site are [$-\pi$, \pi$], [$-0.5\pi, 0.5\pi$] and [$0, 2\pi$]
69 * respectively.
70 */
71
72inline static cxdouble
73_giraffe_compute_zdistance(cxdouble hourangle, cxdouble delta,
74 cxdouble latitude)
75{
76
77 cxdouble p0 = sin(latitude) * sin(delta);
78 cxdouble p1 = cos(latitude) * cos(delta);
79 cxdouble z = p0 + cos(hourangle) * p1;
80
81 if (fabs(z) < TINY) {
82 z = z < 0. ? -TINY : TINY;
83 }
84
85 return 1. / z;
86
87}
88
89/*
90 * @brief
91 * Compute approximated airmass value.
92 *
93 * @param secz Secant of the zenith distance.
94 *
95 * @return
96 * The function returns the approximated airmass value.
97 *
98 * The function uses the approximation given by Young (Young A. T.,
99 * 1994, "Air mass and refraction", Applied Optics, 33, 1108-1110) to
100 * compute the airmass for a given sec(z) @em secz, where z is the true
101 * zenith angle.
102 */
103
104inline static cxdouble
105_giraffe_compute_airmass_young(cxdouble secz)
106{
107
108 cxdouble z = 1. / secz; /* cos(zt) cosine of the true zenith angle */
109 cxdouble x = 0.;
110 cxdouble y = 0.;
111
112 x = 1.002432 * z * z + 0.148386 * z + 0.0096467;
113 y = z * z * z + 0.149864 * z * z + 0.0102963 * z + 0.000303978;
114
115 return x / y;
116
117}
118
119
147cxdouble
148giraffe_compute_airmass(cxdouble alpha, cxdouble delta, cxdouble lst,
149 cxdouble exptime, cxdouble latitude)
150{
151
152 const cxchar* const fctid = "giraffe_compute_airmass";
153
154
155 /* Weights for Stetson's formula */
156
157 const cxdouble weights[] = {1. / 6., 2. / 3., 1. / 6.};
158
159
160 /*
161 * Accuracy limit for airmass approximation (cf. Young A. T., Irvine W. M.,
162 * 1967, Astron. J. 72, 945).
163 */
164
165 const cxdouble airmass_upper_limit = 10.;
166
167
168 cxdouble z = 0.;
169 cxdouble hourangle = 0.;
170 cxdouble airmass = 0.;
171
172
173 /*
174 * Compute hour angle of the observation in degrees.
175 */
176
177 hourangle = lst * SEC_TO_DEG - alpha;
178
179
180 /*
181 * Range adjustments. Angle between line of sight and the meridian
182 * is needed.
183 */
184
185 if (hourangle < -180.) {
186 hourangle += 360.;
187 }
188
189 if (hourangle > 180.) {
190 hourangle -= 360.;
191 }
192
193
194 /*
195 * Convert angles from degrees to radians
196 */
197
198 delta *= DEG_TO_RAD;
199 latitude *= DEG_TO_RAD;
200 hourangle *= DEG_TO_RAD;
201
202
203 /*
204 * Calculate airmass of the observation using the approximation given
205 * by Young (Young A. T., 1994, "Air mass and refraction", Applied
206 * Optics, 33, 1108-1110)for the individual airmass values. For finite
207 * exposure times these airmass values are averaged using the weights
208 * given by Stetson (Stetson P., 1987, PASP 99, 191)
209 */
210
211 z = _giraffe_compute_zdistance(hourangle, delta, latitude);
212
213 if (fabs(z) < TINY) {
214 cpl_msg_debug(fctid, "Airmass computation failed. Object is "
215 "below the horizon.");
216 return -1.;
217 }
218
219 airmass = _giraffe_compute_airmass_young(z);
220
221 if (exptime > 0.) {
222
223 const cxint nweights = CX_N_ELEMENTS(weights);
224
225 cxint i = 0;
226
227 cxdouble timestep = exptime / (nweights - 1) * SEC_TO_DEG *
228 DEG_TO_RAD;
229
230
231 airmass *= weights[0];
232
233 for (i = 1; i < nweights; i++) {
234
235 z = _giraffe_compute_zdistance(hourangle + i * timestep,
236 delta, latitude);
237
238 if (fabs(z) < TINY) {
239
240 cpl_msg_debug(fctid, "Airmass computation failed. Object "
241 "is below the horizon.");
242 return -1.;
243
244 }
245
246 airmass += weights[i] * _giraffe_compute_airmass_young(z);
247
248 }
249
250 }
251
252
253 if (airmass > airmass_upper_limit) {
254 cpl_msg_debug(fctid, "Airmass larger than %f", airmass_upper_limit);
255 }
256
257 return airmass;
258
259}
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:148

This file is part of the GIRAFFE Pipeline Reference Manual 2.19.4.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Fri Feb 6 2026 13:47:22 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2004