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 "omega_recipe.h"
00036 #include "omega_science.h"
00037
00038 #include "omega_background.h"
00039 #include "omega_cosmic.h"
00040 #include "omega_photometry.h"
00041 #include "omega_satellites.h"
00042 #include "omega_wcscor.h"
00043 #include "omega_utils.h"
00082
00083
00084
00085
00086 static int omega_standard_star_create(cpl_plugin *) ;
00087 static int omega_standard_star_exec(cpl_plugin *) ;
00088 static int omega_standard_star_destroy(cpl_plugin *) ;
00089 static int omega_standard_star(cpl_frameset *,cpl_parameterlist *);
00090
00091
00092
00093
00094 omega_fits *omega_std_process(cpl_frameset *stdlist,cpl_parameterlist *pars, int ext);
00095 static int omega_std_retrieve_input_param(const cpl_parameterlist *parlist);
00096 static int omega_std_load_calib(int ext);
00097 static void omega_std_init(void);
00098 static void omega_std_tidy(int level);
00099
00100
00101
00102
00103
00104 static struct {
00105
00106 int extnum;
00107 int oc;
00108 int bckg;
00109 int paf;
00110 double MaxWcsShift;
00111
00112 int nmatches;
00113 int nstars;
00114 double mratio;
00115 double ZP;
00116 double ZPerr;
00117 double Extinction;
00118 double Exterr;
00119 double Seeing;
00120 double Ellipticity;
00121
00122 }omega_std_config;
00123
00124
00125 static struct {
00126
00127
00128 const cpl_frame *bpmfr;
00129 const cpl_frame *extfr;
00130 const cpl_frame *illumfr;
00131 const cpl_frame *mbiasfr;
00132 const cpl_frame *mflatfr;
00133 const cpl_frame *monitfr;
00134 const cpl_frame *reffr;
00135 const cpl_frame *stdfr;
00136 const cpl_frame *usnoa2;
00137 const cpl_frame *colfr;
00138
00139 cpl_size *labels;
00140 cpl_frameset *stdlist;
00141 cpl_image *mbias;
00142 cpl_image *bpm;
00143 cpl_image *mflat;
00144 cpl_image *illum;
00145
00146
00147 char *sname;
00148 char *pname;
00149 char *zname;
00150 omega_fits *stdfits;
00151 cpl_table *zptbl;
00152 cpl_table *photbl;
00153 cpl_table *extratbl;
00154
00155 }ps;
00156
00157
00158
00159
00160
00161 #define RECIPE "omega_standard_star"
00162
00163
00164
00172
00173 int cpl_plugin_get_info(cpl_pluginlist * list)
00174 {
00175 cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe)) ;
00176 cpl_plugin * plugin = &recipe->interface ;
00177
00178 cpl_plugin_init(plugin,
00179 CPL_PLUGIN_API,
00180 OMEGA_BINARY_VERSION,
00181 CPL_PLUGIN_TYPE_RECIPE,
00182 "omega_standard_star",
00183 "OMEGA - This recipe is used to reduce standard star observations.",
00184 "The recipe assumes that the data is for a single CCD. \n"
00185 "The following operations are performed: \n\n"
00186 " 1. Trim and overscan correct; \n"
00187 " 2. Subtract the bias and divide by the flat field; \n"
00188 " 3. Correct for fringing, illumination and the background, if requested; \n"
00189 " 4. Extract the zero point from the data and calculate the extinction \n"
00190 " value and save both in the header and in one table. \n\n"
00191 " ------------------------------------------------------------------------ \n\n"
00192 " Mandatory inputs : \n\n"
00193 " : a raw standard star frame \n"
00194 " : a master bias frame (Calfile 541) \n"
00195 " : a master flat field (Calfile 546) \n\n"
00196 " : a master USNOA2 table \n"
00197 " : a standard stars catalog table \n\n"
00198 " Optional inputs : \n\n"
00199 " : fringe map (Calfile 545) \n"
00200 " : bad pixels map (Calfile 522+535) \n"
00201 " : illumination correction frame (Calfile 548) \n\n"
00202 " The recipe will save the extinction and zero point values in one table.",
00203 "Sandra Castro",
00204 "scastro@eso.org",
00205 omega_get_license(),
00206 omega_standard_star_create,
00207 omega_standard_star_exec,
00208 omega_standard_star_destroy) ;
00209
00210 cpl_pluginlist_append(list, plugin) ;
00211
00212 return 0;
00213 }
00214
00215
00224
00225 static int omega_standard_star_create(cpl_plugin * plugin)
00226 {
00227 cpl_recipe * recipe;
00228 cpl_parameter * p ;
00229 char *path = NULL;
00230
00231
00232 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00233 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
00234 cpl_func, __LINE__, cpl_error_get_where());
00235 return (int)cpl_error_get_code();
00236 }
00237
00238 if (plugin == NULL) {
00239 cpl_msg_error(cpl_func, "Null plugin");
00240 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00241 }
00242
00243
00244 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00245 cpl_msg_error(cpl_func, "Plugin is not a recipe");
00246 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
00247 }
00248
00249
00250 recipe = (cpl_recipe *)plugin;
00251
00252
00253 recipe->parameters = cpl_parameterlist_new() ;
00254 if (recipe->parameters == NULL) {
00255 cpl_msg_error(cpl_func, "Parameter list allocation failed");
00256 cpl_ensure_code(0, (int)CPL_ERROR_ILLEGAL_OUTPUT);
00257 }
00258
00259
00260
00261
00262
00263 p = cpl_parameter_new_value("omega.omega_standard_star.ExtensionNumber",
00264 CPL_TYPE_INT,
00265 "FITS extension number to load (1 to 32). (-1 == all)",
00266 "omega_standard_star",
00267 -1) ;
00268
00269 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"ext") ;
00270 cpl_parameterlist_append(recipe->parameters, p) ;
00271
00272 p = cpl_parameter_new_range("omega.omega_standard_star.OverscanMethod",
00273 CPL_TYPE_INT,
00274 "Overscan Correction Method",
00275 "overscan",
00276 0, 0, 6);
00277 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"oc-meth") ;
00278 cpl_parameterlist_append(recipe->parameters, p) ;
00279
00280 p = cpl_parameter_new_value("omega.omega_standard_star.PAF",
00281 CPL_TYPE_BOOL,
00282 "Boolean value to create PAF files. 1(TRUE), 0(FALSE)",
00283 "omega_standard_star",
00284 1) ;
00285
00286 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "paf") ;
00287 cpl_parameterlist_append(recipe->parameters, p) ;
00288
00289
00290
00291 p = cpl_parameter_new_value("omega.omega_standard_star.LowThreSatuPixel",
00292 CPL_TYPE_DOUBLE,
00293 "Low threshold for calculating the saturated pixels map.",
00294 "omega_standard_star",
00295 -500.0) ;
00296
00297 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "lt-satu") ;
00298 cpl_parameterlist_append(recipe->parameters, p) ;
00299
00300 p = cpl_parameter_new_value("omega.omega_standard_star.HighThreSatuPixel",
00301 CPL_TYPE_DOUBLE,
00302 "High threshold for calculating the saturated pixels map.",
00303 "omega_standard_star",
00304 60000.0) ;
00305
00306 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "ht-satu") ;
00307 cpl_parameterlist_append(recipe->parameters, p) ;
00308
00309
00310 p = cpl_parameter_new_value("omega.omega_standard_star.DetectionThreSatellite",
00311 CPL_TYPE_DOUBLE,
00312 "Minimum SNR for pixels to contribute to Hough map.",
00313 "omega.Hough",
00314 4.0) ;
00315
00316 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "det-sate") ;
00317 cpl_parameterlist_append(recipe->parameters, p) ;
00318
00319 p = cpl_parameter_new_value("omega.omega_standard_star.HoughThreshold",
00320 CPL_TYPE_DOUBLE,
00321 "Threshold for satellite tracks in Hough image.",
00322 "omega.Hough",
00323 400.0) ;
00324
00325 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "hough-thre") ;
00326 cpl_parameterlist_append(recipe->parameters, p) ;
00327
00328
00329
00330 p = cpl_parameter_new_value("omega.omega_standard_star.SigmaFringeScaling",
00331 CPL_TYPE_DOUBLE,
00332 "Sigma threshold in image data for scaling estimate (fringes only)",
00333 "omega_standard_star",
00334 5.0) ;
00335
00336 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "sig-fr-sc") ;
00337 cpl_parameterlist_append(recipe->parameters, p) ;
00338
00339 p = cpl_parameter_new_value("omega.omega_standard_star.LowThreFringe",
00340 CPL_TYPE_DOUBLE,
00341 "Lower bound of fringes to include in scaling (fringes only)",
00342 "omega_standard_star",
00343 1.5) ;
00344
00345 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "lt-fr") ;
00346 cpl_parameterlist_append(recipe->parameters, p) ;
00347
00348 p = cpl_parameter_new_value("omega.omega_standard_star.HighThreFringe",
00349 CPL_TYPE_DOUBLE,
00350 "Higher bound of fringes to include in scaling (fringes only)",
00351 "omega_standard_star",
00352 5.0) ;
00353
00354 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "ht-fr") ;
00355 cpl_parameterlist_append(recipe->parameters, p) ;
00356
00357
00358
00359 p = cpl_parameter_new_value("omega.omega_standard_star.BackRestore",
00360 CPL_TYPE_BOOL,
00361 "Boolean value to restore background after illumination correction. 1(TRUE), 0(FALSE)",
00362 "omega_standard_star",
00363 1) ;
00364
00365 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "backg-rest") ;
00366 cpl_parameterlist_append(recipe->parameters, p) ;
00367
00368 p = cpl_parameter_new_value("omega.omega_standard_star.BackThreshold",
00369 CPL_TYPE_DOUBLE,
00370 "Detection threshold for background in image (Sextractor DETECT_THRESH)",
00371 "omega_standard_star",
00372 1000.) ;
00373
00374 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "backthre") ;
00375 cpl_parameterlist_append(recipe->parameters, p) ;
00376
00377
00378
00379
00380
00381
00382 path = cpl_sprintf("%s", OMEGA_BIN_PATH);
00383 p = cpl_parameter_new_value("omega.omega_standard_star.BinPath",
00384 CPL_TYPE_STRING,
00385 "Path to any external executable program.",
00386 "omega.BinPath",
00387 path);
00388
00389 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "bin-path");
00390 cpl_parameterlist_append(recipe->parameters, p);
00391 cpl_free(path);
00392
00393
00394 path = cpl_sprintf("%s/omega.sex", OMEGA_CONFIG_PATH);
00395 p = cpl_parameter_new_value("omega.omega_standard_star.SexConfig",
00396 CPL_TYPE_STRING,
00397 "Path to Sextractor config file.",
00398 "omega.sextractor",
00399 path);
00400
00401 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "sex-config");
00402 cpl_parameterlist_append(recipe->parameters, p);
00403 cpl_free(path);
00404
00405
00406 path = cpl_sprintf("%s/omega.conv", OMEGA_CONFIG_PATH);
00407 p = cpl_parameter_new_value("omega.omega_standard_star.SexConv",
00408 CPL_TYPE_STRING,
00409 "Path to Sextractor convolution mask file.",
00410 "omega.sextractor",
00411 path);
00412
00413 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "sex-conv");
00414 cpl_parameterlist_append(recipe->parameters, p);
00415 cpl_free(path);
00416
00417
00418 path = cpl_sprintf("%s/omega.param", OMEGA_CONFIG_PATH);
00419 p = cpl_parameter_new_value("omega.omega_standard_star.SexParam",
00420 CPL_TYPE_STRING,
00421 "Path to Sextractor parameters file.",
00422 "omega.sextractor",
00423 path);
00424
00425 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "sex-param");
00426 cpl_parameterlist_append(recipe->parameters, p);
00427 cpl_free(path);
00428
00429 path = cpl_sprintf("%s/omega.nnw", OMEGA_CONFIG_PATH);
00430 p = cpl_parameter_new_value("omega.omega_standard_star.SexNnw",
00431 CPL_TYPE_STRING,
00432 "Path to Sextractor neural network config file.",
00433 "omega.sextractor",
00434 path);
00435
00436 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "sex-nnw");
00437 cpl_parameterlist_append(recipe->parameters, p);
00438 cpl_free(path);
00439
00440 p = cpl_parameter_new_value("omega.omega_standard_star.SexDetThreshold",
00441 CPL_TYPE_DOUBLE,
00442 "Detection threshold for Sextractor sources.",
00443 "omega.sextractor",
00444 1.5);
00445
00446 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "sex-dthre");
00447 cpl_parameterlist_append(recipe->parameters, p);
00448
00449
00450
00451 path = cpl_sprintf("%s/omega.cosmic.sex", OMEGA_CONFIG_PATH);
00452 p = cpl_parameter_new_value("omega.omega_standard_star.SexCosmic",
00453 CPL_TYPE_STRING,
00454 "Path to Sextractor cosmic detection mode config file.",
00455 "omega.Sextractor",
00456 path);
00457
00458 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "sex-cosmic");
00459 cpl_parameterlist_append(recipe->parameters, p);
00460 cpl_free(path);
00461
00462 path = cpl_sprintf("%s/omega.cosmic.param", OMEGA_CONFIG_PATH);
00463 p = cpl_parameter_new_value("omega.omega_standard_star.SexCosmicParam",
00464 CPL_TYPE_STRING,
00465 "Path to Sextractor cosmic parameters file.",
00466 "omega.Sextractor",
00467 path);
00468
00469 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"sex-cosmic-param");
00470 cpl_parameterlist_append(recipe->parameters, p);
00471 cpl_free(path);
00472
00473 path = cpl_sprintf("%s/cosmic.ret", OMEGA_CONFIG_PATH);
00474 p = cpl_parameter_new_value("omega.omega_standard_star.SexCosmicFilt",
00475 CPL_TYPE_STRING,
00476 "Path to Sextractor filter mask for cosmic detection mode.",
00477 "omega.Sextractor",
00478 path);
00479
00480 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "sex-cosfilt");
00481 cpl_parameterlist_append(recipe->parameters, p);
00482 cpl_free(path);
00483
00484 p = cpl_parameter_new_value("omega.omega_standard_star.SexCosmicDet",
00485 CPL_TYPE_DOUBLE,
00486 "Detection threshold for detecting cosmic rays in Sextractor",
00487 "omega.Sextractor",
00488 5.0) ;
00489
00490 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "sex-cosmic-det") ;
00491 cpl_parameterlist_append(recipe->parameters, p) ;
00492
00493
00494
00495 p = cpl_parameter_new_value("omega.omega_standard_star.AstromDetThre",
00496 CPL_TYPE_DOUBLE,
00497 "Sextractor threshold to detect stars for astrometric correction.",
00498 "omega.Astrom",
00499 5.0) ;
00500
00501 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "astrom-thre") ;
00502 cpl_parameterlist_append(recipe->parameters, p) ;
00503
00504 p = cpl_parameter_new_enum("omega.omega_standard_star.PlateSolution",
00505 CPL_TYPE_INT,
00506 "Number of constant plate fits to do for the astrometry solution.",
00507 "omega.Astrom",
00508 4,2,4,6);
00509
00510 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "platesol");
00511 cpl_parameterlist_append(recipe->parameters, p);
00512
00513 p = cpl_parameter_new_value("omega.omega_standard_star.NumIterations",
00514 CPL_TYPE_INT,
00515 "Number of iterations for the plate solution fitting.",
00516 "omega.Astrom",
00517 3);
00518
00519 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "niter");
00520 cpl_parameterlist_append(recipe->parameters, p);
00521
00522 p = cpl_parameter_new_range("omega.omega_standard_star.SextractorFlagLimit",
00523 CPL_TYPE_INT,
00524 "Sextractor FLAG upper limit to preselect good sources for the "
00525 "astrometric correction computation.", "omega.Astrom",
00526 7, 0, 256);
00527 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"SextractorFlagLimit") ;
00528 cpl_parameterlist_append(recipe->parameters, p) ;
00529
00530 p = cpl_parameter_new_range("omega.omega_standard_star.SextractorClassStar",
00531 CPL_TYPE_DOUBLE,
00532 "Sextractor CLASS_STAR lower limit to preselect starlike objects "
00533 "for the astrometric correction computation.", "omega.Astrom",
00534 0.0, 0.0, 1.0);
00535 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,"SextractorClassStar") ;
00536 cpl_parameterlist_append(recipe->parameters, p) ;
00537
00538 p = cpl_parameter_new_value("omega.omega_standard_star.MaxWcsShift",
00539 CPL_TYPE_DOUBLE,
00540 "Maximum allowed x and y pixel shift of the image when refining "
00541 "the WCS solution.",
00542 "omega.Astrom",
00543 200.);
00544
00545 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "MaxWcsShift");
00546 cpl_parameterlist_append(recipe->parameters, p);
00547
00548
00549
00550
00551 p = cpl_parameter_new_value("omega.omega_standard_star.PhotomDetThre",
00552 CPL_TYPE_DOUBLE,
00553 "Sextractor threshold to detect stars for photometric correction.",
00554 "omega.Photom",
00555 5.0) ;
00556
00557 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "photom-thre") ;
00558 cpl_parameterlist_append(recipe->parameters, p) ;
00559
00560 p = cpl_parameter_new_value("omega.omega_standard_star.MatchPhotomRadius",
00561 CPL_TYPE_DOUBLE,
00562 "Radius within which to match photometric stds and stars",
00563 "omega.Photom",
00564 10.0) ;
00565
00566 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "radius") ;
00567 cpl_parameterlist_append(recipe->parameters, p) ;
00568
00569 p = cpl_parameter_new_value("omega.omega_standard_star.PhotomAperture",
00570 CPL_TYPE_DOUBLE,
00571 "Aperture in pixels for photometric measurements in Sextractor",
00572 "omega.Photom",
00573 30.0) ;
00574
00575 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI, "aperture") ;
00576 cpl_parameterlist_append(recipe->parameters, p) ;
00577
00578
00579 p = cpl_parameter_new_value("omega.omega_standard_star.Nstars",
00580 CPL_TYPE_INT,
00581 "Number of stars in image to use in "
00582 "pattern matching",
00583 "omega.Pattern",
00584 25);
00585
00586 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "nstars");
00587 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00588 cpl_parameterlist_append(recipe->parameters, p);
00589
00590
00591 p = cpl_parameter_new_value("omega.omega_standard_star.Npattern",
00592 CPL_TYPE_INT,
00593 "Number of catalogue sources to use in "
00594 "pattern matching",
00595 "omega.Pattern",
00596 15);
00597
00598 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "npattern");
00599 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00600 cpl_parameterlist_append(recipe->parameters, p);
00601
00602
00603 p = cpl_parameter_new_value("omega.omega_standard_star.Tolerance",
00604 CPL_TYPE_DOUBLE,
00605 "Max relative difference of angles and scales from their "
00606 "median value for match acceptance (tolerance)",
00607 "omega.Pattern",
00608 0.1);
00609
00610 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "tol");
00611 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00612 cpl_parameterlist_append(recipe->parameters, p);
00613
00614 p = cpl_parameter_new_value("omega.omega_standard_star.SearchPatternRadius",
00615 CPL_TYPE_DOUBLE,
00616 "Search radius for full PPM (pixels)",
00617 "omega.Pattern",
00618 10.0);
00619 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "pradius");
00620 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00621 cpl_parameterlist_append(recipe->parameters, p);
00622
00623 p = cpl_parameter_new_value("omega.omega_standard_star.MaxPatternRadius",
00624 CPL_TYPE_DOUBLE,
00625 "Maximum search radius for full PPM (pixels)",
00626 "omega.Pattern",
00627 40.0);
00628 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "maxpradius");
00629 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00630 cpl_parameterlist_append(recipe->parameters, p);
00631
00632
00633 return 0;
00634 }
00635
00636
00642
00643 static int omega_standard_star_exec(cpl_plugin * plugin)
00644 {
00645 cpl_recipe * recipe;
00646 int recipe_status;
00647
00648
00649 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00650 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
00651 cpl_func, __LINE__, cpl_error_get_where());
00652 return (int)cpl_error_get_code();
00653 }
00654
00655 if (plugin == NULL) {
00656 cpl_msg_error(cpl_func, "Null plugin");
00657 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00658 }
00659
00660
00661 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00662 cpl_msg_error(cpl_func, "Plugin is not a recipe");
00663 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
00664 }
00665
00666
00667 recipe = (cpl_recipe *)plugin;
00668
00669
00670 if (recipe->parameters == NULL) {
00671 cpl_msg_error(cpl_func, "Recipe invoked with NULL parameter list");
00672 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00673 }
00674 if (recipe->frames == NULL) {
00675 cpl_msg_error(cpl_func, "Recipe invoked with NULL frame set");
00676 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00677 }
00678
00679
00680 recipe_status = omega_standard_star(recipe->frames, recipe->parameters);
00681
00682
00683 if (cpl_dfs_update_product_header(recipe->frames)) {
00684 if (!recipe_status) recipe_status = (int)cpl_error_get_code();
00685 }
00686
00687 return recipe_status;
00688
00689 }
00690
00691
00697
00698 static int omega_standard_star_destroy(cpl_plugin * plugin)
00699 {
00700 cpl_recipe * recipe;
00701
00702 if (plugin == NULL) {
00703 cpl_msg_error(cpl_func, "Null plugin");
00704 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
00705 }
00706
00707
00708 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00709 cpl_msg_error(cpl_func, "Plugin is not a recipe");
00710 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
00711 }
00712
00713
00714 recipe = (cpl_recipe *)plugin;
00715
00716 cpl_parameterlist_delete(recipe->parameters) ;
00717
00718 return 0 ;
00719 }
00720
00721
00731
00732 static int omega_standard_star(cpl_frameset *set, cpl_parameterlist *pars)
00733 {
00734 int j,jst,jfn,isfirst;
00735 cpl_size nlab;
00736 int nraw = 0;
00737 int oscan1 = 0;
00738 double exptime = 0.0;
00739 double gain = 1.0;
00740
00741 char *sname = NULL;
00742 char *pname = NULL;
00743 char *zname = NULL;
00744 const char *stdname = "omega_std.fits";
00745 const char * maskname= NULL;
00746 omega_fits * stdfits_mask=NULL;
00747 cpl_image *image_simple_mask=NULL;
00748 cpl_frame *product_frame = NULL;
00749 cpl_frame *product_frame_mask=NULL ;
00750 cpl_frame *pframe = NULL;
00751 cpl_frame *zpframe = NULL;
00752 cpl_image *image = NULL;
00753 cpl_propertylist *plist,*xlist,*qclist,*alist;
00754 cpl_errorstate prestate = cpl_errorstate_get();
00755
00756
00757
00758 if (pars == NULL) {
00759 cpl_msg_error (cpl_func, "Parameters list not found");
00760 return -1;
00761 }
00762
00763 if (cpl_frameset_is_empty(set) == 1) {
00764 cpl_msg_error (cpl_func, "Frameset not found");
00765 return -1;
00766 }
00767
00768
00769 if(omega_std_retrieve_input_param(pars) != 0){
00770 cpl_msg_error(cpl_func,"Cannot retrieve input parameters. %s", cpl_error_get_message());
00771 return -1;
00772 }
00773
00774
00775 if (oc_dfs_set_groups(set)) {
00776 cpl_msg_error(cpl_func, "Cannot identify RAW and CALIB frames") ;
00777 return -1 ;
00778 }
00779
00780
00781 omega_std_init();
00782
00783
00784 if ((ps.labels = cpl_frameset_labelise(set,omega_compare_tags,
00785 &nlab)) == NULL) {
00786 cpl_msg_error(cpl_func,"Cannot labelise the input frameset");
00787 omega_std_tidy(0);
00788 return -1;
00789 }
00790
00791 if ((ps.stdlist = omega_frameset_subgroup(set,ps.labels,nlab,
00792 STD_RAW)) == NULL) {
00793 cpl_msg_error(cpl_func,"Cannot find standard stars in input frameset");
00794 omega_std_tidy(0);
00795 return -1;
00796 }
00797 nraw = cpl_frameset_count_tags (ps.stdlist, STD_RAW);
00798 cpl_msg_info (cpl_func,"There are %d %s frames in frame set",nraw, STD_RAW);
00799
00800
00801
00802 ps.mbiasfr = cpl_frameset_find_const(set, OMEGA_CALIB_BIAS);
00803 if (ps.mbiasfr == NULL) {
00804 cpl_msg_error(cpl_func,"Cannot find %s frame in frame set", OMEGA_CALIB_BIAS);
00805 omega_std_tidy(0);
00806 return -1;
00807 }
00808 cpl_msg_info(cpl_func,"Using %s %s",OMEGA_CALIB_BIAS, cpl_frame_get_filename(ps.mbiasfr));
00809
00810
00811 ps.mflatfr = cpl_frameset_find_const(set, OMEGA_CALIB_FLAT);
00812 if(ps.mflatfr == NULL) {
00813 cpl_msg_error(cpl_func,"Cannot find %s frame in frame set", OMEGA_CALIB_FLAT);
00814 omega_std_tidy(0);
00815 return -1;
00816 }
00817 cpl_msg_info(cpl_func,"Using %s %s", OMEGA_CALIB_FLAT, cpl_frame_get_filename(ps.mflatfr));
00818
00819
00820
00821 ps.reffr = cpl_frameset_find (set, OMEGA_CALIB_REFSTAR);
00822 if (ps.reffr == NULL) {
00823 cpl_msg_error(cpl_func,"Cannot find %s frame in frame set",OMEGA_CALIB_REFSTAR);
00824 omega_std_tidy(0);
00825 return -1;
00826 }
00827 cpl_msg_info(cpl_func,"Using %s %s", OMEGA_CALIB_REFSTAR, cpl_frame_get_filename(ps.reffr));
00828
00829
00830
00831 ps.monitfr = cpl_frameset_find(set, OMEGA_CALIB_MONIT);
00832 if(ps.monitfr == NULL) {
00833 cpl_msg_error(cpl_func,"Cannot find %s in frame set",OMEGA_CALIB_MONIT );
00834 omega_std_tidy(0);
00835 return -1;
00836 }
00837
00838
00839 ps.extfr = cpl_frameset_find (set,OMEGA_CALIB_EXTCUR);
00840 if(ps.extfr == NULL) {
00841 cpl_msg_error(cpl_func,"Cannot find %s in frame set", OMEGA_CALIB_EXTCUR);
00842 omega_std_tidy(0);
00843 return -1;
00844 }
00845
00846
00847 ps.usnoa2 = cpl_frameset_find (set, OMEGA_USNOA2);
00848 if (ps.usnoa2 == NULL) {
00849 cpl_msg_error(cpl_func,"Cannot find %s frame in frame set",OMEGA_USNOA2);
00850 omega_std_tidy(0);
00851 return -1;
00852 }
00853 else{
00854 cpl_msg_info(cpl_func,"Using %s %s", OMEGA_USNOA2, cpl_frame_get_filename(ps.usnoa2));
00855 }
00856
00857
00858 ps.bpmfr = cpl_frameset_find (set,OMEGA_CALIB_BPM);
00859 if(ps.bpmfr == NULL) {
00860 cpl_msg_error(cpl_func,"Cannot find %s in frame set", OMEGA_CALIB_BPM);
00861 omega_std_tidy(0);
00862 return -1;
00863 }
00864 cpl_msg_info(cpl_func,"Using %s %s",OMEGA_CALIB_BPM,cpl_frame_get_filename(ps.bpmfr));
00865
00866
00867 ps.illumfr = cpl_frameset_find(set, OMEGA_CALIB_ILLUM);
00868 if(ps.illumfr != NULL)
00869 cpl_msg_info(cpl_func,"Using %s %s",OMEGA_CALIB_ILLUM,cpl_frame_get_filename(ps.illumfr));
00870
00871
00872 ps.colfr = cpl_frameset_find(set,OMEGA_CALIB_COLTERMS);
00873 if(ps.colfr != NULL)
00874 cpl_msg_info(cpl_func,"Using %s %s", OMEGA_CALIB_COLTERMS, cpl_frame_get_filename(ps.colfr));
00875
00876
00877 ps.stdfr = cpl_frameset_get_first_const(ps.stdlist);
00878
00879
00880 omega_extensions(ps.stdfr,omega_std_config.extnum,&jst,&jfn);
00881 if(omega_std_config.extnum == 0){
00882 cpl_msg_error(cpl_func,"Unsupported extension request, %d",omega_std_config.extnum);
00883 omega_std_tidy(0);
00884 return -1;
00885 }
00886
00887
00888 for (j = jst; j <= jfn; j++) {
00889 isfirst = (j == jst);
00890 cpl_msg_indent_more();
00891 cpl_msg_info(cpl_func,".....Working on extension %d.....",j);
00892 cpl_msg_indent_less();
00893
00894 omega_std_config.nmatches = 0;
00895 omega_std_config.nstars = 0;
00896 omega_std_config.mratio = 0.0;
00897 omega_std_config.ZP = 0.0;
00898 omega_std_config.ZPerr = 0.0;
00899 omega_std_config.Extinction = 0.0;
00900 omega_std_config.Exterr = 0.0;
00901 omega_std_config.Seeing = 0.0;
00902 omega_std_config.Ellipticity = 0.0;
00903
00904
00905 if(ps.mbiasfr != NULL){
00906 oscan1 = omega_pfits_get_overscan(ps.mbiasfr, j);
00907 if(oscan1 != omega_std_config.oc) {
00908 cpl_msg_warning (cpl_func, "Overscan correction mode for Master Bias (oc = %d) differs from "
00909 "the one used here (oc = %d)", oscan1, omega_std_config.oc);
00910 }
00911 }
00912
00913
00914 if(omega_std_load_calib(j) != 0){
00915 cpl_msg_error(cpl_func,"Cannot load calibration frame(s)");
00916 omega_std_tidy(0);
00917 return -1;
00918 }
00919
00920
00921 if((ps.stdfits = omega_std_process(ps.stdlist,pars,j)) == NULL){
00922 cpl_msg_error(cpl_func, "Cannot reduce image extension");
00923 omega_std_tidy(0);
00924 return -1;
00925 }
00926
00927
00928 omega_std_tidy(1);
00929
00930
00931 if(isfirst){
00932 ps.sname = cpl_sprintf("%s_%s.fits", INSTRUME,STD_PROCATG);
00933 product_frame = omega_product_frame(ps.sname, STD_PROCATG, CPL_FRAME_TYPE_IMAGE);
00934 maskname=cpl_sprintf("%s_%s.fits", INSTRUME,"REDUCED_STD_MASK");
00935 product_frame_mask = omega_product_frame(maskname, "REDUCED_STD_MASK", CPL_FRAME_TYPE_IMAGE);
00936
00937 }
00938 cpl_msg_info(cpl_func,"Saving STD image");
00939 if((omega_save_fits(ps.stdfits,set,pars,NULL,CPL_BPP_IEEE_FLOAT,ps.sname,RECIPE,
00940 product_frame,NULL,isfirst)) == -1){
00941 cpl_msg_error(cpl_func,"Cannot save product");
00942 cpl_free(maskname);
00943 omega_std_tidy(0);
00944 return -1;
00945 }
00946
00947
00948
00949 stdfits_mask=omega_fits_duplicate(ps.stdfits);
00950
00951 image_simple_mask=cpl_image_new_from_mask(cpl_image_get_bpm(stdfits_mask->image));
00952 cpl_image_delete(stdfits_mask->image); stdfits_mask->image=NULL;
00953 stdfits_mask->image=image_simple_mask;
00954
00955 cpl_msg_info(cpl_func,"Saving STD MASK image");
00956 if((omega_save_fits(stdfits_mask,set,pars,NULL,CPL_BPP_8_UNSIGNED,maskname,RECIPE,
00957 product_frame_mask,NULL,isfirst)) == -1){
00958 cpl_msg_error(cpl_func,"Cannot save product");
00959 freefits(stdfits_mask);
00960 cpl_free(maskname);
00961 omega_std_tidy(0);
00962 return -1;
00963 }
00964 freefits(stdfits_mask);
00965
00966
00967
00968
00969 plist = omega_fits_get_phu(ps.stdfits);
00970 xlist = omega_fits_get_ehu(ps.stdfits);
00971
00972 alist = cpl_propertylist_new();
00973 cpl_propertylist_append_string(alist, "EXTNAME",
00974 cpl_propertylist_get_string(xlist, "EXTNAME"));
00975 cpl_propertylist_set_comment(alist,"EXTNAME", "Extension name");
00976
00977
00978 if(cpl_propertylist_has(xlist,"ESO QC STD PPM FAILURE")){
00979 cpl_propertylist_append_int(alist, "ESO QC STD PPM FAILURE",
00980 cpl_propertylist_get_int(xlist, "ESO QC STD PPM FAILURE"));
00981 cpl_propertylist_set_comment(alist, "ESO QC STD PPM FAILURE", "PPM failure if ZERO");
00982 }
00983
00984 omega_pfits_get_conad(xlist,&gain);
00985
00986
00987 cpl_propertylist_update_int(alist, "ESO DRS OVERSCAN METHOD", omega_std_config.oc );
00988 cpl_propertylist_set_comment(alist, "ESO DRS OVERSCAN METHOD", "overscan correction method");
00989
00990 exptime = omega_pfits_get_exptime(xlist);
00991 if(exptime <= 0.0)
00992 exptime = omega_pfits_get_exptime(plist);
00993
00994 image = cpl_image_duplicate(omega_fits_get_image(ps.stdfits));
00995
00996 if(exptime > 0.0)
00997 cpl_image_divide_scalar(image, exptime);
00998
00999 cpl_propertylist_save(plist, stdname, CPL_IO_CREATE);
01000 cpl_image_save(image,stdname,CPL_BPP_IEEE_DOUBLE,xlist,CPL_IO_EXTEND);
01001
01002 freeimage(image);
01003 freefits(ps.stdfits);
01004 ps.stdfits = NULL;
01005
01006
01007 if((ps.photbl = omega_photom_tbl(stdname, gain, ps.reffr,
01008 pars, &ps.extratbl)) == NULL){
01009 cpl_msg_warning(cpl_func,"Cannot create photometric table");
01010 cpl_msg_warning(cpl_func,"Creating an empty photometric table "
01011 "for this extension");
01012 ps.photbl = cpl_table_new(0);
01013
01014
01015 }
01016
01017
01018 if(isfirst){
01019 ps.pname = cpl_sprintf("%s_%s.fits", INSTRUME,PHOT_PROCATG);
01020 pframe = omega_product_frame(ps.pname, PHOT_PROCATG, CPL_FRAME_TYPE_IMAGE);
01021 }
01022 cpl_msg_info(cpl_func,"Saving Photometric table");
01023 if(omega_save_table(ps.photbl,set,pars,alist,NULL,ps.pname,RECIPE,
01024 pframe,NULL,isfirst) == -1){
01025 cpl_msg_error(cpl_func,"Cannot save photometric table");
01026 freeplist(alist);
01027 cpl_free(maskname); maskname=NULL;
01028 omega_std_tidy(0);
01029 return -1;
01030 }
01031
01032 prestate = cpl_errorstate_get();
01033
01034 if((ps.zptbl = omega_zeropoints(ps.photbl, ps.extratbl, ps.monitfr, ps.extfr,
01035 ps.colfr)) == NULL ){
01036 cpl_msg_warning(cpl_func,"Cannot create ZP table");
01037 cpl_msg_warning(cpl_func,"Creating an empty ZP table for this "
01038 "extension");
01039 ps.zptbl = cpl_table_new(0);
01040
01041
01042
01043 }
01044 cpl_errorstate_set(prestate);
01045
01046 freetable(ps.extratbl);
01047 freetable(ps.photbl);
01048
01049
01050 omega_std_config.ZP = cpl_table_get_double(ps.zptbl, "ZEROPOINT", 0, NULL);
01051 omega_std_config.ZPerr = cpl_table_get_double(ps.zptbl, "ZEROPOINT_ERR", 0, NULL);
01052 omega_std_config.Extinction = cpl_table_get_double(ps.zptbl, "EXTINCTION", 0, NULL);
01053 omega_std_config.Exterr = cpl_table_get_double(ps.zptbl, "EXTINCTION_ERR", 0, NULL);
01054 omega_std_config.nstars = cpl_table_get_int(ps.zptbl, "NSTARS", 0, NULL);
01055 omega_std_config.Seeing = cpl_table_get_double(ps.zptbl, "SEEING", 0, NULL);
01056 omega_std_config.Ellipticity = cpl_table_get_double(ps.zptbl, "ELLIPTICITY", 0, NULL);
01057
01058 qclist = cpl_propertylist_new();
01059 cpl_propertylist_update_double(qclist, "ESO QC ZEROPOINT", omega_std_config.ZP) ;
01060 cpl_propertylist_set_comment(qclist, "ESO QC ZEROPOINT", "zp with flux in ADU/sec");
01061 cpl_propertylist_update_double(qclist, "ESO QC ZEROPOINT ERR", omega_std_config.ZPerr) ;
01062 cpl_propertylist_set_comment(qclist, "ESO QC ZEROPOINT ERR", "zp error");
01063
01064 cpl_propertylist_update_double(qclist, "ESO QC ZEROPOINT_ELECTRON", omega_std_config.ZP+(2.5*log10(gain))) ;
01065 cpl_propertylist_set_comment(qclist, "ESO QC ZEROPOINT_ELECTRON", "zp with flux in e-/sec");
01066 cpl_propertylist_update_double(qclist, "ESO QC ZEROPOINT_ELECTRON ERR", omega_std_config.ZPerr) ;
01067 cpl_propertylist_set_comment(qclist, "ESO QC ZEROPOINT_ELECTRON ERR", "zp error");
01068
01069 cpl_propertylist_update_double(qclist, "ESO QC EXTINCTION", omega_std_config.Extinction) ;
01070 cpl_propertylist_set_comment(qclist, "ESO QC EXTINCTION", "calculated extinction");
01071 cpl_propertylist_update_double(qclist, "ESO QC EXTINCTION ERR", omega_std_config.Exterr) ;
01072 cpl_propertylist_set_comment(qclist, "ESO QC EXTINCTION ERR", "calculated extinction error");
01073 cpl_propertylist_update_int(qclist, "ESO QC STD MATCHES", omega_std_config.nmatches);
01074 cpl_propertylist_set_comment(qclist, "ESO QC STD MATCHES", "number matches between USNOA2 cat and stars");
01075 cpl_propertylist_update_double(qclist, "ESO QC STD RATIO MATCHES", omega_std_config.mratio);
01076 cpl_propertylist_set_comment(qclist, "ESO QC STD RATIO MATCHES", "ratio USNOA2 matches/detected stars");
01077 cpl_propertylist_update_double(qclist, "ESO QC STD SEEING", omega_std_config.Seeing);
01078 cpl_propertylist_set_comment(qclist, "ESO QC STD SEEING", "calculated seeing of standard field");
01079 cpl_propertylist_update_double(qclist, "ESO QC STD ELLIPTICITY", omega_std_config.Ellipticity);
01080 cpl_propertylist_set_comment(qclist, "ESO QC STD ELLIPTICITY", "calculated ellipticity of standard field");
01081 cpl_propertylist_update_int(qclist, "ESO QC STD NUMBER STARS", omega_std_config.nstars);
01082 cpl_propertylist_set_comment(qclist, "ESO QC STD NUMBER STARS", "number of std stars used for ZP");
01083
01084
01085 if(isfirst){
01086 ps.zname = cpl_sprintf("%s_%s.fits", INSTRUME,ZP_PROCATG);
01087 zpframe = omega_product_frame(ps.zname, ZP_PROCATG, CPL_FRAME_TYPE_IMAGE);
01088 }
01089 cpl_msg_info(cpl_func,"Saving ZP table");
01090 if((omega_save_table(ps.zptbl,set,pars,alist,qclist,ps.zname,RECIPE,
01091 zpframe,NULL,isfirst)) == -1){
01092 cpl_msg_error(cpl_func,"Cannot save photometric table");
01093 freeplist(qclist);
01094 freeplist(alist);
01095 cpl_free(maskname); maskname=NULL;
01096 omega_std_tidy(0);
01097 return -1;
01098 }
01099
01100 freetable(ps.zptbl);
01101 freeplist(qclist);
01102 freeplist(alist);
01103 }
01104
01105
01106 cpl_free(maskname); maskname=NULL;
01107 omega_std_tidy(0);
01108
01109 return 0;
01110
01111 }
01112
01124 omega_fits *omega_std_process(cpl_frameset *stdlist,cpl_parameterlist *pars, int ext)
01125 {
01126
01127 int i = 0;
01128 int nraw = 0;
01129 const char *smoothed = "omega_smoothed_std.fits";
01130 const char *smoothed_weight = "omega_smoothed_std_weight.fits";
01131 double xshift=0.,yshift=0.;
01132 cpl_image *trim=NULL, *mask_img=NULL, *image=NULL, *combmap=NULL;
01133 cpl_image *back = NULL;
01134 cpl_image *reduced = NULL;
01135 cpl_image *sumwght = NULL;
01136 cpl_mask *satu_map=NULL,*bpm_map=NULL;
01137 cpl_mask *satellite= NULL;
01138 cpl_mask *cosmic=NULL;
01139 cpl_propertylist *plist=NULL, *astrolist=NULL, *wcslist=NULL;
01140 cpl_frame *frame=NULL;
01141 omega_fits *stdfits = NULL;
01142 omega_fits **sfits = NULL;
01143
01144
01145 if(cpl_image_get_mean(ps.mflat) < 0.1){
01146 cpl_msg_error(cpl_func,"Master Flat image is NULL");
01147 return NULL;
01148 }
01149
01150 if(cpl_image_get_min(ps.mflat) <= DBL_EPSILON){
01151 cpl_msg_warning(cpl_func,"Some pixel values of the Master Flat are "
01152 "smaller or equal to %g.", DBL_EPSILON);
01153 cpl_msg_warning(cpl_func,"Thresholding image to a minimum of %g ",
01154 DBL_EPSILON);
01155 cpl_image_threshold(ps.mflat, DBL_EPSILON, DBL_MAX,
01156 DBL_EPSILON, DBL_MAX);
01157 }
01158
01159
01160 nraw = cpl_frameset_get_size(stdlist);
01161 sfits = omega_fits_load_list(stdlist,CPL_TYPE_FLOAT,ext);
01162
01163 for(i = 0; i < nraw; i++){
01164
01165 if((trim = omega_trim_oscan_correct(sfits[i], omega_std_config.oc)) == NULL){
01166 cpl_msg_error(cpl_func,"Unable to trim image %d",i);
01167 freelfits(sfits,nraw);
01168 return NULL;
01169 }
01170
01171
01172 omega_biascor(trim, ps.mbias);
01173
01174
01175 if(omega_flatcor(trim, ps.mflat, NULL) != 0){
01176 cpl_msg_error(cpl_func,"Error in flat correction");
01177 freeimage(trim);
01178 freelfits(sfits,nraw);
01179 return NULL;
01180 }
01181
01182
01183 satu_map = omega_saturated_map(trim, omega_std_config.oc, pars);
01184 bpm_map = cpl_mask_threshold_image_create(ps.bpm, 0.5, 1.5) ;
01185 if(satu_map != NULL){
01186
01187 cpl_mask_or(bpm_map, satu_map);
01188 freemask(satu_map);
01189 }
01190 mask_img = cpl_image_new_from_mask(bpm_map);
01191 cpl_image_save(mask_img,"bpmsatu.fits",CPL_BPP_16_SIGNED,NULL,CPL_IO_CREATE);
01192 freemask(bpm_map);
01193
01194
01195 back = omega_background(trim, pars);
01196
01197 if(back == NULL)
01198 cpl_msg_debug(cpl_func,"Unable to create background image");
01199
01200
01201 image = cpl_image_subtract_create(trim, back);
01202 cosmic = omega_cosmic_rays(image,ps.mflat,ps.illum,mask_img,pars);
01203
01204
01205 if(omega_std_config.bckg == 1){
01206 freeimage(trim);
01207 trim = cpl_image_duplicate(image);
01208 }
01209 freeimage(image);
01210 freeimage(back);
01211
01212
01213
01214 satellite = detsat(trim, pars);
01215
01216
01217
01218 combmap = create_weightframe(ps.mflat,mask_img,cosmic,satellite);
01219 freemask(satellite);
01220 freemask(cosmic);
01221 freeimage(mask_img);
01222
01223 if((ps.illum != NULL) && (combmap != NULL))
01224 cpl_image_divide(combmap, ps.illum);
01225
01226
01227 cpl_image_multiply(trim, combmap);
01228
01229 if(i == 0){
01230 reduced = cpl_image_duplicate(trim);
01231 sumwght = cpl_image_duplicate(combmap);
01232 }
01233 else{
01234 cpl_image_add(reduced, trim);
01235 cpl_image_add(sumwght, combmap);
01236 }
01237 freeimage(trim);
01238 freeimage(combmap);
01239
01240
01241
01242 }
01243
01244 freelfits(sfits,nraw);
01245
01246
01247 if(cpl_image_divide(reduced, sumwght) != CPL_ERROR_NONE){
01248 cpl_msg_error(cpl_func,"Cannot create weighted average of images. %s", cpl_error_get_message());
01249 freeimage(sumwght);
01250 return NULL;
01251 }
01252
01253
01254
01255 frame = cpl_frameset_get_first(stdlist);
01256 plist = cpl_propertylist_load(cpl_frame_get_filename(frame),0);
01257 astrolist = cpl_propertylist_load(cpl_frame_get_filename(frame),ext);
01258 omega_shift_refpix(frame, ext, astrolist);
01259
01260
01261
01262 image = omega_smooth_image(reduced, 1);
01263
01264
01265 cpl_propertylist_save(plist, smoothed, CPL_IO_CREATE);
01266 cpl_image_save(image, smoothed, BITPIX, astrolist, CPL_IO_EXTEND);
01267
01268
01269 cpl_propertylist_save(plist, smoothed_weight, CPL_IO_CREATE);
01270 cpl_image_save(sumwght, smoothed_weight, BITPIX, astrolist, CPL_IO_EXTEND);
01271
01272 freeimage(image);
01273 freeimage(sumwght);
01274
01275
01276 wcslist = omega_match_points(smoothed, smoothed_weight, ps.usnoa2, pars, ext,
01277 &omega_std_config.nmatches, &omega_std_config.mratio);
01278
01279 omega_get_wcsshift(astrolist, wcslist, &xshift, &yshift);
01280
01281
01282 if(wcslist == NULL || fabs(xshift)> omega_std_config.MaxWcsShift ||
01283 fabs(yshift)>omega_std_config.MaxWcsShift){
01284 cpl_msg_warning(cpl_func,"Unable to refine WCS for image");
01285 cpl_msg_warning(cpl_func,"Taking original WCS coordinates");
01286 wcslist = cpl_propertylist_duplicate(astrolist);
01287 cpl_propertylist_update_int (wcslist, "ESO QC STD PPM FAILURE", 0);
01288 cpl_propertylist_set_comment(wcslist, "ESO QC STD PPM FAILURE", "PPM failure if ZERO");
01289 xshift=0.;
01290 yshift=0.;
01291 }
01292 else{
01293 cpl_propertylist_update_int (wcslist, "ESO QC STD PPM FAILURE", 1);
01294 cpl_propertylist_set_comment(wcslist, "ESO QC STD PPM FAILURE", "PPM failure if ZERO");
01295 }
01296
01297 cpl_propertylist_update_double (astrolist, "ESO QC DELTAX SHIFT", xshift);
01298 cpl_propertylist_set_comment(astrolist, "ESO QC DELTAX SHIFT", "WCS shift in x");
01299 cpl_propertylist_update_double (astrolist, "ESO QC DELTAY SHIFT", yshift);
01300 cpl_propertylist_set_comment(astrolist, "ESO QC DELTAY SHIFT", "WCS shift in y");
01301
01302
01303 if(omega_pfits_update_header(astrolist, wcslist) != 0)
01304 cpl_msg_debug(cpl_func,"Cannot append WCS header to extension header");
01305
01306
01307
01308 stdfits = omega_fits_wrap(reduced,NULL,plist,astrolist);
01309
01310 freeplist(plist);
01311 freeplist(astrolist);
01312 freeplist(wcslist);
01313
01314 return stdfits;
01315 }
01316
01317
01318 int omega_std_retrieve_input_param(const cpl_parameterlist *pars)
01319 {
01320
01321 const cpl_parameter *par = NULL;
01322 cpl_errorstate prestate = cpl_errorstate_get();
01323
01324 par = cpl_parameterlist_find_const(pars, "omega.omega_standard_star.ExtensionNumber") ;
01325 omega_std_config.extnum = cpl_parameter_get_int(par) ;
01326 par = cpl_parameterlist_find_const(pars, "omega.omega_standard_star.OverscanMethod") ;
01327 omega_std_config.oc = cpl_parameter_get_int(par) ;
01328 par = cpl_parameterlist_find_const(pars, "omega.omega_standard_star.BackRestore");
01329 omega_std_config.bckg = cpl_parameter_get_bool(par) ;
01330 par = cpl_parameterlist_find_const(pars, "omega.omega_standard_star.PAF");
01331 omega_std_config.paf = cpl_parameter_get_bool(par) ;
01332 par = cpl_parameterlist_find_const(pars, "omega.omega_standard_star.MaxWcsShift") ;
01333 omega_std_config.MaxWcsShift = cpl_parameter_get_double(par) ;
01334
01335 if(!cpl_errorstate_is_equal(prestate)){
01336 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
01337 return -1;
01338 }
01339
01340 return 0;
01341 }
01342
01343 static int omega_std_load_calib(int ext)
01344 {
01345
01346
01347
01348 ps.mbias = cpl_image_load(cpl_frame_get_filename(ps.mbiasfr), CPL_TYPE_FLOAT, 0, ext);
01349 if(ps.mbias == NULL){
01350 cpl_msg_error(cpl_func,"Cannot load Master Bias. %s", cpl_error_get_message());
01351 return -1;
01352 }
01353
01354 ps.mflat = cpl_image_load(cpl_frame_get_filename(ps.mflatfr),CPL_TYPE_FLOAT,0,ext);
01355 if (ps.mflat == NULL){
01356 cpl_msg_error(cpl_func,"Cannot load Master Flat. %s",cpl_error_get_message());
01357 return -1;
01358 }
01359
01360
01361 ps.bpm = cpl_image_load(cpl_frame_get_filename(ps.bpmfr), CPL_TYPE_INT, 0, ext);
01362 if(ps.bpm == NULL){
01363 cpl_msg_error(cpl_func, "Cannot load BPM. %s", cpl_error_get_message());
01364 return -1;
01365 }
01366
01367
01368 if(ps.illumfr != NULL)
01369 ps.illum = cpl_image_load(cpl_frame_get_filename(ps.illumfr),CPL_TYPE_FLOAT,0,ext);
01370
01371 return 0;
01372 }
01373
01374
01375 static void omega_std_init(void) {
01376 ps.stdlist = NULL;
01377 ps.labels = NULL;
01378 ps.bpmfr = NULL;
01379 ps.extfr = NULL;
01380 ps.monitfr = NULL;
01381 ps.stdfr = NULL;
01382 ps.usnoa2 = NULL;
01383 ps.reffr = NULL;
01384 ps.illumfr = NULL;
01385 ps.mbiasfr = NULL;
01386 ps.mflatfr = NULL;
01387 ps.mbias = NULL;
01388 ps.mflat = NULL;
01389 ps.colfr = NULL;
01390 ps.stdfits = NULL;
01391 ps.zptbl = NULL;
01392 ps.photbl = NULL;
01393 ps.sname = NULL;
01394 ps.pname = NULL;
01395 ps.zname = NULL;
01396 }
01397
01398
01399 static void omega_std_tidy(int level) {
01400 freeimage(ps.mbias);
01401 freeimage(ps.bpm);
01402 freeimage(ps.illum);
01403 freeimage(ps.mflat);
01404 if(level == 1)
01405 return;
01406
01407 freeframeset(ps.stdlist);
01408 freefits(ps.stdfits);
01409 freetable(ps.extratbl);
01410 freetable(ps.zptbl);
01411 freetable(ps.photbl);
01412 freespace(ps.labels);
01413 freespace(ps.sname);
01414 freespace(ps.pname);
01415 freespace(ps.zname);
01416 }
01417