00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifdef HAVE_CONFIG_H
00037 #include <config.h>
00038 #endif
00039
00040
00041 #include <strings.h>
00042 #include <string.h>
00043 #include <stdio.h>
00044
00045
00046 #include <cxmacros.h>
00047 #include <cxtypes.h>
00048 #include <cxmessages.h>
00049
00050
00051 #include <xmemory.h>
00052
00053
00054 #include <cpl.h>
00055
00056
00057
00058 #include <sinfoni_pro_types.h>
00059 #include <sinfoni_prepare_stacked_frames_config.h>
00060 #include <sinfoni_wavecal_config.h>
00061 #include <prepare_stacked_frames.h>
00062 #include <wave_cal_slit.h>
00063 #include <sinfoni_raw_types.h>
00064 #include <slit_pos.h>
00065 #include <sinfoni_tpl_utils.h>
00066 #include <sinfoni_tpl_dfs.h>
00067 #include <sinfoni_hidden.h>
00068 #include <sinfoni_globals.h>
00069 #include <sinfoni_functions.h>
00070 #include <sinfoni_memory.h>
00071
00072
00073
00074
00075 static cxint si_rec_wavecal_create(cpl_plugin *);
00076 static cxint si_rec_wavecal_exec(cpl_plugin *);
00077 static cxint si_rec_wavecal_destroy(cpl_plugin *);
00078 static cxint si_rec_wavecal(cpl_parameterlist *, cpl_frameset *);
00079
00080
00081
00082
00083
00084 static char si_rec_wavecal_description1[] =
00085 "This recipe performs wavelength calibration.\n"
00086 "The input files are on/off arc lamp frames with tag WAVE_LAMP\n"
00087 "Master calibration frame input is:\n"
00088 "A corresponding (band) reference line table with tag REF_LINE_ARC\n"
00089 "A corresponding (band) distortion table with tag DISTORTION\n"
00090 "A corresponding (band,preoptic) master flat with tag MASTER_FLAT_LAMP\n"
00091 "A corresponding (band,preoptics) master bad pixel map with tag MASTER_BP_MAP\n";
00092
00093
00094 static char si_rec_wavecal_description2[] =
00095 "If wcal-estimate_ind=TRUE, a corresponding (band,preoptics) slitlet position guess table SLIT_POS_GUESS (for example a copy of the SLIT_POS product)\n"
00096 "If wcal-calib_indicator=FALSE, a corresponding (band,preoptics) parabolic fit coefficients table WAVE_COEF_SLIT\n"
00097 "If sinfoni.wavecal.slitpos_boostrap_switch=FALSE (wcal-calib-slitpos_bootstrap=0),\n"
00098 "a corresponding (band,preoptics) slitlets position table with tag SLIT_POS\n";
00099
00100
00101
00102 static char si_rec_wavecal_description3[] =
00103 "The main products are:\n"
00104 "The master flat field corrected for distortions (PRO.CATG=MFLAT_STACKED_DIST)\n"
00105 "The arc lamp frames stacked (PRO.CATG=WAVE_LAMP_STACKED)\n"
00106 "The wavelength map (PRO.CATG=WAVE_MAP)\n"
00107 "The slitlet position table (PRO.CATG=SLIT_POS)\n"
00108 "A parabolic fit coefficients table (PRO.CATG=WAVE_COEF_SLIT)\n"
00109 "Parameters relative to arc lamp line fit: (PRO.CATG=WAVE_FIT_PARAMS)\n"
00110 "Information on relevant parameters can be found with\n"
00111 "esorex --params si_rec_wavecal\n"
00112 "esorex --help si_rec_wavecal\n"
00113 "\n";
00114
00115
00116 static char si_rec_wavecal_description[1300];
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 cxint
00131 si_rec_wavecal_create(cpl_plugin *plugin)
00132 {
00133
00134
00135
00136
00137
00138
00139 cpl_recipe *recipe = (cpl_recipe *)plugin;
00140 recipe->parameters = cpl_parameterlist_new();
00141 if(recipe->parameters == NULL) {
00142 return 1;
00143 }
00144
00145
00146
00147
00148
00149
00150 sinfoni_prepare_stacked_frames_config_add(recipe->parameters);
00151 sinfoni_wavecal_config_add(recipe->parameters);
00152 return 0;
00153
00154 }
00155
00156 cxint
00157 si_rec_wavecal_exec(cpl_plugin *plugin)
00158 {
00159
00160 cpl_recipe *recipe = (cpl_recipe *) plugin;
00161 if(recipe->parameters == NULL) {
00162 return 1;
00163 }
00164 if(recipe->frames == NULL) {
00165 return 1;
00166 }
00167 cpl_error_reset();
00168 return si_rec_wavecal(recipe->parameters, recipe->frames);
00169
00170 }
00171
00172 cxint
00173 si_rec_wavecal_destroy(cpl_plugin *plugin)
00174 {
00175 cpl_recipe *recipe = (cpl_recipe *) plugin;
00176
00177
00178
00179
00180
00181
00182 cpl_parameterlist_delete(recipe->parameters);
00183
00184 return 0;
00185
00186 }
00187
00188
00189 int
00190 cpl_plugin_get_info(cpl_pluginlist *list)
00191 {
00192
00193 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00194 cpl_plugin *plugin = &recipe->interface;
00195
00196
00197 strcpy(si_rec_wavecal_description,si_rec_wavecal_description1);
00198 strcat(si_rec_wavecal_description,si_rec_wavecal_description2);
00199 strcat(si_rec_wavecal_description,si_rec_wavecal_description3);
00200
00201 cpl_plugin_init(plugin,
00202 CPL_PLUGIN_API,
00203 SINFONI_BINARY_VERSION,
00204 CPL_PLUGIN_TYPE_RECIPE,
00205 "si_rec_wavecal",
00206 "Wavelength calibration and slitpos determination",
00207 si_rec_wavecal_description,
00208 "Andrea Modigliani",
00209 "Andrea.Modigliani@eso.org",
00210 sinfoni_get_license(),
00211 si_rec_wavecal_create,
00212 si_rec_wavecal_exec,
00213 si_rec_wavecal_destroy);
00214
00215 cpl_pluginlist_append(list, plugin);
00216
00217 return 0;
00218
00219 }
00220
00221
00222
00223
00224
00225
00226
00227 static cxint
00228 si_rec_wavecal(cpl_parameterlist *config, cpl_frameset *set)
00229 {
00230
00231 const char *_id = "si_rec_wavecal";
00232 int ind =0;
00233 int sw=0;
00234 fake* fk=NULL;
00235 cpl_parameter* p=NULL;
00236 cpl_frameset* wrk_set=NULL;
00237 cpl_frame* frame=NULL;
00238 cpl_frame* frame_dup=NULL;
00239 int ind_index=0;
00240 fk=fake_new();
00241
00242
00243 if(sinfoni_dfs_set_groups(set)) {
00244
00245 cpl_msg_error(_id, "Cannot indentify RAW and CALIB frames") ;
00246 return -1;
00247
00248 }
00249
00250 p = cpl_parameterlist_find(config,"sinfoni.wavecal.slitpos_boostrap");
00251 sw=cpl_parameter_get_bool(p);
00252
00253 wrk_set=cpl_frameset_duplicate(set);
00254
00255 if( (sw == 1) ) {
00256
00257 p = cpl_parameterlist_find(config,"sinfoni.stacked.ind_index");
00258 ind_index=cpl_parameter_get_bool(p);
00259 cpl_parameter_set_bool(p,TRUE);
00260
00261
00262 {
00263 cpl_msg_info(_id,"---------------------------------------");
00264 cpl_msg_info(_id,"%s FRAME DETERMINATION", PRO_WAVE_LAMP_STACKED);
00265 cpl_msg_info(_id,"---------------------------------------");
00266 if ( -1 == (ind = prepare_stacked_frames(_id,config, wrk_set,
00267 PRO_WAVE_LAMP_STACKED,0,fk)))
00268 {
00269 cpl_msg_error(_id," no: %d\n", ind) ;
00270 cpl_frameset_delete(wrk_set);
00271 fake_delete(fk);
00272 sinfoni_memory_status();
00273 return -1 ;
00274 }
00275 cpl_msg_info(_id,"%s FRAME DETERMINATION SUCCESS",
00276 PRO_WAVE_LAMP_STACKED);
00277 }
00278
00279
00280 {
00281 if ( -1 == (ind = wave_cal_slit(_id,config, wrk_set) ) )
00282 {
00283 cpl_msg_error(_id,"no: %d\n", ind) ;
00284 cpl_frameset_delete(wrk_set);
00285 fake_delete(fk);
00286 sinfoni_memory_status();
00287 return -1 ;
00288 }
00289 cpl_msg_info(_id,"FIRST PART OF WAVELENGTH CALIBRATION") ;
00290 }
00291 frame = cpl_frameset_find(wrk_set,PRO_SLIT_POS_GUESS);
00292 frame_dup = cpl_frame_duplicate(frame);
00293 cpl_frameset_insert(set,frame_dup);
00294
00295 p = cpl_parameterlist_find(config,"sinfoni.stacked.ind_index");
00296 if(ind_index == 1) {
00297 cpl_parameter_set_bool(p,TRUE);
00298 p = cpl_parameterlist_find(config,"sinfoni.wavecal.slitpos_boostrap");
00299 cpl_parameter_set_bool(p,TRUE);
00300 cpl_msg_info(_id,"Set ind_index to TRUE");
00301 } else {
00302 cpl_parameter_set_bool(p,FALSE);
00303 p = cpl_parameterlist_find(config,"sinfoni.wavecal.slitpos_boostrap");
00304 cpl_parameter_set_bool(p,FALSE);
00305 cpl_msg_info(_id,"Set ind_index to FALSE");
00306 }
00307 }
00308
00309
00310 cpl_msg_info(_id,"---------------------------------------------");
00311 cpl_msg_info(_id,"%s FRAME DETERMINATION", PRO_WAVE_LAMP_STACKED);
00312 cpl_msg_info(_id,"---------------------------------------------");
00313 {
00314 if ( -1 == (ind = prepare_stacked_frames(_id,config, set,
00315 PRO_WAVE_LAMP_STACKED,0,fk )))
00316 {
00317 cpl_msg_error(_id," no: %d\n", ind) ;
00318 cpl_frameset_delete(wrk_set);
00319 fake_delete(fk);
00320 sinfoni_memory_status();
00321 return -1 ;
00322 }
00323 cpl_msg_info(_id,"%s FRAME DETERMINATION SUCCESS", PRO_WAVE_LAMP_STACKED);
00324 }
00325
00326 cpl_frameset_delete(wrk_set);
00327
00328
00329 cpl_msg_info(_id,"---------------------------------------------");
00330 cpl_msg_info(_id,"WAVELENGTH CALIBRATION");
00331 cpl_msg_info(_id,"---------------------------------------------");
00332 {
00333 if ( -1 == (ind = wave_cal_slit(_id,config, set ) ) )
00334 {
00335 cpl_msg_error(_id,"no: %d\n", ind) ;
00336 fake_delete(fk);
00337 sinfoni_memory_status();
00338 return -1 ;
00339 }
00340 cpl_msg_info(_id,"SUCCESS WAVELENGTH CALIBRATION") ;
00341 }
00342
00343 fake_delete(fk);
00344 sinfoni_memory_status();
00345 return 0 ;
00346
00347 }
00348
00349
00350
00351
00352
00353
00354
00355