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 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033
00034 #include <stdio.h>
00035 #include <math.h>
00036 #include <string.h>
00037 #include <cpl.h>
00038
00039 #include "vircam_utils.h"
00040 #include "vircam_mask.h"
00041 #include "vircam_pfits.h"
00042 #include "vircam_dfs.h"
00043 #include "vircam_mods.h"
00044 #include "vircam_fits.h"
00045 #include "vircam_tfits.h"
00046 #include "vircam_jmp_utils.h"
00047
00048
00049
00050 static int vircam_standard_process_create(cpl_plugin *);
00051 static int vircam_standard_process_exec(cpl_plugin *);
00052 static int vircam_standard_process_destroy(cpl_plugin *);
00053 static int vircam_standard_process(cpl_parameterlist *,cpl_frameset *);
00054 static cpl_propertylist *vircam_standard_process_dummyqc(int type);
00055
00056
00057 static char vircam_standard_process_description[] =
00058 "vircam_standard_process -- VIRCAM standard field processing recipe.\n\n"
00059 "Process a complete pawprint for standard fields in VIRCAM data.\n"
00060 "Remove instrumental signature, interleave microstep sequences (if done),\n"
00061 "combine jitters, photometrically and astrometrically calibrate the pawprint\n"
00062 "image. Photometric calibration can be done with 2mass and 1 other source\n\n"
00063 "The program accepts the following files in the SOF:\n\n"
00064 " Tag Description\n"
00065 " -----------------------------------------------------------------------\n"
00066 " %-21s A list of raw science images\n"
00067 " %-21s A master dark frame\n"
00068 " %-21s A master twilight flat frame\n"
00069 " %-21s A channel table\n"
00070 " %-21s A photometric calibration table\n"
00071 " %-21s A readnoise/gain file\n"
00072 " %-21s A master confidence map or\n"
00073 " %-21s A master bad pixel mask\n"
00074 " %-21s A master 2mass catalogue index\n"
00075 " %-21s A second reference catalogue index\n"
00076 "All of the above are required\n"
00077 "\n";
00078
00215
00216
00217
00225
00226
00227 int cpl_plugin_get_info(cpl_pluginlist *list) {
00228 cpl_recipe *recipe = cpl_calloc(1,sizeof(*recipe));
00229 cpl_plugin *plugin = &recipe->interface;
00230 char alldesc[SZ_ALLDESC];
00231 (void)snprintf(alldesc,SZ_ALLDESC,vircam_standard_process_description,
00232 VIRCAM_STD_OBJECT_RAW,VIRCAM_CAL_DARK,
00233 VIRCAM_CAL_TWILIGHT_FLAT,VIRCAM_CAL_CHANTAB,
00234 VIRCAM_CAL_PHOTTAB,VIRCAM_CAL_READGAINFILE,VIRCAM_CAL_CONF,
00235 VIRCAM_CAL_BPM,VIRCAM_CAL_2MASS,VIRCAM_CAL_REFCAT);
00236
00237 cpl_plugin_init(plugin,
00238 CPL_PLUGIN_API,
00239 VIRCAM_BINARY_VERSION,
00240 CPL_PLUGIN_TYPE_RECIPE,
00241 "vircam_standard_process",
00242 "VIRCAM standard field processing recipe",
00243 alldesc,
00244 "Jim Lewis",
00245 "jrl@ast.cam.ac.uk",
00246 vircam_get_license(),
00247 vircam_standard_process_create,
00248 vircam_standard_process_exec,
00249 vircam_standard_process_destroy);
00250
00251 cpl_pluginlist_append(list,plugin);
00252
00253 return(0);
00254 }
00255
00256
00265
00266
00267 static int vircam_standard_process_create(cpl_plugin *plugin) {
00268 cpl_recipe *recipe;
00269 cpl_parameter *p;
00270
00271
00272
00273 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00274 recipe = (cpl_recipe *)plugin;
00275 else
00276 return(-1);
00277
00278
00279
00280 recipe->parameters = cpl_parameterlist_new();
00281
00282
00283
00284 p = cpl_parameter_new_value("vircam.vircam_standard_process.ipix",
00285 CPL_TYPE_INT,
00286 "Minimum pixel area for each detected object",
00287 "vircam.vircam_standard_process",5);
00288 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"ipix");
00289 cpl_parameterlist_append(recipe->parameters,p);
00290
00291
00292
00293 p = cpl_parameter_new_value("vircam.vircam_standard_process.thresh",
00294 CPL_TYPE_DOUBLE,
00295 "Detection threshold in sigma above sky",
00296 "vircam.vircam_standard_process",2.0);
00297 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"thr");
00298 cpl_parameterlist_append(recipe->parameters,p);
00299
00300
00301
00302 p = cpl_parameter_new_value("vircam.vircam_standard_process.icrowd",
00303 CPL_TYPE_BOOL,"Use deblending?",
00304 "vircam.vircam_standard_process",0);
00305 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"icrowd");
00306 cpl_parameterlist_append(recipe->parameters,p);
00307
00308
00309
00310 p = cpl_parameter_new_value("vircam.vircam_standard_process.rcore",
00311 CPL_TYPE_DOUBLE,"Value of Rcore in pixels",
00312 "vircam.vircam_standard_process",4.0);
00313 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"rcore");
00314 cpl_parameterlist_append(recipe->parameters,p);
00315
00316
00317
00318 p = cpl_parameter_new_value("vircam.vircam_standard_process.nbsize",
00319 CPL_TYPE_INT,"Background smoothing box size",
00320 "vircam.vircam_standard_process",64);
00321 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"nb");
00322 cpl_parameterlist_append(recipe->parameters,p);
00323
00324
00325
00326 p = cpl_parameter_new_value("vircam.vircam_standard_process.savecat",
00327 CPL_TYPE_BOOL,"Save catalogue?",
00328 "vircam.vircam_standard_process",1);
00329 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"savecat");
00330 cpl_parameterlist_append(recipe->parameters,p);
00331
00332
00333
00334
00335 p = cpl_parameter_new_value("vircam.vircam_standard_process.destripe",
00336 CPL_TYPE_BOOL,"Destripe images?",
00337 "vircam.vircam_standard_process",1);
00338 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"destripe");
00339 cpl_parameterlist_append(recipe->parameters,p);
00340
00341
00342
00343 p = cpl_parameter_new_value("vircam.vircam_standard_process.skycor",
00344 CPL_TYPE_BOOL,"Sky correct images?",
00345 "vircam.vircam_standard_process",1);
00346 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"skycor");
00347 cpl_parameterlist_append(recipe->parameters,p);
00348
00349
00350
00351 p = cpl_parameter_new_range("vircam.vircam_standard_process.extenum",
00352 CPL_TYPE_INT,
00353 "Extension number to be done, 0 == all",
00354 "vircam.vircam_standard_process",
00355 1,0,16);
00356 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"ext");
00357 cpl_parameterlist_append(recipe->parameters,p);
00358
00359
00360
00361 return(0);
00362 }
00363
00364
00365
00371
00372
00373 static int vircam_standard_process_exec(cpl_plugin *plugin) {
00374 cpl_recipe *recipe;
00375
00376
00377
00378 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00379 recipe = (cpl_recipe *)plugin;
00380 else
00381 return(-1);
00382
00383 return(vircam_standard_process(recipe->parameters,recipe->frames));
00384 }
00385
00386
00392
00393
00394 static int vircam_standard_process_destroy(cpl_plugin *plugin) {
00395 cpl_recipe *recipe ;
00396
00397
00398
00399 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00400 recipe = (cpl_recipe *)plugin;
00401 else
00402 return(-1);
00403
00404 cpl_parameterlist_delete(recipe->parameters);
00405 return(0);
00406 }
00407
00408
00415
00416
00417 static int vircam_standard_process(cpl_parameterlist *parlist,
00418 cpl_frameset *framelist) {
00419 const char *fctid="vircam_standard_process";
00420 cpl_parameter *p;
00421 int nlab,jst,jfn,status,j,i,retval,nusteps,isconf,live,ndit;
00422 float readnoise,gain,gaincor_fac;
00423 vir_fits *ff;
00424 cpl_propertylist *ehu,*pp;
00425 cpl_frame *catindex;
00426
00427
00428
00429 if (framelist == NULL || cpl_frameset_get_size(framelist) <= 0) {
00430 cpl_msg_error(fctid,"Input framelist NULL or has no input data\n");
00431 return(-1);
00432 }
00433
00434
00435
00436 vircam_jmp_init();
00437 (void)strncpy(vircam_recipename,fctid,VIRCAM_PATHSZ);
00438 (void)snprintf(vircam_recipepaf,VIRCAM_PATHSZ,"VIRCAM/%s",fctid);
00439 recflag = RECSTD;
00440
00441
00442
00443 p = cpl_parameterlist_find(parlist,
00444 "vircam.vircam_standard_process.ipix");
00445 vircam_jmp_config.ipix = cpl_parameter_get_int(p);
00446 p = cpl_parameterlist_find(parlist,
00447 "vircam.vircam_standard_process.thresh");
00448 vircam_jmp_config.threshold = (float)cpl_parameter_get_double(p);
00449 p = cpl_parameterlist_find(parlist,
00450 "vircam.vircam_standard_process.icrowd");
00451 vircam_jmp_config.icrowd = cpl_parameter_get_bool(p);
00452 p = cpl_parameterlist_find(parlist,
00453 "vircam.vircam_standard_process.rcore");
00454 vircam_jmp_config.rcore = (float)cpl_parameter_get_double(p);
00455 p = cpl_parameterlist_find(parlist,
00456 "vircam.vircam_standard_process.nbsize");
00457 vircam_jmp_config.nbsize = cpl_parameter_get_int(p);
00458 p = cpl_parameterlist_find(parlist,
00459 "vircam.vircam_standard_process.savecat");
00460 vircam_jmp_config.savecat = cpl_parameter_get_bool(p);
00461 p = cpl_parameterlist_find(parlist,
00462 "vircam.vircam_standard_process.destripe");
00463 vircam_jmp_config.destripe = cpl_parameter_get_bool(p);
00464 p = cpl_parameterlist_find(parlist,
00465 "vircam.vircam_standard_process.skycor");
00466 vircam_jmp_config.skycor = cpl_parameter_get_bool(p);
00467 p = cpl_parameterlist_find(parlist,
00468 "vircam.vircam_standard_process.extenum");
00469 vircam_jmp_config.extenum = cpl_parameter_get_int(p);
00470
00471
00472
00473 if (vircam_dfs_set_groups(framelist) != VIR_OK) {
00474 cpl_msg_error(fctid,"Cannot identify RAW and CALIB frames");
00475 vircam_jmp_tidy(0);
00476 return(-1);
00477 }
00478
00479
00480
00481 if ((ps.labels = cpl_frameset_labelise(framelist,vircam_compare_tags,
00482 &nlab)) == NULL) {
00483 cpl_msg_error(fctid,"Cannot labelise the input frames");
00484 vircam_jmp_tidy(0);
00485 return(-1);
00486 }
00487
00488
00489
00490 if ((ps.science_frames =
00491 vircam_frameset_subgroup(framelist,ps.labels,nlab,
00492 VIRCAM_STD_OBJECT_RAW)) == NULL) {
00493 cpl_msg_error(fctid,"No science images to process!");
00494 vircam_jmp_tidy(0);
00495 return(-1);
00496 }
00497
00498
00499
00500 if ((ps.master_dark =
00501 vircam_frameset_subgroup_1(framelist,ps.labels,nlab,
00502 VIRCAM_CAL_DARK)) == NULL) {
00503 cpl_msg_error(fctid,"No master dark found");
00504 vircam_jmp_tidy(0);
00505 return(-1);
00506 }
00507
00508
00509
00510 if ((ps.master_twilight_flat =
00511 vircam_frameset_subgroup_1(framelist,ps.labels,nlab,
00512 VIRCAM_CAL_TWILIGHT_FLAT)) == NULL) {
00513 cpl_msg_error(fctid,"No master twilight flat found");
00514 vircam_jmp_tidy(0);
00515 return(-1);
00516 }
00517
00518
00519
00520 status = VIR_OK;
00521 if (vircam_gaincor_calc(ps.master_twilight_flat,&i,&(ps.gaincors),
00522 &status) != VIR_OK) {
00523 cpl_msg_error(fctid,"Error calculating gain corrections");
00524 vircam_jmp_tidy(0);
00525 return(-1);
00526 }
00527
00528
00529
00530 if ((ps.readgain_file =
00531 vircam_frameset_subgroup_1(framelist,ps.labels,nlab,
00532 VIRCAM_CAL_READGAINFILE)) == NULL) {
00533 cpl_msg_error(fctid,"No master readnoise/gain file found");
00534 vircam_jmp_tidy(0);
00535 return(-1);
00536 }
00537
00538
00539
00540
00541
00542 isconf = 1;
00543 if ((ps.master_conf =
00544 vircam_frameset_subgroup_1(framelist,ps.labels,nlab,
00545 VIRCAM_CAL_CONF)) == NULL) {
00546 isconf = 0;
00547 if ((ps.master_conf =
00548 vircam_frameset_subgroup_1(framelist,ps.labels,nlab,
00549 VIRCAM_CAL_BPM)) == NULL) {
00550 cpl_msg_error(fctid,"No master confidence map found");
00551 vircam_jmp_tidy(0);
00552 return(-1);
00553 }
00554 }
00555 ps.mask = vircam_mask_define(framelist,ps.labels,nlab);
00556
00557
00558
00559 if ((ps.chantab = vircam_frameset_subgroup_1(framelist,ps.labels,nlab,
00560 VIRCAM_CAL_CHANTAB)) == NULL) {
00561 cpl_msg_error(fctid,"No channel table found");
00562 vircam_jmp_tidy(0);
00563 return(-1);
00564 }
00565
00566
00567
00568 if ((ps.phottab = vircam_frameset_subgroup_1(framelist,ps.labels,nlab,
00569 VIRCAM_CAL_PHOTTAB)) == NULL) {
00570 cpl_msg_error(fctid,"No photometric table found");
00571 vircam_jmp_tidy(0);
00572 return(-1);
00573 }
00574 if ((ps.tphottab = cpl_table_load(cpl_frame_get_filename(ps.phottab),1,0)) == NULL) {
00575 cpl_msg_error(fctid,"Unable to load photometric table");
00576 vircam_jmp_tidy(0);
00577 return(-1);
00578 }
00579
00580
00581
00582 if ((catindex = vircam_frameset_subgroup_1(framelist,ps.labels,nlab,
00583 VIRCAM_CAL_2MASS)) == NULL) {
00584 cpl_msg_info(fctid,"No 2MASS index found -- cannot continue");
00585 vircam_jmp_tidy(0);
00586 return(-1);
00587 }
00588
00589
00590
00591 if (vircam_catpars(catindex,&(ps.catpath),&(ps.catname)) == VIR_FATAL) {
00592 vircam_jmp_tidy(0);
00593 cpl_frame_delete(catindex);
00594 return(-1);
00595 }
00596 cpl_frame_delete(catindex);
00597
00598
00599
00600 if ((catindex = vircam_frameset_subgroup_1(framelist,ps.labels,nlab,
00601 VIRCAM_CAL_2MASS)) != NULL) {
00602
00603
00604
00605 if (vircam_catpars(catindex,&(ps.catpath2),&(ps.catname2)) == VIR_FATAL) {
00606 vircam_jmp_tidy(0);
00607 cpl_frame_delete(catindex);
00608 return(-1);
00609 }
00610 cpl_frame_delete(catindex);
00611 }
00612
00613
00614
00615 pp = cpl_propertylist_load(cpl_frame_get_filename(cpl_frameset_get_frame(ps.science_frames,0)),0);
00616 if (vircam_pfits_get_ndit(pp,&ndit) != VIR_OK) {
00617 cpl_msg_error(fctid,"No value for NDIT available");
00618 freepropertylist(pp);
00619 vircam_jmp_tidy(0);
00620 return(-1);
00621 }
00622 cpl_propertylist_delete(pp);
00623
00624
00625
00626
00627
00628 vircam_exten_range(vircam_jmp_config.extenum,
00629 (const cpl_frame *)cpl_frameset_get_frame(ps.science_frames,0),
00630 &jst,&jfn);
00631 if (jst == -1 || jfn == -1) {
00632 cpl_msg_error(fctid,"Unable to continue");
00633 vircam_jmp_tidy(0);
00634 return(-1);
00635 }
00636
00637
00638
00639 status = VIR_OK;
00640 for (j = jst; j <= jfn; j++) {
00641 isfirst = (j == jst);
00642 gaincor_fac = (ps.gaincors)[j-1];
00643
00644
00645
00646
00647 ps.fdark = vircam_fits_load(ps.master_dark,CPL_TYPE_FLOAT,j);
00648 if (ps.fdark == NULL) {
00649 cpl_msg_error(fctid,"Error loading master dark %s[%d]\n%s",
00650 cpl_frame_get_filename(ps.master_dark),j,
00651 cpl_error_get_message());
00652 vircam_jmp_tidy(0);
00653 return(-1);
00654 }
00655 ps.fflat = vircam_fits_load(ps.master_twilight_flat,CPL_TYPE_FLOAT,j);
00656 if (ps.fflat == NULL) {
00657 cpl_msg_error(fctid,"Error loading master flat %s[%d]\n%s",
00658 cpl_frame_get_filename(ps.master_twilight_flat),j,
00659 cpl_error_get_message());
00660 vircam_jmp_tidy(0);
00661 return(-1);
00662 }
00663 ps.fconf = vircam_fits_load(ps.master_conf,CPL_TYPE_INT,j);
00664 if (ps.fconf == NULL) {
00665 cpl_msg_error(fctid,"Error loading master conf %s[%d]\n%s",
00666 cpl_frame_get_filename(ps.master_conf),j,
00667 cpl_error_get_message());
00668 vircam_jmp_tidy(0);
00669 return(-1);
00670 }
00671 if (! isconf)
00672 vircam_jmp_bpm2conf();
00673 if (vircam_mask_load(ps.mask,j,
00674 cpl_image_get_size_x(vircam_fits_get_image(ps.fconf)),
00675 cpl_image_get_size_y(vircam_fits_get_image(ps.fconf))) != VIR_OK) {
00676 cpl_msg_error(fctid,"Error loading mask from master conf %s[%d]\n%s",
00677 cpl_frame_get_filename(ps.master_conf),j,
00678 cpl_error_get_message());
00679 vircam_jmp_tidy(0);
00680 return(-1);
00681 }
00682 ps.fchantab = vircam_tfits_load(ps.chantab,j);
00683 if (ps.fchantab == NULL) {
00684 cpl_msg_error(fctid,"Error loading channel table %s[%d]\n%s",
00685 cpl_frame_get_filename(ps.chantab),j,
00686 cpl_error_get_message());
00687 vircam_jmp_tidy(0);
00688 return(-1);
00689 }
00690
00691
00692
00693 ps.nscience = cpl_frameset_get_size(ps.science_frames);
00694 ps.sci_fits = vircam_fits_load_list(ps.science_frames,CPL_TYPE_FLOAT,j);
00695 if (ps.sci_fits == NULL) {
00696 cpl_msg_error(fctid,"Error loading science frames extension %d: %s",
00697 j,cpl_error_get_message());
00698 vircam_jmp_tidy(0);
00699 return(-1);
00700 }
00701
00702
00703
00704
00705 for (i = 0; i < ps.nscience; i++) {
00706 ff = ps.sci_fits[i];
00707 vircam_pfits_get_detlive(vircam_fits_get_ehu(ff),&live);
00708 if (! live)
00709 vircam_fits_set_error(ff,VIR_FATAL);
00710 }
00711
00712
00713
00714 vircam_jmp_get_readnoise_gain(j,&readnoise,&gain);
00715
00716
00717
00718 cpl_msg_info(fctid,"Doing stage1 corrections on %s",
00719 vircam_fits_get_extname(ps.sci_fits[0]));
00720 for (i = 0; i < ps.nscience; i++) {
00721 ff = ps.sci_fits[i];
00722 cpl_propertylist_update_float(vircam_fits_get_ehu(ff),"READNOIS",
00723 readnoise);
00724 cpl_propertylist_set_comment(vircam_fits_get_ehu(ff),"READNOIS",
00725 "[e-] Readnoise used in processing");
00726 cpl_propertylist_update_float(vircam_fits_get_ehu(ff),"GAIN",gain);
00727 cpl_propertylist_set_comment(vircam_fits_get_ehu(ff),"GAIN",
00728 "[e-/adu] Gain used in processing");
00729 if (vircam_fits_get_status(ff) == VIR_FATAL) {
00730 cpl_msg_info(fctid,"Detector is flagged dead in %s",
00731 vircam_fits_get_fullname(ff));
00732 continue;
00733 }
00734 status = VIR_OK;
00735 (void)vircam_darkcor(ff,ps.fdark,1.0,&status);
00736 (void)vircam_lincor(ff,ps.fchantab,1,ndit,&status);
00737 (void)vircam_flatcor(ff,ps.fflat,&status);
00738 (void)vircam_gaincor(ff,gaincor_fac,&status);
00739 if (vircam_jmp_config.destripe)
00740 (void)vircam_destripe(ff,ps.mask,&status);
00741 vircam_fits_set_error(ff,status);
00742 }
00743
00744
00745
00746 if (vircam_jmp_config.skycor) {
00747 cpl_msg_info(fctid,"Doing sky correction");
00748 vircam_jmp_skycor();
00749 }
00750
00751
00752
00753 cpl_msg_info(fctid,"Doing illumination correction");
00754 (void)strcpy(current_cat,ps.catname);
00755 (void)strcpy(current_catpath,ps.catpath);
00756 vircam_jmp_illum();
00757
00758
00759
00760 cpl_msg_info(fctid,"Saving simple images");
00761 vircam_jmp_save_simple(framelist,parlist);
00762 vircam_mask_clear(ps.mask);
00763
00764
00765
00766 cpl_msg_info(fctid,"Saving illumination correction table");
00767 dummyqc = vircam_standard_process_dummyqc(3);
00768 vircam_jmp_save_illum(framelist,parlist);
00769 freepropertylist(dummyqc);
00770
00771
00772
00773
00774
00775 retval = vircam_pfits_get_nusteps(vircam_fits_get_phu(ps.sci_fits[0]),
00776 &nusteps);
00777 if (retval != VIR_OK) {
00778 cpl_msg_warning(fctid,"Unable to get nusteps from header.\nAssuming no microstepping");
00779 nusteps = 1;
00780 }
00781
00782
00783
00784
00785 ps.ndith = 0;
00786 if (nusteps == 1) {
00787 cpl_msg_info(fctid,"No interleaving will be done");
00788 ps.dith_input = cpl_malloc(ps.nscience*sizeof(vir_fits *));
00789 ps.dithc_input = cpl_malloc(sizeof(vir_fits *));
00790 for (i = 0; i < ps.nscience; i++) {
00791 if (vircam_fits_get_status(ps.sci_fits[i]) == VIR_OK)
00792 ps.dith_input[ps.ndith++] = ps.sci_fits[i];
00793 }
00794 ps.dithc_input[0] = ps.fconf;
00795 ps.ndithc = 1;
00796 interlv = 0;
00797
00798
00799
00800
00801
00802 } else {
00803 cpl_msg_info(fctid,"Interleaving");
00804 vircam_jmp_interleave();
00805 cpl_msg_info(fctid,"Saving superframe images");
00806 vircam_jmp_save_super(framelist,parlist);
00807 interlv = 1;
00808 }
00809
00810
00811
00812 cpl_msg_info(fctid,"Working out jitter offsets");
00813 vircam_jmp_dither_offsets();
00814 cpl_msg_info(fctid,"Stacking jittered frame");
00815 vircam_jmp_dither_images();
00816
00817
00818
00819 cpl_msg_info(fctid,"Doing object extraction");
00820 vircam_jmp_catalogue();
00821
00822
00823
00824 cpl_msg_info(fctid,"Matching objects with 2mass standards");
00825 vircam_jmp_matched_stds();
00826
00827
00828
00829 cpl_msg_info(fctid,"Fitting a WCS");
00830 vircam_jmp_wcsfit();
00831
00832
00833
00834 cpl_msg_info(fctid,"Doing 2mass photometric zeropoint calculation");
00835 vircam_jmp_photcal();
00836 if (vircam_fits_get_status(ps.stack_frame) == VIR_OK) {
00837 ehu = vircam_fits_get_ehu(ps.stack_frame);
00838 cpl_propertylist_update_float(ehu,"ESO QC ZPT_2MASS",
00839 cpl_propertylist_get_float(ehu,"ESO QC MAGZPT"));
00840 cpl_propertylist_set_comment(ehu,"ESO QC ZPT_2MASS",
00841 cpl_propertylist_get_comment(ehu,"ESO QC MAGZPT"));
00842 }
00843
00844
00845
00846
00847 if (ps.catpath2 != NULL) {
00848 freetable(ps.matchstds);
00849 (void)strcpy(current_cat,ps.catname2);
00850 (void)strcpy(current_catpath,ps.catpath2);
00851 cpl_msg_info(fctid,"Matching objects with %s standards",
00852 ps.catname2);
00853 vircam_jmp_matched_stds();
00854 cpl_msg_info(fctid,"Doing %s photometric zeropoint calculation",
00855 ps.catname2);
00856 vircam_jmp_photcal();
00857 if (vircam_fits_get_status(ps.stack_frame) == VIR_OK) {
00858 ehu = vircam_fits_get_ehu(ps.stack_frame);
00859 cpl_propertylist_update_float(ehu,"ESO QC ZPT_STDS",
00860 cpl_propertylist_get_float(ehu,"ESO QC MAGZPT"));
00861 cpl_propertylist_set_comment(ehu,"ESO QC ZPT_STDS",
00862 cpl_propertylist_get_comment(ehu,"ESO QC MAGZPT"));
00863 cpl_propertylist_update_string(ehu,"ESO QC ZPT_STDS_CAT",
00864 ps.catname2);
00865 cpl_propertylist_set_comment(ehu,"ESO QC ZPT_STDS_CAT",
00866 "Catalogue used in zeropoint calc");
00867 }
00868 }
00869
00870
00871
00872 cpl_msg_info(fctid,"Saving stacked images");
00873 dummyqc = vircam_standard_process_dummyqc(1);
00874 vircam_jmp_save_stack(framelist,parlist);
00875 freepropertylist(dummyqc);
00876 if (vircam_jmp_config.savecat) {
00877 cpl_msg_info(fctid,"Saving stacked image catalogues");
00878 dummyqc = vircam_standard_process_dummyqc(2);
00879 vircam_jmp_save_catalogue(framelist,parlist);
00880 freepropertylist(dummyqc);
00881 }
00882
00883
00884
00885 vircam_jmp_tidy(1);
00886 }
00887
00888
00889
00890 vircam_jmp_tidy(0);
00891 return(0);
00892 }
00893
00894 static cpl_propertylist *vircam_standard_process_dummyqc(int type) {
00895 cpl_propertylist *p;
00896
00897
00898
00899 p = cpl_propertylist_new();
00900
00901
00902
00903 switch (type) {
00904
00905
00906
00907 case 1:
00908 cpl_propertylist_update_double(p,"ESO QC WCS_DCRVAL1",0.0);
00909 cpl_propertylist_set_comment(p,"ESO QC WCS_DCRVAL1",
00910 "[deg] change in crval1");
00911 cpl_propertylist_update_double(p,"ESO QC WCS_DCRVAL2",0.0);
00912 cpl_propertylist_set_comment(p,"ESO QC WCS_DCRVAL2",
00913 "[deg] change in crval2");
00914 cpl_propertylist_update_double(p,"ESO QC WCS_DTHETA",0.0);
00915 cpl_propertylist_set_comment(p,"ESO QC WCS_DTHETA",
00916 "[deg] change in rotation");
00917 cpl_propertylist_update_double(p,"ESO QC WCS_SCALE",0.0);
00918 cpl_propertylist_set_comment(p,"ESO QC WCS_SCALE",
00919 "[arcsec] mean plate scale");
00920 cpl_propertylist_update_double(p,"ESO QC WCS_SHEAR",0.0);
00921 cpl_propertylist_set_comment(p,"ESO QC WCS_SHEAR",
00922 "[deg] abs(xrot) - abs(yrot)");
00923 cpl_propertylist_update_double(p,"ESO QC WCS_RMS",0.0);
00924 cpl_propertylist_set_comment(p,"ESO QC WCS_RMS",
00925 "[arcsec] Average error in WCS fit");
00926 cpl_propertylist_update_float(p,"ESO QC MAGZPT",0.0);
00927 cpl_propertylist_set_comment(p,"ESO QC MAGZPT",
00928 "[mag] photometric zeropoint");
00929 cpl_propertylist_update_float(p,"ESO QC MAGZERR",0.0);
00930 cpl_propertylist_set_comment(p,"ESO QC MAGZERR",
00931 "[mag] photometric zeropoint error");
00932 cpl_propertylist_update_int(p,"ESO QC MAGNZPT",0);
00933 cpl_propertylist_set_comment(p,"ESO QC MAGNZPT",
00934 "number of stars in magzpt calc");
00935 cpl_propertylist_update_float(p,"ESO QC LIMITING_MAG",0.0);
00936 cpl_propertylist_set_comment(p,"ESO QC LIMITING_MAG",
00937 "[mag] 5 sigma limiting mag");
00938 cpl_propertylist_update_float(p,"ESO QC ZPT_2MASS",0.0);
00939 cpl_propertylist_set_comment(p,"ESO QC ZPT_2MASS",
00940 "[mag] photometric zeropoint");
00941 cpl_propertylist_update_float(p,"ESO QC ZPT_STDS",0.0);
00942 cpl_propertylist_set_comment(p,"ESO QC ZPT_STDS",
00943 "[mag] photometric zeropoint");
00944 cpl_propertylist_update_string(p,"ESO QC ZPT_STDS_CAT","");
00945 cpl_propertylist_set_comment(p,"ESO QC ZPT_STDS_CAT",
00946 "Catalogue used in zeropoint calc");
00947 break;
00948
00949
00950
00951 case 2:
00952 cpl_propertylist_update_float(p,"ESO QC SATURATION",0.0);
00953 cpl_propertylist_set_comment(p,"ESO QC SATURATION",
00954 "[adu] Saturation level");
00955 cpl_propertylist_update_float(p,"ESO QC MEAN_SKY",0.0);
00956 cpl_propertylist_set_comment(p,"ESO QC MEAN_SKY",
00957 "[adu] Median sky brightness");
00958 cpl_propertylist_update_float(p,"ESO QC SKY_NOISE",0.0);
00959 cpl_propertylist_set_comment(p,"ESO QC SKY_NOISE",
00960 "[adu] Pixel noise at sky level");
00961 cpl_propertylist_update_float(p,"ESO QC IMAGE_SIZE",0.0);
00962 cpl_propertylist_set_comment(p,"ESO QC IMAGE_SIZE",
00963 "[pixels] Average FWHM of stellar objects");
00964 cpl_propertylist_update_float(p,"ESO QC ELLIPTICITY",0.0);
00965 cpl_propertylist_set_comment(p,"ESO QC ELLIPTICITY",
00966 "Average stellar ellipticity (1-b/a)");
00967 cpl_propertylist_update_float(p,"ESO QC APERTURE_CORR",0.0);
00968 cpl_propertylist_set_comment(p,"ESO QC APERTURE_CORR",
00969 "Stellar ap-corr 1x core flux");
00970 cpl_propertylist_update_int(p,"ESO QC NOISE_OBJ",0);
00971 cpl_propertylist_set_comment(p,"ESO QC NOISE_OBJ",
00972 "Number of noise objects");
00973 break;
00974
00975
00976
00977 case 3:
00978 cpl_propertylist_update_float(p,"ESO QC ILLUMCOR_RMS",0.0);
00979 cpl_propertylist_set_comment(p,"ESO QC ILLUMCOR_RMS",
00980 "RMS of illumination correction map");
00981 break;
00982 default:
00983 break;
00984 }
00985
00986
00987
00988 return(p);
00989 }
00990
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067