40 #include "irplib_utils.h"
42 #include "hawki_alloc.h"
43 #include "hawki_utils.h"
44 #include "hawki_load.h"
45 #include "hawki_save.h"
46 #include "hawki_pfits.h"
47 #include "hawki_dfs.h"
48 #include "irplib_cat.h"
49 #include "irplib_stdstar.h"
58 int cpl_plugin_get_info(cpl_pluginlist * list);
60 static int hawki_step_photom_2mass_create(cpl_plugin *) ;
61 static int hawki_step_photom_2mass_exec(cpl_plugin *) ;
62 static int hawki_step_photom_2mass_destroy(cpl_plugin *) ;
63 static int hawki_step_photom_2mass(cpl_parameterlist * parlist,
64 cpl_frameset * frameset);
67 cpl_table ** hawki_step_photom_2mass_get_zpoints
68 (cpl_frameset * cat_2mass,
69 cpl_frameset * obj_param,
70 cpl_frameset * obj_ima);
72 static cpl_table * hawki_step_photom_2mass_retrieve_stars
73 (cpl_frameset * cat_2mass,
74 cpl_propertylist * wcs_keywords);
76 static cpl_array * hawki_step_photom_2mass_ppm
77 (cpl_table * stars_2mass,
80 static cpl_table * hawki_step_photom_2mass_fill_zpoint_table
81 (cpl_table * stars_2mass,
82 cpl_table * obj_det_param,
84 cpl_propertylist * plist,
87 static cpl_propertylist ** hawki_step_photom_2mass_qc
88 (cpl_table ** zpoint_table);
90 static int hawki_step_photom_2mass_save
91 (cpl_table ** zpoints,
92 cpl_parameterlist * parlist,
93 cpl_propertylist ** qclists,
100 static char hawki_step_photom_2mass_description[] =
101 "hawki_step_photom_2mass -- HAWK-I photometric autocalibration using 2MASS.\n"
102 "The input files must be tagged:\n"
103 "obj_param.fits "HAWKI_CALPRO_OBJ_PARAM
"\n"
104 "image.fits "HAWKI_CALPRO_COMBINED
"\n"
105 "2mass_master_index.fits "HAWKI_UTIL_CAT_2MASS
"\n"
106 "The recipe creates as an output:\n"
107 "hawki_cal_photom_2mass.fits ("HAWKI_CALPRO_ZPOINT_TAB
"): \n"
108 "The recipe does the following steps:\n"
109 "-Search the 2MASS catalogue for stars in the FOV\n"
110 "-Matches the input detected object catalogue and the 2MASS stars\n"
111 "-Computes photometric characteristics for each matched star\n"
113 "esorex exits with an error code of 0 if the recipe completes successfully\n"
129 int cpl_plugin_get_info(cpl_pluginlist * list)
131 cpl_recipe * recipe = cpl_calloc(1,
sizeof(*recipe)) ;
132 cpl_plugin * plugin = &recipe->interface ;
134 cpl_plugin_init(plugin,
136 HAWKI_BINARY_VERSION,
137 CPL_PLUGIN_TYPE_RECIPE,
138 "hawki_step_photom_2mass",
139 "2MASS photometric calibration",
140 hawki_step_photom_2mass_description,
141 "Cesar Enrique Garcia Dabo",
144 hawki_step_photom_2mass_create,
145 hawki_step_photom_2mass_exec,
146 hawki_step_photom_2mass_destroy);
148 cpl_pluginlist_append(list, plugin) ;
163 static int hawki_step_photom_2mass_create(cpl_plugin * plugin)
165 cpl_recipe * recipe ;
168 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
169 recipe = (cpl_recipe *)plugin ;
173 recipe->parameters = cpl_parameterlist_new() ;
174 if (recipe->parameters == NULL)
188 static int hawki_step_photom_2mass_exec(cpl_plugin * plugin)
190 cpl_recipe * recipe ;
193 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
194 recipe = (cpl_recipe *)plugin ;
200 return hawki_step_photom_2mass(recipe->parameters, recipe->frames) ;
210 static int hawki_step_photom_2mass_destroy(cpl_plugin * plugin)
212 cpl_recipe * recipe ;
215 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
216 recipe = (cpl_recipe *)plugin ;
219 cpl_parameterlist_delete(recipe->parameters) ;
230 static int hawki_step_photom_2mass(cpl_parameterlist * parlist,
231 cpl_frameset * frameset)
233 cpl_frameset * cat_2mass;
234 cpl_frameset * obj_param;
235 cpl_frameset * obj_ima;
236 cpl_table ** zpoint_table;
237 cpl_propertylist ** qclists;
242 cpl_msg_error(__func__,
"Cannot identify RAW and CALIB frames") ;
248 HAWKI_UTIL_CAT_2MASS)) == NULL)
250 cpl_msg_error(__func__,
"Cannot find 2MASS catalogue (%s)",
251 HAWKI_UTIL_CAT_2MASS);
257 (frameset, HAWKI_CALPRO_OBJ_PARAM)) == NULL)
259 cpl_msg_error(__func__,
"Cannot find object parameters (%s)",
260 HAWKI_CALPRO_OBJ_PARAM);
266 (frameset, HAWKI_CALPRO_COMBINED)) == NULL)
268 cpl_msg_error(__func__,
"Cannot find combined image (%s) ",
269 HAWKI_CALPRO_COMBINED);
274 zpoint_table = hawki_step_photom_2mass_get_zpoints
275 (cat_2mass, obj_param, obj_ima);
276 if(zpoint_table == NULL)
278 cpl_msg_error(__func__,
"Could not get the zpoints");
279 cpl_frameset_delete(cat_2mass);
280 cpl_frameset_delete(obj_param);
281 cpl_frameset_delete(obj_ima);
286 qclists = hawki_step_photom_2mass_qc(zpoint_table);
287 if(zpoint_table == NULL)
289 cpl_msg_error(__func__,
"Could not compute quality controls");
290 cpl_frameset_delete(cat_2mass);
291 cpl_frameset_delete(obj_param);
292 cpl_frameset_delete(obj_ima);
298 cpl_msg_info(__func__,
"Saving products");
299 if(hawki_step_photom_2mass_save(zpoint_table, parlist, qclists, frameset) == -1)
301 cpl_msg_error(__func__,
"Could not save products");
302 cpl_frameset_delete(cat_2mass);
303 cpl_frameset_delete(obj_param);
304 cpl_frameset_delete(obj_ima);
310 cpl_frameset_delete(cat_2mass);
311 cpl_frameset_delete(obj_param);
312 cpl_frameset_delete(obj_ima);
314 for (idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++)
315 cpl_propertylist_delete(qclists[idet]);
319 if (cpl_error_get_code())
321 cpl_msg_error(__func__,
322 "HAWK-I pipeline could not recover from previous errors");
328 cpl_table ** hawki_step_photom_2mass_get_zpoints
329 (cpl_frameset * cat_2mass,
330 cpl_frameset * obj_param,
331 cpl_frameset * obj_ima)
333 cpl_table ** zpoint_table;
334 cpl_table ** obj_det_param;
335 cpl_propertylist * plist;
337 cpl_errorstate error_prevstate = cpl_errorstate_get();
340 zpoint_table = cpl_malloc(
sizeof(cpl_table *) * HAWKI_NB_DETECTORS);
346 plist = cpl_propertylist_load
347 (cpl_frame_get_filename(cpl_frameset_get_first(obj_ima)), 0);
349 for(idet = 0; idet < HAWKI_NB_DETECTORS; ++idet)
351 cpl_propertylist * wcs_info;
352 cpl_table * stars_2mass;
356 cpl_msg_info(__func__,
"Working on chip %d", idet + 1);
357 cpl_msg_indent_more();
361 (cpl_frame_get_filename(cpl_frameset_get_first(obj_ima)),idet+1);
362 wcs_info = cpl_propertylist_load
363 (cpl_frame_get_filename(cpl_frameset_get_first(obj_ima)), ext_nb);
365 hawki_step_photom_2mass_retrieve_stars(cat_2mass, wcs_info);
366 if(stars_2mass == NULL)
369 cpl_msg_error(__func__,
"Cannot retrieve stars");
370 cpl_propertylist_delete(plist);
371 cpl_propertylist_delete(wcs_info);
373 for(jdet = 0; jdet <idet; ++jdet)
374 cpl_table_delete(zpoint_table[jdet]);
375 cpl_free(zpoint_table);
380 cpl_msg_info(__func__,
"Matching %"CPL_SIZE_FORMAT
381 " 2MASS stars and %"CPL_SIZE_FORMAT
" detections",
382 cpl_table_get_nrow(stars_2mass),
383 cpl_table_get_nrow(obj_det_param[idet]));
384 matches = hawki_step_photom_2mass_ppm(stars_2mass, obj_det_param[idet]);
387 cpl_msg_info(__func__,
"Computing zero points");
388 zpoint_table[idet] = hawki_step_photom_2mass_fill_zpoint_table
389 (stars_2mass, obj_det_param[idet], matches, plist, idet);
390 if(zpoint_table[idet] == NULL)
393 cpl_msg_error(__func__,
"Could not compute the zero points");
394 cpl_propertylist_delete(plist);
395 cpl_propertylist_delete(wcs_info);
397 cpl_table_delete(stars_2mass);
398 for(jdet = 0; jdet <idet; ++jdet)
399 cpl_table_delete(zpoint_table[jdet]);
400 cpl_free(zpoint_table);
401 cpl_array_delete(matches);
406 cpl_msg_indent_less();
407 cpl_propertylist_delete(wcs_info);
408 cpl_table_delete(stars_2mass);
409 cpl_array_delete(matches);
414 cpl_propertylist_delete(plist);
415 if(!cpl_errorstate_is_equal(error_prevstate))
418 for(jdet = 0; jdet <HAWKI_NB_DETECTORS; ++jdet)
419 cpl_table_delete(zpoint_table[jdet]);
420 cpl_free(zpoint_table);
421 cpl_msg_error(__func__,
"A problem happened computing the zero point");
422 cpl_errorstate_set(CPL_ERROR_NONE);
428 static cpl_table * hawki_step_photom_2mass_retrieve_stars
429 (cpl_frameset * cat_2mass,
430 cpl_propertylist * wcs_keywords)
442 double extra_search = 0.;
443 cpl_matrix * from_coord;
444 cpl_matrix * to_coord;
449 if (irplib_2mass_get_catpars(cpl_frameset_get_first(cat_2mass),
450 &catpath, &catname) != CPL_ERROR_NONE)
454 wcs = cpl_wcs_new_from_propertylist(wcs_keywords);
455 if(cpl_error_get_code() == CPL_ERROR_NO_WCS)
457 cpl_msg_error(__func__,
"Not compiled with WCS support.");
462 if(irplib_cat_get_image_limits(wcs, extra_search,
463 &ra1, &ra2, &dec1, &dec2) ==
464 CPL_ERROR_DATA_NOT_FOUND)
466 cpl_msg_error(__func__,
"No WCS information found");
472 cpl_msg_info(__func__,
"Searching stars in RA=[%f,%f] DEC=[%f,%f]",
473 ra1/15., ra2/15., dec1, dec2);
477 stars = irplib_2mass_extract(catpath, ra1, ra2, dec1, dec2);
480 cpl_msg_error(__func__,
"Error retrieving 2mass stars: %s ",
481 cpl_error_get_message());
487 nstars = cpl_table_get_nrow(stars);
488 cpl_msg_indent_more();
489 cpl_msg_info(__func__,
"%d 2MASS stars found", nstars);
492 from_coord = cpl_matrix_new(nstars, 2);
493 for (istar=0; istar<nstars; istar++)
495 cpl_matrix_set(from_coord, istar, 0, cpl_table_get_float
496 (stars, HAWKI_COL_2MASS_RA, istar, NULL));
497 cpl_matrix_set(from_coord, istar, 1, cpl_table_get_float
498 (stars, HAWKI_COL_2MASS_DEC, istar, NULL));
503 if(cpl_wcs_convert(wcs, from_coord, &to_coord,
504 &status, CPL_WCS_WORLD2PHYS) != CPL_ERROR_NONE)
506 cpl_array_delete(status);
507 cpl_matrix_delete(from_coord);
508 cpl_matrix_delete(to_coord);
512 cpl_msg_error(cpl_func,
"Error in cpl_wcs conversion. %s",
513 cpl_error_get_message());
518 cpl_table_new_column(stars, HAWKI_COL_2MASS_XPREDICT, CPL_TYPE_FLOAT);
519 cpl_table_set_column_unit(stars,HAWKI_COL_2MASS_XPREDICT,
"pixels");
520 cpl_table_new_column(stars, HAWKI_COL_2MASS_YPREDICT, CPL_TYPE_FLOAT);
521 cpl_table_set_column_unit(stars, HAWKI_COL_2MASS_YPREDICT,
"pixels");
522 for(istar=0; istar< nstars; istar++)
524 float xpredict = (float)cpl_matrix_get(to_coord, istar, 0);
525 float ypredict = (float)cpl_matrix_get(to_coord, istar, 1);
526 cpl_table_set_float(stars,
"xpredict", istar, xpredict);
527 cpl_table_set_float(stars,
"ypredict", istar, ypredict);
531 cpl_array_delete(status);
532 cpl_matrix_delete(from_coord);
533 cpl_matrix_delete(to_coord);
537 cpl_msg_indent_less();
548 static cpl_array * hawki_step_photom_2mass_ppm
549 (cpl_table * stars_2mass,
556 int nstars_2mass_used_match;
560 int nmax_match_pattern = 30;
561 cpl_matrix * pattern;
564 double pradius = 30.0;
565 double mean_data_pos_err = 5.;
566 int ppm_max_iter = 5;
569 cpl_matrix * obj_pos;
570 cpl_propertylist * sort_prop;
574 cpl_msg_indent_more();
575 sort_prop = cpl_propertylist_new();
576 cpl_propertylist_append_bool(sort_prop, HAWKI_COL_OBJ_FLUX, 1);
577 if (cpl_table_sort(obj_det, sort_prop) != CPL_ERROR_NONE)
579 cpl_msg_error(cpl_func,
"Cannot sort detected sources table");
580 cpl_propertylist_delete(sort_prop);
585 nobj = cpl_table_get_nrow(obj_det);
586 obj_pos = cpl_matrix_new(2, nobj);
587 for (iobj=0; iobj<nobj; iobj++)
589 float xim = cpl_table_get_double
590 (obj_det, HAWKI_COL_OBJ_POSX, iobj, NULL);
591 float yim = cpl_table_get_double
592 (obj_det, HAWKI_COL_OBJ_POSY, iobj, NULL);
593 cpl_matrix_set(obj_pos, 0, iobj, xim);
594 cpl_matrix_set(obj_pos, 1, iobj, yim);
598 cpl_propertylist_empty(sort_prop);
599 cpl_propertylist_append_bool(sort_prop, HAWKI_COL_2MASS_K_MAG, 0);
600 if (cpl_table_sort(stars_2mass, sort_prop) != CPL_ERROR_NONE)
602 cpl_msg_error(cpl_func,
"Cannot sort 2MASS stars table");
603 cpl_propertylist_delete(sort_prop);
608 nstars_2mass = cpl_table_get_nrow(stars_2mass);
609 pattern = cpl_matrix_new(2, nstars_2mass);
610 for(istar=0; istar<nstars_2mass ; istar++)
612 float x = cpl_table_get_float
613 (stars_2mass, HAWKI_COL_2MASS_XPREDICT, istar, NULL);
614 float y = cpl_table_get_float
615 (stars_2mass, HAWKI_COL_2MASS_YPREDICT, istar, NULL);
616 cpl_matrix_set(pattern, 0, istar, x);
617 cpl_matrix_set(pattern, 1, istar, y);
621 nstars_2mass_used_match = nmax_match_pattern;
622 if(nstars_2mass < nmax_match_pattern)
623 nstars_2mass_used_match = nstars_2mass;
624 nobj_used_match = (int)(1.7 * nstars_2mass_used_match);
625 if(nobj_used_match > nobj)
626 nobj_used_match = nobj;
627 if(nobj_used_match < nstars_2mass_used_match)
628 nobj_used_match = nstars_2mass_used_match;
629 cpl_msg_info(__func__,
"The first step match will use %d stars "
630 "and %d objects", nstars_2mass_used_match,nobj_used_match);
631 for (iter = 0; iter < ppm_max_iter; iter++)
635 matches = cpl_ppm_match_points(obj_pos, nobj_used_match,
637 pattern, nstars_2mass_used_match,
639 NULL, NULL, &scale, &angle);
642 nmatchsize = cpl_array_get_size(matches);
643 nmatches = nmatchsize -
644 cpl_array_count_invalid(matches);
652 cpl_msg_info(cpl_func,
"Total matches: %d. Valid matches: %d",
653 nmatchsize, nmatches);
654 cpl_msg_info(cpl_func,
"Scale=%g angle=%g", scale, angle);
655 if((matches == NULL) || (nmatches < floor(nobj_used_match*0.1)))
657 nobj_used_match = nobj_used_match + 10;
658 cpl_msg_info(cpl_func,
659 "Increasing number of detections used in PPM to %d",
668 cpl_msg_indent_more();
669 cpl_msg_debug(__func__,
"Matched stars:");
670 cpl_msg_indent_more();
671 cpl_msg_debug(__func__,
"X_OBJ Y_OBJ X_STAR Y_STAR X_DIFF Y_DIFF:");
672 for(istar=0; istar < nstars_2mass; ++istar)
675 double x_obj, y_obj, x_star, y_star, x_diff, y_diff;
676 iobj = cpl_array_get_int(matches, istar, &null);
680 x_obj = cpl_matrix_get(obj_pos, 0, iobj);
681 y_obj = cpl_matrix_get(obj_pos, 1, iobj);
682 x_star = cpl_matrix_get(pattern, 0, istar);
683 y_star = cpl_matrix_get(pattern, 1, istar);
684 x_diff = x_obj - x_star;
685 y_diff = y_obj - y_star;
686 cpl_msg_debug(__func__,
"%6.1f %6.1f %6.1f %6.1f %6.1f %6.1f\n",
687 x_obj, y_obj, x_star, y_star, x_diff, y_diff);
689 cpl_msg_indent_less();
690 cpl_msg_indent_less();
692 cpl_matrix_delete(pattern);
693 cpl_msg_info(cpl_func,
"%d points matched", nmatches);
695 if(matches == NULL || nmatches == 0)
698 cpl_array_delete(matches);
699 cpl_msg_error(cpl_func,
"Error in PPM. %s",cpl_error_get_message());
700 cpl_matrix_delete(obj_pos);
701 cpl_propertylist_delete(sort_prop);
702 cpl_msg_indent_less();
706 if(nmatches < floor(nobj_used_match*0.1))
708 cpl_msg_warning(cpl_func,
"PPM detected matched only %d objects."
709 " Results could be unreliable",nmatches);
713 cpl_matrix_delete(obj_pos);
714 cpl_propertylist_delete(sort_prop);
715 cpl_msg_indent_less();
725 static cpl_table * hawki_step_photom_2mass_fill_zpoint_table
726 (cpl_table * stars_2mass,
727 cpl_table * obj_det_param,
729 cpl_propertylist * plist,
738 char magcol_2mass[100];
739 char magerrcol_2mass[100];
744 cpl_errorstate error_prevstate = cpl_errorstate_get();
756 strncpy(magcol_2mass, HAWKI_COL_2MASS_J_MAG, 98);
757 strncpy(magerrcol_2mass, HAWKI_COL_2MASS_J_MAGSIG, 98);
761 strncpy(magcol_2mass, HAWKI_COL_2MASS_H_MAG, 98);
762 strncpy(magerrcol_2mass, HAWKI_COL_2MASS_H_MAGSIG, 98);
766 strncpy(magcol_2mass, HAWKI_COL_2MASS_K_MAG, 98);
767 strncpy(magerrcol_2mass, HAWKI_COL_2MASS_K_MAGSIG, 98);
771 cpl_msg_warning(__func__,
"The filter %s does not exist in 2MASS. "
772 "The 2MASS K band will be used instead. "
773 "Columns %s, %s, %s and %s in product will not "
774 "be accurate", filter,
775 HAWKI_COL_ZPOINT_MAG, HAWKI_COL_ZPOINT_ERRMAG,
776 HAWKI_COL_ZPOINT_ZPOINT, HAWKI_COL_ZPOINT_ATX0);
777 strncpy(magcol_2mass, HAWKI_COL_2MASS_K_MAG, 98);
778 strncpy(magerrcol_2mass, HAWKI_COL_2MASS_K_MAGSIG, 98);
787 nstars = cpl_table_get_nrow(stars_2mass);
788 nmatches = cpl_array_get_size(matches) - cpl_array_count_invalid(matches);
789 zpoints = cpl_table_new(nmatches) ;
790 cpl_table_new_column(zpoints, HAWKI_COL_ZPOINT_CHIP, CPL_TYPE_INT) ;
791 cpl_table_new_column(zpoints, HAWKI_COL_ZPOINT_POSX, CPL_TYPE_DOUBLE) ;
792 cpl_table_new_column(zpoints, HAWKI_COL_ZPOINT_POSY, CPL_TYPE_DOUBLE) ;
793 cpl_table_new_column(zpoints, HAWKI_COL_ZPOINT_ZPOINT, CPL_TYPE_DOUBLE) ;
794 cpl_table_new_column(zpoints, HAWKI_COL_ZPOINT_ATX0, CPL_TYPE_DOUBLE) ;
795 cpl_table_new_column(zpoints, HAWKI_COL_ZPOINT_MAG, CPL_TYPE_DOUBLE) ;
796 cpl_table_new_column(zpoints, HAWKI_COL_ZPOINT_ERRMAG, CPL_TYPE_DOUBLE) ;
797 cpl_table_new_column(zpoints, HAWKI_COL_ZPOINT_AIRMASS, CPL_TYPE_DOUBLE) ;
798 cpl_table_new_column(zpoints, HAWKI_COL_ZPOINT_FLUX, CPL_TYPE_DOUBLE) ;
799 cpl_table_new_column(zpoints, HAWKI_COL_ZPOINT_FILTER, CPL_TYPE_STRING) ;
802 cpl_table_new_column(zpoints, HAWKI_COL_ZPOINT_FWHMX, CPL_TYPE_DOUBLE) ;
803 cpl_table_new_column(zpoints, HAWKI_COL_ZPOINT_FWHMY, CPL_TYPE_DOUBLE) ;
804 cpl_table_new_column(zpoints, HAWKI_COL_ZPOINT_FWHM, CPL_TYPE_DOUBLE) ;
805 cpl_table_new_column(zpoints, HAWKI_COL_ZPOINT_FWHMX_AS, CPL_TYPE_DOUBLE) ;
806 cpl_table_new_column(zpoints, HAWKI_COL_ZPOINT_FWHMY_AS, CPL_TYPE_DOUBLE) ;
807 cpl_table_new_column(zpoints, HAWKI_COL_ZPOINT_FWHM_AS, CPL_TYPE_DOUBLE) ;
810 for (istar=0; istar<nstars; istar++)
823 iobj = cpl_array_get_int(matches, istar, &null);
827 if(!cpl_table_is_selected(stars_2mass, istar))
830 flux = cpl_table_get_double
831 (obj_det_param, HAWKI_COL_OBJ_FLUX, iobj, NULL);
832 mag = cpl_table_get_float
833 (stars_2mass, magcol_2mass, istar, NULL);
834 errmag = cpl_table_get_float
835 (stars_2mass, magerrcol_2mass, istar, NULL);
836 zpoint = mag + 2.5 * log10(flux) - 2.5 * log10(dit);
837 atx0 = zpoint + airmass * extinction;
838 fwhm_x = cpl_table_get_double
839 (obj_det_param, HAWKI_COL_OBJ_FWHM_MAJAX, iobj, NULL);
840 fwhm_y = cpl_table_get_double
841 (obj_det_param, HAWKI_COL_OBJ_FWHM_MINAX, iobj, NULL);
842 fwhm = sqrt(fwhm_x*fwhm_y);
844 cpl_table_set_int(zpoints, HAWKI_COL_ZPOINT_CHIP, imatch, idet + 1) ;
846 (zpoints, HAWKI_COL_ZPOINT_MAG, imatch, mag);
848 (zpoints, HAWKI_COL_ZPOINT_ERRMAG, imatch, errmag);
850 (zpoints, HAWKI_COL_ZPOINT_FILTER, imatch, filter);
852 (zpoints, HAWKI_COL_ZPOINT_AIRMASS, imatch, airmass);
854 (zpoints, HAWKI_COL_ZPOINT_POSX, imatch, cpl_table_get_double
855 (obj_det_param, HAWKI_COL_OBJ_POSX, iobj, NULL));
857 (zpoints, HAWKI_COL_ZPOINT_POSY, imatch, cpl_table_get_double
858 (obj_det_param, HAWKI_COL_OBJ_POSY, iobj, NULL));
859 cpl_table_set_double(zpoints, HAWKI_COL_ZPOINT_ZPOINT, imatch, zpoint);
860 cpl_table_set_double(zpoints, HAWKI_COL_ZPOINT_ATX0, imatch, atx0);
862 (zpoints, HAWKI_COL_ZPOINT_FLUX, imatch, flux);
868 (zpoints, HAWKI_COL_ZPOINT_FWHMX, imatch, fwhm_x);
870 (zpoints, HAWKI_COL_ZPOINT_FWHMY, imatch, fwhm_y);
872 (zpoints, HAWKI_COL_ZPOINT_FWHM, imatch, fwhm);
874 (zpoints, HAWKI_COL_ZPOINT_FWHMX_AS, imatch, fwhm_x * pixscale);
876 (zpoints, HAWKI_COL_ZPOINT_FWHMY_AS, imatch, fwhm_y * pixscale);
878 (zpoints, HAWKI_COL_ZPOINT_FWHM_AS, imatch, fwhm * pixscale);
883 if(!cpl_errorstate_is_equal(error_prevstate))
885 cpl_msg_error(__func__,
"An error happened filling the zpoint table: %s",
886 cpl_error_get_message());
887 cpl_table_delete(zpoints);
899 static cpl_propertylist ** hawki_step_photom_2mass_qc
900 (cpl_table ** zpoint_table)
903 cpl_propertylist ** qclists;
906 qclists = cpl_malloc(HAWKI_NB_DETECTORS *
sizeof(cpl_propertylist*)) ;
909 for(idet = 0 ; idet < HAWKI_NB_DETECTORS ; ++idet)
914 qclists[idet] = cpl_propertylist_new() ;
917 mean_zpoint = cpl_table_get_column_mean(zpoint_table[idet],
918 HAWKI_COL_ZPOINT_ZPOINT);
920 cpl_propertylist_append_double
921 (qclists[idet],
"ESO QC ZPOINT", mean_zpoint);
938 static int hawki_step_photom_2mass_save
939 (cpl_table ** zpoints,
940 cpl_parameterlist * parlist,
941 cpl_propertylist ** qclists,
944 cpl_propertylist * protype;
945 cpl_frame * ref_frame ;
946 cpl_frameset * combinedframes;
948 const char * recipe_name =
"hawki_step_photom_2mass" ;
951 nframes = cpl_frameset_get_size(
set) ;
955 ref_frame = cpl_frameset_get_first(combinedframes);
958 protype = cpl_propertylist_new();
959 cpl_propertylist_append_string(protype,
"ESO PRO TYPE",
960 HAWKI_PROTYPE_ZPOINT_TAB);
966 (
const cpl_table **)zpoints,
968 HAWKI_CALPRO_ZPOINT_TAB,
969 HAWKI_PROTYPE_ZPOINT_TAB,
971 (
const cpl_propertylist **)qclists,
972 "hawki_step_photom_2mass.fits") ;
975 cpl_propertylist_delete(protype);
976 cpl_frameset_delete(combinedframes);