CRIRES Pipeline Reference Manual 2.3.19
crires_model_wlmap.c
1/* $Id: crires_model_wlmap.c,v 1.35 2011-03-22 09:17:12 yjung Exp $
2 *
3 * This file is part of the CRIRES Pipeline
4 * Copyright (C) 2002,2003 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * $Author: yjung $
23 * $Date: 2011-03-22 09:17:12 $
24 * $Revision: 1.35 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32/*-----------------------------------------------------------------------------
33 Includes
34 -----------------------------------------------------------------------------*/
35
36#include "crires_recipe.h"
37
38#include "crires_model_kernel.h"
39
40/*-----------------------------------------------------------------------------
41 Define
42 -----------------------------------------------------------------------------*/
43
44#define RECIPE_STRING "crires_model_wlmap"
45
46/*-----------------------------------------------------------------------------
47 Functions prototypes
48 -----------------------------------------------------------------------------*/
49
50static int crires_model_wlmap_save(const cpl_imagelist *,
51 const cpl_parameterlist *, cpl_frameset *) ;
52
53static char crires_model_wlmap_description[] =
54"crires_model_wlmap -- Wavelength map creation using the model\n"
55"The files listed in the Set Of Frames (sof-file) must be tagged:\n"
56"raw-file.fits "CRIRES_MODEL_WLMAP_RAW" or\n"
57"config-file.fits "CRIRES_CALPRO_MODEL_CONFIG" or\n"
58"config-file.fits "CRIRES_CALPRO_MODEL_REFINE_CONF".\n" ;
59
60CRIRES_RECIPE_DEFINE(crires_model_wlmap,
61 CRIRES_PARAM_ORDER,
62 "Model wavelength map recipe",
63 crires_model_wlmap_description) ;
64
65/*-----------------------------------------------------------------------------
66 Static variables
67 -----------------------------------------------------------------------------*/
68
69static struct {
70 /* Inputs */
71 int order ;
72 /* Outputs */
73 crires_illum_period period ;
74} crires_model_wlmap_config ;
75
76/*-----------------------------------------------------------------------------
77 Functions code
78 -----------------------------------------------------------------------------*/
79
80/*----------------------------------------------------------------------------*/
87/*----------------------------------------------------------------------------*/
88static int crires_model_wlmap(
89 cpl_frameset * frameset,
90 const cpl_parameterlist * parlist)
91{
92 cpl_frameset * rawframes ;
93 const char * config ;
94 cpl_frame * ref_frame ;
95 cpl_imagelist * wlmap ;
96 //cpl_vector * profile ;
97
98 /* The Model is switched off */
99 if (crires_model_off()) {
100 return 0 ;
101 }
102
103 /* Initialise */
104 rawframes = NULL ;
105
106 /* Retrieve input parameters */
107 crires_model_wlmap_config.order = crires_parameterlist_get_int(parlist,
108 RECIPE_STRING, CRIRES_PARAM_ORDER) ;
109
110 /* Identify the RAW and CALIB frames in the input frameset */
111 if (crires_dfs_set_groups(frameset, "crires_model_wlmap")) {
112 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
113 return -1 ;
114 }
115
116 /* Retrieve calibration data */
117 config = crires_extract_filename(frameset, CRIRES_CALPRO_MODEL_CONFIG) ;
118 if (config == NULL) {
119 config = crires_extract_filename(frameset,
120 CRIRES_CALPRO_MODEL_REFINE_CONF) ;
121 }
122 if (config == NULL) {
123 cpl_msg_error(__func__, "No config file in input") ;
124 return -1 ;
125 }
126
127 /* Retrieve raw frames */
128 if ((rawframes = crires_extract_frameset(frameset,
129 CRIRES_MODEL_WLMAP_RAW)) == NULL) {
130 cpl_msg_error(__func__, "No raw frame in input") ;
131 return -1 ;
132 }
133 ref_frame = cpl_frameset_get_position(rawframes, 0) ;
134
135 /* Check the model config file validity vs. the current data */
136 if (crires_model_config_check(config,
137 cpl_frame_get_filename(ref_frame)) != 0) {
138 cpl_msg_error(__func__,
139 "The model configuration file version is wrong") ;
140 cpl_frameset_delete(rawframes) ;
141 return -1 ;
142 }
143
144 /* Get the detector illumination period */
145 crires_model_wlmap_config.period =
146 crires_get_detector_illum_period(cpl_frame_get_filename(ref_frame)) ;
147 if (crires_model_wlmap_config.period == CRIRES_ILLUM_UNKNOWN) {
148 cpl_msg_error(__func__,
149 "Cannot determine the detector illumination period") ;
150 cpl_frameset_delete(rawframes) ;
151 return -1 ;
152 } else {
153 crires_display_detector_illum(crires_model_wlmap_config.period) ;
154 }
155
156 /* if ((profile=crires_model_profile(cpl_frame_get_filename(ref_frame),
157 config, -1,
158 1000.0)) == NULL) {
159 cpl_msg_error(__func__, "Cannot compute the profile") ;
160 cpl_frameset_delete(rawframes) ;
161 return -1 ;
162 }
163 if ((line_list=crires_model_predict(cpl_frame_get_filename(ref_frame),
164 "ThAr_use.fits",
165 config,-1)) == NULL) {
166 cpl_msg_error(__func__, "cannot predict the line positions") ;
167 cpl_frameset_delete(rawframes) ;
168 return -1 ;
169 }
170 int ii=0;
171 while (line_list[0][ii]!=0.0) {
172 printf("here %lf %lf %lf %lf %lf %lf \n",line_list[0][ii],line_list[1][ii],line_list[2][ii],line_list[3][ii],line_list[4][ii],line_list[5][ii]);
173 ii+=1;
174 }
175 crires_model_free2Darray(line_list,6);
176 cpl_vector_delete(profile);
177 */
178
179 /* Compute the wavelength map */
180 if ((wlmap = crires_model_wavpix(cpl_frame_get_filename(ref_frame),
181 config, crires_model_wlmap_config.order)) == NULL) {
182 cpl_msg_error(__func__, "Cannot compute the WL map") ;
183 cpl_frameset_delete(rawframes) ;
184 return -1 ;
185 }
186 cpl_frameset_delete(rawframes) ;
187
188 /* Save the product */
189 if (crires_model_wlmap_save(wlmap, parlist, frameset) == -1) {
190 cpl_msg_error(__func__, "Cannot save products") ;
191 cpl_imagelist_delete(wlmap) ;
192 return -1 ;
193 }
194 cpl_imagelist_delete(wlmap) ;
195
196 /* Return */
197 if (cpl_error_get_code()) return -1 ;
198 else return 0 ;
199}
200
201/*----------------------------------------------------------------------------*/
209/*----------------------------------------------------------------------------*/
210static int crires_model_wlmap_save(
211 const cpl_imagelist * wlmap,
212 const cpl_parameterlist * parlist,
213 cpl_frameset * set)
214{
215 const char * recipe_name = "crires_model_wlmap" ;
216
217 /* Write the flat image */
218 crires_image_save(set,
219 parlist,
220 set,
221 wlmap,
222 recipe_name,
223 CRIRES_WL_MAP_MODEL_IMA,
224 CRIRES_PROTYPE_WL_MAP,
225 crires_model_wlmap_config.period,
226 NULL,
227 NULL,
228 PACKAGE "/" PACKAGE_VERSION,
229 "crires_model_wlmap.fits") ;
230
231 return 0;
232}