MOONS Pipeline Reference Manual 0.13.1
moo_line_table.c
1/*
2 * This file is part of the MOONS Pipeline
3 * Copyright (C) 2002-2016 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27#include <math.h>
28#include <cpl.h>
29#include <string.h>
30#include "moo_pfits.h"
31#include "moo_fits.h"
32#include "moo_utils.h"
33#include "moo_line_table.h"
34/*----------------------------------------------------------------------------*/
48/*----------------------------------------------------------------------------*/
49
52/*-----------------------------------------------------------------------------
53 Function codes
54 -----------------------------------------------------------------------------*/
55
56/*----------------------------------------------------------------------------*/
67/*----------------------------------------------------------------------------*/
68cpl_table *
70{
71 cpl_table *table = cpl_table_new(0);
72
73 cpl_table_new_column(table, MOO_LINE_TABLE_NAME, CPL_TYPE_STRING);
74 cpl_table_new_column(table, MOO_LINE_TABLE_WAVE, CPL_TYPE_DOUBLE);
75 cpl_table_new_column(table, MOO_LINE_TABLE_FLUX, CPL_TYPE_DOUBLE);
76 cpl_table_new_column(table, MOO_LINE_TABLE_SPECTRO, CPL_TYPE_INT);
77 cpl_table_new_column(table, MOO_LINE_TABLE_DETECTOR, CPL_TYPE_STRING);
78 cpl_table_new_column(table, MOO_LINE_TABLE_SLITLET, CPL_TYPE_INT);
79 cpl_table_new_column(table, MOO_LINE_TABLE_INDEXEXT, CPL_TYPE_INT);
80 cpl_table_new_column(table, MOO_LINE_TABLE_INDEXRBN, CPL_TYPE_INT);
81
82 cpl_errorstate prestate = cpl_errorstate_get();
83 if (isGuess) {
84 cpl_table_new_column(table, MOO_LINE_TABLE_INTENSITY, CPL_TYPE_DOUBLE);
85 cpl_table_new_column(table, MOO_LINE_TABLE_XGAUSS, CPL_TYPE_DOUBLE);
86 cpl_table_new_column(table, MOO_LINE_TABLE_XBARY, CPL_TYPE_DOUBLE);
87 cpl_table_new_column(table, MOO_LINE_TABLE_YLOC, CPL_TYPE_DOUBLE);
88 cpl_table_new_column(table, MOO_LINE_TABLE_AMPLITUDE, CPL_TYPE_DOUBLE);
89 cpl_table_new_column(table, MOO_LINE_TABLE_BACKGROUND, CPL_TYPE_DOUBLE);
90 cpl_table_new_column(table, MOO_LINE_TABLE_FWHM, CPL_TYPE_DOUBLE);
91 cpl_table_new_column(table, MOO_LINE_TABLE_FIT_FLUX, CPL_TYPE_DOUBLE);
92 cpl_table_new_column(table, MOO_LINE_TABLE_FIT_ERR, CPL_TYPE_DOUBLE);
93 cpl_table_new_column(table, MOO_LINE_TABLE_FIT_MSE, CPL_TYPE_DOUBLE);
94 cpl_table_new_column(table, MOO_LINE_TABLE_FIT_CHI2, CPL_TYPE_DOUBLE);
95 cpl_table_new_column(table, MOO_LINE_TABLE_MATCHED, CPL_TYPE_INT);
96 cpl_table_new_column(table, MOO_LINE_TABLE_DISP, CPL_TYPE_DOUBLE);
97 }
98 else {
99 cpl_table_new_column(table, MOO_LINE_TABLE_XGUESS, CPL_TYPE_DOUBLE);
100 cpl_table_new_column(table, MOO_LINE_TABLE_INTENSITY, CPL_TYPE_DOUBLE);
101 cpl_table_new_column(table, MOO_LINE_TABLE_GFITTED, CPL_TYPE_INT);
102 cpl_table_new_column(table, MOO_LINE_TABLE_XGAUSS, CPL_TYPE_DOUBLE);
103 cpl_table_new_column(table, MOO_LINE_TABLE_XBARY, CPL_TYPE_DOUBLE);
104 cpl_table_new_column(table, MOO_LINE_TABLE_XDIFF, CPL_TYPE_DOUBLE);
105 cpl_table_new_column(table, MOO_LINE_TABLE_WAVEDIFF, CPL_TYPE_DOUBLE);
106 cpl_table_new_column(table, MOO_LINE_TABLE_YLOC, CPL_TYPE_DOUBLE);
107 cpl_table_new_column(table, MOO_LINE_TABLE_AMPLITUDE, CPL_TYPE_DOUBLE);
108 cpl_table_new_column(table, MOO_LINE_TABLE_BACKGROUND, CPL_TYPE_DOUBLE);
109 cpl_table_new_column(table, MOO_LINE_TABLE_FWHM, CPL_TYPE_DOUBLE);
110 cpl_table_new_column(table, MOO_LINE_TABLE_FIT_FLUX, CPL_TYPE_DOUBLE);
111 cpl_table_new_column(table, MOO_LINE_TABLE_FIT_ERR, CPL_TYPE_DOUBLE);
112 cpl_table_new_column(table, MOO_LINE_TABLE_FIT_MSE, CPL_TYPE_DOUBLE);
113 cpl_table_new_column(table, MOO_LINE_TABLE_FIT_CHI2, CPL_TYPE_DOUBLE);
114 cpl_table_new_column(table, MOO_LINE_TABLE_FILTERED, CPL_TYPE_INT);
115 }
116 cpl_table_new_column(table, MOO_LINE_TABLE_MFITTED, CPL_TYPE_INT);
117 cpl_table_new_column(table, MOO_LINE_TABLE_WAVEFIT, CPL_TYPE_DOUBLE);
118 cpl_table_new_column(table, MOO_LINE_TABLE_RESOLUTION, CPL_TYPE_DOUBLE);
119
120 if (!cpl_errorstate_is_equal(prestate)) {
121 cpl_table_delete(table);
122 table = NULL;
123 }
124 return table;
125}
126
127cpl_table *
128moo_slitlet_shift_table_new(int size)
129{
130 cpl_table *detected_table = cpl_table_new(size);
131
132 cpl_errorstate prestate = cpl_errorstate_get();
133 cpl_table_new_column(detected_table, MOO_SLITLET_SHIFT_TABLE_SLITLET,
134 CPL_TYPE_INT);
135 cpl_table_new_column(detected_table, MOO_SLITLET_SHIFT_TABLE_WAVE,
136 CPL_TYPE_DOUBLE);
137 cpl_table_new_column(detected_table, MOO_SLITLET_SHIFT_TABLE_XDIFF,
138 CPL_TYPE_DOUBLE);
139
140 if (!cpl_errorstate_is_equal(prestate)) {
141 cpl_table_delete(detected_table);
142 detected_table = NULL;
143 }
144 return detected_table;
145}
146
147cpl_table *
148moo_detected_table_new(int size, int isGuess)
149{
150 cpl_table *detected_table = cpl_table_new(size);
151
152 cpl_errorstate prestate = cpl_errorstate_get();
153 cpl_table_new_column(detected_table, MOO_LINE_TABLE_INDEXEXT, CPL_TYPE_INT);
154 cpl_table_new_column(detected_table, MOO_LINE_TABLE_SLITLET, CPL_TYPE_INT);
155
156 if (isGuess) {
157 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_MIN,
158 CPL_TYPE_INT);
159 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_MAX,
160 CPL_TYPE_INT);
161 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_WIN_CEN,
162 CPL_TYPE_DOUBLE);
163 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_NGOOD,
164 CPL_TYPE_INT);
165 cpl_table_new_column(detected_table, MOO_LINE_TABLE_INTENSITY,
166 CPL_TYPE_DOUBLE);
167 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_BADFIT,
168 CPL_TYPE_INT);
169 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_FIT_FLUX,
170 CPL_TYPE_DOUBLE);
171 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_FIT_ERR,
172 CPL_TYPE_DOUBLE);
173 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_FIT_MSE,
174 CPL_TYPE_DOUBLE);
175 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_FIT_CHI2,
176 CPL_TYPE_DOUBLE);
177 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_FIT_BACKGROUND,
178 CPL_TYPE_DOUBLE);
179 cpl_table_new_column(detected_table, MOO_LINE_TABLE_XGAUSS,
180 CPL_TYPE_DOUBLE);
181 cpl_table_new_column(detected_table, MOO_LINE_TABLE_AMPLITUDE,
182 CPL_TYPE_DOUBLE);
183 cpl_table_new_column(detected_table, MOO_LINE_TABLE_BACKGROUND,
184 CPL_TYPE_DOUBLE);
185 cpl_table_new_column(detected_table, MOO_LINE_TABLE_XBARY,
186 CPL_TYPE_DOUBLE);
187 cpl_table_new_column(detected_table, MOO_LINE_TABLE_FWHM,
188 CPL_TYPE_DOUBLE);
189 cpl_table_new_column(detected_table, MOO_LINE_TABLE_FILTERED,
190 CPL_TYPE_INT);
191 }
192 else {
193 cpl_table_new_column(detected_table, MOO_LINE_TABLE_WAVE,
194 CPL_TYPE_DOUBLE);
195 cpl_table_new_column(detected_table, MOO_LINE_TABLE_XGUESS,
196 CPL_TYPE_DOUBLE);
197 cpl_table_new_column(detected_table, MOO_LINE_TABLE_XDIFF,
198 CPL_TYPE_DOUBLE);
199 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_NOT_IN_RANGE,
200 CPL_TYPE_INT);
201 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_WIN_CEN,
202 CPL_TYPE_DOUBLE);
203 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_WIN_MIN,
204 CPL_TYPE_DOUBLE);
205 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_WIN_MAX,
206 CPL_TYPE_DOUBLE);
207 cpl_table_new_column(detected_table, MOO_LINE_TABLE_INTENSITY,
208 CPL_TYPE_DOUBLE);
209
210 cpl_table_new_column(detected_table, MOO_LINE_TABLE_GFITTED,
211 CPL_TYPE_INT);
212 cpl_table_new_column(detected_table, MOO_LINE_TABLE_XGAUSS,
213 CPL_TYPE_DOUBLE);
214 cpl_table_new_column(detected_table, MOO_LINE_TABLE_AMPLITUDE,
215 CPL_TYPE_DOUBLE);
216 cpl_table_new_column(detected_table, MOO_LINE_TABLE_BACKGROUND,
217 CPL_TYPE_DOUBLE);
218 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_FIT_FLUX,
219 CPL_TYPE_DOUBLE);
220 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_FIT_ERR,
221 CPL_TYPE_DOUBLE);
222 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_FIT_MSE,
223 CPL_TYPE_DOUBLE);
224 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_FIT_CHI2,
225 CPL_TYPE_DOUBLE);
226 cpl_table_new_column(detected_table, MOO_LINE_TABLE_XBARY,
227 CPL_TYPE_DOUBLE);
228 cpl_table_new_column(detected_table, MOO_LINE_TABLE_FWHM,
229 CPL_TYPE_DOUBLE);
230 cpl_table_new_column(detected_table, MOO_LINE_TABLE_FILTERED,
231 CPL_TYPE_INT);
232 cpl_table_new_column(detected_table, MOO_DETECTED_TABLE_WAVETH,
233 CPL_TYPE_DOUBLE);
234 }
235
236 if (!cpl_errorstate_is_equal(prestate)) {
237 cpl_table_delete(detected_table);
238 detected_table = NULL;
239 }
240 return detected_table;
241}
242
243cpl_error_code
244moo_table_append(cpl_table *global_line_table, cpl_table *line_table)
245{
246 cpl_ensure_code(global_line_table != NULL, CPL_ERROR_NULL_INPUT);
247 cpl_ensure_code(line_table != NULL, CPL_ERROR_NULL_INPUT);
248
249 cpl_size nrow = cpl_table_get_nrow(global_line_table);
250 cpl_error_code status =
251 cpl_table_insert(global_line_table, line_table, nrow);
252
253 return status;
254}
cpl_table * moo_line_table_new(int isGuess)
create a line table