CR2RE Pipeline Reference Manual 1.6.2
hdrl_cat_seeing.c
1/*
2 * This file is part of the HDRL
3 * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include "hdrl_cat_seeing.h"
21
22#include "hdrl_cat_utils_sort.h"
23
24
25/*---------------------------------------------------------------------------*/
33/*----------------------------------------------------------------------------*/
34
37/* ---------------------------------------------------------------------------*/
56/* ---------------------------------------------------------------------------*/
57cpl_error_code hdrl_seeing(
58 ap_t *ap, cpl_size nrows, double *ellipt, double *pkht,
59 double **areal, double *work, double *fwhm)
60{
61 double log5t = log(0.5 / ap->thresh);
62 double log2 = log(2.);
63
64 /* Do the seeing calculation */
65 cpl_size ii = 0;
66 for (cpl_size i = 0; i < nrows; i++) {
67 if (ellipt[i] < 0.2 && pkht[i] < 30000. && pkht[i] > 10. * ap->thresh) {
68
69 double aper = (log5t + log(pkht[i])) / log2 + 1.;
70 cpl_size iaper = (cpl_size)aper;
71
72 double delaper = aper - iaper;
73
74 if (iaper > 0 && iaper < NAREAL && areal[1][i] > 0.) {
75
76 double area = (1. - delaper) * areal[iaper - 1][i] + delaper * areal[iaper][i];
77
78 work[ii++] = CPL_MATH_2_SQRTPI * sqrt(area);
79 }
80 }
81 }
82
83 /* Sort the resulting array and choose a location that allows for contamination by galaxies */
84 if (ii >= 3) {
85
86 sort_array(work, ii, sizeof(*work), HDRL_SORT_DOUBLE, CPL_SORT_ASCENDING);
87
88 *fwhm = work[ii / 3 - 1];
89
90 /* Allow for finite pixel size */
91 double arg = 0.25 * CPL_MATH_PI * pow(*fwhm, 2.) - 1;
92
93 *fwhm = 2. * sqrt(CPL_MAX(0., arg / CPL_MATH_PI));
94
95 } else {
96
97 *fwhm = 0.;
98 }
99
100 return CPL_ERROR_NONE;
101}
102
cpl_error_code hdrl_seeing(ap_t *ap, cpl_size nrows, double *ellipt, double *pkht, double **areal, double *work, double *fwhm)
Work out the median seeing.
cpl_error_code sort_array(void *a, cpl_size nE, cpl_size sE, hdrl_sort_type type, cpl_sort_direction dir)
sort_array hdrl function for order arrays with know types. Using the type parameter for select the co...