29 #include "visir_recipe.h"
30 #include "visir_pfits.h"
31 #include "irplib_strehl.h"
32 #include "irplib_framelist.h"
37 #define SQR(a) ((a) * (a))
43 #define VISIR_IMG_PHOT_POS_WARN 10.0
44 #define VISIR_IMG_PHOT_POS_ERROR 25.0
45 #define VISIR_IMG_PHOT_POS_UNCERTAINTY 10.0
48 #define STREHL_BOX_SIZE 64
49 #define STREHL_STAR_RADIUS 2.0
50 #define STREHL_BG_R1 2.0
51 #define STREHL_BG_R2 3.0
53 #define RECIPE_STRING "visir_old_img_phot"
55 #define RECIPE_SAVE_STRING "visir_img_phot"
59 #define RECIPE_KEYS_REGEXP_ALL \
60 VISIR_PFITS_REGEXP_IMG_RECOMBINE \
61 "|" VISIR_PFITS_REGEXP_IMG_SENSIT
64 #define RECIPE_KEYS_REGEXP \
65 RECIPE_KEYS_REGEXP_ALL \
66 "|" VISIR_PFITS_IMG_PHOT_COPY \
67 "|" VISIR_PFITS_REGEXP_IMG_PHOT_PAF
70 #define RECIPE_KEYS_REGEXP_WCS \
72 "|" IRPLIB_PFITS_WCS_REGEXP
81 double fwhm_x, fwhm_y;
83 double peak, peak_err;
84 double major, major_err;
85 double minor, minor_err;
86 double angle, angle_err;
90 static double visir_img_phot_eccent_four(
const cpl_apertures *,
int,
int,
91 const cpl_apertures *,
int,
int);
93 static int visir_img_phot_flux_one(
const cpl_image *,
const cpl_image *,
94 const cpl_image *,
const cpl_propertylist *);
95 #ifdef VISIR_IMG_PHOT_USE_ECCENT_THREE
96 static double visir_img_phot_eccent_three(
const cpl_apertures *,
int,
97 const cpl_apertures *,
int,
int);
100 static double visir_img_phot_jy_from_cat(
const char *,
const char *,
double,
101 double,
const char *);
102 static int visir_img_phot_sensit(
const cpl_image *,
const cpl_image *,
103 const cpl_image *,
const irplib_framelist *,
104 const char *, cpl_boolean, cpl_propertylist *);
105 static int visir_img_phot_flux_three(
const cpl_image *);
106 static int visir_img_phot_flux_four(
const cpl_image *);
107 static int visir_img_phot_flux(
const cpl_image *,
const cpl_image *,
108 const cpl_image *,
double,
109 double,
int,
int,
int,
double *,
112 static cpl_error_code visir_get_filter_infos(
const char *,
double *,
double *);
114 static cpl_error_code visir_img_phot_qc(cpl_propertylist *,
116 const irplib_framelist *);
118 static cpl_error_code visir_img_phot_save(cpl_frameset *,
119 const cpl_parameterlist *,
120 const cpl_propertylist *,
127 static char * visir_img_phot_filter2label(
const char *);
130 #define cpl_plugin_get_info visir_old_img_phot_get_info
132 VISIR_RECIPE_DEFINE(visir_old_img_phot,
133 VISIR_PARAM_RADII | VISIR_PARAM_JYVAL |
134 VISIR_PARAM_REFINE | VISIR_PARAM_XCORR |
135 VISIR_PARAM_OFFSETS | VISIR_PARAM_OBJECTS |
136 VISIR_PARAM_NODPOS | VISIR_PARAM_AUTOBPM |
137 VISIR_PARAM_GLITCH | VISIR_PARAM_PURGE |
138 VISIR_PARAM_UNION | VISIR_PARAM_REJECT |
139 VISIR_PARAM_COMBINE | VISIR_PARAM_ECCMAX |
140 VISIR_PARAM_STRIPITE | VISIR_PARAM_STRIPMOR |
142 "Old DRS detector: Sensitivity computation",
143 "This recipe computes the conversion factor and the "
145 "standard star. It requires a standard star catalog.\n"
146 "The files listed in the Set Of Frames (sof-file) "
148 "VISIR-std-star-observation.fits " VISIR_IMG_PHOT_RAW
150 "VISIR-Imaging-Standard-Star-Catalog.fits "
151 VISIR_IMA_STD_CAT_PROCATG
"\n"
153 "The primary product will have a FITS card\n"
154 "'HIERARCH " CPL_DFS_PRO_CATG
"' with a string value of\n"
155 "'" VISIR_IMG_PHOT_COMBINED_PROCATG
"'\n"
156 " and the corresponding beam-collapsed product will "
158 "'HIERARCH " CPL_DFS_PRO_CATG
"' with a value of\n"
159 VISIR_IMG_PHOT_ONEBEAM_PROCATG
161 MAN_VISIR_CALIB_BPM_IMG);
167 static const int fits_strlen = IRPLIB_FITS_STRLEN;
179 char star_name[IRPLIB_FITS_STRLEN+1];
180 char filter[IRPLIB_FITS_STRLEN+1];
183 double flux_snr_noise;
184 int flux_snr_radius[4];
202 } visir_img_phot_config;
216 static cpl_error_code
217 propagate_qc_header(cpl_propertylist * qclist,
const cpl_propertylist * ppqc)
223 s = cpl_propertylist_get_string(ppqc,
"BUNIT");
224 cpl_propertylist_append_string(qclist,
"BUNIT", s);
226 d = cpl_propertylist_get_double(ppqc,
"ESO QC BACKGD MEAN");
227 cpl_propertylist_append_double(qclist,
"ESO QC BACKGD MEAN", d);
229 d = cpl_propertylist_get_double(ppqc,
"ESO QC EXPTIME EFFECTIVE");
230 cpl_propertylist_append_double(qclist,
"ESO QC EXPTIME EFFECTIVE", d);
232 if (cpl_propertylist_has(ppqc,
"ESO QC EXECTIME")) {
233 d = cpl_propertylist_get_double(ppqc,
"ESO QC EXECTIME");
234 cpl_propertylist_append_double(qclist,
"ESO QC EXECTIME", d);
237 i = cpl_propertylist_get_int(ppqc,
"ESO QC NIMAGES TOTAL");
238 cpl_propertylist_append_int(qclist,
"ESO QC NIMAGES TOTAL", i);
240 i = cpl_propertylist_get_int(ppqc,
"ESO QC NIMAGES EFFECTIVE");
241 cpl_propertylist_append_int(qclist,
"ESO QC NIMAGES EFFECTIVE", i);
243 s = cpl_propertylist_get_string(ppqc,
"ESO QC BEAMID");
244 cpl_propertylist_append_string(qclist,
"ESO QC BEAMID", s);
246 error_if(strcmp(s,
"UNDEFINED") == 0, CPL_ERROR_ILLEGAL_INPUT,
247 "Object detection was not successful, "
248 "please provide visir_util_detect_position with the object "
249 "positions to allow photometry");
250 if (strcmp(s,
"COMBINED") != 0) {
251 d = cpl_propertylist_get_double(ppqc,
"ESO QC BEAMX");
252 cpl_propertylist_append_double(qclist,
"ESO QC BEAMX", d);
254 d = cpl_propertylist_get_double(ppqc,
"ESO QC BEAMY");
255 cpl_propertylist_append_double(qclist,
"ESO QC BEAMY", d);
260 return cpl_error_get_code();
272 static int visir_old_img_phot(cpl_frameset * framelist,
273 const cpl_parameterlist * parlist)
275 cpl_errorstate cleanstate = cpl_errorstate_get();
276 irplib_framelist * allframes = NULL;
277 irplib_framelist * rawframes = NULL;
278 cpl_propertylist * ppqc = NULL;
279 cpl_propertylist * qclist = NULL;
281 const char * star_cat;
283 cpl_image * weights = NULL;
284 cpl_image * contrib = NULL;
285 cpl_image ** combined = NULL;
286 cpl_image ** beam1 = NULL;
288 cpl_boolean drop_wcs = CPL_FALSE;
289 const char * keys_regexp =
"^(" RECIPE_KEYS_REGEXP_WCS
290 "|"VISIR_PFITS_REGEXP_DIT
292 const char * combine_string;
293 cpl_geom_combine combine_mode;
294 cpl_boolean one_beam = CPL_FALSE;
295 const char * dit_key = VISIR_PFITS_DOUBLE_DIT;
299 visir_img_phot_config.exptime = -1.0;
300 visir_img_phot_config.pscale = -1.0;
301 visir_img_phot_config.star_name[0] = (char)0;
302 visir_img_phot_config.filter[0] = (char)0;
303 visir_img_phot_config.bg_sigma = -1.0;
304 visir_img_phot_config.flux_snr = -1.0;
305 visir_img_phot_config.flux_snr_noise = -1.0;
306 visir_img_phot_config.flux_snr_radius[0] = -1;
307 visir_img_phot_config.flux_snr_radius[1] = -1;
308 visir_img_phot_config.flux_snr_radius[2] = -1;
309 visir_img_phot_config.flux_snr_radius[3] = -1;
310 visir_img_phot_config.flux_tot = -1.0;
311 visir_img_phot_config.nelec = -1.0;
312 visir_img_phot_config.nphot = -1.0;
313 visir_img_phot_config.beamshape =
315 .peak = -1., .peak_err = 0.,
316 .major = -1., .major_err = 0.,
317 .minor = -1., .minor_err = 0.,
318 .angle = -1., .angle_err = 0.};
319 visir_img_phot_config.fwhm_x_pos1 = -1.0;
320 visir_img_phot_config.fwhm_y_pos1 = -1.0;
321 visir_img_phot_config.fwhm_x_pos2 = -1.0;
322 visir_img_phot_config.fwhm_y_pos2 = -1.0;
323 visir_img_phot_config.fwhm_x_neg1 = -1.0;
324 visir_img_phot_config.fwhm_y_neg1 = -1.0;
325 visir_img_phot_config.fwhm_x_neg2 = -1.0;
326 visir_img_phot_config.fwhm_y_neg2 = -1.0;
327 visir_img_phot_config.sensitivity = -1.0;
328 visir_img_phot_config.area_sensit = -1.0;
329 visir_img_phot_config.conversion = -1.0;
330 visir_img_phot_config.strehl = -1.0;
331 visir_img_phot_config.strehl_err = -1.0;
335 VISIR_PARAM_COMBINE);
337 bug_if (combine_string == NULL);
339 if (combine_string[0] ==
'u')
340 combine_mode = CPL_GEOM_UNION;
341 else if (combine_string[0] ==
'f')
342 combine_mode = CPL_GEOM_FIRST;
343 else if (combine_string[0] ==
'i')
344 combine_mode = CPL_GEOM_INTERSECT;
349 visir_img_phot_config.jy_val =
354 skip_if (sval == NULL);
356 skip_if (sscanf(sval,
"%d%*c%d%*c%d",
357 &visir_img_phot_config.r0_max,
358 &visir_img_phot_config.r1,
359 &visir_img_phot_config.r2) != 3);
366 skip_if(allframes == NULL);
369 if (rawframes == NULL) {
370 cpl_errorstate_set(cleanstate);
372 "IM_CAL_PHOT_PREPROCESSED");
373 skip_if (rawframes == NULL);
377 cpl_msg_error(cpl_func,
"The input files has no header tagged "
378 "%s", VISIR_UTIL_QC_PROCATG);
379 visir_error_set(CPL_ERROR_DATA_NOT_FOUND);
382 ppqc = cpl_propertylist_load(fn, 0);
387 skip_if (rawframes == NULL);
395 skip_if(propagate_qc_header(qclist, ppqc));
398 RECIPE_KEYS_REGEXP_ALL
399 "|"VISIR_PFITS_REGEXP_DIT
405 VISIR_PFITS_DOUBLE_SEQ1_DIT))
406 dit_key = VISIR_PFITS_DOUBLE_SEQ1_DIT;
411 if (star_cat == NULL) {
412 cpl_msg_error(cpl_func,
"The input files has no star catalog tagged "
413 "%s", VISIR_CALIB_STDSTAR_IMG);
414 visir_error_set(CPL_ERROR_DATA_NOT_FOUND);
427 CPL_TYPE_DOUBLE, CPL_FALSE, 0.0));
429 CPL_TYPE_DOUBLE, CPL_TRUE, 1e-5)) {
432 visir_error_reset(
"DIT differs by more than %g", 1e-5);
437 CPL_TYPE_DOUBLE, CPL_FALSE, 0.0));
441 CPL_TYPE_DOUBLE, CPL_TRUE, 1.0));
444 CPL_TYPE_INT, CPL_TRUE, 0.0));
447 CPL_TYPE_INT, CPL_TRUE, 0.0));
450 CPL_TYPE_STRING, CPL_TRUE, 0.0));
453 CPL_TYPE_STRING, CPL_TRUE, 0.0));
459 CPL_TYPE_STRING, CPL_TRUE, 0.0));
462 CPL_TYPE_STRING, CPL_TRUE, 0.0));
466 CPL_TYPE_STRING, CPL_TRUE, 0.0));
473 cpl_msg_info(cpl_func,
"Loading weight map %s", prew);
474 weights = cpl_image_load(prew, CPL_TYPE_UNSPECIFIED, 0, 0);
482 cpl_msg_info(cpl_func,
"Loading contribution map %s", prec);
483 contrib = cpl_image_load(prec, CPL_TYPE_INT, 0, 0);
489 cpl_msg_info(cpl_func,
"Combining the images");
494 combined = cpl_calloc(2,
sizeof(combined[0]));
495 combined[0] = cpl_image_load(pre, CPL_TYPE_UNSPECIFIED, 0, 0);
496 combined[1] = contrib ? cpl_image_duplicate(contrib) : NULL;
497 if (combined[0] == NULL) {
498 cpl_msg_error(cpl_func,
"Could not load the input frames");
502 cpl_mask * m = cpl_mask_threshold_image_create(weights, -1,
504 cpl_image_reject_from_mask(combined[0], m);
510 badpix, flat, combine_mode,
511 &drop_wcs, CPL_FALSE, 0.0, 0);
512 if (combined == NULL) {
513 cpl_msg_error(cpl_func,
"Could not combine the input frames");
521 irplib_error_recover(cleanstate,
"Could not collapse the "
522 "beams of the combined image");
526 skip_if(visir_qc_append_background(qclist, rawframes, 0, 0));
531 cpl_msg_info(cpl_func,
"Computing the sensitivity");
532 if (visir_img_phot_sensit(combined[0], weights, contrib, rawframes,
533 star_cat, one_beam, ppqc)) {
534 cpl_msg_error(cpl_func,
"Could not compute sensitivity: '%s' in %s",
535 cpl_error_get_message(), cpl_error_get_where());
539 skip_if (visir_img_phot_qc(qclist, drop_wcs, rawframes));
544 cpl_msg_info(cpl_func,
"Saving the combined image with its contribution "
546 skip_if (visir_img_phot_save(framelist, parlist, qclist, combined[0],
547 combined[1], NULL, NULL, weights));
549 cpl_msg_info(cpl_func,
"Saving the combined and the beam-combined "
550 "images with their contribution maps");
551 skip_if (visir_img_phot_save(framelist, parlist, qclist, combined[0],
552 combined[1], beam1[0], beam1[1], weights));
557 cpl_propertylist_delete(qclist);
560 cpl_propertylist_delete(ppqc);
561 cpl_image_delete(weights);
562 cpl_image_delete(contrib);
565 cpl_image_delete(combined[0]);
566 cpl_image_delete(combined[1]);
571 cpl_image_delete(beam1[0]);
572 cpl_image_delete(beam1[1]);
576 return cpl_error_get_code();
606 static int visir_img_phot_sensit(
const cpl_image * combined,
607 const cpl_image * weights,
608 const cpl_image * contrib,
609 const irplib_framelist * rawframes,
610 const char * star_cat,
611 cpl_boolean one_beam,
612 cpl_propertylist * ppqc)
614 cpl_errorstate cleanstate = cpl_errorstate_get();
615 const cpl_propertylist * plist = NULL;
631 exptime = cpl_propertylist_get_double(ppqc,
"ESO QC EXPTIME TOTAL");
634 exptime = visir_utils_get_exptime(nnod, plist);
636 visir_img_phot_config.exptime = exptime;
638 if (exptime <= 0 || cpl_error_get_code()) {
639 cpl_msg_error(cpl_func,
"Illegal exposure time: %g", exptime);
646 (void) strncpy(visir_img_phot_config.star_name, sval, fits_strlen);
650 (void)strncpy(visir_img_phot_config.filter, sval, fits_strlen);
662 if (visir_img_phot_config.jy_val < -998) {
663 visir_img_phot_config.jy_val =
664 visir_img_phot_jy_from_cat(star_cat, visir_img_phot_config.filter,
665 ra,dec, visir_img_phot_config.star_name);
666 skip_if (visir_img_phot_config.jy_val < -998);
670 cpl_msg_info(cpl_func,
"Star %s with filter %s : %g Jy",
671 visir_img_phot_config.star_name,
672 visir_img_phot_config.filter,
673 visir_img_phot_config.jy_val);
676 visir_img_phot_config.bg_sigma = visir_img_phot_sigma_clip(combined);
680 cpl_msg_info(cpl_func,
"Compute the star flux");
684 skip_if (visir_img_phot_flux_one(combined, weights, contrib, plist));
686 else if (sval != NULL && !strcmp(sval,
"PERPENDICULAR")) {
688 skip_if (visir_img_phot_flux_four(combined));
689 }
else if (sval != NULL && !strcmp(sval,
"PARALLEL")) {
691 skip_if (visir_img_phot_flux_three(combined));
694 visir_error_reset(
"Could not get FITS key");
696 cpl_msg_warning(cpl_func,
"Unknown chopping direction: %s", sval);
698 cpl_msg_warning(cpl_func,
"Proceeding as if FITS card %s had value %s",
699 "ESO SEQ CHOPNOD DIR",
"PERPENDICULAR");
700 if (visir_img_phot_flux_four(combined)) {
701 visir_error_reset(
"Proceeding as if FITS card %s had value %s",
702 "ESO SEQ CHOPNOD DIR",
"PARALLEL");
703 skip_if (visir_img_phot_flux_three(combined));
708 visir_error_reset(
"Could not get chopping direction");
709 if (visir_img_phot_flux_three(combined)) {
710 cpl_msg_error(cpl_func,
"Could not compute the flux");
713 }
else if (!strcmp(sval,
"PARALLEL")) {
715 if (visir_img_phot_flux_three(combined)) {
716 cpl_msg_error(cpl_func,
"Could not compute the flux");
721 if (strcmp(sval,
"PERPENDICULAR"))
722 cpl_msg_warning(cpl_func,
"Unknown chopping direction: %s", sval);
723 if (visir_img_phot_flux_four(combined)) {
724 cpl_msg_error(cpl_func,
"Could not compute the flux");
733 double fluxSI = visir_img_phot_config.jy_val * 1e-26;
736 double area = (8.2/2.) * (8.2/2.) * CPL_MATH_PI;
743 if (ppqc && cpl_propertylist_has(ppqc,
"ESO DET CHIP1 GAIN"))
744 gain = cpl_propertylist_get_double(ppqc,
"ESO DET CHIP1 GAIN");
745 else if (ppqc && cpl_propertylist_has(ppqc,
"ESO DET CHIP GAIN"))
746 gain = cpl_propertylist_get_double(ppqc,
"ESO DET CHIP GAIN");
748 cpl_msg_warning(cpl_func,
"ESO DET CHIP1 GAIN not found, "
749 "assuming %g", gain);
751 if (filter && !visir_get_filter_infos(filter, &wl, &bandwidth)) {
753 double bwh, ptot, ephot;
757 bwh = CPL_PHYS_C / (wl * wl) * bandwidth;
759 ptot = fluxSI * area * bwh;
761 ephot = CPL_PHYS_H * CPL_PHYS_C / wl;
763 visir_img_phot_config.nelec = visir_img_phot_config.flux_tot * gain;
764 visir_img_phot_config.nphot = ptot / ephot * dit;
767 cpl_msg_warning(cpl_func,
"Unknown filter: %s", filter);
772 skip_if ( visir_img_phot_config.flux_snr == 0 );
773 skip_if ( visir_img_phot_config.flux_snr_noise == 0 );
774 skip_if ( visir_img_phot_config.jy_val == 0 );
776 f2 = visir_img_phot_config.flux_snr / visir_img_phot_config.flux_snr_noise;
777 f2 *= sqrt(3600/visir_img_phot_config.exptime);
778 visir_img_phot_config.sensitivity = visir_img_phot_config.jy_val*1000*10/f2;
780 visir_img_phot_config.conversion = visir_img_phot_config.flux_tot /
781 visir_img_phot_config.jy_val /
785 visir_img_phot_config.area_sensit =
786 visir_img_phot_config.sensitivity *
787 sqrt((1. / SQR(visir_img_phot_config.pscale)) /
788 SQR(visir_img_phot_config.flux_snr_radius[0]));
792 cpl_msg_info(cpl_func,
"Sensitivity : %g", visir_img_phot_config.sensitivity);
793 cpl_msg_info(cpl_func,
"Conversion : %g", visir_img_phot_config.conversion);
794 cpl_msg_info(cpl_func,
"Strehl : %g", visir_img_phot_config.strehl);
795 cpl_msg_info(cpl_func,
"Strehl error: %g", visir_img_phot_config.strehl_err);
796 cpl_msg_info(cpl_func,
"Exposure : %g s", visir_img_phot_config.exptime);
798 return cpl_error_get_code();
812 static double visir_img_phot_jy_from_cat(
813 const char * star_cat,
817 const char * star_name)
819 cpl_table * tab = NULL;
820 cpl_vector * v_ra = NULL;
821 cpl_vector * v_dec = NULL;
822 const char * stdstar;
825 const double max_radius = VISIR_STAR_MAX_RADIUS;
833 skip_if( star_cat == NULL );
834 skip_if( star_name == NULL );
835 skip_if( filter == NULL );
837 label = visir_img_phot_filter2label(filter);
838 skip_if(label == NULL);
841 if ((tab = cpl_table_load(star_cat, 1, 1)) == NULL) {
842 cpl_error_set_message(cpl_func, cpl_error_get_code(),
843 "Could not load the star catalog: %s",
849 if (!cpl_table_has_column(tab, label)) {
850 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
851 "Catalog %s has no column for filter: %s",
856 if (!cpl_table_has_column(tab,
"STARS")) {
857 cpl_error_set_message(cpl_func, CPL_ERROR_BAD_FILE_FORMAT,
858 "Catalog %s does not have a column labeled %s",
863 nb_stars = cpl_table_get_nrow(tab);
864 skip_if (nb_stars < 1);
867 v_ra = cpl_vector_wrap(nb_stars, cpl_table_get_data_double(tab,
"RA"));
868 skip_if( v_ra == NULL);
870 v_dec = cpl_vector_wrap(nb_stars, cpl_table_get_data_double(tab,
"DEC"));
871 skip_if( v_dec == NULL);
873 min_dist_ind = visir_star_find(v_ra, v_dec, ra, dec, max_radius, &dist);
875 if (min_dist_ind < 0) {
876 cpl_error_set_message(cpl_func, cpl_error_get_code(),
877 "Observation target '%s' was not found among "
878 "the %d entries in the standard star catalog %s",
879 star_name, nb_stars, star_cat);
883 stdstar = cpl_table_get_string(tab,
"STARS", min_dist_ind);
884 skip_if ( stdstar == NULL );
887 jy = cpl_table_get(tab, label, min_dist_ind, &null);
890 if (null || isnan(jy)) {
891 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
892 "Catalog does not contain a value for %s in "
893 "filter %s", star_name, filter);
899 if (strcmp(stdstar, star_name) != 0 && dist > 0.0) {
901 cpl_msg_warning(cpl_func,
"The standard star '%s' at (RA,DEC)=(%g,%g) "
902 "in the FITS header is closest to the catalog star "
903 "'%s' at (RA,DEC)=(%g,%g) at distance %g degrees",
904 star_name, ra, dec, stdstar,
905 cpl_vector_get(v_ra, min_dist_ind),
906 cpl_vector_get(v_dec, min_dist_ind), dist);
907 }
else if (dist > 0.0) {
909 cpl_msg_warning(cpl_func,
"The location of the standard star '%s' in "
910 "the FITS header (RA,DEC)=(%g,%g) and the catalog "
911 "(RA,DEC)=(%g,%g) differ by %g degrees", stdstar, ra,
912 dec, cpl_vector_get(v_ra, min_dist_ind),
913 cpl_vector_get(v_dec, min_dist_ind), dist);
914 }
else if (strcmp(stdstar, star_name) != 0) {
916 cpl_msg_warning(cpl_func,
"The name of the standard star at (RA,DEC)="
917 "(%g,%g) in the FITS header '%s' and the catalog '%s' "
918 "are different", ra, dec, star_name, stdstar);
920 cpl_msg_info(cpl_func,
"Standard star is '%s' at (RA, DEC)=(%g,%g)",
923 if (cpl_msg_get_level() <= CPL_MSG_DEBUG)
924 cpl_table_dump(tab, min_dist_ind, 1, stdout);
927 cpl_msg_info(cpl_func,
"The standard star '%s' has %g Jy through filter %s",
928 stdstar, value, filter);
933 cpl_table_delete(tab);
934 cpl_vector_unwrap(v_ra);
935 cpl_vector_unwrap(v_dec);
950 static int visir_img_phot_flux_three(
const cpl_image * combined)
952 cpl_errorstate cleanstate = cpl_errorstate_get();
953 cpl_image * min_combined = NULL;
954 cpl_apertures * appos = NULL;
955 cpl_apertures * apneg = NULL;
956 cpl_vector * sigmas = NULL;
957 double psigmas[] = {5, 2, 1, 0.5};
961 double flux_snr_noise[3];
962 int flux_snr_radius[3];
968 double star_bg,star_peak,star_flux,psf_peak,psf_flux,bg_noise;
969 double eccmin = DBL_MAX;
970 const int nsigmas =
sizeof(psigmas)/
sizeof(
double);
972 #ifdef VISIR_IMG_PHOT_USE_ECCENT_THREE
973 int ipos, ineg1, ineg2;
975 int iappos, iapneg2[2];
979 if (cpl_error_get_code())
return cpl_error_get_code();
981 cpl_ensure_code(combined != NULL, CPL_ERROR_NULL_INPUT);
983 cpl_msg_info(cpl_func,
"Detecting the 3-source star using %d sigma-levels "
984 "ranging from %g down to %g", nsigmas, psigmas[0],
987 sigmas = cpl_vector_new(1);
988 min_combined = cpl_image_multiply_scalar_create(combined, -1.0);
990 for (isigma = 0; isigma < nsigmas; isigma++) {
993 irplib_error_recover(cleanstate,
"Resetting error (why?)");
995 bug_if(cpl_vector_set(sigmas, 0, psigmas[isigma]));
998 cpl_apertures_delete(appos);
999 appos = cpl_apertures_extract(combined, sigmas, NULL);
1000 if (appos == NULL) {
1001 cpl_msg_warning(cpl_func,
"Found no positive star at sigma=%g",
1007 cpl_apertures_delete(apneg);
1008 apneg = cpl_apertures_extract(min_combined, sigmas, NULL);
1009 if (apneg == NULL) {
1010 cpl_msg_warning(cpl_func,
"Found no negative stars at sigma=%g",
1014 if (cpl_apertures_get_size(apneg) < 2) {
1015 cpl_msg_warning(cpl_func,
"Found just 1 negative star at sigma=%g, "
1016 "need two", psigmas[isigma]);
1020 cpl_msg_info(cpl_func,
"Found positive and negative stars at sigma=%g",
1025 skip_if(appos == NULL);
1026 skip_if(apneg == NULL);
1027 skip_if (cpl_apertures_get_size(apneg) < 2);
1029 if (cpl_msg_get_level() == CPL_MSG_DEBUG) {
1030 cpl_apertures_dump(appos, stdout);
1031 cpl_apertures_dump(apneg, stdout);
1034 #ifndef VISIR_IMG_PHOT_USE_ECCENT_THREE
1038 if (cpl_apertures_get_size(appos) > 1 || cpl_apertures_get_size(apneg) > 2)
1039 cpl_msg_info(cpl_func,
"Selecting from %d positive and %d negative "
1040 "stars 3 stars on a vertical line",
1041 cpl_apertures_get_size(appos),
1042 cpl_apertures_get_size(apneg));
1044 for (ipos = 1; ipos <= cpl_apertures_get_size(appos); ipos++) {
1045 for (ineg1 = 2; ineg1 <= cpl_apertures_get_size(apneg); ineg1++) {
1046 for (ineg2 = 1; ineg2 < ineg1; ineg2++) {
1047 const double ecc = visir_img_phot_eccent_three(appos, ipos,
1051 if (eccmin < DBL_MAX)
1052 cpl_msg_debug(cpl_func,
"Found star positions with "
1053 "reduced mis-alignment [pixel]: "
1054 "%g < %g", ecc, eccmin);
1065 if (cpl_apertures_get_flux(apneg, iapneg2[0]) <
1066 cpl_apertures_get_flux(apneg, iapneg2[1])) {
1067 const int tmp = iapneg2[0];
1068 iapneg2[0] = iapneg2[1];
1074 x[0] = cpl_apertures_get_centroid_x(appos, iappos);
1075 y[0] = cpl_apertures_get_centroid_y(appos, iappos);
1077 x[1] = cpl_apertures_get_centroid_x(apneg, iapneg2[0]);
1078 y[1] = cpl_apertures_get_centroid_y(apneg, iapneg2[0]);
1079 x[2] = cpl_apertures_get_centroid_x(apneg, iapneg2[1]);
1080 y[2] = cpl_apertures_get_centroid_y(apneg, iapneg2[1]);
1082 cpl_apertures_delete(appos);
1083 cpl_apertures_delete(apneg);
1087 cpl_msg_info(cpl_func,
"Positive star at position %g %g", x[0], y[0]);
1088 cpl_msg_info(cpl_func,
"Negative star 1 at position %g %g", x[1], y[1]);
1089 cpl_msg_info(cpl_func,
"Negative star 2 at position %g %g", x[2], y[2]);
1091 dist1 = sqrt((x[1]-x[0])*(x[1]-x[0])+(y[1]-y[0])*(y[1]-y[0]));
1092 dist2 = sqrt((x[2]-x[0])*(x[2]-x[0])+(y[2]-y[0])*(y[2]-y[0]));
1093 cpl_msg_info(cpl_func,
"Star 1 Pos/Neg Distance: %g", dist1);
1094 cpl_msg_info(cpl_func,
"Star 2 Pos/Neg Distance: %g", dist2);
1097 if (eccmin < DBL_MAX) {
1098 cpl_msg_info(cpl_func,
"The deviation from a vertical line by "
1099 "the three stars [pixel]: %g", eccmin);
1100 if (eccmin > VISIR_IMG_PHOT_POS_WARN) {
1101 if (eccmin > VISIR_IMG_PHOT_POS_ERROR) {
1102 cpl_msg_error(cpl_func,
"The deviation from a vertical line"
1103 " by the three stars exceed %g, the detected "
1104 "objects are wrong", VISIR_IMG_PHOT_POS_ERROR);
1107 cpl_msg_warning(cpl_func,
"The deviation from a vertical line "
1108 "by the three stars exceed %g, the detected "
1109 "objects may be wrong", VISIR_IMG_PHOT_POS_WARN);
1114 if ((
int)x[0]-IRPLIB_STREHL_BORDER <= 0 ||
1115 (
int)y[0]-IRPLIB_STREHL_BORDER <= 0 ||
1116 (
int)x[0]+IRPLIB_STREHL_BORDER > cpl_image_get_size_x(combined) ||
1117 (
int)y[0]+IRPLIB_STREHL_BORDER > cpl_image_get_size_y(combined)) {
1118 cpl_msg_error(cpl_func,
"Positive star at (%g,%g) is less than %d "
1119 "pixels from the image border", x[0], y[0],
1120 1+IRPLIB_STREHL_BORDER);
1126 if (fabs(dist1-dist2) > VISIR_IMG_PHOT_POS_UNCERTAINTY) {
1127 cpl_msg_error(cpl_func,
"Too large Pos/Neg Distance between the two "
1128 "stars: %g > %g", fabs(dist1-dist2),
1129 VISIR_IMG_PHOT_POS_UNCERTAINTY);
1134 skip_if (visir_img_phot_flux(combined, NULL, NULL,
1136 visir_img_phot_config.r0_max,
1137 visir_img_phot_config.r1,
1138 visir_img_phot_config.r2,
1140 &(flux_snr_noise[0]),
1141 &(flux_snr_radius[0]),
1146 for (i=1 ; i<3 ; i++)
1147 skip_if (visir_img_phot_flux(min_combined, NULL, NULL,
1149 visir_img_phot_config.r0_max,
1150 visir_img_phot_config.r1,
1151 visir_img_phot_config.r2,
1153 &(flux_snr_noise[i]),
1154 &(flux_snr_radius[i]),
1158 cpl_image_delete(min_combined);
1159 min_combined = NULL;
1163 visir_img_phot_config.flux_snr = 0.0;
1164 for (i=0 ; i<3 ; i++) visir_img_phot_config.flux_snr += flux_snr[i];
1167 visir_img_phot_config.flux_snr_noise = 0.0;
1168 for (i=0 ; i<3 ; i++) visir_img_phot_config.flux_snr_noise +=
1169 flux_snr_noise[i]*flux_snr_noise[i];
1170 visir_img_phot_config.flux_snr_noise =
1171 sqrt(visir_img_phot_config.flux_snr_noise);
1173 for (i=0 ; i<3 ; i++)
1174 visir_img_phot_config.flux_snr_radius[i] = flux_snr_radius[i];
1177 visir_img_phot_config.flux_tot = 0.0;
1178 for (i=0 ; i<3 ; i++) visir_img_phot_config.flux_tot += flux_tot[i];
1182 visir_img_phot_config.beamshape.fwhm_x = 0.0;
1183 for (i=0 ; i<3 ; i++) {
1184 if (beamshapes[i].fwhm_x > 0.0) {
1185 visir_img_phot_config.beamshape.fwhm_x += beamshapes[i].fwhm_x;
1189 if (ngood_fwhm > 0) visir_img_phot_config.beamshape.fwhm_x /= ngood_fwhm;
1190 else visir_img_phot_config.beamshape.fwhm_x = -1.0;
1192 visir_img_phot_config.beamshape.fwhm_y = 0.0;
1193 for (i=0 ; i<3 ; i++) {
1194 if (beamshapes[i].fwhm_y > 0.0) {
1195 visir_img_phot_config.beamshape.fwhm_y += beamshapes[i].fwhm_y;
1199 if (ngood_fwhm > 0) visir_img_phot_config.beamshape.fwhm_y /= ngood_fwhm;
1200 else visir_img_phot_config.beamshape.fwhm_y = -1.0;
1201 visir_img_phot_config.fwhm_x_pos1 = beamshapes[0].fwhm_x;
1202 visir_img_phot_config.fwhm_y_pos1 = beamshapes[0].fwhm_y;
1203 visir_img_phot_config.fwhm_x_neg1 = beamshapes[1].fwhm_x;
1204 visir_img_phot_config.fwhm_y_neg1 = beamshapes[1].fwhm_y;
1205 visir_img_phot_config.fwhm_x_neg2 = beamshapes[2].fwhm_x;
1206 visir_img_phot_config.fwhm_y_neg2 = beamshapes[2].fwhm_y;
1209 if (visir_get_filter_infos(visir_img_phot_config.filter, &lam, &dlam)) {
1210 cpl_msg_error(cpl_func,
"Could not get info for filter: %s",
1211 visir_img_phot_config.filter);
1216 cpl_errorstate errstate = cpl_errorstate_get();
1217 if (irplib_strehl_compute(combined, STREHL_M1, STREHL_M2, lam, dlam,
1218 visir_img_phot_config.pscale,
1219 STREHL_BOX_SIZE, x[0], y[0], STREHL_STAR_RADIUS,
1220 STREHL_BG_R1, STREHL_BG_R2, -1, -1,
1221 &(visir_img_phot_config.strehl),
1222 &(visir_img_phot_config.strehl_err),
1223 &star_bg, &star_peak, &star_flux, &psf_peak, &psf_flux,
1225 cpl_msg_error(cpl_func,
"Could not compute the strehl: '%s' in %s",
1226 cpl_error_get_message(), cpl_error_get_where());
1227 cpl_errorstate_set(errstate);
1233 cpl_apertures_delete(appos);
1234 cpl_apertures_delete(apneg);
1235 cpl_vector_delete(sigmas);
1236 cpl_image_delete(min_combined);
1238 return cpl_error_get_code();
1241 static int visir_img_phot_flux_one(
const cpl_image * combined,
1242 const cpl_image * weights,
1243 const cpl_image * contrib,
1244 const cpl_propertylist * plist)
1249 double flux_snr_noise;
1250 int flux_snr_radius;
1254 double star_bg,star_peak,star_flux,psf_peak,psf_flux,bg_noise;
1256 if (cpl_error_get_code())
return cpl_error_get_code();
1258 cpl_ensure_code(combined != NULL, CPL_ERROR_NULL_INPUT);
1260 x = cpl_propertylist_get_double(plist,
"CRPIX1");
1261 y = cpl_propertylist_get_double(plist,
"CRPIX2");
1268 cpl_image_get_maxpos_window(combined, x - 5, y - 5,
1269 x + 5, y + 5, &xp, &yp);
1274 cpl_msg_info(cpl_func,
"Positive star 1 at position %g %g", x, y);
1276 if ((
int)x-IRPLIB_STREHL_BORDER <= 0 ||
1277 (
int)y-IRPLIB_STREHL_BORDER <= 0) {
1278 cpl_msg_error(cpl_func,
"Positive star 1 at (%g,%g) is less than %d "
1279 "pixels from the image border", x, y,
1280 1+IRPLIB_STREHL_BORDER);
1285 skip_if (visir_img_phot_flux(combined, weights, contrib,
1287 visir_img_phot_config.r0_max,
1288 visir_img_phot_config.r1,
1289 visir_img_phot_config.r2,
1299 visir_img_phot_config.flux_snr = flux_snr;
1302 visir_img_phot_config.flux_snr_noise = flux_snr_noise;
1304 visir_img_phot_config.flux_snr_radius[0] = flux_snr_radius;
1307 visir_img_phot_config.flux_tot = flux_tot;
1310 visir_img_phot_config.beamshape = beamshape;
1311 visir_img_phot_config.fwhm_x_pos1 = beamshape.fwhm_x;
1312 visir_img_phot_config.fwhm_y_pos1 = beamshape.fwhm_y;
1315 if (visir_get_filter_infos(visir_img_phot_config.filter, &lam, &dlam)) {
1316 cpl_msg_error(cpl_func,
"Central wavelength and width is missing for "
1317 "filter: %s", visir_img_phot_config.filter);
1322 cpl_errorstate errstate = cpl_errorstate_get();
1323 if (irplib_strehl_compute(combined, STREHL_M1, STREHL_M2, lam, dlam,
1324 visir_img_phot_config.pscale,
1325 STREHL_BOX_SIZE, x, y, STREHL_STAR_RADIUS,
1326 STREHL_BG_R1, STREHL_BG_R2, -1, -1,
1327 &(visir_img_phot_config.strehl),
1328 &(visir_img_phot_config.strehl_err),
1329 &star_bg, &star_peak, &star_flux, &psf_peak, &psf_flux,
1331 cpl_msg_error(cpl_func,
"Could not compute the strehl: '%s' in %s",
1332 cpl_error_get_message(), cpl_error_get_where());
1333 cpl_errorstate_set(errstate);
1339 return cpl_error_get_code();
1353 static int visir_img_phot_flux_four(
const cpl_image * combined)
1355 cpl_errorstate cleanstate = cpl_errorstate_get();
1356 cpl_image * min_combined = NULL;
1357 cpl_apertures * appos = NULL;
1358 cpl_apertures * apneg = NULL;
1359 cpl_vector * sigmas = NULL;
1360 double psigmas[] = {5, 2, 1, 0.5};
1364 double flux_snr_noise[4];
1365 int flux_snr_radius[4];
1368 double dist1, dist2;
1371 double star_bg,star_peak,star_flux,psf_peak,psf_flux,bg_noise;
1372 double eccmin = DBL_MAX;
1373 const int nsigmas =
sizeof(psigmas)/
sizeof(
double);
1375 int ipos1, ipos2, ineg1, ineg2;
1377 int iappos2[] = {0, 0};
1378 int iapneg2[] = {0, 0};
1381 if (cpl_error_get_code())
return cpl_error_get_code();
1383 cpl_ensure_code(combined != NULL, CPL_ERROR_NULL_INPUT);
1385 cpl_msg_info(cpl_func,
"Detecting the 4-source star using %d sigma-levels "
1386 "ranging from %g down to %g", nsigmas, psigmas[0],
1387 psigmas[nsigmas-1]);
1389 sigmas = cpl_vector_new(1);
1390 min_combined = cpl_image_multiply_scalar_create(combined, -1.0);
1392 for (isigma = 0; isigma < nsigmas; isigma++) {
1395 irplib_error_recover(cleanstate,
"Resetting error (why?)");
1397 bug_if(cpl_vector_set(sigmas, 0, psigmas[isigma]));
1400 cpl_apertures_delete(appos);
1401 appos = cpl_apertures_extract(combined, sigmas, NULL);
1402 if (appos == NULL) {
1403 cpl_msg_warning(cpl_func,
"Found no positive stars at sigma=%g",
1407 if (cpl_apertures_get_size(appos) < 2) {
1408 cpl_msg_warning(cpl_func,
"Found just 1 positive star at sigma=%g, "
1409 "need two", psigmas[isigma]);
1414 cpl_apertures_delete(apneg);
1415 apneg = cpl_apertures_extract(min_combined, sigmas, NULL);
1416 if (apneg == NULL) {
1417 cpl_msg_warning(cpl_func,
"Found no negative stars at sigma=%g",
1421 if (cpl_apertures_get_size(apneg) < 2) {
1422 cpl_msg_warning(cpl_func,
"Found just 1 negative star at sigma=%g, "
1423 "need two", psigmas[isigma]);
1427 cpl_msg_info(cpl_func,
"Found positive and negative stars at sigma=%g",
1432 skip_if(appos == NULL);
1433 skip_if(apneg == NULL);
1434 skip_if (cpl_apertures_get_size(appos) < 2);
1435 skip_if (cpl_apertures_get_size(apneg) < 2);
1437 if (cpl_msg_get_level() == CPL_MSG_DEBUG) {
1438 cpl_apertures_dump(appos, stdout);
1439 cpl_apertures_dump(apneg, stdout);
1442 if (cpl_apertures_get_size(appos) > 2 || cpl_apertures_get_size(apneg) > 2)
1443 cpl_msg_info(cpl_func,
"Selecting from %d positive and %d negative "
1444 "stars two pairs that outline a square",
1445 (
int)cpl_apertures_get_size(appos),
1446 (
int)cpl_apertures_get_size(apneg));
1448 for (ipos1 = 2; ipos1 <= cpl_apertures_get_size(appos); ipos1++) {
1449 for (ipos2 = 1; ipos2 < ipos1; ipos2++) {
1450 for (ineg1 = 2; ineg1 <= cpl_apertures_get_size(apneg); ineg1++) {
1451 for (ineg2 = 1; ineg2 < ineg1; ineg2++) {
1452 const double ecc = visir_img_phot_eccent_four(appos, ipos1,
1457 if (eccmin < DBL_MAX)
1458 cpl_msg_debug(cpl_func,
"Found star positions with "
1459 "reduced non-square-ness [pixel]: "
1460 "%g < %g", ecc, eccmin);
1473 if (cpl_apertures_get_flux(appos, iappos2[0]) <
1474 cpl_apertures_get_flux(appos, iappos2[1])) {
1475 const int tmp = iappos2[0];
1476 iappos2[0] = iappos2[1];
1479 if (cpl_apertures_get_flux(apneg, iapneg2[0]) <
1480 cpl_apertures_get_flux(apneg, iapneg2[1])) {
1481 const int tmp = iapneg2[0];
1482 iapneg2[0] = iapneg2[1];
1487 x[0] = cpl_apertures_get_centroid_x(appos, iappos2[0]);
1488 y[0] = cpl_apertures_get_centroid_y(appos, iappos2[0]);
1489 x[1] = cpl_apertures_get_centroid_x(appos, iappos2[1]);
1490 y[1] = cpl_apertures_get_centroid_y(appos, iappos2[1]);
1492 x[2] = cpl_apertures_get_centroid_x(apneg, iapneg2[0]);
1493 y[2] = cpl_apertures_get_centroid_y(apneg, iapneg2[0]);
1494 x[3] = cpl_apertures_get_centroid_x(apneg, iapneg2[1]);
1495 y[3] = cpl_apertures_get_centroid_y(apneg, iapneg2[1]);
1497 cpl_apertures_delete(appos);
1498 cpl_apertures_delete(apneg);
1502 cpl_msg_info(cpl_func,
"Positive star 1 at position %g %g", x[0], y[0]);
1503 cpl_msg_info(cpl_func,
"Positive star 2 at position %g %g", x[1], y[1]);
1505 cpl_msg_info(cpl_func,
"Negative star 1 at position %g %g", x[2], y[2]);
1506 cpl_msg_info(cpl_func,
"Negative star 2 at position %g %g", x[3], y[3]);
1509 dist1 = sqrt((x[2]-x[0])*(x[2]-x[0])+(y[2]-y[0])*(y[2]-y[0]));
1510 dist2 = sqrt((x[3]-x[1])*(x[3]-x[1])+(y[3]-y[1])*(y[3]-y[1]));
1511 cpl_msg_info(cpl_func,
"Star 1 Pos/Neg Distance: %g", dist1);
1512 cpl_msg_info(cpl_func,
"Star 2 Pos/Neg Distance: %g", dist2);
1514 if (eccmin < DBL_MAX) {
1515 cpl_msg_info(cpl_func,
"The deviation from a horizontal square by "
1516 "the two star pairs [pixel]: %g", eccmin);
1517 if (eccmin > VISIR_IMG_PHOT_POS_WARN) {
1518 if (eccmin > VISIR_IMG_PHOT_POS_ERROR) {
1519 cpl_msg_error(cpl_func,
"The deviation from a horizontal square"
1520 " by the two star pairs exceed %g, the detected "
1521 "objects are wrong", VISIR_IMG_PHOT_POS_ERROR);
1524 cpl_msg_warning(cpl_func,
"The deviation from a horizontal square "
1525 "by the two star pairs exceed %g, the detected "
1526 "objects may be wrong", VISIR_IMG_PHOT_POS_WARN);
1530 if ((
int)x[0]-IRPLIB_STREHL_BORDER <= 0 ||
1531 (
int)y[0]-IRPLIB_STREHL_BORDER <= 0 ||
1532 (
int)x[0]+IRPLIB_STREHL_BORDER > cpl_image_get_size_x(combined) ||
1533 (
int)y[0]+IRPLIB_STREHL_BORDER > cpl_image_get_size_y(combined)) {
1534 cpl_msg_error(cpl_func,
"Positive star 1 at (%g,%g) is less than %d "
1535 "pixels from the image border", x[0], y[0],
1536 1+IRPLIB_STREHL_BORDER);
1541 if (fabs(dist1-dist2) > VISIR_IMG_PHOT_POS_UNCERTAINTY) {
1542 cpl_msg_error(cpl_func,
"Too large Pos/Neg Distance between the two "
1543 "stars: %g > %g", fabs(dist1-dist2),
1544 VISIR_IMG_PHOT_POS_UNCERTAINTY);
1549 for (i=0 ; i<2 ; i++)
1550 skip_if (visir_img_phot_flux(combined, NULL, NULL,
1552 visir_img_phot_config.r0_max,
1553 visir_img_phot_config.r1,
1554 visir_img_phot_config.r2,
1556 &(flux_snr_noise[i]),
1557 &(flux_snr_radius[i]),
1562 for (i=2 ; i<4 ; i++)
1563 skip_if (visir_img_phot_flux(min_combined, NULL, NULL,
1565 visir_img_phot_config.r0_max,
1566 visir_img_phot_config.r1,
1567 visir_img_phot_config.r2,
1569 &(flux_snr_noise[i]),
1570 &(flux_snr_radius[i]),
1574 cpl_image_delete(min_combined);
1575 min_combined = NULL;
1579 visir_img_phot_config.flux_snr = 0.0;
1580 for (i=0 ; i<4 ; i++) visir_img_phot_config.flux_snr += flux_snr[i];
1583 visir_img_phot_config.flux_snr_noise = 0.0;
1584 for (i=0 ; i<4 ; i++) visir_img_phot_config.flux_snr_noise +=
1585 flux_snr_noise[i]*flux_snr_noise[i];
1586 visir_img_phot_config.flux_snr_noise =
1587 sqrt(visir_img_phot_config.flux_snr_noise);
1589 for (i=0 ; i<4 ; i++)
1590 visir_img_phot_config.flux_snr_radius[i] = flux_snr_radius[i];
1593 visir_img_phot_config.flux_tot = 0.0;
1594 for (i=0 ; i<4 ; i++) visir_img_phot_config.flux_tot += flux_tot[i];
1598 visir_img_phot_config.beamshape.fwhm_x = 0.0;
1599 for (i=0 ; i<4 ; i++) {
1600 if (beamshapes[i].fwhm_x > 0.0) {
1601 visir_img_phot_config.beamshape.fwhm_x += beamshapes[i].fwhm_x;
1605 if (ngood_fwhm > 0) visir_img_phot_config.beamshape.fwhm_x /= ngood_fwhm;
1606 else visir_img_phot_config.beamshape.fwhm_x = -1.0;
1608 visir_img_phot_config.beamshape.fwhm_y = 0.0;
1609 for (i=0 ; i<4 ; i++) {
1610 if (beamshapes[i].fwhm_y > 0.0) {
1611 visir_img_phot_config.beamshape.fwhm_y += beamshapes[i].fwhm_y;
1615 if (ngood_fwhm > 0) visir_img_phot_config.beamshape.fwhm_y /= ngood_fwhm;
1616 else visir_img_phot_config.beamshape.fwhm_y = -1.0;
1617 visir_img_phot_config.fwhm_x_pos1 = beamshapes[0].fwhm_x;
1618 visir_img_phot_config.fwhm_y_pos1 = beamshapes[0].fwhm_y;
1619 visir_img_phot_config.fwhm_x_pos2 = beamshapes[1].fwhm_x;
1620 visir_img_phot_config.fwhm_y_pos2 = beamshapes[1].fwhm_y;
1621 visir_img_phot_config.fwhm_x_neg1 = beamshapes[2].fwhm_x;
1622 visir_img_phot_config.fwhm_y_neg1 = beamshapes[2].fwhm_y;
1623 visir_img_phot_config.fwhm_x_neg2 = beamshapes[3].fwhm_x;
1624 visir_img_phot_config.fwhm_y_neg2 = beamshapes[3].fwhm_y;
1627 if (visir_get_filter_infos(visir_img_phot_config.filter, &lam, &dlam)) {
1628 cpl_msg_error(cpl_func,
"Central wavelength and width is missing for "
1629 "filter: %s", visir_img_phot_config.filter);
1634 cpl_errorstate errstate = cpl_errorstate_get();
1635 if (irplib_strehl_compute(combined, STREHL_M1, STREHL_M2, lam, dlam,
1636 visir_img_phot_config.pscale,
1637 STREHL_BOX_SIZE, x[0], y[0], STREHL_STAR_RADIUS,
1638 STREHL_BG_R1, STREHL_BG_R2, -1, -1,
1639 &(visir_img_phot_config.strehl),
1640 &(visir_img_phot_config.strehl_err),
1641 &star_bg, &star_peak, &star_flux, &psf_peak, &psf_flux,
1643 cpl_msg_error(cpl_func,
"Could not compute the strehl: '%s' in %s",
1644 cpl_error_get_message(), cpl_error_get_where());
1645 cpl_errorstate_set(errstate);
1651 cpl_apertures_delete(appos);
1652 cpl_apertures_delete(apneg);
1653 cpl_vector_delete(sigmas);
1654 cpl_image_delete(min_combined);
1656 return cpl_error_get_code();
1678 static double visir_img_phot_eccent_four(
const cpl_apertures * appos,
1679 int ipos1,
int ipos2,
1680 const cpl_apertures * apneg,
1681 int ineg1,
int ineg2)
1687 const double xp1 = cpl_apertures_get_centroid_x(appos, ipos1);
1688 const double xp2 = cpl_apertures_get_centroid_x(appos, ipos2);
1689 const double yp1 = cpl_apertures_get_centroid_y(appos, ipos1);
1690 const double yp2 = cpl_apertures_get_centroid_y(appos, ipos2);
1693 const double xpl = xp1 < xp2 ? xp1 : xp2;
1694 const double ypl = xp1 < xp2 ? yp1 : yp2;
1697 const double xpr = xp1 < xp2 ? xp2 : xp1;
1698 const double ypr = xp1 < xp2 ? yp2 : yp1;
1701 const double xn1 = cpl_apertures_get_centroid_x(apneg, ineg1);
1702 const double yn1 = cpl_apertures_get_centroid_y(apneg, ineg1);
1703 const double xn2 = cpl_apertures_get_centroid_x(apneg, ineg2);
1704 const double yn2 = cpl_apertures_get_centroid_y(apneg, ineg2);
1707 const double xln = xn1 < xn2 ? xn1 : xn2;
1708 const double yln = xn1 < xn2 ? yn1 : yn2;
1711 const double xrn = xn1 < xn2 ? xn2 : xn1;
1712 const double yrn = xn1 < xn2 ? yn2 : yn1;
1714 const double lx1 = xrn - xpl;
1715 const double lx2 = xpr - xln;
1716 const double ly1 = ypl - yln;
1717 const double ly2 = yrn - ypr;
1719 const double lmean = 0.25 * ( lx1 + lx2 + ly1 + ly2);
1721 const double dx1 = lx1 - lmean;
1722 const double dx2 = lx2 - lmean;
1723 const double dy1 = ly1 - lmean;
1724 const double dy2 = ly2 - lmean;
1726 const double ey1 = yrn - ypl;
1727 const double ey2 = ypr - yln;
1728 const double ex1 = xpl - xln;
1729 const double ex2 = xpr - xrn;
1731 const double result = sqrt(dx1 * dx1 + dx2 * dx2 + dy1 * dy1 + dy2 * dy2 +
1732 ex1 * ex1 + ex2 * ex2 + ey1 * ey1 + ey2 * ey2);
1737 bug_if(appos == apneg);
1738 bug_if(ipos1 == ipos2);
1739 bug_if(ineg1 == ineg2);
1748 #ifdef VISIR_IMG_PHOT_USE_ECCENT_THREE
1765 static double visir_img_phot_eccent_three(
const cpl_apertures * appos,
1767 const cpl_apertures * apneg,
1768 int ineg1,
int ineg2)
1774 const double xp = cpl_apertures_get_centroid_x(appos, ipos);
1775 const double yp = cpl_apertures_get_centroid_y(appos, ipos);
1778 const double xn1 = cpl_apertures_get_centroid_x(apneg, ineg1);
1779 const double yn1 = cpl_apertures_get_centroid_y(apneg, ineg1);
1780 const double xn2 = cpl_apertures_get_centroid_x(apneg, ineg2);
1781 const double yn2 = cpl_apertures_get_centroid_y(apneg, ineg2);
1784 const double xnb = xn1 < xn2 ? xn1 : xn2;
1785 const double ynb = xn1 < xn2 ? yn1 : yn2;
1788 const double xnt = xn1 < xn2 ? xn2 : xn1;
1789 const double ynt = xn1 < xn2 ? yn2 : yn1;
1791 const double l1 = ynt - yp;
1792 const double l2 = yp - ynb;
1793 const double ln = ynt - ynb;
1795 const double lmean = 0.25 * ( l1 + l2 + ln);
1797 const double d1 = l1 - lmean;
1798 const double d2 = l2 - lmean;
1799 const double dn = 0.5 * ln - lmean;
1801 const double e1 = xp - xnt;
1802 const double e2 = xp - xnb;
1804 const double result = sqrt(d1 * d1 + d2 * d2 + dn * dn + e1 * e1 + e2 * e2);
1809 bug_if(appos == apneg);
1810 bug_if(ineg1 == ineg2);
1844 static int visir_img_phot_flux(
1845 const cpl_image * combined,
1846 const cpl_image * weights_,
1847 const cpl_image * contrib,
1854 double * flux_snr_noise,
1855 int * flux_snr_radius,
1859 cpl_apertures * apert = NULL;
1861 cpl_image * bg_subtracted = NULL;
1862 cpl_vector * r0 = NULL;
1863 cpl_vector * fl = NULL;
1864 cpl_vector * fl_noise = NULL;
1865 cpl_vector * snr = NULL;
1867 double max_val = 0.0;
1871 int max_contrib = 1;
1872 cpl_image * weights = weights_ == NULL ?
1873 NULL : cpl_image_duplicate(weights_);
1876 if (cpl_error_get_code())
return cpl_error_get_code();
1878 cpl_ensure_code(combined != NULL, CPL_ERROR_NULL_INPUT);
1879 cpl_ensure_code(r0_max > 0, CPL_ERROR_ILLEGAL_INPUT);
1881 nx = cpl_image_get_size_x(combined);
1882 ny = cpl_image_get_size_y(combined);
1885 cpl_ensure_code(nx == cpl_image_get_size_x(weights) &&
1886 ny == cpl_image_get_size_y(weights),
1887 CPL_ERROR_ILLEGAL_INPUT);
1891 cpl_ensure_code(nx == cpl_image_get_size_x(contrib) &&
1892 ny == cpl_image_get_size_y(contrib),
1893 CPL_ERROR_ILLEGAL_INPUT);
1894 max_contrib = cpl_image_get_max(contrib);
1895 cpl_ensure_code(max_contrib >= 1, CPL_ERROR_ILLEGAL_INPUT);
1899 if ((labels = visir_create_ring_intimage(nx, ny,
1900 (
int)x_pos, (
int)y_pos, r1, r2)) == NULL) {
1901 cpl_msg_error(cpl_func,
"Could not create a ring image");
1905 apert = cpl_apertures_new_from_image(combined, labels);
1906 cpl_image_delete(labels);
1908 bg = cpl_apertures_get_median(apert, 1);
1909 cpl_apertures_delete(apert);
1911 cpl_msg_info(cpl_func,
"Background : %g", bg);
1914 if ((labels = visir_create_disk_intimage(nx, ny,
1915 (
int)x_pos, (
int)y_pos, r0_max)) == NULL) {
1916 cpl_msg_error(cpl_func,
"Could not create a disk image");
1922 bg_subtracted = cpl_image_subtract_scalar_create(combined, bg);
1926 cpl_image * scale = cpl_image_cast(contrib, CPL_TYPE_DOUBLE);
1927 cpl_image_power(scale, -1);
1928 cpl_image_multiply_scalar(scale, max_contrib);
1929 cpl_image_multiply(bg_subtracted, scale);
1931 cpl_image_multiply(weights, scale);
1932 cpl_image_delete(scale);
1935 apert = cpl_apertures_new_from_image(bg_subtracted, labels);
1936 cpl_image_delete(labels);
1938 *flux_tot = cpl_apertures_get_flux(apert, 1);
1939 cpl_apertures_delete(apert);
1941 cpl_msg_info(cpl_func,
"Star total flux (error): %g", *flux_tot);
1944 r0 = cpl_vector_new(r0_max);
1945 for (i=0 ; i<r0_max ; i++) cpl_vector_set(r0, i, i+1);
1948 fl = cpl_vector_new(r0_max);
1949 fl_noise = cpl_vector_new(r0_max);
1952 for (i=0 ; i<r0_max ; i++) {
1953 float fl_val = 0.f, fl_noise_val = 0.f;
1955 if ((labels = visir_create_disk_intimage(nx, ny,
1956 (
int)x_pos, (
int)y_pos, (
int)cpl_vector_get(r0, i))) == NULL) {
1957 cpl_msg_error(cpl_func,
"Could not create a disk image: %d", i);
1962 double sum = 0, esum = 0;
1964 for (
int ix = 1; ix < 1 + nx; ix++) {
1965 for (
int iy = 1; iy < 1 + ny; iy++) {
1966 if (!cpl_image_get(labels, ix, iy, &d) || d)
1969 sum += cpl_image_get(bg_subtracted, ix, iy, &d);
1972 esum += (1. / cpl_image_get(weights, ix, iy, &d));
1976 fl_noise_val = sqrt(esum);
1979 cpl_apertures * pert =
1980 cpl_apertures_new_from_image(bg_subtracted, labels);
1982 fl_val = cpl_apertures_get_flux(pert, 1);
1983 fl_noise_val = visir_img_phot_config.bg_sigma *
1984 sqrt((
double)cpl_apertures_get_npix(pert, 1));
1985 cpl_apertures_delete(pert);
1989 cpl_image_delete(labels);
1991 cpl_vector_set(fl, i, fl_val);
1992 cpl_vector_set(fl_noise, i, fl_noise_val);
1997 snr = cpl_vector_duplicate(fl);
1998 cpl_vector_divide(snr, fl_noise);
1999 for (i=0 ; i<r0_max ; i++) {
2000 if (i == 0 || max_val < cpl_vector_get(snr, i)) {
2001 max_val = cpl_vector_get(snr, i);
2005 *flux_snr = cpl_vector_get(fl, max_ind);
2006 *flux_snr_noise = cpl_vector_get(fl_noise, max_ind);
2007 *flux_snr_radius = (int)cpl_vector_get(r0, max_ind);
2008 cpl_msg_info(cpl_func,
"Best SNR star flux : %g (%g) for radius %d <= %d "
2009 " [pixel]", *flux_snr, *flux_snr_noise,
2010 (
int)cpl_vector_get(r0, max_ind),
2011 (
int)cpl_vector_get(r0, r0_max-1));
2013 if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
2014 cpl_matrix * mdump = cpl_matrix_new(1+r0_max, 3);
2015 for (i = 0; i < r0_max; i++) {
2016 cpl_matrix_set(mdump, i+1, 0, cpl_vector_get(fl, i));
2017 cpl_matrix_set(mdump, i+1, 1, cpl_vector_get(fl_noise, i));
2018 cpl_matrix_set(mdump, i+1, 2, cpl_vector_get(snr, i));
2020 cpl_msg_debug(cpl_func,
"Flux, flux-noise and S/N for radii out to %d",
2021 (
int)cpl_vector_get(r0, r0_max-1));
2023 cpl_matrix_dump(mdump, stdout);
2024 cpl_matrix_delete(mdump);
2027 *beamshape = (
beamshape_t){.fwhm_x = -1., .fwhm_y = -1.,
2028 .peak = -1., .peak_err = 0.,
2029 .major = -1., .major_err = 0.,
2030 .minor = -1., .minor_err = 0.,
2031 .angle = -1., .angle_err = 0.};
2034 skip_if (cpl_image_get_fwhm(bg_subtracted, (
int)x_pos, (
int)y_pos, &beamshape->fwhm_x,
2035 &beamshape->fwhm_y));
2037 skip_if ( beamshape->fwhm_x <= 0.0 );
2038 skip_if ( beamshape->fwhm_y <= 0.0 );
2040 cpl_errorstate cleanstate = cpl_errorstate_get();
2042 if (fit_2d_gauss(bg_subtracted, weights, (cpl_size)x_pos, (cpl_size)y_pos,
2043 beamshape->fwhm_x, beamshape->fwhm_y,
2044 &beamshape->peak, &beamshape->peak_err,
2045 &beamshape->major, &beamshape->major_err,
2046 &beamshape->minor, &beamshape->minor_err,
2047 &beamshape->angle, &beamshape->angle_err) == CPL_ERROR_NONE) {
2048 cpl_msg_info(cpl_func,
"Peak: %g +- %g, FWHM : %g +- %g major ; %g +- %g minor, "
2049 "angle %g +- %g", beamshape->peak, beamshape->peak_err,
2050 beamshape->major, beamshape->major_err,
2051 beamshape->minor, beamshape->minor_err, beamshape->angle *
2052 CPL_MATH_DEG_RAD, beamshape->angle_err *
2056 cpl_msg_warning(cpl_func,
"2D gauss fit failed, approximate FWHM : %g"
2057 "in x ; %g in y ", beamshape->fwhm_x, beamshape->fwhm_y);
2058 cpl_errorstate_set(cleanstate);
2063 cpl_apertures_delete(apert);
2064 cpl_image_delete(labels);
2065 cpl_image_delete(bg_subtracted);
2066 cpl_image_delete(weights);
2068 cpl_vector_delete(r0);
2069 cpl_vector_delete(fl);
2070 cpl_vector_delete(snr);
2071 cpl_vector_delete(fl_noise);
2073 return cpl_error_get_code();
2089 static cpl_error_code visir_get_filter_infos(
2098 cpl_ensure_code(f, CPL_ERROR_NULL_INPUT);
2099 cpl_ensure_code(pcwlen, CPL_ERROR_NULL_INPUT);
2100 cpl_ensure_code(pdwlen, CPL_ERROR_NULL_INPUT);
2102 skip_if (!strcmp(f,
"MV"));
2104 if (!strcmp(f,
"N-BAND") || !strcmp(f,
"N_BAND"))
2105 { cwlen = 10.56; dwlen = 5.37;}
2106 else if (!strcmp(f,
"SIC")) { cwlen = 11.848;dwlen = 2.34;}
2107 else if (!strcmp(f,
"PAH1_1")) { cwlen = 8.19;dwlen = 0.15;}
2108 else if (!strcmp(f,
"PAH1")) { cwlen = 8.586;dwlen = 0.421;}
2109 else if (!strcmp(f,
"ARIII")) { cwlen = 8.992;dwlen = 0.138;}
2110 else if (!strcmp(f,
"SIV_1")) { cwlen = 10.02;dwlen = 0.18;}
2111 else if (!strcmp(f,
"SIV")) { cwlen = 10.485;dwlen = 0.159;}
2112 else if (!strcmp(f,
"PAH2_1")) { cwlen = 10.76;dwlen = 0.69;}
2113 else if (!strcmp(f,
"SIV_2")) { cwlen = 11.1;dwlen = 0.19;}
2114 else if (!strcmp(f,
"PAH2")) { cwlen = 11.254;dwlen = 0.594;}
2115 else if (!strcmp(f,
"PAH2_2")) { cwlen = 12.13;dwlen = 0.37;}
2116 else if (!strcmp(f,
"NEII_1")) { cwlen = 12.51;dwlen = 0.18;}
2117 else if (!strcmp(f,
"NEII")) { cwlen = 12.805;dwlen = 0.21;}
2118 else if (!strcmp(f,
"NEII_2")) { cwlen = 13.036;dwlen = 0.219;}
2119 else if (!strcmp(f,
"Q0")) { cwlen = 16.554;dwlen = 0.398;}
2120 else if (!strcmp(f,
"QH2")) { cwlen = 17.11;dwlen = 0.398;}
2121 else if (!strcmp(f,
"Q1")) { cwlen = 17.653;dwlen = 0.83;}
2122 else if (!strcmp(f,
"Q2")) { cwlen = 18.718;dwlen = 0.878;}
2123 else if (!strcmp(f,
"Q3")) { cwlen = 19.5;dwlen = 0.4;}
2124 else if (!strcmp(f,
"Q4")) { cwlen = 20.5;dwlen = 1.0;}
2125 else if (!strcmp(f,
"Q7")) { cwlen = 23.1;dwlen = 0.8;}
2126 else if (!strcmp(f,
"Q8")) { cwlen = 24.5;dwlen = 0.8;}
2127 else if (!strcmp(f,
"N-SW-spec") || !strcmp(f,
"N_SW_spec"))
2128 { cwlen = 8.85; dwlen = 2.7;}
2129 else if (!strcmp(f,
"H2S4-spec") || !strcmp(f,
"H2S4_spec"))
2130 { cwlen = 8.12; dwlen = 0.3;}
2131 else if (!strcmp(f,
"ARIII-spec") || !strcmp(f,
"ARIII_spec"))
2132 { cwlen = 8.44; dwlen = 0.78;}
2133 else if (!strcmp(f,
"NEII_2-spec") || !strcmp(f,
"NEII_2_spec"))
2134 { cwlen = 12.805; dwlen = 0.2;}
2135 else if (!strcmp(f,
"H2S3-spec") || !strcmp(f,
"H2S3_spec"))
2136 { cwlen = 9.62; dwlen = 0.2;}
2137 else if (!strcmp(f,
"H2S1-spec") || !strcmp(f,
"H2S1_spec"))
2138 { cwlen = 17.0;dwlen = 0.4;}
2139 else if (!strcmp(f,
"M-BAND") || !strcmp(f,
"M_BAND"))
2140 { cwlen = 4.82;dwlen = 0.35;}
2144 else if (!strcmp(f,
"J7.9") || !strcmp(f,
"J7_9"))
2145 { cwlen = (7.483 + 8.035)/2.0;
2146 dwlen = 8.035 - 7.483;}
2147 else if (!strcmp(f,
"J8.9") || !strcmp(f,
"J8_9"))
2148 { cwlen = (8.338 + 9.068)/2.0;
2149 dwlen = 9.068 - 8.338;}
2150 else if (!strcmp(f,
"J9.8") || !strcmp(f,
"J9_8"))
2151 { cwlen = (9.123 + 10.059)/2.0;
2152 dwlen = 10.059 - 9.123;}
2153 else if (!strcmp(f,
"J12.2") || !strcmp(f,
"J12_2"))
2154 { cwlen = (11.700 + 12.216)/2.0;
2155 dwlen = 12.216 - 11.700;}
2156 else if (!strcmp(f,
"B8.7") || !strcmp(f,
"B8_7"))
2157 { cwlen = (8.436 + 9.410)/2.0;
2158 dwlen = 9.410 - 8.436;}
2159 else if (!strcmp(f,
"B9.7") || !strcmp(f,
"B9_7"))
2160 { cwlen = (9.402 + 10.242)/2.0;
2161 dwlen = 10.242 - 9.402;}
2162 else if (!strcmp(f,
"B10.7") || !strcmp(f,
"B10_7"))
2163 { cwlen = (9.970 + 11.338)/2.0;
2164 dwlen = 11.338 - 9.970;}
2165 else if (!strcmp(f,
"B11.7") || !strcmp(f,
"B11_7"))
2166 { cwlen = (11.098 + 11.950)/2.0;
2167 dwlen = 11.950 - 11.098;}
2168 else if (!strcmp(f,
"B12.4") || !strcmp(f,
"B12_4"))
2169 { cwlen = (11.971 + 12.961)/2.0;
2170 dwlen = 12.961 - 11.971;}
2175 cpl_ensure_code(cwlen > 0, CPL_ERROR_DATA_NOT_FOUND);
2176 cpl_ensure_code(dwlen > 0, CPL_ERROR_DATA_NOT_FOUND);
2180 return cpl_error_get_code();
2192 static cpl_error_code visir_img_phot_qc(cpl_propertylist * qclist,
2193 cpl_boolean drop_wcs,
2194 const irplib_framelist * rawframes)
2197 const cpl_propertylist * reflist
2202 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC EXPTIME",
2203 visir_img_phot_config.exptime));
2205 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC JYVAL",
2206 visir_img_phot_config.jy_val));
2208 bug_if (cpl_propertylist_append_string(qclist,
"ESO QC STARNAME",
2209 visir_img_phot_config.star_name));
2211 bug_if (cpl_propertylist_append_string(qclist,
"ESO QC FILTER",
2212 visir_img_phot_config.filter));
2215 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC NELEC",
2216 visir_img_phot_config.nelec));
2218 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC NPHOT",
2219 visir_img_phot_config.nphot));
2221 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC BACKGD SIGMA",
2222 visir_img_phot_config.bg_sigma));
2224 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FLUXTOT",
2225 visir_img_phot_config.flux_tot));
2227 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FLUXSNR",
2228 visir_img_phot_config.flux_snr));
2230 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FLUXSNR NOISE",
2231 visir_img_phot_config.flux_snr_noise));
2233 for (
int i = 0; i < 4; i++) {
2234 const int r = visir_img_phot_config.flux_snr_radius[i];
2236 sprintf(buffer,
"ESO QC FLUXSNR RADIUS%d", i + 1);
2237 bug_if (cpl_propertylist_append_int(qclist, buffer, r));
2240 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMX",
2241 visir_img_phot_config.beamshape.fwhm_x));
2243 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMY",
2244 visir_img_phot_config.beamshape.fwhm_y));
2245 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC GAUSSFIT FWHM_MAX",
2246 visir_img_phot_config.beamshape.major));
2247 cpl_propertylist_set_comment(qclist,
"ESO QC GAUSSFIT FWHM_MAX",
2248 "major axis [pix]");
2249 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC GAUSSFIT FWHM_MAX_ERR",
2250 visir_img_phot_config.beamshape.major_err));
2251 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC GAUSSFIT FWHM_MIN",
2252 visir_img_phot_config.beamshape.minor));
2253 cpl_propertylist_set_comment(qclist,
"ESO QC GAUSSFIT FWHM_MIN",
2254 "minor axis [pix]");
2255 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC GAUSSFIT FWHM_MIN_ERR",
2256 visir_img_phot_config.beamshape.minor_err));
2257 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC GAUSSFIT ANGLE",
2258 visir_img_phot_config.beamshape.angle * CPL_MATH_DEG_RAD));
2259 cpl_propertylist_set_comment(qclist,
"ESO QC GAUSSFIT ANGLE",
2261 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC GAUSSFIT ANGLE_ERR",
2262 visir_img_phot_config.beamshape.angle_err * CPL_MATH_DEG_RAD));
2263 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC GAUSSFIT PEAK",
2264 visir_img_phot_config.beamshape.peak));
2265 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC GAUSSFIT PEAK_ERR",
2266 visir_img_phot_config.beamshape.peak_err));
2268 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMX POS1",
2269 visir_img_phot_config.fwhm_x_pos1));
2271 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMY POS1",
2272 visir_img_phot_config.fwhm_y_pos1));
2274 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMX POS2",
2275 visir_img_phot_config.fwhm_x_pos2));
2277 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMY POS2",
2278 visir_img_phot_config.fwhm_y_pos2));
2280 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMX NEG1",
2281 visir_img_phot_config.fwhm_x_neg1));
2283 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMY NEG1",
2284 visir_img_phot_config.fwhm_y_neg1));
2286 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMX NEG2",
2287 visir_img_phot_config.fwhm_x_neg2));
2289 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMY NEG2",
2290 visir_img_phot_config.fwhm_y_neg2));
2292 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC SENSIT",
2293 visir_img_phot_config.sensitivity));
2295 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC AREA SENSIT",
2296 visir_img_phot_config.area_sensit));
2297 cpl_propertylist_set_comment(qclist,
"ESO QC AREA SENSIT",
2298 "scaled to noise of 1 arcsecond");
2300 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC CONVER",
2301 visir_img_phot_config.conversion));
2303 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC STREHL",
2304 visir_img_phot_config.strehl));
2306 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC STREHL ERROR",
2307 visir_img_phot_config.strehl_err));
2310 skip_if (visir_qc_append_capa(qclist, rawframes));
2313 cpl_propertylist * pcopy = cpl_propertylist_new();
2314 const cpl_error_code error
2315 = cpl_propertylist_copy_property_regexp(pcopy, reflist,
"^("
2316 IRPLIB_PFITS_WCS_REGEXP
2318 if (!error && cpl_propertylist_get_size(pcopy) > 0) {
2319 cpl_msg_warning(cpl_func,
"Combined image will have no WCS "
2322 cpl_propertylist_delete(pcopy);
2325 bug_if(cpl_propertylist_copy_property_regexp(qclist, reflist,
"^("
2326 VISIR_PFITS_IMG_PHOT_COPY
2329 bug_if(cpl_propertylist_copy_property_regexp(qclist, reflist,
"^("
2330 VISIR_PFITS_IMG_PHOT_COPY
2331 "|" IRPLIB_PFITS_WCS_REGEXP
2339 return cpl_error_get_code();
2356 static cpl_error_code visir_img_phot_save(cpl_frameset *
self,
2357 const cpl_parameterlist * parlist,
2358 const cpl_propertylist * qclist,
2359 const cpl_image * combined,
2360 const cpl_image * contrib,
2361 const cpl_image * beam1,
2362 const cpl_image * beam1i,
2363 const cpl_image * weights)
2366 cpl_propertylist * xtlist = cpl_propertylist_new();
2367 const char * procatg = VISIR_IMG_PHOT_COMBINED_PROCATG;
2372 const char * s = cpl_propertylist_get_string(qclist,
"ESO QC BEAMID");
2375 if (strcmp(s,
"COMBINED") == 0)
2376 procatg = VISIR_IMG_PHOT_COMBINED_PROCATG;
2378 procatg = VISIR_IMG_PHOT_ONEBEAM_PROCATG;
2383 CPL_BPP_IEEE_FLOAT, RECIPE_SAVE_STRING,
2384 procatg, qclist, NULL, visir_pipe_id,
2385 RECIPE_SAVE_STRING CPL_DFS_FITS));
2389 bug_if(cpl_propertylist_append_string(xtlist,
"EXTNAME",
2390 "Contribution Map"));
2391 skip_if (cpl_image_save(contrib, RECIPE_SAVE_STRING CPL_DFS_FITS,
2392 CPL_BPP_16_UNSIGNED, xtlist, CPL_IO_EXTEND));
2395 if (beam1 != NULL) {
2399 CPL_BPP_IEEE_FLOAT, RECIPE_SAVE_STRING,
2400 VISIR_IMG_PHOT_ONEBEAM_PROCATG, qclist,
2401 NULL, visir_pipe_id,
2402 RECIPE_SAVE_STRING
"_onebeam" CPL_DFS_FITS));
2405 skip_if (cpl_image_save(beam1i, RECIPE_SAVE_STRING
"_onebeam" CPL_DFS_FITS,
2406 CPL_BPP_8_UNSIGNED, xtlist, CPL_IO_EXTEND));
2411 cpl_propertylist_delete(xtlist);
2413 return cpl_error_get_code();
2428 static char * visir_img_phot_filter2label(
const char *
self)
2431 char * label = NULL;
2434 bug_if(
self == NULL);
2436 label = cpl_strdup(
self);
2438 for (p = label; *p != (char)0; p++) {
2439 if (*p ==
'.' || *p ==
'-') *p =
'_';
double visir_parameterlist_get_double(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR parameter of type double.
double visir_pfits_get_dec(const cpl_propertylist *self)
The DEC.
cpl_error_code visir_dfs_check_framelist_tag(const irplib_framelist *self)
Check the tags in a frameset (group raw only)
cpl_error_code irplib_apertures_find_max_flux(const cpl_apertures *self, int *ind, int nfind)
Find the aperture(s) with the greatest flux.
const char * visir_pfits_get_starname(const cpl_propertylist *self)
The std star name.
cpl_error_code irplib_pfits_set_airmass(cpl_propertylist *self, const irplib_framelist *rawframes)
Update/Set the AIRMASS property.
const char * visir_pfits_get_filter(const cpl_propertylist *self)
The filter.
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.
const char * visir_parameterlist_get_string(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR string parameter.
const char * visir_pfits_get_insmode(const cpl_propertylist *self)
The mode.
double visir_pfits_get_img_weight(const cpl_propertylist *self)
The relative weight of the image compared to the other images.
irplib_framelist * irplib_framelist_extract(const irplib_framelist *self, const char *tag)
Extract the frames with the given tag from a framelist.
int visir_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
double visir_pfits_get_dit(const cpl_propertylist *self)
The DIT.
double visir_pfits_get_pixscale(const cpl_propertylist *self)
The pixel scale.
void irplib_framelist_delete(irplib_framelist *self)
Deallocate an irplib_framelist with its frames and properties.
const char * visir_pfits_get_chopnod_dir(const cpl_propertylist *self)
The chopping direction.
cpl_error_code irplib_framelist_contains(const irplib_framelist *self, const char *key, cpl_type type, cpl_boolean is_equal, double fp_tol)
Verify that a property is present for all frames.
const char * irplib_frameset_find_file(const cpl_frameset *self, const char *tag)
Find the filename with the given tag in a frame set.
cpl_propertylist * irplib_framelist_get_propertylist(irplib_framelist *self, int pos)
Get the propertylist of the specified frame in the framelist.
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.
double visir_pfits_get_ra(const cpl_propertylist *self)
The RA.
int irplib_framelist_get_size(const irplib_framelist *self)
Get the size of a framelist.