36 #include "naco_recipe.h"
37 #include "naco_strehl.h"
39 #include "irplib_strehl.h"
40 #include "irplib_wcs.h"
41 #include "irplib_stdstar.h"
49 #define RECIPE_STRING "naco_img_zpoint"
52 typedef enum _NACO_BAND_ {
76 static cpl_table * naco_img_zpoint_reduce(cpl_propertylist *,
77 const irplib_framelist *,
78 const cpl_parameterlist *,
79 const char *,
const char *,
82 static cpl_error_code naco_img_zpoint_qc(cpl_propertylist *,
84 const irplib_framelist *);
86 static cpl_error_code naco_img_zpoint_save(cpl_frameset *,
87 const cpl_parameterlist *,
88 const cpl_propertylist *,
89 const cpl_propertylist *,
93 static cpl_error_code naco_img_zpoint_reduce_one(cpl_table *, cpl_vector *,
int,
95 const cpl_parameterlist *,
96 const char *,
double,
double,
97 double,
double *,
double *,
98 double *,
double *,
double *);
100 static double naco_img_zpoint_find_mag(cpl_propertylist *,
double,
double,
101 const char *,
const char *);
103 static cpl_table * naco_img_zpoint_load_std_star(
const char *,
double,
double,
double);
105 static cpl_error_code naco_img_zpoint_find_std_star(cpl_table *,
112 static cpl_error_code naco_img_zpoint_qc_all(cpl_propertylist *,
114 const irplib_framelist *);
116 static cpl_error_code naco_img_zpoint_check_im(cpl_image **,
const cpl_image *,
117 int,
int,
double,
double,
118 double,
double,
double);
120 static naco_band naco_get_bbfilter(
const char *);
122 static const char * naco_std_band_name(naco_band);
125 NACO_RECIPE_DEFINE(naco_img_zpoint,
136 "Zero point computation recipe",
137 RECIPE_STRING
" -- Zero point recipe\n"
138 "The files listed in the Set Of Frames (sof-file) "
140 "NACO-raw-file.fits " NACO_IMG_ZPOINT_CHOP
" or\n"
141 "NACO-raw-file.fits " NACO_IMG_ZPOINT_JITTER
".\n"
142 "NACO-Imaging-Standard-Star-Catalog.fits "
143 NACO_IMG_STD_CAT
"\n"
144 "Optionally, a flat field frame may be inluded:\n"
145 "NACO-flat-file.fits " NACO_CALIB_FLAT
"\n");
158 double phot_star_radius;
164 } naco_img_zpoint_config;
186 static int naco_img_zpoint(cpl_frameset * framelist,
187 const cpl_parameterlist * parlist)
189 irplib_framelist* allframes = NULL;
190 irplib_framelist* rawframes = NULL;
191 cpl_propertylist* qclist = cpl_propertylist_new();
192 cpl_propertylist* paflist = cpl_propertylist_new();
194 const char * star_cat;
195 cpl_table * tab = NULL;
196 cpl_image * check_im = NULL;
200 naco_img_zpoint_config.ra
203 naco_img_zpoint_config.dec
206 naco_img_zpoint_config.pscale
209 naco_img_zpoint_config.magnitude
212 naco_img_zpoint_config.sx
215 skip_if_lt(naco_img_zpoint_config.sx, 1,
216 "for the size of the search window in X-direction [pixel]");
219 naco_img_zpoint_config.sy
222 skip_if_lt(naco_img_zpoint_config.sy, 1,
223 "for the size of the search window in Y-direction [pixel]");
226 naco_img_zpoint_config.phot_star_radius
230 naco_img_zpoint_config.phot_bg_r1
234 naco_img_zpoint_config.phot_bg_r2
238 naco_img_zpoint_config.check_im
245 skip_if(allframes == NULL);
248 "^(" NACO_IMG_ZPOINT_JITTER
249 "|" NACO_IMG_ZPOINT_CHOP
")$",
251 skip_if(rawframes == NULL);
256 error_if (star_cat == NULL, CPL_ERROR_DATA_NOT_FOUND,
"The input "
257 "file(s) have no star catalog tagged %s", NACO_IMG_STD_CAT);
264 IRPLIB_PFITS_REGEXP_RECAL
"|"
265 NACO_PFITS_REGEXP_ZPOINT
"|"
266 NACO_PFITS_REGEXP_ZPOINT_PAF
"|"
267 NACO_PFITS_REGEXP_ZPOINT_REF
271 NACO_PFITS_REGEXP_ZPOINT
275 tab = naco_img_zpoint_reduce(qclist, rawframes, parlist, star_cat, flat,
277 skip_if (tab == NULL);
279 skip_if(naco_img_zpoint_qc(qclist, paflist, rawframes));
285 bug_if (cpl_propertylist_append_string(paflist, CPL_DFS_PRO_CATG,
286 NACO_IMG_ZPOINT_RES));
289 skip_if (naco_img_zpoint_save(framelist, parlist, qclist, paflist, tab,
294 cpl_table_delete(tab);
295 cpl_image_delete(check_im);
298 cpl_propertylist_delete(qclist);
299 cpl_propertylist_delete(paflist);
301 return cpl_error_get_code();
317 static cpl_table * naco_img_zpoint_reduce(cpl_propertylist * qclist,
318 const irplib_framelist * rawframes,
319 const cpl_parameterlist * parlist,
320 const char * star_cat,
322 cpl_image ** pcheck_im)
324 const cpl_propertylist * plist
326 cpl_image * flat_im = NULL;
327 cpl_image * rawimage = NULL;
328 cpl_image * imdiff = NULL;
331 double pos_x_cen = DBL_MAX;
332 double pos_y_cen = DBL_MAX;
333 cpl_apertures * aperts = NULL;
334 double psigmas[] = {20.0, 10.0, 8.0, 6.0, 5.0};
335 const int nsigmas = (int)(
sizeof(psigmas)/
sizeof(double));
337 cpl_vector * sigmas = NULL;
338 cpl_table * out_tab = NULL;
339 cpl_vector * zpoints = NULL;
341 double off_x0 = DBL_MAX;
342 double off_y0 = DBL_MAX;
343 double off_x = DBL_MAX;
344 double off_y = DBL_MAX;
345 double str_sum = 0.0;
346 double str_err_sum = 0.0;
349 double bg_no_sum = 0.0;
367 bug_if (pcheck_im == NULL);
368 bug_if (*pcheck_im != NULL);
370 skip_if_lt(ndiff/2+1, 3,
"raw frames");
375 skip_if (dit <= 0.0);
376 if (naco_img_zpoint_config.ra > 998.0)
378 if (naco_img_zpoint_config.dec > 998.0)
382 if (naco_img_zpoint_config.pscale <= 0.0) {
384 skip_if(naco_img_zpoint_config.pscale <= 0.0);
387 cpl_msg_info(cpl_func,
"Using star at position: RA = %g ; DEC = %g",
388 naco_img_zpoint_config.ra, naco_img_zpoint_config.dec);
394 if (naco_img_zpoint_config.magnitude > IRPLIB_STDSTAR_LIMIT) {
395 naco_img_zpoint_config.magnitude
396 = naco_img_zpoint_find_mag(qclist,
397 naco_img_zpoint_config.ra,
398 naco_img_zpoint_config.dec,
400 if (cpl_error_get_code()) {
401 const cpl_propertylist * reflist
405 if (starname != NULL) {
406 error_if (0, cpl_error_get_code(),
"Star '%s' has "
407 "no magnitude for filter '%s' in catalogue '%s'",
408 starname, filter, star_cat);
412 cpl_msg_info(cpl_func,
"Star magnitude with filter %s : %g", filter,
413 naco_img_zpoint_config.magnitude);
414 bug_if(cpl_propertylist_append_double(qclist,
"ESO QC STARMAG",
415 naco_img_zpoint_config.magnitude));
417 zpoints = cpl_vector_new(ndiff);
418 out_tab = cpl_table_new(ndiff);
419 cpl_table_new_column(out_tab,
"POSX", CPL_TYPE_DOUBLE);
420 cpl_table_new_column(out_tab,
"POSY", CPL_TYPE_DOUBLE);
421 cpl_table_new_column(out_tab,
"ZPOINT", CPL_TYPE_DOUBLE);
422 cpl_table_new_column(out_tab,
"PEAK", CPL_TYPE_DOUBLE);
423 cpl_table_new_column(out_tab,
"FLUX", CPL_TYPE_DOUBLE);
424 cpl_table_new_column(out_tab,
"BGD_NOISE", CPL_TYPE_DOUBLE);
425 cpl_table_new_column(out_tab,
"STREHL", CPL_TYPE_DOUBLE);
426 cpl_table_new_column(out_tab,
"STREHL_ERR", CPL_TYPE_DOUBLE);
427 cpl_table_new_column(out_tab,
"BGD", CPL_TYPE_DOUBLE);
428 cpl_table_new_column(out_tab,
"FWHMX", CPL_TYPE_DOUBLE);
429 cpl_table_new_column(out_tab,
"FWHMY", CPL_TYPE_DOUBLE);
434 cpl_msg_info(cpl_func,
"Loading the flat field from %s", flat);
435 flat_im = cpl_image_load(flat, CPL_TYPE_FLOAT, 0, 0);
437 if (flat_im == NULL) {
438 cpl_msg_error(cpl_func,
"Could not load flat field");
443 cpl_msg_info(cpl_func,
"Loading the image from raw frame %d",1);
444 rawimage = cpl_image_load(cpl_frame_get_filename(
446 CPL_TYPE_FLOAT, 0, 0);
447 if (rawimage == NULL) {
448 cpl_msg_error(cpl_func,
"Could not load image from first raw frame");
452 for (i=0; i < ndiff; i++) {
455 double str, str_err, pe, fl, bg_no;
460 if (i == 0 || i % 2 == 1) {
476 cpl_msg_info(cpl_func,
"Offsets for difference image %d: (%g,%g)",
486 const char * filename = cpl_frame_get_filename(
491 cpl_image_delete(imdiff);
494 cpl_msg_info(cpl_func,
"Loading the image from raw frame %d",2+i/2);
495 rawimage = cpl_image_load(filename, CPL_TYPE_FLOAT, 0, 0);
496 if (rawimage == NULL) {
497 cpl_msg_error(cpl_func,
"Could not load image %d", 2+i/2);
500 bug_if(cpl_image_subtract(imdiff, rawimage));
501 if (flat_im != NULL) skip_if(cpl_image_divide(imdiff, flat_im));
503 bug_if(cpl_image_multiply_scalar(imdiff, -1.0));
507 double min_dist = DBL_MAX;
508 const int size_x = cpl_image_get_size_x(imdiff);
509 const int size_y = cpl_image_get_size_y(imdiff);
513 cpl_msg_info(cpl_func,
"Detecting a bright object in the first "
514 "difference image using %d sigma-levels ranging from "
515 "%g down to %g", nsigmas, psigmas[0],
517 sigmas = cpl_vector_wrap(nsigmas, psigmas);
519 aperts = cpl_apertures_extract(imdiff, sigmas, &isigma);
520 if (aperts == NULL || cpl_apertures_get_size(aperts) < 1) {
521 cpl_msg_error(cpl_func,
"Could not detect any bright object");
524 for (iap=0; iap < cpl_apertures_get_size(aperts); iap++) {
526 = cpl_apertures_get_centroid_x(aperts, iap+1) - size_x/2.0;
528 = cpl_apertures_get_centroid_y(aperts, iap+1) - size_y/2.0;
529 const double dist = d_x * d_x + d_y * d_y;
530 if (iap == 0 || dist < min_dist) {
536 cpl_apertures_delete(aperts);
539 pos_x_cen += size_x/2.0;
540 pos_y_cen += size_y/2.0;
541 cpl_msg_info(cpl_func,
"Detected a bright object at sigma=%g, at "
542 "position: %g %g", psigmas[isigma], pos_x_cen,
547 pos_x = pos_x_cen + off_x;
548 pos_y = pos_y_cen + off_y;
552 const int llx = (int)pos_x - naco_img_zpoint_config.sx;
553 const int urx = (
int)pos_x + naco_img_zpoint_config.sx;
554 const int lly = (int)pos_y - naco_img_zpoint_config.sy;
555 const int ury = (
int)pos_y + naco_img_zpoint_config.sy;
556 pos_x = cpl_image_get_centroid_x_window(imdiff, llx, lly, urx, ury);
557 pos_y = cpl_image_get_centroid_y_window(imdiff, llx, lly, urx, ury);
558 error_if (0, cpl_error_get_code(),
"Could not refine the positions "
559 "of difference image %d", i+1);
565 if (naco_img_zpoint_config.check_im) {
566 const double r1 = naco_img_zpoint_config.phot_star_radius
567 /naco_img_zpoint_config.pscale;
568 const double r2 = naco_img_zpoint_config.phot_bg_r1
569 /naco_img_zpoint_config.pscale;
570 const double r3 = naco_img_zpoint_config.phot_bg_r2
571 /naco_img_zpoint_config.pscale;
573 skip_if(naco_img_zpoint_check_im(pcheck_im, imdiff, i, ndiff,
574 pos_x, pos_y, r1, r2, r3));
578 skip_if (naco_img_zpoint_reduce_one(out_tab, zpoints, i, imdiff,
581 &str, &str_err, &pe, &fl, &bg_no));
584 if (str <= 0.0 || str >= 1.0)
continue;
588 str_err_sum += str_err;
594 skip_if_lt(nok_strehl, 1,
"valid strehl measurements");
596 strehl = str_sum / (double)nok_strehl;
597 strehl_err = str_err_sum / (double)nok_strehl;
598 strehl_rms = bg_no_sum / (double)nok_strehl;
599 star_peak = pe_sum / (double)nok_strehl;
600 star_flux = fl_sum / (double)nok_strehl;
603 cpl_vector_sort(zpoints, 1);
605 for (i=1; i < ndiff-1; i++) {
606 const double zp = cpl_vector_get(zpoints, i);
613 cpl_vector_delete(zpoints);
616 skip_if_lt(nok_zp, 1,
"valid zpoint measurements");
618 avg_zp /= (double)nok_zp;
619 sqsum /= (double)nok_zp;
620 zpointrms = sqsum - avg_zp * avg_zp;
621 zpointrms = zpointrms > 0.0 ? sqrt(zpointrms) : 0.0;
624 cpl_msg_info(cpl_func,
"***** FINAL RESULTS *****");
625 cpl_msg_info(cpl_func,
"Strehl : %g", strehl);
626 cpl_msg_info(cpl_func,
"Strehl error : %g", strehl_err);
627 cpl_msg_info(cpl_func,
"Peak : %g", star_peak);
628 cpl_msg_info(cpl_func,
"Flux : %g", star_flux);
629 cpl_msg_info(cpl_func,
"Strehl RMS %g", strehl_rms);
630 cpl_msg_info(cpl_func,
"Zero point : %g", avg_zp);
631 cpl_msg_info(cpl_func,
"Zero p. RMS: %g", zpointrms);
633 cpl_propertylist_append_double(qclist,
"ESO QC ZPOINT", avg_zp);
634 cpl_propertylist_append_double(qclist,
"ESO QC ZPOINTRMS", zpointrms);
635 cpl_propertylist_append_double(qclist,
"ESO QC STREHL", strehl);
636 cpl_propertylist_append_double(qclist,
"ESO QC STREHL ERROR", strehl_err);
637 cpl_propertylist_append_double(qclist,
"ESO QC STREHL RMS", strehl_rms);
638 cpl_propertylist_append_double(qclist,
"ESO QC STREHL PEAK", star_peak);
639 cpl_propertylist_append_double(qclist,
"ESO QC STREHL FLUX", star_flux);
640 cpl_propertylist_append_string(qclist,
"ESO QC FILTER OBS", filter);
646 cpl_image_delete(rawimage);
647 cpl_image_delete(imdiff);
648 cpl_image_delete(flat_im);
649 cpl_apertures_delete(aperts);
650 cpl_vector_unwrap(sigmas);
651 cpl_vector_delete(zpoints);
653 if (cpl_error_get_code()) {
654 cpl_image_delete(*pcheck_im);
656 cpl_table_delete(out_tab);
684 static cpl_error_code naco_img_zpoint_check_im(cpl_image **
self,
685 const cpl_image * imdiff,
694 const float * pin_ima = cpl_image_get_data_float_const(imdiff);
696 const int in_nx = cpl_image_get_size_x(imdiff);
697 const int in_ny = cpl_image_get_size_y(imdiff);
698 const int box_sz = 2 * (int)r3 + 1;
699 const int nx = box_sz * nima;
700 const int ny = box_sz;
702 const int llx = (int)(pos_x - r3);
703 const int lly = (int)(pos_y - r3);
709 bug_if(
self == NULL);
715 bug_if(*
self != NULL);
717 cpl_msg_info(cpl_func,
"Creating %d X %d X %d check-image",
718 nima, box_sz, box_sz);
721 *
self = cpl_image_new(nx, ny, CPL_TYPE_FLOAT);
724 pout_ima = cpl_image_get_data_float(*
self);
728 for (j=0; j < box_sz; j++) {
729 if (j + lly < 0 || j + lly >= in_ny)
continue;
730 for (i=0; i < box_sz; i++) {
731 if (i + llx >= 0 && i + llx < in_nx) {
732 const int in_pos = llx + i + (lly+j) * in_nx;
733 const int out_pos = (box_sz * idiff) + i + j * nx;
735 bug_if ( in_pos < 0 || in_pos >= in_nx*in_ny);
736 bug_if (out_pos < 0 || out_pos >= nx* ny);
738 pout_ima[out_pos] = pin_ima[in_pos];
745 const double sqr1 = sqrt(r1*r1);
746 const double sqr2 = sqrt(r2*r2);
747 const double sqr3 = sqrt(r3*r3);
748 for (j=0; j < box_sz; j++) {
749 const int jdist = j - box_sz/2;
750 for (i=0; i < box_sz; i++) {
751 const int idist = i - box_sz/2;
753 = sqrt((
double)(idist * idist + jdist * jdist));
754 if (fabs(dist-sqr1) < 0.5 ||
755 fabs(dist-sqr2) < 0.5 ||
756 fabs(dist-sqr3) < 0.5) pout_ima[i + j * nx] = 10000;
763 return cpl_error_get_code();
789 cpl_error_code naco_img_zpoint_reduce_one(cpl_table * zptab,
790 cpl_vector * zpoints,
792 const cpl_image * ima,
793 const cpl_parameterlist * parlist,
799 double * pstrehl_err,
804 cpl_errorstate cleanstate = cpl_errorstate_get();
805 double zeropoint, background;
808 double star_bg, psf_peak, psf_flux;
809 double fwhm_x, fwhm_y;
812 bug_if(pstar_flux == NULL);
813 bug_if(filter == NULL);
816 r = naco_img_zpoint_config.phot_star_radius/naco_img_zpoint_config.pscale;
817 r1 = naco_img_zpoint_config.phot_bg_r1/naco_img_zpoint_config.pscale;
818 r2 = naco_img_zpoint_config.phot_bg_r2/naco_img_zpoint_config.pscale;
819 background = irplib_strehl_ring_background(ima, pos_x, pos_y, r1, r2,
820 IRPLIB_BG_METHOD_AVER_REJ);
822 *pstar_flux = irplib_strehl_disk_flux(ima, pos_x, pos_y, r, background);
827 "Cannot get filter infos [%s]", filter);
832 naco_img_zpoint_config.pscale,
833 pstrehl, pstrehl_err, &star_bg,
834 pstar_peak, pstar_flux,
835 &psf_peak, &psf_flux, pbg_noise),
836 "Could not compute the Strehl ratio");
839 if (cpl_image_get_fwhm(ima, (
int)pos_x, (
int)pos_y, &fwhm_x, &fwhm_y)) {
840 irplib_error_recover(cleanstate,
"Could not compute FWHM for image %d:",
842 fwhm_x = fwhm_y = 0.0;
845 cpl_msg_warning(cpl_func,
"Could not compute FWHM in x for image "
850 cpl_msg_warning(cpl_func,
"Could not compute FWHM in y for image "
856 zeropoint = naco_img_zpoint_config.magnitude + 2.5 * log10(*pstar_flux/dit);
858 cpl_msg_info(cpl_func,
"Strehl : %g", *pstrehl);
859 cpl_msg_info(cpl_func,
"Strehl error : %g", *pstrehl_err);
860 cpl_msg_info(cpl_func,
"Peak : %g", *pstar_peak);
861 cpl_msg_info(cpl_func,
"Flux : %g", *pstar_flux);
862 cpl_msg_info(cpl_func,
"Background : %g", background);
863 cpl_msg_info(cpl_func,
"Bg noise : %g", *pbg_noise);
864 cpl_msg_info(cpl_func,
"Zero point : %g", zeropoint);
865 cpl_msg_info(cpl_func,
"FWHM in x : %g", fwhm_x);
866 cpl_msg_info(cpl_func,
"FWHM in y : %g", fwhm_y);
869 cpl_vector_set(zpoints, idiff, zeropoint);
870 cpl_table_set_double(zptab,
"POSX", idiff, pos_x);
871 cpl_table_set_double(zptab,
"POSY", idiff, pos_y);
872 cpl_table_set_double(zptab,
"ZPOINT", idiff, zeropoint);
873 cpl_table_set_double(zptab,
"PEAK", idiff, *pstar_peak);
874 cpl_table_set_double(zptab,
"FLUX", idiff, *pstar_flux);
875 cpl_table_set_double(zptab,
"BGD_NOISE", idiff, *pbg_noise);
876 cpl_table_set_double(zptab,
"STREHL", idiff, *pstrehl);
877 cpl_table_set_double(zptab,
"STREHL_ERR", idiff, *pstrehl_err);
878 cpl_table_set_double(zptab,
"BGD", idiff, background);
879 cpl_table_set_double(zptab,
"FWHMX", idiff, fwhm_x);
880 cpl_table_set_double(zptab,
"FWHMY", idiff, fwhm_y);
886 if (cpl_error_get_code())
887 cpl_msg_error(cpl_func,
"Cannot reduce the image %d", idiff+1);
889 return cpl_error_get_code();
904 static double naco_img_zpoint_find_mag(cpl_propertylist * qclist,
907 const char * star_cat,
910 cpl_error_code error;
911 const char * star_name;
912 const char * star_type;
913 const char * cat_name;
915 double star_mag = 0.0;
917 const char * bandname = NULL;
918 cpl_table * stdstars = NULL;
919 const char * sw_cat[] = {
"LCO-Palomar",
"LCO-Palomar-NICMOS-Red-Stars",
920 "ESO-VanDerBliek",
"UKIRT-Extended",
921 "UKIRT-Fundamental",
"SAAO-Carter", NULL};
922 const char * lw_cat[] = {
"ESO-VanDerBliek",
"UKIRT-Standards",
925 bug_if (filter == NULL);
927 cpl_msg_info(cpl_func,
"Get the star magnitude with filter: %s", filter);
929 band = naco_get_bbfilter(filter);
934 stdstars = naco_img_zpoint_load_std_star(star_cat, ra, dec,
935 (IRPLIB_STDSTAR_MAXDIST)/60.0);
937 skip_if(stdstars == NULL);
938 skip_if(cpl_table_get_nrow(stdstars) == 0);
949 bandname = naco_std_band_name(band);
951 error = naco_img_zpoint_find_std_star(stdstars, sw_cat, ra, dec,
952 bandname, CPL_FALSE, &istar);
955 if (istar >= 0)
break;
959 if (band == BAND_K) {
960 bandname = naco_std_band_name(BAND_KS);
962 cpl_msg_info(cpl_func,
"Retrying with alternative band: %s",
965 error = naco_img_zpoint_find_std_star(stdstars, sw_cat, ra, dec,
966 bandname, CPL_TRUE, &istar);
968 }
else if (band == BAND_KS) {
969 bandname = naco_std_band_name(BAND_K);
971 cpl_msg_info(cpl_func,
"Retrying with alternative band: %s",
974 error = naco_img_zpoint_find_std_star(stdstars, sw_cat, ra, dec,
975 bandname, CPL_TRUE, &istar);
985 bandname = naco_std_band_name(band);
987 error = naco_img_zpoint_find_std_star(stdstars, lw_cat, ra, dec,
988 bandname, CPL_FALSE, &istar);
992 naco_band other = BAND_UNKNOWN;
1011 bandname = naco_std_band_name(other);
1013 cpl_msg_info(cpl_func,
"Retrying with alternative band: %s",
1016 error = naco_img_zpoint_find_std_star(stdstars, lw_cat, ra, dec,
1017 bandname, CPL_TRUE, &istar);
1024 error_if (error || istar < 0, CPL_ERROR_DATA_NOT_FOUND,
"Star magnitude "
1025 "for filter '%s' not found in catalog(s) at (RA,DEC)=(%g,%g)"
1026 " with tolerance=%g (degrees)", filter, ra, dec,
1027 IRPLIB_STDSTAR_MAXDIST/60.0);
1029 star_mag = cpl_table_get_double(stdstars, bandname, istar, NULL);
1030 star_name = cpl_table_get_string(stdstars, IRPLIB_STDSTAR_STAR_COL, istar);
1031 star_type = cpl_table_get_string(stdstars, IRPLIB_STDSTAR_TYPE_COL, istar);
1032 cat_name = cpl_table_get_string(stdstars,
"CAT_NAME", istar);
1036 bug_if(cpl_propertylist_append_string(qclist,
"ESO QC STDNAME",
1038 bug_if(cpl_propertylist_append_string(qclist,
"ESO QC CATNAME",
1040 bug_if(cpl_propertylist_append_string(qclist,
"ESO QC SPECTYPE",
1043 cpl_msg_info(cpl_func,
"Found standard star '%s' of type '%s' with "
1044 "magnitude %g for filter %s from catalog '%s'",
1045 star_name, star_type, star_mag, bandname, cat_name);
1049 cpl_table_delete(stdstars);
1078 static cpl_error_code naco_img_zpoint_find_std_star(cpl_table *
self,
1080 double ra,
double dec,
1081 const char * bandname,
1086 double min_dist = IRPLIB_STDSTAR_MAXDIST / 60.0;
1089 bug_if (pistar == NULL);
1092 bug_if (
self == NULL);
1093 bug_if (bandname == NULL);
1096 ? cpl_table_or_selected_double
1097 : cpl_table_and_selected_double)(
self, bandname,
1099 IRPLIB_STDSTAR_LIMIT);
1102 cpl_msg_info(cpl_func,
"None of the standard star catalog(s) have "
1103 "a star with a known magnitude for band %s within a "
1104 "distance of tol=%g [degrees] from (RA,DEC)=(%g,%g)",
1105 bandname, min_dist, ra, dec);
1111 const int nrows = cpl_table_get_nrow(
self);
1117 bug_if (cat == NULL);
1119 for (icat = 0; cat[icat] != NULL; icat++) {
1121 char * regexp = cpl_sprintf(
"^%s$", cat[icat]);
1123 cpl_msg_info(cpl_func,
"Trying %s", cat[icat]);
1125 nsel = cpl_table_and_selected_string(
self,
"CAT_NAME",
1126 CPL_EQUAL_TO, regexp);
1129 if (nsel > 0)
break;
1132 nsel = cpl_table_or_selected_double(
self, bandname,
1134 IRPLIB_STDSTAR_LIMIT);
1142 for (i=0; i < nrows; i++) {
1143 if (cpl_table_is_selected(
self, i)) {
1145 const double distance
1146 = irplib_wcs_great_circle_dist(ra, dec,
1147 cpl_table_get_double(
self, IRPLIB_STDSTAR_RA_COL, i, NULL),
1148 cpl_table_get_double(
self, IRPLIB_STDSTAR_DEC_COL, i,NULL));
1150 if (distance < min_dist) {
1151 min_dist = distance;
1159 cpl_msg_info(cpl_func,
"Found %d star(s) with known magnitude in band "
1160 "%s - selected one with distance %g", nsel, bandname,
1168 return cpl_error_get_code();
1182 static cpl_error_code naco_img_zpoint_qc(cpl_propertylist * qclist,
1183 cpl_propertylist * paflist,
1184 const irplib_framelist * rawframes)
1187 cpl_errorstate cleanstate = cpl_errorstate_get();
1188 const cpl_propertylist * reflist
1197 bug_if(cpl_propertylist_copy_property_regexp(paflist, reflist,
"^("
1198 NACO_PFITS_REGEXP_ZPOINT_PAF
1205 naco_error_reset(
"Could not get FITS key:");
1207 bug_if(cpl_propertylist_append_string(qclist,
"ESO QC FILTER NDENS",
1211 naco_error_reset(
"Could not get FITS key:");
1213 bug_if(cpl_propertylist_append_string(qclist,
"ESO QC FILTER POL",
1216 skip_if (naco_img_zpoint_qc_all(qclist, paflist, rawframes));
1218 bug_if(cpl_propertylist_append(paflist, qclist));
1220 bug_if(cpl_propertylist_copy_property_regexp(qclist, reflist,
"^("
1221 IRPLIB_PFITS_REGEXP_RECAL
1225 bug_if(cpl_propertylist_append_double(qclist,
"ESO QC AIRMASS",
1226 irplib_pfits_get_double(qclist,
1231 return cpl_error_get_code();
1247 static cpl_error_code naco_img_zpoint_save(cpl_frameset * set,
1248 const cpl_parameterlist * parlist,
1249 const cpl_propertylist * qclist,
1250 const cpl_propertylist * paflist,
1251 const cpl_table * tab,
1252 const cpl_image * check_im)
1259 NACO_IMG_ZPOINT_RES, qclist, NULL, naco_pipe_id,
1260 RECIPE_STRING CPL_DFS_FITS));
1266 CPL_BPP_IEEE_FLOAT, RECIPE_STRING,
1267 NACO_IMG_ZPOINT_CHECK, qclist, NULL,
1269 RECIPE_STRING
"_check" CPL_DFS_FITS));
1271 skip_if (cpl_dfs_save_paf(
"NACO", RECIPE_STRING, paflist,
1272 RECIPE_STRING CPL_DFS_PAF));
1276 return cpl_error_get_code();
1289 static cpl_error_code naco_img_zpoint_qc_all(cpl_propertylist * qclist,
1290 cpl_propertylist * paflist,
1291 const irplib_framelist * rawframes)
1294 cpl_vector * ec_vec = cpl_vector_new(nframes);
1295 cpl_vector * flux_vec = cpl_vector_new(nframes);
1296 cpl_vector * l0_vec = cpl_vector_new(nframes);
1297 cpl_vector * t0_vec = cpl_vector_new(nframes);
1298 cpl_vector * r0_vec = cpl_vector_new(nframes);
1299 cpl_vector * hum_vec = cpl_vector_new(nframes);
1300 double ec, flux, l0, t0, r0, hum;
1306 bug_if(nframes <= 0);
1308 for (i = 0; i < nframes; i++) {
1309 const cpl_propertylist * plist
1319 skip_if(cpl_vector_set(hum_vec, i,
1326 ec = cpl_vector_get_median(ec_vec);
1327 flux = cpl_vector_get_median(flux_vec);
1328 l0 = cpl_vector_get_median(l0_vec);
1329 t0 = cpl_vector_get_median(t0_vec);
1330 r0 = cpl_vector_get_median(r0_vec);
1331 hum = cpl_vector_get_mean(hum_vec);
1334 cpl_propertylist_append_double(qclist,
"ESO QC AMBI RHUM AVG", hum);
1335 cpl_propertylist_append_double(paflist,
1336 "ESO AOS RTC DET DST L0MEAN", l0);
1337 cpl_propertylist_append_double(paflist,
1338 "ESO AOS RTC DET DST T0MEAN", t0);
1339 cpl_propertylist_append_double(paflist,
1340 "ESO AOS RTC DET DST R0MEAN", r0);
1341 cpl_propertylist_append_double(paflist,
1342 "ESO AOS RTC DET DST ECMEAN", ec);
1343 cpl_propertylist_append_double(paflist,
1344 "ESO AOS RTC DET DST FLUXMEAN", flux);
1350 cpl_vector_delete(ec_vec);
1351 cpl_vector_delete(flux_vec);
1352 cpl_vector_delete(r0_vec);
1353 cpl_vector_delete(t0_vec);
1354 cpl_vector_delete(l0_vec);
1355 cpl_vector_delete(hum_vec);
1357 return cpl_error_get_code();
1369 static naco_band naco_get_bbfilter(
const char * filter)
1371 naco_band
self = BAND_UNKNOWN;
1374 bug_if (filter == NULL);
1376 if (!strcmp(filter,
"J"))
self = BAND_J;
1377 else if (!strcmp(filter,
"Jc"))
self = BAND_J;
1378 else if (!strcmp(filter,
"H"))
self = BAND_H;
1379 else if (!strcmp(filter,
"K"))
self = BAND_K;
1380 else if (!strcmp(filter,
"Ks"))
self = BAND_KS;
1381 else if (!strcmp(filter,
"L"))
self = BAND_L;
1382 else if (!strcmp(filter,
"L_prime"))
self = BAND_LP;
1383 else if (!strcmp(filter,
"M_prime"))
self = BAND_MP;
1384 else if (!strcmp(filter,
"NB_1.04"))
self = BAND_J;
1385 else if (!strcmp(filter,
"NB_1.08"))
self = BAND_J;
1386 else if (!strcmp(filter,
"NB_1.09"))
self = BAND_J;
1387 else if (!strcmp(filter,
"NB_1.24"))
self = BAND_J;
1388 else if (!strcmp(filter,
"NB_1.26"))
self = BAND_J;
1389 else if (!strcmp(filter,
"NB_1.28"))
self = BAND_J;
1390 else if (!strcmp(filter,
"NB_1.64"))
self = BAND_H;
1391 else if (!strcmp(filter,
"NB_1.75"))
self = BAND_H;
1392 else if (!strcmp(filter,
"NB_3.74"))
self = BAND_L;
1393 else if (!strcmp(filter,
"IB_2.00"))
self = BAND_K;
1394 else if (!strcmp(filter,
"IB_2.03"))
self = BAND_K;
1395 else if (!strcmp(filter,
"IB_2.06"))
self = BAND_K;
1396 else if (!strcmp(filter,
"IB_2.09"))
self = BAND_K;
1397 else if (!strcmp(filter,
"IB_2.12"))
self = BAND_K;
1398 else if (!strcmp(filter,
"NB_2.12"))
self = BAND_K;
1399 else if (!strcmp(filter,
"IB_2.15"))
self = BAND_K;
1400 else if (!strcmp(filter,
"NB_2.17"))
self = BAND_K;
1401 else if (!strcmp(filter,
"IB_2.18"))
self = BAND_K;
1402 else if (!strcmp(filter,
"IB_2.21"))
self = BAND_K;
1403 else if (!strcmp(filter,
"IB_2.24"))
self = BAND_K;
1404 else if (!strcmp(filter,
"IB_2.27"))
self = BAND_K;
1405 else if (!strcmp(filter,
"IB_2.30"))
self = BAND_K;
1406 else if (!strcmp(filter,
"IB_2.33"))
self = BAND_K;
1407 else if (!strcmp(filter,
"IB_2.36"))
self = BAND_K;
1408 else if (!strcmp(filter,
"IB_2.39"))
self = BAND_K;
1409 else if (!strcmp(filter,
"IB_2.42"))
self = BAND_K;
1410 else if (!strcmp(filter,
"IB_2.45"))
self = BAND_K;
1411 else if (!strcmp(filter,
"IB_2.48"))
self = BAND_K;
1412 else if (!strcmp(filter,
"NB_4.05"))
self = BAND_M;
1414 else if (!strcmp(filter,
"IB_4.05"))
self = BAND_M;
1415 else if (!strcmp(filter,
"SJ"))
self = BAND_UNKNOWN;
1416 else if (!strcmp(filter,
"SH"))
self = BAND_UNKNOWN;
1417 else if (!strcmp(filter,
"SK"))
self = BAND_UNKNOWN;
1419 error_if (
self == BAND_UNKNOWN, CPL_ERROR_UNSUPPORTED_MODE,
"No broad-"
1420 "band could be associated with the filter: %s", filter);
1440 static cpl_table * naco_img_zpoint_load_std_star(
const char * star_cat,
1441 double ra,
double dec,
1445 cpl_table *
self = cpl_table_load(star_cat, 1, 0);
1447 = cpl_table_get_data_double_const(
self, IRPLIB_STDSTAR_RA_COL);
1449 = cpl_table_get_data_double_const(
self, IRPLIB_STDSTAR_DEC_COL);
1450 const int nrow = cpl_table_get_nrow(
self);
1453 skip_if(
self == NULL);
1454 bug_if(star_cat == NULL);
1455 skip_if(pra == NULL);
1456 skip_if(pdec == NULL);
1459 bug_if(cpl_table_unselect_all(
self));
1461 for (i = 0; i < nrow; i++) {
1462 const double deci = pdec[i];
1464 if (deci > dec + tol ||
1466 irplib_wcs_great_circle_dist(ra, dec, pra[i], deci) > tol) {
1468 bug_if(cpl_table_select_row(
self, i));
1473 if (cpl_table_count_selected(
self) == nrow) {
1474 double mindist = DBL_MAX;
1477 for (i = 0; i < nrow; i++) {
1479 = irplib_wcs_great_circle_dist(ra, dec, pra[i], pdec[i]);
1481 if (i == 0 || dist < mindist) {
1487 (void)cpl_error_set_message_macro(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
1488 __FILE__, __LINE__,
"Catalog '%s' "
1489 "star %d of %d at (RA,DEC)=(%g,%g) "
1490 "is closest to target at "
1491 "(RA,DEC)=(%g,%g) with a too large "
1492 "distance of %g [degrees] > %g",
1493 star_cat, 1+idist, nrow, pra[idist],
1494 pdec[idist], ra, dec, mindist, tol);
1497 bug_if(cpl_table_erase_selected(
self));
1499 cpl_msg_info(cpl_func,
"Loaded %d of %d stars from '%s' which are within "
1500 "%g degrees from (RA,DEC)=(%g,%g)",
1501 (
int)cpl_table_get_nrow(
self), nrow, star_cat, tol, ra, dec);
1502 if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
1503 cpl_table_dump(
self, 0, cpl_table_get_nrow(
self), stdout);
1520 static const char * naco_std_band_name(naco_band band)
1523 case BAND_J:
return "J";
1524 case BAND_JS:
return "Js";
1525 case BAND_JBLOCK:
return "J+Block";
1526 case BAND_H:
return "H";
1527 case BAND_K:
return "K";
1528 case BAND_KS:
return "Ks";
1529 case BAND_L:
return "L";
1530 case BAND_M:
return "M";
1531 case BAND_LP:
return "Lp";
1532 case BAND_MP:
return "Mp";
1533 case BAND_Z:
return "Z";
1534 case BAND_SZ:
return "SZ";
1535 case BAND_SH:
return "SH";
1536 case BAND_SK:
return "SK";
1537 case BAND_SL:
return "SL";
1538 default:
return "Unknown";
cpl_error_code irplib_dfs_save_table(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_table *table, const cpl_propertylist *tablelist, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)
Save a table as a DFS-compliant pipeline product.
cpl_error_code naco_strehl_compute(const cpl_image *self, const cpl_parameterlist *parlist, const char *recipename, double lam, double dlam, double pos_x, double pos_y, double pixscale, double *pstrehl, double *pstrehl_err, double *pstar_bg, double *pstar_peak, double *pstar_flux, double *ppsf_peak, double *ppsf_flux, double *pbg_noise)
Compute the strehl ratio in an image.
double naco_pfits_get_dit(const cpl_propertylist *self)
find out the DIT
double naco_pfits_get_pixscale(const cpl_propertylist *self)
find out the pixel scale
double naco_pfits_get_cumoffsety(const cpl_propertylist *self)
find out the cumulative offset in Y
const char * naco_pfits_get_opti4_name(const cpl_propertylist *self)
find out the OPTI4.NAME key
cpl_error_code naco_get_filter_infos(const char *f, double *lam, double *dlam)
Get the infos of one of the filters.
double naco_pfits_get_t0mean(const cpl_propertylist *self)
find out the T0MEAN key
double naco_pfits_get_ra(const cpl_propertylist *self)
find out the RA
int naco_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
double naco_pfits_get_cumoffsetx(const cpl_propertylist *self)
find out the cumulative offset in X
cpl_error_code irplib_pfits_set_airmass(cpl_propertylist *self, const irplib_framelist *rawframes)
Update/Set the AIRMASS property.
double naco_pfits_get_dec(const cpl_propertylist *self)
find out the DEC
irplib_framelist * irplib_framelist_extract_regexp(const irplib_framelist *self, const char *regexp, cpl_boolean invert)
Extract the frames with the given tag from a framelist.
double naco_pfits_get_l0mean(const cpl_propertylist *self)
find out the L0MEAN
int naco_parameterlist_get_int(const cpl_parameterlist *self, const char *recipe, naco_parameter bitmask)
Retrieve the value of a NACO integer parameter.
const cpl_propertylist * irplib_framelist_get_propertylist_const(const irplib_framelist *self, int pos)
Get the propertylist of the specified frame in the framelist.
void irplib_framelist_empty(irplib_framelist *self)
Erase all frames from a framelist.
cpl_error_code irplib_dfs_save_image(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_image *image, cpl_type_bpp bpp, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)
Save an image as a DFS-compliant pipeline product.
cpl_error_code irplib_framelist_load_propertylist_all(irplib_framelist *self, int ind, const char *regexp, cpl_boolean invert)
Load the propertylists of all frames in the framelist.
double naco_parameterlist_get_double(const cpl_parameterlist *self, const char *recipe, naco_parameter bitmask)
Retrieve the value of a NACO parameter of type double.
cpl_boolean naco_parameterlist_get_bool(const cpl_parameterlist *self, const char *recipe, naco_parameter bitmask)
Retrieve the value of a NACO boolean parameter.
double naco_pfits_get_fluxmean(const cpl_propertylist *self)
find out the FLUXMEAN key
double naco_pfits_get_humidity_level(const cpl_propertylist *self)
find out the humidity level
const char * naco_pfits_get_object(const cpl_propertylist *self)
Get the Object name.
const cpl_frame * irplib_framelist_get_const(const irplib_framelist *self, int pos)
Get the specified frame from the framelist.
const char * naco_pfits_get_opti3_name(const cpl_propertylist *self)
find out the OPTI3.NAME key
void irplib_framelist_delete(irplib_framelist *self)
Deallocate an irplib_framelist with its frames and properties.
const char * irplib_frameset_find_file(const cpl_frameset *self, const char *tag)
Find the filename with the given tag in a frame set.
double naco_pfits_get_r0mean(const cpl_propertylist *self)
find out the R0MEAN key
cpl_error_code irplib_framelist_load_propertylist(irplib_framelist *self, int pos, int ind, const char *regexp, cpl_boolean invert)
Load the propertylist of the specified frame in the framelist.
irplib_framelist * irplib_framelist_cast(const cpl_frameset *frameset)
Create an irplib_framelist from a cpl_framelist.
int irplib_framelist_get_size(const irplib_framelist *self)
Get the size of a framelist.
double naco_pfits_get_ecmean(const cpl_propertylist *self)
find out the ECMEAN key
const char * naco_pfits_get_filter(const cpl_propertylist *self)
find out the filter