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 #ifdef HAVE_CONFIG_H
00032 #include <config.h>
00033 #endif
00034
00035
00036
00037
00038
00039
00040 #include <strings.h>
00041 #include <string.h>
00042 #include <stdio.h>
00043 #include <math.h>
00044 #include <libgen.h>
00045
00046
00047
00048 #include <cpl.h>
00049
00050
00051 #include <irplib_utils.h>
00052
00053
00054 #include <sinfo_utilities.h>
00055 #include <sinfo_pro_types.h>
00056 #include <sinfo_general_config.h>
00057 #include <sinfo_product_config.h>
00058 #include <sinfo_prepare_stacked_frames_config.h>
00059 #include <sinfo_objnod_config.h>
00060 #include <sinfo_skycor_config.h>
00061 #include <sinfo_psf_config.h>
00062 #include <sinfo_standard_star_config.h>
00063 #include <sinfo_new_prepare_stacked_frames.h>
00064 #include <sinfo_new_cubes_coadd.h>
00065 #include <sinfo_new_stdstar.h>
00066 #include <sinfo_new_psf.h>
00067 #include <sinfo_key_names.h>
00068 #include <sinfo_raw_types.h>
00069 #include <sinfo_functions.h>
00070 #include <sinfo_tpl_utils.h>
00071 #include <sinfo_tpl_dfs.h>
00072 #include <sinfo_hidden.h>
00073 #include <sinfo_globals.h>
00074 #include <sinfo_msg.h>
00075 #include <sinfo_rec_utils.h>
00076 #include <sinfo_error.h>
00077 #include <sinfo_utils_wrappers.h>
00078
00079
00080
00081
00082
00083 static int sinfo_rec_jitter_create(cpl_plugin *) ;
00084 static int sinfo_rec_jitter_exec(cpl_plugin *) ;
00085 static int sinfo_rec_jitter_destroy(cpl_plugin *) ;
00086 static int sinfo_rec_jitter(cpl_parameterlist *config, cpl_frameset *set);
00087
00088
00089
00090
00091 static char sinfo_rec_jitter_description1[] =
00092 "This recipe performs science data reduction.\n"
00093 "The input files are:\n"
00094 "science object and sky frames with tags OBJECT_NODDING and SKY_NODDING or\n"
00095 "Telluric standard star frames and sky frames with tags STD and SKY_STD or\n"
00096 "PSF standard star and sky frames with tags \n"
00097 "PSF_CALIBRATOR and SKY_PSF_CALIBRATOR\n"
00098 "and Master calibration frames:\n";
00099
00100
00101 static char sinfo_rec_jitter_description2[] =
00102 "A corresponding (band,preoptics) wavelength map image with tag WAVE_MAP\n"
00103 "A corresponding (band,preoptics) master flat field with tag MASTER_FLAT_LAMP\n"
00104 "A corresponding (band,preoptics) master bad pixel map with tag MASTER_BP_MAP\n"
00105 "A corresponding (band,preoptics) slitlets position frame with tag SLIT_POS\n"
00106 "A corresponding (band) distortion table with tag DISTORTION\n"
00107 "A corresponding (band) slitlet distance table with tag SLITLETS_DISTANCE\n";
00108
00109
00110 static char sinfo_rec_jitter_description3[] =
00111 "The output is an image resulting from the IMA1 op IMA2 where op indicates\n"
00112 "A reference table with the position of the first "
00113 "column with tag FIRST_COLUMN\n"
00114 "Relevant outputs are:\n"
00115 "combined cubes (PRO.CATG=x_OBS x=STD,OBJ,PSF)\n"
00116 "reconstructed cube (PRO.CATG=COADD_x_OBS x=STD,OBJ,PSF)\n"
00117 "An average along Z of the reconstructed cube \n"
00118 "(PRO.CATG=MED_x_OBS x=STD,OBJ,PSF)\n"
00119 "The bad pixel map associated to the cube \n"
00120 "(PRO.CATG=BP_MAP_COADD_x_OBS x=STD,OBJ,PSF)\n";
00121
00122
00123 static char sinfo_rec_jitter_description4[] =
00124 "Information on relevant parameters can be found with\n"
00125 "esorex --params sinfo_rec_jitter\n"
00126 "esorex --help sinfo_rec_jitter\n"
00127 "\n";
00128
00129 static char sinfo_rec_jitter_description[1400];
00130
00131
00132
00133
00134
00138
00140
00149
00150
00151 int
00152 cpl_plugin_get_info(cpl_pluginlist *list)
00153 {
00154
00155 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00156 cpl_plugin *plugin = &recipe->interface;
00157
00158 strcpy(sinfo_rec_jitter_description,sinfo_rec_jitter_description1);
00159 strcat(sinfo_rec_jitter_description,sinfo_rec_jitter_description2);
00160 strcat(sinfo_rec_jitter_description,sinfo_rec_jitter_description3);
00161 strcat(sinfo_rec_jitter_description,sinfo_rec_jitter_description4);
00162
00163 cpl_plugin_init(plugin,
00164 CPL_PLUGIN_API,
00165 SINFONI_BINARY_VERSION,
00166 CPL_PLUGIN_TYPE_RECIPE,
00167 "sinfo_rec_jitter",
00168 "Object or STD star or PSF star data reduction",
00169 sinfo_rec_jitter_description,
00170 "Andrea Modigliani",
00171 "Andrea.Mdigliani@eso.org",
00172 sinfo_get_license(),
00173 sinfo_rec_jitter_create,
00174 sinfo_rec_jitter_exec,
00175 sinfo_rec_jitter_destroy);
00176
00177 cpl_pluginlist_append(list, plugin);
00178
00179 return 0;
00180
00181 }
00182
00183
00191
00192 static int sinfo_rec_jitter_create(cpl_plugin *plugin)
00193 {
00194 cpl_recipe * recipe ;
00195
00196
00197
00198 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00199 recipe = (cpl_recipe *)plugin ;
00200 else return -1 ;
00201 cpl_error_reset();
00202 irplib_reset();
00203
00204
00205 recipe->parameters = cpl_parameterlist_new() ;
00206
00207
00208
00209
00210
00211
00212 sinfo_general_config_add(recipe->parameters);
00213 sinfo_product_config_add(recipe->parameters);
00214 sinfo_prepare_stacked_frames_config_add(recipe->parameters);
00215 sinfo_objnod_config_add(recipe->parameters);
00216 sinfo_skycor_config_add(recipe->parameters);
00217 sinfo_standard_star_config_add(recipe->parameters);
00218 sinfo_psf_config_add(recipe->parameters);
00219
00220
00221
00222 return 0;
00223
00224 }
00225
00226
00232
00233 static int sinfo_rec_jitter_exec(cpl_plugin *plugin)
00234 {
00235
00236 cpl_recipe *recipe = (cpl_recipe *) plugin;
00237
00238 cpl_errorstate initial_errorstate = cpl_errorstate_get();
00239
00240
00241 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00242 recipe = (cpl_recipe *)plugin ;
00243 else return -1 ;
00244
00245 if (!cpl_errorstate_is_equal(initial_errorstate)) {
00246
00247
00248 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
00249 }
00250 return sinfo_rec_jitter(recipe->parameters, recipe->frames);
00251
00252 }
00253
00254
00260
00261 static int sinfo_rec_jitter_destroy(cpl_plugin *plugin)
00262 {
00263
00264 cpl_recipe * recipe ;
00265
00266
00267 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00268 recipe = (cpl_recipe *)plugin ;
00269 else return -1 ;
00270
00271 cpl_parameterlist_delete(recipe->parameters);
00272
00273 return 0;
00274
00275 }
00276
00277
00284
00285
00286
00287
00288
00289
00290 static int sinfo_rec_jitter(cpl_parameterlist *config, cpl_frameset *set)
00291 {
00292 const char* pro_ctg_cube;
00293 cpl_parameter* p=NULL;
00294 int psf_sw=0;
00295 int std_sw=0;
00296 cpl_frameset* ref_set=NULL;
00297 int line_cor=0;
00298
00299 sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
00300 SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
00301
00302 if(sinfo_dfs_set_groups(set)) {
00303 sinfo_msg_error("Cannot indentify RAW and CALIB frames") ;
00304 return -1;
00305 }
00306
00307 check_nomsg(p=cpl_parameterlist_find(config, "sinfoni.general.lc_sw"));
00308 check_nomsg(line_cor=cpl_parameter_get_bool(p));
00309 if(line_cor==1) {
00310 check_nomsg(sinfo_ima_line_cor(config,set));
00311 }
00312
00313 check_nomsg(ref_set=cpl_frameset_duplicate(set));
00314
00315
00316
00317
00318 ck0(sinfo_cub_stk_frames(config,&set,cpl_func,&pro_ctg_cube),
00319 "Cannot stack RAW frames") ;
00320
00321
00322
00323
00324 sinfo_msg("------------------------------") ;
00325 sinfo_msg("COADDING CUBES");
00326 sinfo_msg("------------------------------") ;
00327 ck0(sinfo_new_cubes_coadd(cpl_func,config, set, pro_ctg_cube),
00328 "COADDING CUBES") ;
00329
00330 sinfo_msg("------------------------------") ;
00331 sinfo_msg("COADDED CUBES");
00332 sinfo_msg("------------------------------") ;
00333
00334
00335
00336
00337
00338 if((strcmp(pro_ctg_cube,PRO_COADD_PSF) == 0) ||
00339 (strcmp(pro_ctg_cube,PRO_COADD_STD) == 0) ||
00340 (strcmp(pro_ctg_cube,PRO_COADD_PUPIL) == 0) ) {
00341
00342
00343 p = cpl_parameterlist_find(config, "sinfoni.psf.switch");
00344 psf_sw = cpl_parameter_get_bool(p);
00345 sinfo_msg("switch=%d",psf_sw);
00346 if(psf_sw) {
00347 sinfo_msg("------------------------------") ;
00348 sinfo_msg("REDUCE PSF STD STAR FRAMES");
00349 sinfo_msg("------------------------------") ;
00350 if ( -1 == sinfo_new_psf(cpl_func,config,set,set) ) {
00351 sinfo_msg_error("REDUCING PSF STD STAR FRAMES") ;
00352 cpl_error_reset();
00353 } else {
00354 sinfo_msg("SUCCESS REDUCE PSF STD STAR FRAMES") ;
00355 }
00356 }
00357
00358 p = cpl_parameterlist_find(config, "sinfoni.std_star.switch");
00359 std_sw = cpl_parameter_get_bool(p);
00360 sinfo_msg("switch=%d",std_sw);
00361 if(std_sw) {
00362 sinfo_msg("------------------------------") ;
00363 sinfo_msg("STD STAR DATA REDUCTION");
00364 sinfo_msg("------------------------------") ;
00365 if ( -1 == sinfo_new_stdstar(cpl_func,config, set,set ) ) {
00366 sinfo_msg_error("REDUCING STD STAR DATA") ;
00367 cpl_error_reset();
00368 } else {
00369 sinfo_msg("STD STAR DATA REDUCTION SUCCESS") ;
00370 }
00371 }
00372 }
00373
00374 cleanup:
00375 sinfo_free_frameset(&ref_set);
00376 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00377 sinfo_check_rec_status(0);
00378 return -1;
00379 } else {
00380 return 0;
00381 }
00382
00383
00384 }
00385