30#include <giastroutils.h>
42static const cxdouble TINY = 1.e-12;
44static const cxdouble DEG_TO_RAD =
45 0.017453292519943295769236907684886127134428718885417;
47static const cxdouble SEC_TO_DEG = 15. / 3600.;
73_giraffe_compute_zdistance(cxdouble hourangle, cxdouble delta,
77 cxdouble p0 = sin(latitude) * sin(delta);
78 cxdouble p1 = cos(latitude) * cos(delta);
79 cxdouble z = p0 + cos(hourangle) * p1;
82 z = z < 0. ? -TINY : TINY;
104inline static cxdouble
105_giraffe_compute_airmass_young(cxdouble secz)
108 cxdouble z = 1. / secz;
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;
149 cxdouble exptime, cxdouble latitude)
152 const cxchar*
const fctid =
"giraffe_compute_airmass";
157 const cxdouble weights[] = {1. / 6., 2. / 3., 1. / 6.};
165 const cxdouble airmass_upper_limit = 10.;
169 cxdouble hourangle = 0.;
170 cxdouble airmass = 0.;
177 hourangle = lst * SEC_TO_DEG - alpha;
185 if (hourangle < -180.) {
189 if (hourangle > 180.) {
199 latitude *= DEG_TO_RAD;
200 hourangle *= DEG_TO_RAD;
211 z = _giraffe_compute_zdistance(hourangle, delta, latitude);
213 if (fabs(z) < TINY) {
214 cpl_msg_debug(fctid,
"Airmass computation failed. Object is "
215 "below the horizon.");
219 airmass = _giraffe_compute_airmass_young(z);
223 const cxint nweights = CX_N_ELEMENTS(weights);
227 cxdouble timestep = exptime / (nweights - 1) * SEC_TO_DEG *
231 airmass *= weights[0];
233 for (i = 1; i < nweights; i++) {
235 z = _giraffe_compute_zdistance(hourangle + i * timestep,
238 if (fabs(z) < TINY) {
240 cpl_msg_debug(fctid,
"Airmass computation failed. Object "
241 "is below the horizon.");
246 airmass += weights[i] * _giraffe_compute_airmass_young(z);
253 if (airmass > airmass_upper_limit) {
254 cpl_msg_debug(fctid,
"Airmass larger than %f", airmass_upper_limit);
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.