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 <string.h>
00036 #include <cpl.h>
00037 #include <irplib_utils.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 cpl_errorstate initial_errorstate = cpl_errorstate_get();
00156
00157 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00158 recipe = (cpl_recipe *)plugin ;
00159 else return -1 ;
00160
00161
00162 code = sinfo_utl_skycor(recipe->parameters, recipe->frames) ;
00163
00164 if (!cpl_errorstate_is_equal(initial_errorstate)) {
00165
00166
00167 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
00168 }
00169 return code;
00170 }
00171
00172
00178
00179 static int sinfo_utl_skycor_destroy(cpl_plugin * plugin)
00180 {
00181 cpl_recipe * recipe ;
00182
00183
00184 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00185 recipe = (cpl_recipe *)plugin ;
00186 else return -1 ;
00187
00188 cpl_parameterlist_delete(recipe->parameters) ;
00189 return 0 ;
00190 }
00191
00192
00199
00200 static int
00201 sinfo_utl_skycor(cpl_parameterlist * config, cpl_frameset* set)
00202 {
00203
00204 cpl_frame* obj_frm=NULL;
00205 cpl_frame* sky_frm=NULL;
00206 cpl_imagelist* obj_cor=NULL;
00207 const char * name_o=NULL ;
00208 cpl_frame* product_frame=NULL;
00209
00210 cpl_propertylist* plist=NULL;
00211 sinfo_skycor_qc* sqc=NULL;
00212 char obj_tag[MAX_NAME_SIZE];
00213 cpl_table* int_obj=NULL;
00214
00215 sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
00216 SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
00217
00218
00219 ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
00220
00221
00222
00223 obj_frm=cpl_frameset_find(set,PRO_OBS_OBJ);
00224 if(obj_frm == NULL) {
00225 obj_frm=cpl_frameset_find(set,PRO_OBS_PSF);
00226 strcpy(obj_tag,PRO_OBS_PSF);
00227 } else {
00228 strcpy(obj_tag,PRO_OBS_OBJ);
00229 }
00230
00231
00232 if(obj_frm == NULL) {
00233 obj_frm=cpl_frameset_find(set,PRO_OBS_STD);
00234 strcpy(obj_tag,PRO_OBS_STD);
00235 }
00236 cknull(obj_frm,"No %s or %s or %s frame found",
00237 PRO_OBS_OBJ,PRO_OBS_PSF,PRO_OBS_STD);
00238 check(sky_frm=cpl_frameset_find(set,PRO_OBS_SKY),
00239 "No %s found",PRO_OBS_SKY);
00240 sqc=sinfo_skycor_qc_new();
00241
00242 check(plist=cpl_propertylist_load(cpl_frame_get_filename(obj_frm),0),
00243 "Cannot read the FITS header") ;
00244
00245 ck0(sinfo_skycor(config, obj_frm,sky_frm,sqc,&obj_cor,&int_obj),
00246 "determining sky residuals corrected object");
00247 sinfo_msg("Write out adjusted cube");
00248
00249
00250 cpl_frameset_erase(set,obj_tag);
00251 cpl_frameset_erase(set,PRO_OBS_SKY);
00252 name_o = "out_obj_cor.fits" ;
00253
00254
00255
00256 check_nomsg(product_frame = cpl_frame_new());
00257 check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
00258 check_nomsg(cpl_frame_set_tag(product_frame, obj_tag)) ;
00259 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
00260 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
00261 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
00262 "Error while initialising the product frame") ;
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281 check(cpl_imagelist_save(obj_cor,
00282 name_o,
00283 CPL_BPP_IEEE_FLOAT,
00284 plist,
00285 CPL_IO_DEFAULT),
00286 "Could not save product");
00287
00288 check_nomsg(cpl_frameset_insert(set,cpl_frame_duplicate(product_frame))) ;
00289 sinfo_free_frame(&product_frame);
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299 sinfo_free_imagelist(&obj_cor);
00300
00301
00302
00303 name_o = "out_obj_int.fits" ;
00304
00305
00306 check_nomsg(product_frame = cpl_frame_new());
00307 check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
00308 check_nomsg(cpl_frame_set_tag(product_frame, PRO_SPECTRA_QC)) ;
00309 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE)) ;
00310 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
00311 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
00312 "Error while initialising the product frame") ;
00313 check_nomsg(cpl_propertylist_update_string(plist, "ESO PRO CATG",
00314 PRO_SPECTRA_QC));
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 check(cpl_table_save(int_obj, plist, NULL, name_o, 0),
00335 "Could not save product");
00336 sinfo_free_propertylist(&plist) ;
00337
00338
00339 check_nomsg(cpl_frameset_insert(set, cpl_frame_duplicate(product_frame))) ;
00340 sinfo_free_frame(&product_frame);
00341
00342
00343
00344
00345 cleanup:
00346 sinfo_free_imagelist(&obj_cor);
00347 sinfo_free_table(&int_obj);
00348 sinfo_skycor_qc_delete(&sqc);
00349 sinfo_free_propertylist(&plist);
00350 sinfo_free_frame(&product_frame);
00351 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00352 return -1;
00353 } else {
00354 return 0;
00355 }
00356
00357
00358 }