MOONS Pipeline Reference Manual 0.13.1
moo_dfs.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
28#include <string.h>
29#include <math.h>
30
31#include <cpl.h>
32
33#include "moo_pfits.h"
34#include "moo_dfs.h"
35
36/*----------------------------------------------------------------------------*/
42/*----------------------------------------------------------------------------*/
43
46/*----------------------------------------------------------------------------*/
57/*----------------------------------------------------------------------------*/
58cpl_frameset **
59moo_dfs_split_by_offset(cpl_frameset *set)
60{
61 cpl_frameset **res;
62 cpl_ensure(set != NULL, CPL_ERROR_NULL_INPUT, NULL);
63
64 res = cpl_calloc(sizeof(cpl_frameset *), 2);
65 res[0] = cpl_frameset_new();
66 res[1] = cpl_frameset_new();
67
68 int i;
69
70 for (i = 0; i < cpl_frameset_get_size(set); ++i) {
71 const cpl_frame *frame = cpl_frameset_get_position_const(set, i);
72 const char *filename = cpl_frame_get_filename(frame);
73 cpl_propertylist *list = cpl_propertylist_load(filename, 0);
74
75 double offset = moo_pfits_get_slit_offset(list);
76
77 if (fabs(offset - MOONS_SLIT_OFFSET_POS1) <=
78 MOONS_SLIT_OFFSET_EPSILON) {
79 cpl_frameset_insert(res[0], cpl_frame_duplicate(frame));
80 }
81 else if (fabs(offset - MOONS_SLIT_OFFSET_POS2) <=
82 MOONS_SLIT_OFFSET_EPSILON) {
83 cpl_frameset_insert(res[1], cpl_frame_duplicate(frame));
84 }
85 cpl_propertylist_delete(list);
86 }
87
88 return res;
89}
90
91/*----------------------------------------------------------------------------*/
101/*----------------------------------------------------------------------------*/
102
103cpl_error_code
104moo_dfs_set_groups(cpl_frameset *set)
105{
106 cpl_errorstate prestate = cpl_errorstate_get();
107
108
109 /* Loop on frames */
110 cpl_frameset_iterator *it = cpl_frameset_iterator_new(set);
111
112 int i = 0;
113 cpl_frame *frame = NULL;
114 while ((frame = cpl_frameset_iterator_get(it)) != NULL) {
115 const char *tag = cpl_frame_get_tag(frame);
116
117 if (tag == NULL) {
118 cpl_msg_warning(cpl_func, "Frame %d has no tag", i);
119 }
120 else if (!strcmp(tag, MOONS_TAG_BIAS) ||
121 !strcmp(tag, MOONS_TAG_LINEARITY) ||
122 !strcmp(tag, MOONS_TAG_LINEARITY_OFF) ||
123 !strcmp(tag, MOONS_TAG_OBJECT) ||
124 !strcmp(tag, MOONS_TAG_DARK_VIS) ||
125 !strcmp(tag, MOONS_TAG_DARK_NIR) ||
126 !strcmp(tag, MOONS_TAG_FLAT) ||
127 !strcmp(tag, MOONS_TAG_FLAT_ATTACHED) ||
128 !strcmp(tag, MOONS_TAG_FLAT_OFF) ||
129 !strcmp(tag, MOONS_TAG_ARC) ||
130 !strcmp(tag, MOONS_TAG_ARC_OFF) ||
131 !strcmp(tag, MOONS_TAG_STD_FLUX) ||
132 !strcmp(tag, MOONS_TAG_STD_TELL) ||
133 !strcmp(tag, MOONS_TAG_OBJECT_STARE) ||
134 !strcmp(tag, MOONS_TAG_OBJECT_STARENOD) ||
135 !strcmp(tag, MOONS_TAG_SKY_STARENOD) ||
136 !strcmp(tag, MOONS_TAG_OBJECT_XSWITCH) ||
137 !strcmp(tag, MOONS_TAG_MOLECFIT_SCI)) {
138 /* RAW frames */
139 cpl_frame_set_group(frame, CPL_FRAME_GROUP_RAW);
140 }
141 else if (!strcmp(tag, MOONS_TAG_LINE_CATALOG) ||
142 !strcmp(tag, MOONS_TAG_FLUX_STD_CATALOG) ||
143 !strcmp(tag, MOONS_TAG_ATMOS_EXT) ||
144 !strcmp(tag, MOONS_TAG_ARC_LINE_LIST) ||
145 !strcmp(tag, MOONS_TAG_SKY_LINE_LIST) ||
146 !strcmp(tag, MOONS_TAG_MASTER_BIAS) ||
147 !strcmp(tag, MOONS_TAG_MASTER_DARK_VIS) ||
148 !strcmp(tag, MOONS_TAG_MASTER_DARK_NIR) ||
149 !strcmp(tag, MOONS_TAG_BP_MAP_RP) ||
150 !strcmp(tag, MOONS_TAG_BP_MAP_NL) ||
151 !strcmp(tag, MOONS_TAG_FF_TRACE_GUESS) ||
152 !strcmp(tag, MOONS_TAG_FF_TRACE) ||
153 !strcmp(tag, MOONS_TAG_P2P_MAP) ||
154 !strcmp(tag, MOONS_TAG_SPECTRAL_FORMAT) ||
155 !strcmp(tag, MOONS_TAG_LAYOUT) ||
156 !strcmp(tag, MOONS_TAG_WAVEMAP_GUESS) ||
157 !strcmp(tag, MOONS_TAG_WAVEMAP) ||
158 !strcmp(tag, MOONS_TAG_F2F_TABLE) ||
159 !strcmp(tag, MOONS_TAG_FF_EXTSPECTRA) ||
160 !strcmp(tag, MOONS_TAG_LINEARITY_COEFF_CUBE) ||
161 !strcmp(tag, MOONS_TAG_TELLURIC_CORR) ||
162 !strcmp(tag, MOONS_TAG_RESPONSE) ||
163 !strcmp(tag, MOONS_TAG_MOLECFIT_MOLECULES) ||
164 !strcmp(tag, MOONS_TAG_MOLECFIT_ATM_PARAMS) ||
165 !strcmp(tag, MOONS_TAG_MOLECFIT_BEST_FIT_PARAMS) ||
166 !strcmp(tag, MOONS_TAG_MOLECFIT_KERNEL_LIBRARY) ||
167 !strcmp(tag, MOONS_TAG_MOLECFIT_WINCLUDE)) {
168 /* CALIB frames */
169 cpl_frame_set_group(frame, CPL_FRAME_GROUP_CALIB);
170 }
171
172 cpl_frameset_iterator_advance(it, 1);
173 ++i;
174 }
175 cpl_frameset_iterator_delete(it);
176
177 if (!cpl_errorstate_is_equal(prestate)) {
178 return cpl_error_set_message(cpl_func, cpl_error_get_code(),
179 "Could not identify RAW and CALIB "
180 "frames");
181 }
182
183 return CPL_ERROR_NONE;
184}
185
186/*----------------------------------------------------------------------------*/
196/*----------------------------------------------------------------------------*/
197double *
198moo_dfs_get_exptime(cpl_frameset *set)
199{
200 double *res = NULL;
201 cpl_ensure(set != NULL, CPL_ERROR_NULL_INPUT, NULL);
202 int size = cpl_frameset_get_size(set);
203 res = cpl_malloc(sizeof(double) * size);
204
205 int i;
206
207 for (i = 0; i < size; i++) {
208 const cpl_frame *frame = cpl_frameset_get_position_const(set, i);
209 const char *filename = cpl_frame_get_filename(frame);
210 cpl_propertylist *list = cpl_propertylist_load(filename, 0);
211 res[i] = moo_pfits_get_exptime(list);
212 cpl_propertylist_delete(list);
213 }
214
215 return res;
216}
217
218
double * moo_dfs_get_exptime(cpl_frameset *set)
Get the EXPTIME from the frameset.
Definition: moo_dfs.c:198
cpl_error_code moo_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
Definition: moo_dfs.c:104
cpl_frameset ** moo_dfs_split_by_offset(cpl_frameset *set)
Get the EXPTIME from the frameset.
Definition: moo_dfs.c:59
int moo_pfits_get_slit_offset(const cpl_propertylist *plist)
find out the INS SLIT OFFSET value
Definition: moo_pfits.c:1110
double moo_pfits_get_exptime(const cpl_propertylist *plist)
find out the EXPTIME value
Definition: moo_pfits.c:1039