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 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035 #include <cpl.h>
00036 #include <irplib_utils.h>
00037 #include <irplib_error.h>
00038 #include <sinfo_skycor.h>
00039 #include <sinfo_skycor_config.h>
00040 #include <sinfo_tpl_utils.h>
00041 #include <sinfo_tpl_dfs.h>
00042 #include <sinfo_pro_types.h>
00043 #include <sinfo_utils_wrappers.h>
00044 #include <sinfo_error.h>
00045 #include <sinfo_msg.h>
00046 #include <sinfo_pro_save.h>
00047 #include <sinfo_globals.h>
00048
00049
00050
00051
00052
00053
00054
00055 static int sinfo_utl_skycor_create(cpl_plugin *) ;
00056 static int sinfo_utl_skycor_exec(cpl_plugin *) ;
00057 static int sinfo_utl_skycor_destroy(cpl_plugin *) ;
00058 static int sinfo_utl_skycor(cpl_parameterlist * config, cpl_frameset* set);
00059
00060
00061
00062
00063 static char sinfo_utl_skycor_description[] =
00064 "This recipe perform a correction of possible sky line residuals in the \n"
00065 "object cube after standard data reduction.\n"
00066 "Input frames are cubes with target and sky observations.\n"
00067 "Their tags can be respectively OBS_OBJ (or OBS_PSF or OBS_STD) and OBS_SKY.\n"
00068 "The output is a cube with same tag as the corresponding input target frame.\n"
00069 "\n";
00070
00071
00072
00073
00074
00075
00076
00080
00082
00090
00091 int cpl_plugin_get_info(cpl_pluginlist * list)
00092 {
00093 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
00094 cpl_plugin * plugin = &recipe->interface ;
00095
00096 cpl_plugin_init(plugin,
00097 CPL_PLUGIN_API,
00098 SINFONI_BINARY_VERSION,
00099 CPL_PLUGIN_TYPE_RECIPE,
00100 "sinfo_utl_skycor",
00101 "Sky lines residuals correction",
00102 sinfo_utl_skycor_description,
00103 "Andrea Modigliani",
00104 "Andrea.Modigliani@eso.org",
00105 sinfo_get_license(),
00106 sinfo_utl_skycor_create,
00107 sinfo_utl_skycor_exec,
00108 sinfo_utl_skycor_destroy) ;
00109
00110 cpl_pluginlist_append(list, plugin) ;
00111 return 0;
00112 }
00113
00114
00123
00124 static int sinfo_utl_skycor_create(cpl_plugin * plugin)
00125 {
00126 cpl_recipe * recipe ;
00127
00128
00129 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00130 recipe = (cpl_recipe *)plugin ;
00131 else return -1 ;
00132
00133
00134 irplib_reset();
00135
00136 recipe->parameters = cpl_parameterlist_new() ;
00137 sinfo_skycor_config_add(recipe->parameters);
00138
00139
00140 return 0;
00141 }
00142
00143
00149
00150 static int sinfo_utl_skycor_exec(cpl_plugin * plugin)
00151 {
00152 cpl_recipe * recipe ;
00153 int code=0;
00154
00155 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00156 recipe = (cpl_recipe *)plugin ;
00157 else return -1 ;
00158
00159
00160 code = sinfo_utl_skycor(recipe->parameters, recipe->frames) ;
00161 return code;
00162 }
00163
00164
00170
00171 static int sinfo_utl_skycor_destroy(cpl_plugin * plugin)
00172 {
00173 cpl_recipe * recipe ;
00174
00175
00176 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00177 recipe = (cpl_recipe *)plugin ;
00178 else return -1 ;
00179
00180 cpl_parameterlist_delete(recipe->parameters) ;
00181 return 0 ;
00182 }
00183
00184
00191
00192 static int
00193 sinfo_utl_skycor(cpl_parameterlist * config, cpl_frameset* set)
00194 {
00195
00196 cpl_frame* obj_frm=NULL;
00197 cpl_frame* sky_frm=NULL;
00198 cpl_imagelist* obj_cor=NULL;
00199 const char * name_o=NULL ;
00200 cpl_frame* product_frame=NULL;
00201
00202 cpl_propertylist* plist=NULL;
00203 sinfo_skycor_qc* sqc=NULL;
00204 char obj_tag[MAX_NAME_SIZE];
00205 cpl_table* int_obj=NULL;
00206
00207 sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
00208 SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
00209
00210
00211 ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
00212
00213
00214
00215 obj_frm=cpl_frameset_find(set,PRO_OBS_OBJ);
00216 if(obj_frm == NULL) {
00217 obj_frm=cpl_frameset_find(set,PRO_OBS_PSF);
00218 strcpy(obj_tag,PRO_OBS_PSF);
00219 } else {
00220 strcpy(obj_tag,PRO_OBS_OBJ);
00221 }
00222
00223
00224 if(obj_frm == NULL) {
00225 obj_frm=cpl_frameset_find(set,PRO_OBS_STD);
00226 strcpy(obj_tag,PRO_OBS_STD);
00227 }
00228 cknull(obj_frm,"No %s or %s or %s frame found",
00229 PRO_OBS_OBJ,PRO_OBS_PSF,PRO_OBS_STD);
00230 check(sky_frm=cpl_frameset_find(set,PRO_OBS_SKY),
00231 "No %s found",PRO_OBS_SKY);
00232 sqc=sinfo_skycor_qc_new();
00233
00234 check(plist=cpl_propertylist_load(cpl_frame_get_filename(obj_frm),0),
00235 "Cannot read the FITS header") ;
00236
00237 ck0(sinfo_skycor(config, obj_frm,sky_frm,sqc,&obj_cor,&int_obj),
00238 "determining sky residuals corrected object");
00239 sinfo_msg("Write out adjusted cube");
00240
00241
00242 cpl_frameset_erase(set,obj_tag);
00243 cpl_frameset_erase(set,PRO_OBS_SKY);
00244 name_o = "out_obj_cor.fits" ;
00245
00246
00247
00248 check_nomsg(product_frame = cpl_frame_new());
00249 check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
00250 check_nomsg(cpl_frame_set_tag(product_frame, PRO_OBS_OBJ)) ;
00251 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
00252 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
00253 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
00254 "Error while initialising the product frame") ;
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 check(cpl_imagelist_save(obj_cor,
00274 name_o,
00275 CPL_BPP_DEFAULT,
00276 plist,
00277 CPL_IO_DEFAULT),
00278 "Could not save product");
00279
00280
00281 check_nomsg(cpl_frameset_insert(set,cpl_frame_duplicate(product_frame))) ;
00282 sinfo_free_frame(&product_frame);
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 sinfo_free_imagelist(&obj_cor);
00294
00295
00296
00297 name_o = "out_obj_int.fits" ;
00298
00299
00300 check_nomsg(product_frame = cpl_frame_new());
00301 check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
00302 check_nomsg(cpl_frame_set_tag(product_frame, PRO_SPECTRA_QC)) ;
00303 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE)) ;
00304 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
00305 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
00306 "Error while initialising the product frame") ;
00307 check_nomsg(cpl_propertylist_update_string(plist, "ESO PRO CATG",
00308 PRO_SPECTRA_QC));
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328 check(cpl_table_save(int_obj, plist, NULL, name_o, 0),
00329 "Could not save product");
00330 sinfo_free_propertylist(&plist) ;
00331
00332
00333 check_nomsg(cpl_frameset_insert(set, cpl_frame_duplicate(product_frame))) ;
00334 sinfo_free_frame(&product_frame);
00335
00336
00337
00338
00339 cleanup:
00340 sinfo_free_imagelist(&obj_cor);
00341 sinfo_free_table(&int_obj);
00342 sinfo_skycor_qc_delete(&sqc);
00343 sinfo_free_propertylist(&plist);
00344 sinfo_free_frame(&product_frame);
00345 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00346 irplib_error_dump(CPL_MSG_ERROR,CPL_MSG_ERROR);
00347 return -1;
00348 } else {
00349 return 0;
00350 }
00351
00352
00353 }