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
79typedef struct beamshape_ {
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;
90static double visir_img_phot_eccent_four(
const cpl_apertures *,
int,
int,
91 const cpl_apertures *,
int,
int);
93static 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
96static double visir_img_phot_eccent_three(
const cpl_apertures *,
int,
97 const cpl_apertures *,
int,
int);
100static double visir_img_phot_jy_from_cat(
const char *,
const char *,
double,
101 double,
const char *);
102static 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 *);
105static int visir_img_phot_flux_three(
const cpl_image *);
106static int visir_img_phot_flux_four(
const cpl_image *);
107static int visir_img_phot_flux(
const cpl_image *,
const cpl_image *,
108 const cpl_image *,
double,
109 double,
int,
int,
int,
double *,
110 double *,
int *,
double *, beamshape_t *);
112static cpl_error_code visir_get_filter_infos(
const char *,
double *,
double *);
114static cpl_error_code visir_img_phot_qc(cpl_propertylist *,
116 const irplib_framelist *);
118static cpl_error_code visir_img_phot_save(cpl_frameset *,
119 const cpl_parameterlist *,
120 const cpl_propertylist *,
127static char * visir_img_phot_filter2label(
const char *);
130#define cpl_plugin_get_info visir_old_img_phot_get_info
132VISIR_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);
167static 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];
188 beamshape_t beamshape;
202} visir_img_phot_config;
217propagate_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 s = cpl_propertylist_get_string(ppqc,
"ESO DRS CATG");
227 cpl_propertylist_append_string(qclist,
"ESO DRS CATG", s);
229 d = cpl_propertylist_get_double(ppqc,
"ESO QC BACKGD MEAN");
230 cpl_propertylist_append_double(qclist,
"ESO QC BACKGD MEAN", d);
232 d = cpl_propertylist_get_double(ppqc,
"ESO QC EXPTIME EFFECTIVE");
233 cpl_propertylist_append_double(qclist,
"ESO QC EXPTIME EFFECTIVE", d);
235 if (cpl_propertylist_has(ppqc,
"ESO QC EXECTIME")) {
236 d = cpl_propertylist_get_double(ppqc,
"ESO QC EXECTIME");
237 cpl_propertylist_append_double(qclist,
"ESO QC EXECTIME", d);
240 i = cpl_propertylist_get_int(ppqc,
"ESO QC NIMAGES TOTAL");
241 cpl_propertylist_append_int(qclist,
"ESO QC NIMAGES TOTAL", i);
243 i = cpl_propertylist_get_int(ppqc,
"ESO QC NIMAGES EFFECTIVE");
244 cpl_propertylist_append_int(qclist,
"ESO QC NIMAGES EFFECTIVE", i);
246 s = cpl_propertylist_get_string(ppqc,
"ESO QC BEAMID");
247 cpl_propertylist_append_string(qclist,
"ESO QC BEAMID", s);
249 error_if(strcmp(s,
"UNDEFINED") == 0, CPL_ERROR_ILLEGAL_INPUT,
250 "Object detection was not successful, "
251 "please provide visir_util_detect_position with the object "
252 "positions to allow photometry");
253 if (strcmp(s,
"COMBINED") != 0) {
254 d = cpl_propertylist_get_double(ppqc,
"ESO QC BEAMX");
255 cpl_propertylist_append_double(qclist,
"ESO QC BEAMX", d);
257 d = cpl_propertylist_get_double(ppqc,
"ESO QC BEAMY");
258 cpl_propertylist_append_double(qclist,
"ESO QC BEAMY", d);
263 return cpl_error_get_code();
275static int visir_old_img_phot(cpl_frameset * framelist,
276 const cpl_parameterlist * parlist)
278 cpl_errorstate cleanstate = cpl_errorstate_get();
279 irplib_framelist * allframes = NULL;
280 irplib_framelist * rawframes = NULL;
281 cpl_propertylist * ppqc = NULL;
282 cpl_propertylist * qclist = NULL;
284 const char * star_cat;
286 cpl_image * weights = NULL;
287 cpl_image * contrib = NULL;
288 cpl_image ** combined = NULL;
289 cpl_image ** beam1 = NULL;
291 cpl_boolean drop_wcs = CPL_FALSE;
292 const char * keys_regexp =
"^(" RECIPE_KEYS_REGEXP_WCS
293 "|"VISIR_PFITS_REGEXP_DIT
295 const char * combine_string;
296 cpl_geom_combine combine_mode;
297 cpl_boolean one_beam = CPL_FALSE;
298 const char * dit_key = VISIR_PFITS_DOUBLE_DIT;
302 visir_img_phot_config.exptime = -1.0;
303 visir_img_phot_config.pscale = -1.0;
304 visir_img_phot_config.star_name[0] = (char)0;
305 visir_img_phot_config.filter[0] = (char)0;
306 visir_img_phot_config.bg_sigma = -1.0;
307 visir_img_phot_config.flux_snr = -1.0;
308 visir_img_phot_config.flux_snr_noise = -1.0;
309 visir_img_phot_config.flux_snr_radius[0] = -1;
310 visir_img_phot_config.flux_snr_radius[1] = -1;
311 visir_img_phot_config.flux_snr_radius[2] = -1;
312 visir_img_phot_config.flux_snr_radius[3] = -1;
313 visir_img_phot_config.flux_tot = -1.0;
314 visir_img_phot_config.nelec = -1.0;
315 visir_img_phot_config.nphot = -1.0;
316 visir_img_phot_config.beamshape =
317 (beamshape_t){.fwhm_x = -1., .fwhm_y = -1.,
318 .peak = -1., .peak_err = 0.,
319 .major = -1., .major_err = 0.,
320 .minor = -1., .minor_err = 0.,
321 .angle = -1., .angle_err = 0.};
322 visir_img_phot_config.fwhm_x_pos1 = -1.0;
323 visir_img_phot_config.fwhm_y_pos1 = -1.0;
324 visir_img_phot_config.fwhm_x_pos2 = -1.0;
325 visir_img_phot_config.fwhm_y_pos2 = -1.0;
326 visir_img_phot_config.fwhm_x_neg1 = -1.0;
327 visir_img_phot_config.fwhm_y_neg1 = -1.0;
328 visir_img_phot_config.fwhm_x_neg2 = -1.0;
329 visir_img_phot_config.fwhm_y_neg2 = -1.0;
330 visir_img_phot_config.sensitivity = -1.0;
331 visir_img_phot_config.area_sensit = -1.0;
332 visir_img_phot_config.conversion = -1.0;
333 visir_img_phot_config.strehl = -1.0;
334 visir_img_phot_config.strehl_err = -1.0;
338 VISIR_PARAM_COMBINE);
340 bug_if (combine_string == NULL);
342 if (combine_string[0] ==
'u')
343 combine_mode = CPL_GEOM_UNION;
344 else if (combine_string[0] ==
'f')
345 combine_mode = CPL_GEOM_FIRST;
346 else if (combine_string[0] ==
'i')
347 combine_mode = CPL_GEOM_INTERSECT;
352 visir_img_phot_config.jy_val =
357 skip_if (sval == NULL);
359 skip_if (sscanf(sval,
"%d%*c%d%*c%d",
360 &visir_img_phot_config.r0_max,
361 &visir_img_phot_config.r1,
362 &visir_img_phot_config.r2) != 3);
368 allframes = irplib_framelist_cast(framelist);
369 skip_if(allframes == NULL);
371 rawframes = irplib_framelist_extract(allframes, VISIR_IMG_PHOT_RAW);
372 if (rawframes == NULL) {
373 cpl_errorstate_set(cleanstate);
374 rawframes = irplib_framelist_extract(allframes,
375 VISIR_IMG_CAL_PHOT_PP);
376 skip_if (rawframes == NULL);
378 irplib_frameset_find_file(framelist, VISIR_UTIL_QC_PROCATG);
380 cpl_msg_error(cpl_func,
"The input files has no header tagged "
381 "%s", VISIR_UTIL_QC_PROCATG);
382 visir_error_set(CPL_ERROR_DATA_NOT_FOUND);
385 ppqc = cpl_propertylist_load(fn, 0);
390 skip_if (rawframes == NULL);
392 irplib_framelist_empty(allframes);
394 skip_if(irplib_framelist_load_propertylist(rawframes, 0, 0, keys_regexp,
396 qclist = cpl_propertylist_duplicate(irplib_framelist_get_propertylist(rawframes, 0));
398 skip_if(propagate_qc_header(qclist, ppqc));
400 skip_if(irplib_framelist_load_propertylist_all(rawframes, 0,
"^("
401 RECIPE_KEYS_REGEXP_ALL
402 "|"VISIR_PFITS_REGEXP_DIT
407 if (cpl_propertylist_has(irplib_framelist_get_propertylist(rawframes, 0),
408 VISIR_PFITS_DOUBLE_SEQ1_DIT))
409 dit_key = VISIR_PFITS_DOUBLE_SEQ1_DIT;
413 star_cat = irplib_frameset_find_file(framelist, VISIR_CALIB_STDSTAR_IMG);
414 if (star_cat == NULL) {
415 cpl_msg_error(cpl_func,
"The input files has no star catalog tagged "
416 "%s", VISIR_CALIB_STDSTAR_IMG);
417 visir_error_set(CPL_ERROR_DATA_NOT_FOUND);
422 badpix = irplib_frameset_find_file(framelist, VISIR_CALIB_BPM);
425 flat = irplib_frameset_find_file(framelist, VISIR_CALIB_FLAT);
429 skip_if(irplib_framelist_contains(rawframes, dit_key,
430 CPL_TYPE_DOUBLE, CPL_FALSE, 0.0));
431 if(irplib_framelist_contains(rawframes, dit_key,
432 CPL_TYPE_DOUBLE, CPL_TRUE, 1e-5)) {
435 visir_error_reset(
"DIT differs by more than %g", 1e-5);
439 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_DOUBLE_RA,
440 CPL_TYPE_DOUBLE, CPL_FALSE, 0.0));
443 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_DOUBLE_DEC,
444 CPL_TYPE_DOUBLE, CPL_TRUE, 1.0));
446 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_INT_CHOP_NCYCLES,
447 CPL_TYPE_INT, CPL_TRUE, 0.0));
449 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_INT_NDIT,
450 CPL_TYPE_INT, CPL_TRUE, 0.0));
452 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_STRING_STARNAME,
453 CPL_TYPE_STRING, CPL_TRUE, 0.0));
455 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_STRING_INSMODE,
456 CPL_TYPE_STRING, CPL_TRUE, 0.0));
459 irplib_framelist_get_propertylist_const(rawframes, 0)),
461 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_STRING_FILTER1,
462 CPL_TYPE_STRING, CPL_TRUE, 0.0));
464 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_STRING_FILTER2,
465 CPL_TYPE_STRING, CPL_TRUE, 0.0));
468 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_STRING_PIXSCALE,
469 CPL_TYPE_STRING, CPL_TRUE, 0.0));
474 irplib_frameset_find_file(framelist,
"WEIGHT_MAP");
476 cpl_msg_info(cpl_func,
"Loading weight map %s", prew);
477 weights = cpl_image_load(prew, CPL_TYPE_UNSPECIFIED, 0, 0);
483 irplib_frameset_find_file(framelist,
"CONTRIBUTION_MAP");
485 cpl_msg_info(cpl_func,
"Loading contribution map %s", prec);
486 contrib = cpl_image_load(prec, CPL_TYPE_INT, 0, 0);
492 cpl_msg_info(cpl_func,
"Combining the images");
495 irplib_frameset_find_file(framelist, VISIR_IMG_CAL_PHOT_PP);
497 combined = cpl_calloc(2,
sizeof(combined[0]));
498 combined[0] = cpl_image_load(pre, CPL_TYPE_UNSPECIFIED, 0, 0);
499 combined[1] = contrib ? cpl_image_duplicate(contrib) : NULL;
500 if (combined[0] == NULL) {
501 cpl_msg_error(cpl_func,
"Could not load the input frames");
505 cpl_mask * m = cpl_mask_threshold_image_create(weights, -1,
507 cpl_image_reject_from_mask(combined[0], m);
513 badpix, flat, combine_mode,
514 &drop_wcs, CPL_FALSE, 0.0, 0);
515 if (combined == NULL) {
516 cpl_msg_error(cpl_func,
"Could not combine the input frames");
521 irplib_framelist_get_propertylist_const
524 irplib_error_recover(cleanstate,
"Could not collapse the "
525 "beams of the combined image");
529 skip_if(visir_qc_append_background(qclist, rawframes, 0, 0));
534 cpl_msg_info(cpl_func,
"Computing the sensitivity");
535 if (visir_img_phot_sensit(combined[0], weights, contrib, rawframes,
536 star_cat, one_beam, ppqc)) {
537 cpl_msg_error(cpl_func,
"Could not compute sensitivity: '%s' in %s",
538 cpl_error_get_message(), cpl_error_get_where());
542 skip_if (visir_img_phot_qc(qclist, drop_wcs, rawframes));
543 irplib_framelist_empty(rawframes);
547 cpl_msg_info(cpl_func,
"Saving the combined image with its contribution "
549 skip_if (visir_img_phot_save(framelist, parlist, qclist, combined[0],
550 combined[1], NULL, NULL, weights));
552 cpl_msg_info(cpl_func,
"Saving the combined and the beam-combined "
553 "images with their contribution maps");
554 skip_if (visir_img_phot_save(framelist, parlist, qclist, combined[0],
555 combined[1], beam1[0], beam1[1], weights));
560 cpl_propertylist_delete(qclist);
561 irplib_framelist_delete(allframes);
562 irplib_framelist_delete(rawframes);
563 cpl_propertylist_delete(ppqc);
564 cpl_image_delete(weights);
565 cpl_image_delete(contrib);
568 cpl_image_delete(combined[0]);
569 cpl_image_delete(combined[1]);
574 cpl_image_delete(beam1[0]);
575 cpl_image_delete(beam1[1]);
579 return cpl_error_get_code();
609static int visir_img_phot_sensit(
const cpl_image * combined,
610 const cpl_image * weights,
611 const cpl_image * contrib,
612 const irplib_framelist * rawframes,
613 const char * star_cat,
614 cpl_boolean one_beam,
615 cpl_propertylist * ppqc)
617 cpl_errorstate cleanstate = cpl_errorstate_get();
618 const cpl_propertylist * plist = NULL;
626 plist = irplib_framelist_get_propertylist_const(rawframes, 0);
634 exptime = cpl_propertylist_get_double(ppqc,
"ESO QC EXPTIME TOTAL");
636 const int nnod = irplib_framelist_get_size(rawframes);
637 exptime = visir_utils_get_exptime(nnod, plist);
639 visir_img_phot_config.exptime = exptime;
641 if (exptime <= 0 || cpl_error_get_code()) {
642 cpl_msg_error(cpl_func,
"Illegal exposure time: %g", exptime);
649 (void) strncpy(visir_img_phot_config.star_name, sval, fits_strlen);
653 (void)strncpy(visir_img_phot_config.filter, sval, fits_strlen);
665 if (visir_img_phot_config.jy_val < -998) {
666 visir_img_phot_config.jy_val =
667 visir_img_phot_jy_from_cat(star_cat, visir_img_phot_config.filter,
668 ra,dec, visir_img_phot_config.star_name);
669 skip_if (visir_img_phot_config.jy_val < -998);
673 cpl_msg_info(cpl_func,
"Star %s with filter %s : %g Jy",
674 visir_img_phot_config.star_name,
675 visir_img_phot_config.filter,
676 visir_img_phot_config.jy_val);
679 visir_img_phot_config.bg_sigma = visir_img_phot_sigma_clip(combined);
683 cpl_msg_info(cpl_func,
"Compute the star flux");
687 skip_if (visir_img_phot_flux_one(combined, weights, contrib, plist));
689 else if (sval != NULL && !strcmp(sval,
"PERPENDICULAR")) {
691 skip_if (visir_img_phot_flux_four(combined));
692 }
else if (sval != NULL && !strcmp(sval,
"PARALLEL")) {
694 skip_if (visir_img_phot_flux_three(combined));
697 visir_error_reset(
"Could not get FITS key");
699 cpl_msg_warning(cpl_func,
"Unknown chopping direction: %s", sval);
701 cpl_msg_warning(cpl_func,
"Proceeding as if FITS card %s had value %s",
702 "ESO SEQ CHOPNOD DIR",
"PERPENDICULAR");
703 if (visir_img_phot_flux_four(combined)) {
704 visir_error_reset(
"Proceeding as if FITS card %s had value %s",
705 "ESO SEQ CHOPNOD DIR",
"PARALLEL");
706 skip_if (visir_img_phot_flux_three(combined));
711 visir_error_reset(
"Could not get chopping direction");
712 if (visir_img_phot_flux_three(combined)) {
713 cpl_msg_error(cpl_func,
"Could not compute the flux");
716 }
else if (!strcmp(sval,
"PARALLEL")) {
718 if (visir_img_phot_flux_three(combined)) {
719 cpl_msg_error(cpl_func,
"Could not compute the flux");
724 if (strcmp(sval,
"PERPENDICULAR"))
725 cpl_msg_warning(cpl_func,
"Unknown chopping direction: %s", sval);
726 if (visir_img_phot_flux_four(combined)) {
727 cpl_msg_error(cpl_func,
"Could not compute the flux");
736 double fluxSI = visir_img_phot_config.jy_val * 1e-26;
739 double area = (8.2/2.) * (8.2/2.) * CPL_MATH_PI;
746 if (ppqc && cpl_propertylist_has(ppqc,
"ESO DET CHIP1 GAIN"))
747 gain = cpl_propertylist_get_double(ppqc,
"ESO DET CHIP1 GAIN");
748 else if (ppqc && cpl_propertylist_has(ppqc,
"ESO DET CHIP GAIN"))
749 gain = cpl_propertylist_get_double(ppqc,
"ESO DET CHIP GAIN");
751 cpl_msg_warning(cpl_func,
"ESO DET CHIP1 GAIN not found, "
752 "assuming %g", gain);
754 if (filter && !visir_get_filter_infos(filter, &wl, &bandwidth)) {
756 double bwh, ptot, ephot;
760 bwh = CPL_PHYS_C / (wl * wl) * bandwidth;
762 ptot = fluxSI * area * bwh;
764 ephot = CPL_PHYS_H * CPL_PHYS_C / wl;
766 visir_img_phot_config.nelec = visir_img_phot_config.flux_tot * gain;
767 visir_img_phot_config.nphot = ptot / ephot * dit;
770 cpl_msg_warning(cpl_func,
"Unknown filter: %s", filter);
775 skip_if ( visir_img_phot_config.flux_snr == 0 );
776 skip_if ( visir_img_phot_config.flux_snr_noise == 0 );
777 skip_if ( visir_img_phot_config.jy_val == 0 );
779 f2 = visir_img_phot_config.flux_snr / visir_img_phot_config.flux_snr_noise;
780 f2 *= sqrt(3600/visir_img_phot_config.exptime);
781 visir_img_phot_config.sensitivity = visir_img_phot_config.jy_val*1000*10/f2;
783 visir_img_phot_config.conversion = visir_img_phot_config.flux_tot /
784 visir_img_phot_config.jy_val /
788 visir_img_phot_config.area_sensit =
789 visir_img_phot_config.sensitivity *
790 sqrt((1. / SQR(visir_img_phot_config.pscale)) /
791 SQR(visir_img_phot_config.flux_snr_radius[0]));
795 cpl_msg_info(cpl_func,
"Sensitivity : %g", visir_img_phot_config.sensitivity);
796 cpl_msg_info(cpl_func,
"Conversion : %g", visir_img_phot_config.conversion);
797 cpl_msg_info(cpl_func,
"Strehl : %g", visir_img_phot_config.strehl);
798 cpl_msg_info(cpl_func,
"Strehl error: %g", visir_img_phot_config.strehl_err);
799 cpl_msg_info(cpl_func,
"Exposure : %g s", visir_img_phot_config.exptime);
801 return cpl_error_get_code();
815static double visir_img_phot_jy_from_cat(
816 const char * star_cat,
820 const char * star_name)
822 cpl_table * tab = NULL;
823 cpl_vector * v_ra = NULL;
824 cpl_vector * v_dec = NULL;
825 const char * stdstar;
828 const double max_radius = VISIR_STAR_MAX_RADIUS;
836 skip_if( star_cat == NULL );
837 skip_if( star_name == NULL );
838 skip_if( filter == NULL );
840 label = visir_img_phot_filter2label(filter);
841 skip_if(label == NULL);
844 if ((tab = cpl_table_load(star_cat, 1, 1)) == NULL) {
845 cpl_error_set_message(cpl_func, cpl_error_get_code(),
846 "Could not load the star catalog: %s",
852 if (!cpl_table_has_column(tab, label)) {
853 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
854 "Catalog %s has no column for filter: %s",
859 if (!cpl_table_has_column(tab,
"STARS")) {
860 cpl_error_set_message(cpl_func, CPL_ERROR_BAD_FILE_FORMAT,
861 "Catalog %s does not have a column labeled %s",
866 nb_stars = cpl_table_get_nrow(tab);
867 skip_if (nb_stars < 1);
870 v_ra = cpl_vector_wrap(nb_stars, cpl_table_get_data_double(tab,
"RA"));
871 skip_if( v_ra == NULL);
873 v_dec = cpl_vector_wrap(nb_stars, cpl_table_get_data_double(tab,
"DEC"));
874 skip_if( v_dec == NULL);
876 min_dist_ind = visir_star_find(v_ra, v_dec, ra, dec, max_radius, &dist);
878 if (min_dist_ind < 0) {
879 cpl_error_set_message(cpl_func, cpl_error_get_code(),
880 "Observation target '%s' was not found among "
881 "the %d entries in the standard star catalog %s",
882 star_name, nb_stars, star_cat);
886 stdstar = cpl_table_get_string(tab,
"STARS", min_dist_ind);
887 skip_if ( stdstar == NULL );
890 jy = cpl_table_get(tab, label, min_dist_ind, &null);
893 if (null || isnan(jy)) {
894 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
895 "Catalog does not contain a value for %s in "
896 "filter %s", star_name, filter);
902 if (strcmp(stdstar, star_name) != 0 && dist > 0.0) {
904 cpl_msg_warning(cpl_func,
"The standard star '%s' at (RA,DEC)=(%g,%g) "
905 "in the FITS header is closest to the catalog star "
906 "'%s' at (RA,DEC)=(%g,%g) at distance %g degrees",
907 star_name, ra, dec, stdstar,
908 cpl_vector_get(v_ra, min_dist_ind),
909 cpl_vector_get(v_dec, min_dist_ind), dist);
910 }
else if (dist > 0.0) {
912 cpl_msg_warning(cpl_func,
"The location of the standard star '%s' in "
913 "the FITS header (RA,DEC)=(%g,%g) and the catalog "
914 "(RA,DEC)=(%g,%g) differ by %g degrees", stdstar, ra,
915 dec, cpl_vector_get(v_ra, min_dist_ind),
916 cpl_vector_get(v_dec, min_dist_ind), dist);
917 }
else if (strcmp(stdstar, star_name) != 0) {
919 cpl_msg_warning(cpl_func,
"The name of the standard star at (RA,DEC)="
920 "(%g,%g) in the FITS header '%s' and the catalog '%s' "
921 "are different", ra, dec, star_name, stdstar);
923 cpl_msg_info(cpl_func,
"Standard star is '%s' at (RA, DEC)=(%g,%g)",
926 if (cpl_msg_get_level() <= CPL_MSG_DEBUG)
927 cpl_table_dump(tab, min_dist_ind, 1, stdout);
930 cpl_msg_info(cpl_func,
"The standard star '%s' has %g Jy through filter %s",
931 stdstar, value, filter);
936 cpl_table_delete(tab);
937 cpl_vector_unwrap(v_ra);
938 cpl_vector_unwrap(v_dec);
953static int visir_img_phot_flux_three(
const cpl_image * combined)
955 cpl_errorstate cleanstate = cpl_errorstate_get();
956 cpl_image * min_combined = NULL;
957 cpl_apertures * appos = NULL;
958 cpl_apertures * apneg = NULL;
959 cpl_vector * sigmas = NULL;
960 double psigmas[] = {5, 2, 1, 0.5};
964 double flux_snr_noise[3];
965 int flux_snr_radius[3];
967 beamshape_t beamshapes[3];
971 double star_bg,star_peak,star_flux,psf_peak,psf_flux,bg_noise;
972 double eccmin = DBL_MAX;
973 const int nsigmas =
sizeof(psigmas)/
sizeof(
double);
975#ifdef VISIR_IMG_PHOT_USE_ECCENT_THREE
976 int ipos, ineg1, ineg2;
978 int iappos, iapneg2[2];
982 if (cpl_error_get_code())
return cpl_error_get_code();
984 cpl_ensure_code(combined != NULL, CPL_ERROR_NULL_INPUT);
986 cpl_msg_info(cpl_func,
"Detecting the 3-source star using %d sigma-levels "
987 "ranging from %g down to %g", nsigmas, psigmas[0],
990 sigmas = cpl_vector_new(1);
991 min_combined = cpl_image_multiply_scalar_create(combined, -1.0);
993 for (isigma = 0; isigma < nsigmas; isigma++) {
996 irplib_error_recover(cleanstate,
"Resetting error (why?)");
998 bug_if(cpl_vector_set(sigmas, 0, psigmas[isigma]));
1001 cpl_apertures_delete(appos);
1002 appos = cpl_apertures_extract(combined, sigmas, NULL);
1003 if (appos == NULL) {
1004 cpl_msg_warning(cpl_func,
"Found no positive star at sigma=%g",
1010 cpl_apertures_delete(apneg);
1011 apneg = cpl_apertures_extract(min_combined, sigmas, NULL);
1012 if (apneg == NULL) {
1013 cpl_msg_warning(cpl_func,
"Found no negative stars at sigma=%g",
1017 if (cpl_apertures_get_size(apneg) < 2) {
1018 cpl_msg_warning(cpl_func,
"Found just 1 negative star at sigma=%g, "
1019 "need two", psigmas[isigma]);
1023 cpl_msg_info(cpl_func,
"Found positive and negative stars at sigma=%g",
1028 skip_if(appos == NULL);
1029 skip_if(apneg == NULL);
1030 skip_if (cpl_apertures_get_size(apneg) < 2);
1032 if (cpl_msg_get_level() == CPL_MSG_DEBUG) {
1033 cpl_apertures_dump(appos, stdout);
1034 cpl_apertures_dump(apneg, stdout);
1037#ifndef VISIR_IMG_PHOT_USE_ECCENT_THREE
1038 bug_if(irplib_apertures_find_max_flux(appos, &iappos, 1));
1039 bug_if(irplib_apertures_find_max_flux(apneg, iapneg2, 2));
1041 if (cpl_apertures_get_size(appos) > 1 || cpl_apertures_get_size(apneg) > 2)
1042 cpl_msg_info(cpl_func,
"Selecting from %d positive and %d negative "
1043 "stars 3 stars on a vertical line",
1044 cpl_apertures_get_size(appos),
1045 cpl_apertures_get_size(apneg));
1047 for (ipos = 1; ipos <= cpl_apertures_get_size(appos); ipos++) {
1048 for (ineg1 = 2; ineg1 <= cpl_apertures_get_size(apneg); ineg1++) {
1049 for (ineg2 = 1; ineg2 < ineg1; ineg2++) {
1050 const double ecc = visir_img_phot_eccent_three(appos, ipos,
1054 if (eccmin < DBL_MAX)
1055 cpl_msg_debug(cpl_func,
"Found star positions with "
1056 "reduced mis-alignment [pixel]: "
1057 "%g < %g", ecc, eccmin);
1068 if (cpl_apertures_get_flux(apneg, iapneg2[0]) <
1069 cpl_apertures_get_flux(apneg, iapneg2[1])) {
1070 const int tmp = iapneg2[0];
1071 iapneg2[0] = iapneg2[1];
1077 x[0] = cpl_apertures_get_centroid_x(appos, iappos);
1078 y[0] = cpl_apertures_get_centroid_y(appos, iappos);
1080 x[1] = cpl_apertures_get_centroid_x(apneg, iapneg2[0]);
1081 y[1] = cpl_apertures_get_centroid_y(apneg, iapneg2[0]);
1082 x[2] = cpl_apertures_get_centroid_x(apneg, iapneg2[1]);
1083 y[2] = cpl_apertures_get_centroid_y(apneg, iapneg2[1]);
1085 cpl_apertures_delete(appos);
1086 cpl_apertures_delete(apneg);
1090 cpl_msg_info(cpl_func,
"Positive star at position %g %g", x[0], y[0]);
1091 cpl_msg_info(cpl_func,
"Negative star 1 at position %g %g", x[1], y[1]);
1092 cpl_msg_info(cpl_func,
"Negative star 2 at position %g %g", x[2], y[2]);
1094 dist1 = sqrt((x[1]-x[0])*(x[1]-x[0])+(y[1]-y[0])*(y[1]-y[0]));
1095 dist2 = sqrt((x[2]-x[0])*(x[2]-x[0])+(y[2]-y[0])*(y[2]-y[0]));
1096 cpl_msg_info(cpl_func,
"Star 1 Pos/Neg Distance: %g", dist1);
1097 cpl_msg_info(cpl_func,
"Star 2 Pos/Neg Distance: %g", dist2);
1100 if (eccmin < DBL_MAX) {
1101 cpl_msg_info(cpl_func,
"The deviation from a vertical line by "
1102 "the three stars [pixel]: %g", eccmin);
1103 if (eccmin > VISIR_IMG_PHOT_POS_WARN) {
1104 if (eccmin > VISIR_IMG_PHOT_POS_ERROR) {
1105 cpl_msg_error(cpl_func,
"The deviation from a vertical line"
1106 " by the three stars exceed %g, the detected "
1107 "objects are wrong", VISIR_IMG_PHOT_POS_ERROR);
1110 cpl_msg_warning(cpl_func,
"The deviation from a vertical line "
1111 "by the three stars exceed %g, the detected "
1112 "objects may be wrong", VISIR_IMG_PHOT_POS_WARN);
1117 if ((
int)x[0]-IRPLIB_STREHL_BORDER <= 0 ||
1118 (
int)y[0]-IRPLIB_STREHL_BORDER <= 0 ||
1119 (
int)x[0]+IRPLIB_STREHL_BORDER > cpl_image_get_size_x(combined) ||
1120 (
int)y[0]+IRPLIB_STREHL_BORDER > cpl_image_get_size_y(combined)) {
1121 cpl_msg_error(cpl_func,
"Positive star at (%g,%g) is less than %d "
1122 "pixels from the image border", x[0], y[0],
1123 1+IRPLIB_STREHL_BORDER);
1129 if (fabs(dist1-dist2) > VISIR_IMG_PHOT_POS_UNCERTAINTY) {
1130 cpl_msg_error(cpl_func,
"Too large Pos/Neg Distance between the two "
1131 "stars: %g > %g", fabs(dist1-dist2),
1132 VISIR_IMG_PHOT_POS_UNCERTAINTY);
1137 skip_if (visir_img_phot_flux(combined, NULL, NULL,
1139 visir_img_phot_config.r0_max,
1140 visir_img_phot_config.r1,
1141 visir_img_phot_config.r2,
1143 &(flux_snr_noise[0]),
1144 &(flux_snr_radius[0]),
1149 for (i=1 ; i<3 ; i++)
1150 skip_if (visir_img_phot_flux(min_combined, NULL, NULL,
1152 visir_img_phot_config.r0_max,
1153 visir_img_phot_config.r1,
1154 visir_img_phot_config.r2,
1156 &(flux_snr_noise[i]),
1157 &(flux_snr_radius[i]),
1161 cpl_image_delete(min_combined);
1162 min_combined = NULL;
1166 visir_img_phot_config.flux_snr = 0.0;
1167 for (i=0 ; i<3 ; i++) visir_img_phot_config.flux_snr += flux_snr[i];
1170 visir_img_phot_config.flux_snr_noise = 0.0;
1171 for (i=0 ; i<3 ; i++) visir_img_phot_config.flux_snr_noise +=
1172 flux_snr_noise[i]*flux_snr_noise[i];
1173 visir_img_phot_config.flux_snr_noise =
1174 sqrt(visir_img_phot_config.flux_snr_noise);
1176 for (i=0 ; i<3 ; i++)
1177 visir_img_phot_config.flux_snr_radius[i] = flux_snr_radius[i];
1180 visir_img_phot_config.flux_tot = 0.0;
1181 for (i=0 ; i<3 ; i++) visir_img_phot_config.flux_tot += flux_tot[i];
1185 visir_img_phot_config.beamshape.fwhm_x = 0.0;
1186 for (i=0 ; i<3 ; i++) {
1187 if (beamshapes[i].fwhm_x > 0.0) {
1188 visir_img_phot_config.beamshape.fwhm_x += beamshapes[i].fwhm_x;
1192 if (ngood_fwhm > 0) visir_img_phot_config.beamshape.fwhm_x /= ngood_fwhm;
1193 else visir_img_phot_config.beamshape.fwhm_x = -1.0;
1195 visir_img_phot_config.beamshape.fwhm_y = 0.0;
1196 for (i=0 ; i<3 ; i++) {
1197 if (beamshapes[i].fwhm_y > 0.0) {
1198 visir_img_phot_config.beamshape.fwhm_y += beamshapes[i].fwhm_y;
1202 if (ngood_fwhm > 0) visir_img_phot_config.beamshape.fwhm_y /= ngood_fwhm;
1203 else visir_img_phot_config.beamshape.fwhm_y = -1.0;
1204 visir_img_phot_config.fwhm_x_pos1 = beamshapes[0].fwhm_x;
1205 visir_img_phot_config.fwhm_y_pos1 = beamshapes[0].fwhm_y;
1206 visir_img_phot_config.fwhm_x_neg1 = beamshapes[1].fwhm_x;
1207 visir_img_phot_config.fwhm_y_neg1 = beamshapes[1].fwhm_y;
1208 visir_img_phot_config.fwhm_x_neg2 = beamshapes[2].fwhm_x;
1209 visir_img_phot_config.fwhm_y_neg2 = beamshapes[2].fwhm_y;
1212 if (visir_get_filter_infos(visir_img_phot_config.filter, &lam, &dlam)) {
1213 cpl_msg_error(cpl_func,
"Could not get info for filter: %s",
1214 visir_img_phot_config.filter);
1219 cpl_errorstate errstate = cpl_errorstate_get();
1220 if (irplib_strehl_compute(combined, STREHL_M1, STREHL_M2, lam, dlam,
1221 visir_img_phot_config.pscale,
1222 STREHL_BOX_SIZE, x[0], y[0], STREHL_STAR_RADIUS,
1223 STREHL_BG_R1, STREHL_BG_R2, -1, -1,
1224 &(visir_img_phot_config.strehl),
1225 &(visir_img_phot_config.strehl_err),
1226 &star_bg, &star_peak, &star_flux, &psf_peak, &psf_flux,
1228 cpl_msg_error(cpl_func,
"Could not compute the strehl: '%s' in %s",
1229 cpl_error_get_message(), cpl_error_get_where());
1230 cpl_errorstate_set(errstate);
1236 cpl_apertures_delete(appos);
1237 cpl_apertures_delete(apneg);
1238 cpl_vector_delete(sigmas);
1239 cpl_image_delete(min_combined);
1241 return cpl_error_get_code();
1244static int visir_img_phot_flux_one(
const cpl_image * combined,
1245 const cpl_image * weights,
1246 const cpl_image * contrib,
1247 const cpl_propertylist * plist)
1252 double flux_snr_noise;
1253 int flux_snr_radius;
1255 beamshape_t beamshape;
1257 double star_bg,star_peak,star_flux,psf_peak,psf_flux,bg_noise;
1259 if (cpl_error_get_code())
return cpl_error_get_code();
1261 cpl_ensure_code(combined != NULL, CPL_ERROR_NULL_INPUT);
1263 x = cpl_propertylist_get_double(plist,
"CRPIX1");
1264 y = cpl_propertylist_get_double(plist,
"CRPIX2");
1271 cpl_image_get_maxpos_window(combined,
1272 CX_MAX(1, x - 5), CX_MAX(1, y - 5),
1273 CX_MIN(cpl_image_get_size_x(combined), x + 5),
1274 CX_MIN(cpl_image_get_size_y(combined), y + 5), &xp, &yp);
1279 cpl_msg_info(cpl_func,
"Positive star 1 at position %g %g", x, y);
1281 if ((
int)x-IRPLIB_STREHL_BORDER <= 0 ||
1282 (
int)y-IRPLIB_STREHL_BORDER <= 0) {
1283 cpl_msg_error(cpl_func,
"Positive star 1 at (%g,%g) is less than %d "
1284 "pixels from the image border", x, y,
1285 1+IRPLIB_STREHL_BORDER);
1290 skip_if (visir_img_phot_flux(combined, weights, contrib,
1292 visir_img_phot_config.r0_max,
1293 visir_img_phot_config.r1,
1294 visir_img_phot_config.r2,
1304 visir_img_phot_config.flux_snr = flux_snr;
1307 visir_img_phot_config.flux_snr_noise = flux_snr_noise;
1309 visir_img_phot_config.flux_snr_radius[0] = flux_snr_radius;
1312 visir_img_phot_config.flux_tot = flux_tot;
1315 visir_img_phot_config.beamshape = beamshape;
1316 visir_img_phot_config.fwhm_x_pos1 = beamshape.fwhm_x;
1317 visir_img_phot_config.fwhm_y_pos1 = beamshape.fwhm_y;
1320 if (visir_get_filter_infos(visir_img_phot_config.filter, &lam, &dlam)) {
1321 cpl_msg_error(cpl_func,
"Central wavelength and width is missing for "
1322 "filter: %s", visir_img_phot_config.filter);
1327 cpl_errorstate errstate = cpl_errorstate_get();
1328 if (irplib_strehl_compute(combined, STREHL_M1, STREHL_M2, lam, dlam,
1329 visir_img_phot_config.pscale,
1330 STREHL_BOX_SIZE, x, y, STREHL_STAR_RADIUS,
1331 STREHL_BG_R1, STREHL_BG_R2, -1, -1,
1332 &(visir_img_phot_config.strehl),
1333 &(visir_img_phot_config.strehl_err),
1334 &star_bg, &star_peak, &star_flux, &psf_peak, &psf_flux,
1336 cpl_msg_error(cpl_func,
"Could not compute the strehl: '%s' in %s",
1337 cpl_error_get_message(), cpl_error_get_where());
1338 cpl_errorstate_set(errstate);
1344 return cpl_error_get_code();
1358static int visir_img_phot_flux_four(
const cpl_image * combined)
1360 cpl_errorstate cleanstate = cpl_errorstate_get();
1361 cpl_image * min_combined = NULL;
1362 cpl_apertures * appos = NULL;
1363 cpl_apertures * apneg = NULL;
1364 cpl_vector * sigmas = NULL;
1365 double psigmas[] = {5, 2, 1, 0.5};
1369 double flux_snr_noise[4];
1370 int flux_snr_radius[4];
1372 beamshape_t beamshapes[4];
1373 double dist1, dist2;
1376 double star_bg,star_peak,star_flux,psf_peak,psf_flux,bg_noise;
1377 double eccmin = DBL_MAX;
1378 const int nsigmas =
sizeof(psigmas)/
sizeof(
double);
1380 int ipos1, ipos2, ineg1, ineg2;
1382 int iappos2[] = {0, 0};
1383 int iapneg2[] = {0, 0};
1386 if (cpl_error_get_code())
return cpl_error_get_code();
1388 cpl_ensure_code(combined != NULL, CPL_ERROR_NULL_INPUT);
1390 cpl_msg_info(cpl_func,
"Detecting the 4-source star using %d sigma-levels "
1391 "ranging from %g down to %g", nsigmas, psigmas[0],
1392 psigmas[nsigmas-1]);
1394 sigmas = cpl_vector_new(1);
1395 min_combined = cpl_image_multiply_scalar_create(combined, -1.0);
1397 for (isigma = 0; isigma < nsigmas; isigma++) {
1400 irplib_error_recover(cleanstate,
"Resetting error (why?)");
1402 bug_if(cpl_vector_set(sigmas, 0, psigmas[isigma]));
1405 cpl_apertures_delete(appos);
1406 appos = cpl_apertures_extract(combined, sigmas, NULL);
1407 if (appos == NULL) {
1408 cpl_msg_warning(cpl_func,
"Found no positive stars at sigma=%g",
1412 if (cpl_apertures_get_size(appos) < 2) {
1413 cpl_msg_warning(cpl_func,
"Found just 1 positive star at sigma=%g, "
1414 "need two", psigmas[isigma]);
1419 cpl_apertures_delete(apneg);
1420 apneg = cpl_apertures_extract(min_combined, sigmas, NULL);
1421 if (apneg == NULL) {
1422 cpl_msg_warning(cpl_func,
"Found no negative stars at sigma=%g",
1426 if (cpl_apertures_get_size(apneg) < 2) {
1427 cpl_msg_warning(cpl_func,
"Found just 1 negative star at sigma=%g, "
1428 "need two", psigmas[isigma]);
1432 cpl_msg_info(cpl_func,
"Found positive and negative stars at sigma=%g",
1437 skip_if(appos == NULL);
1438 skip_if(apneg == NULL);
1439 skip_if (cpl_apertures_get_size(appos) < 2);
1440 skip_if (cpl_apertures_get_size(apneg) < 2);
1442 if (cpl_msg_get_level() == CPL_MSG_DEBUG) {
1443 cpl_apertures_dump(appos, stdout);
1444 cpl_apertures_dump(apneg, stdout);
1447 if (cpl_apertures_get_size(appos) > 2 || cpl_apertures_get_size(apneg) > 2)
1448 cpl_msg_info(cpl_func,
"Selecting from %d positive and %d negative "
1449 "stars two pairs that outline a square",
1450 (
int)cpl_apertures_get_size(appos),
1451 (
int)cpl_apertures_get_size(apneg));
1453 for (ipos1 = 2; ipos1 <= cpl_apertures_get_size(appos); ipos1++) {
1454 for (ipos2 = 1; ipos2 < ipos1; ipos2++) {
1455 for (ineg1 = 2; ineg1 <= cpl_apertures_get_size(apneg); ineg1++) {
1456 for (ineg2 = 1; ineg2 < ineg1; ineg2++) {
1457 const double ecc = visir_img_phot_eccent_four(appos, ipos1,
1462 if (eccmin < DBL_MAX)
1463 cpl_msg_debug(cpl_func,
"Found star positions with "
1464 "reduced non-square-ness [pixel]: "
1465 "%g < %g", ecc, eccmin);
1478 if (cpl_apertures_get_flux(appos, iappos2[0]) <
1479 cpl_apertures_get_flux(appos, iappos2[1])) {
1480 const int tmp = iappos2[0];
1481 iappos2[0] = iappos2[1];
1484 if (cpl_apertures_get_flux(apneg, iapneg2[0]) <
1485 cpl_apertures_get_flux(apneg, iapneg2[1])) {
1486 const int tmp = iapneg2[0];
1487 iapneg2[0] = iapneg2[1];
1492 x[0] = cpl_apertures_get_centroid_x(appos, iappos2[0]);
1493 y[0] = cpl_apertures_get_centroid_y(appos, iappos2[0]);
1494 x[1] = cpl_apertures_get_centroid_x(appos, iappos2[1]);
1495 y[1] = cpl_apertures_get_centroid_y(appos, iappos2[1]);
1497 x[2] = cpl_apertures_get_centroid_x(apneg, iapneg2[0]);
1498 y[2] = cpl_apertures_get_centroid_y(apneg, iapneg2[0]);
1499 x[3] = cpl_apertures_get_centroid_x(apneg, iapneg2[1]);
1500 y[3] = cpl_apertures_get_centroid_y(apneg, iapneg2[1]);
1502 cpl_apertures_delete(appos);
1503 cpl_apertures_delete(apneg);
1507 cpl_msg_info(cpl_func,
"Positive star 1 at position %g %g", x[0], y[0]);
1508 cpl_msg_info(cpl_func,
"Positive star 2 at position %g %g", x[1], y[1]);
1510 cpl_msg_info(cpl_func,
"Negative star 1 at position %g %g", x[2], y[2]);
1511 cpl_msg_info(cpl_func,
"Negative star 2 at position %g %g", x[3], y[3]);
1514 dist1 = sqrt((x[2]-x[0])*(x[2]-x[0])+(y[2]-y[0])*(y[2]-y[0]));
1515 dist2 = sqrt((x[3]-x[1])*(x[3]-x[1])+(y[3]-y[1])*(y[3]-y[1]));
1516 cpl_msg_info(cpl_func,
"Star 1 Pos/Neg Distance: %g", dist1);
1517 cpl_msg_info(cpl_func,
"Star 2 Pos/Neg Distance: %g", dist2);
1519 if (eccmin < DBL_MAX) {
1520 cpl_msg_info(cpl_func,
"The deviation from a horizontal square by "
1521 "the two star pairs [pixel]: %g", eccmin);
1522 if (eccmin > VISIR_IMG_PHOT_POS_WARN) {
1523 if (eccmin > VISIR_IMG_PHOT_POS_ERROR) {
1524 cpl_msg_error(cpl_func,
"The deviation from a horizontal square"
1525 " by the two star pairs exceed %g, the detected "
1526 "objects are wrong", VISIR_IMG_PHOT_POS_ERROR);
1529 cpl_msg_warning(cpl_func,
"The deviation from a horizontal square "
1530 "by the two star pairs exceed %g, the detected "
1531 "objects may be wrong", VISIR_IMG_PHOT_POS_WARN);
1535 if ((
int)x[0]-IRPLIB_STREHL_BORDER <= 0 ||
1536 (
int)y[0]-IRPLIB_STREHL_BORDER <= 0 ||
1537 (
int)x[0]+IRPLIB_STREHL_BORDER > cpl_image_get_size_x(combined) ||
1538 (
int)y[0]+IRPLIB_STREHL_BORDER > cpl_image_get_size_y(combined)) {
1539 cpl_msg_error(cpl_func,
"Positive star 1 at (%g,%g) is less than %d "
1540 "pixels from the image border", x[0], y[0],
1541 1+IRPLIB_STREHL_BORDER);
1546 if (fabs(dist1-dist2) > VISIR_IMG_PHOT_POS_UNCERTAINTY) {
1547 cpl_msg_error(cpl_func,
"Too large Pos/Neg Distance between the two "
1548 "stars: %g > %g", fabs(dist1-dist2),
1549 VISIR_IMG_PHOT_POS_UNCERTAINTY);
1554 for (i=0 ; i<2 ; i++)
1555 skip_if (visir_img_phot_flux(combined, NULL, NULL,
1557 visir_img_phot_config.r0_max,
1558 visir_img_phot_config.r1,
1559 visir_img_phot_config.r2,
1561 &(flux_snr_noise[i]),
1562 &(flux_snr_radius[i]),
1567 for (i=2 ; i<4 ; i++)
1568 skip_if (visir_img_phot_flux(min_combined, NULL, NULL,
1570 visir_img_phot_config.r0_max,
1571 visir_img_phot_config.r1,
1572 visir_img_phot_config.r2,
1574 &(flux_snr_noise[i]),
1575 &(flux_snr_radius[i]),
1579 cpl_image_delete(min_combined);
1580 min_combined = NULL;
1584 visir_img_phot_config.flux_snr = 0.0;
1585 for (i=0 ; i<4 ; i++) visir_img_phot_config.flux_snr += flux_snr[i];
1588 visir_img_phot_config.flux_snr_noise = 0.0;
1589 for (i=0 ; i<4 ; i++) visir_img_phot_config.flux_snr_noise +=
1590 flux_snr_noise[i]*flux_snr_noise[i];
1591 visir_img_phot_config.flux_snr_noise =
1592 sqrt(visir_img_phot_config.flux_snr_noise);
1594 for (i=0 ; i<4 ; i++)
1595 visir_img_phot_config.flux_snr_radius[i] = flux_snr_radius[i];
1598 visir_img_phot_config.flux_tot = 0.0;
1599 for (i=0 ; i<4 ; i++) visir_img_phot_config.flux_tot += flux_tot[i];
1603 visir_img_phot_config.beamshape.fwhm_x = 0.0;
1604 for (i=0 ; i<4 ; i++) {
1605 if (beamshapes[i].fwhm_x > 0.0) {
1606 visir_img_phot_config.beamshape.fwhm_x += beamshapes[i].fwhm_x;
1610 if (ngood_fwhm > 0) visir_img_phot_config.beamshape.fwhm_x /= ngood_fwhm;
1611 else visir_img_phot_config.beamshape.fwhm_x = -1.0;
1613 visir_img_phot_config.beamshape.fwhm_y = 0.0;
1614 for (i=0 ; i<4 ; i++) {
1615 if (beamshapes[i].fwhm_y > 0.0) {
1616 visir_img_phot_config.beamshape.fwhm_y += beamshapes[i].fwhm_y;
1620 if (ngood_fwhm > 0) visir_img_phot_config.beamshape.fwhm_y /= ngood_fwhm;
1621 else visir_img_phot_config.beamshape.fwhm_y = -1.0;
1622 visir_img_phot_config.fwhm_x_pos1 = beamshapes[0].fwhm_x;
1623 visir_img_phot_config.fwhm_y_pos1 = beamshapes[0].fwhm_y;
1624 visir_img_phot_config.fwhm_x_pos2 = beamshapes[1].fwhm_x;
1625 visir_img_phot_config.fwhm_y_pos2 = beamshapes[1].fwhm_y;
1626 visir_img_phot_config.fwhm_x_neg1 = beamshapes[2].fwhm_x;
1627 visir_img_phot_config.fwhm_y_neg1 = beamshapes[2].fwhm_y;
1628 visir_img_phot_config.fwhm_x_neg2 = beamshapes[3].fwhm_x;
1629 visir_img_phot_config.fwhm_y_neg2 = beamshapes[3].fwhm_y;
1632 if (visir_get_filter_infos(visir_img_phot_config.filter, &lam, &dlam)) {
1633 cpl_msg_error(cpl_func,
"Central wavelength and width is missing for "
1634 "filter: %s", visir_img_phot_config.filter);
1639 cpl_errorstate errstate = cpl_errorstate_get();
1640 if (irplib_strehl_compute(combined, STREHL_M1, STREHL_M2, lam, dlam,
1641 visir_img_phot_config.pscale,
1642 STREHL_BOX_SIZE, x[0], y[0], STREHL_STAR_RADIUS,
1643 STREHL_BG_R1, STREHL_BG_R2, -1, -1,
1644 &(visir_img_phot_config.strehl),
1645 &(visir_img_phot_config.strehl_err),
1646 &star_bg, &star_peak, &star_flux, &psf_peak, &psf_flux,
1648 cpl_msg_error(cpl_func,
"Could not compute the strehl: '%s' in %s",
1649 cpl_error_get_message(), cpl_error_get_where());
1650 cpl_errorstate_set(errstate);
1656 cpl_apertures_delete(appos);
1657 cpl_apertures_delete(apneg);
1658 cpl_vector_delete(sigmas);
1659 cpl_image_delete(min_combined);
1661 return cpl_error_get_code();
1683static double visir_img_phot_eccent_four(
const cpl_apertures * appos,
1684 int ipos1,
int ipos2,
1685 const cpl_apertures * apneg,
1686 int ineg1,
int ineg2)
1692 const double xp1 = cpl_apertures_get_centroid_x(appos, ipos1);
1693 const double xp2 = cpl_apertures_get_centroid_x(appos, ipos2);
1694 const double yp1 = cpl_apertures_get_centroid_y(appos, ipos1);
1695 const double yp2 = cpl_apertures_get_centroid_y(appos, ipos2);
1698 const double xpl = xp1 < xp2 ? xp1 : xp2;
1699 const double ypl = xp1 < xp2 ? yp1 : yp2;
1702 const double xpr = xp1 < xp2 ? xp2 : xp1;
1703 const double ypr = xp1 < xp2 ? yp2 : yp1;
1706 const double xn1 = cpl_apertures_get_centroid_x(apneg, ineg1);
1707 const double yn1 = cpl_apertures_get_centroid_y(apneg, ineg1);
1708 const double xn2 = cpl_apertures_get_centroid_x(apneg, ineg2);
1709 const double yn2 = cpl_apertures_get_centroid_y(apneg, ineg2);
1712 const double xln = xn1 < xn2 ? xn1 : xn2;
1713 const double yln = xn1 < xn2 ? yn1 : yn2;
1716 const double xrn = xn1 < xn2 ? xn2 : xn1;
1717 const double yrn = xn1 < xn2 ? yn2 : yn1;
1719 const double lx1 = xrn - xpl;
1720 const double lx2 = xpr - xln;
1721 const double ly1 = ypl - yln;
1722 const double ly2 = yrn - ypr;
1724 const double lmean = 0.25 * ( lx1 + lx2 + ly1 + ly2);
1726 const double dx1 = lx1 - lmean;
1727 const double dx2 = lx2 - lmean;
1728 const double dy1 = ly1 - lmean;
1729 const double dy2 = ly2 - lmean;
1731 const double ey1 = yrn - ypl;
1732 const double ey2 = ypr - yln;
1733 const double ex1 = xpl - xln;
1734 const double ex2 = xpr - xrn;
1736 const double result = sqrt(dx1 * dx1 + dx2 * dx2 + dy1 * dy1 + dy2 * dy2 +
1737 ex1 * ex1 + ex2 * ex2 + ey1 * ey1 + ey2 * ey2);
1742 bug_if(appos == apneg);
1743 bug_if(ipos1 == ipos2);
1744 bug_if(ineg1 == ineg2);
1753#ifdef VISIR_IMG_PHOT_USE_ECCENT_THREE
1770static double visir_img_phot_eccent_three(
const cpl_apertures * appos,
1772 const cpl_apertures * apneg,
1773 int ineg1,
int ineg2)
1779 const double xp = cpl_apertures_get_centroid_x(appos, ipos);
1780 const double yp = cpl_apertures_get_centroid_y(appos, ipos);
1783 const double xn1 = cpl_apertures_get_centroid_x(apneg, ineg1);
1784 const double yn1 = cpl_apertures_get_centroid_y(apneg, ineg1);
1785 const double xn2 = cpl_apertures_get_centroid_x(apneg, ineg2);
1786 const double yn2 = cpl_apertures_get_centroid_y(apneg, ineg2);
1789 const double xnb = xn1 < xn2 ? xn1 : xn2;
1790 const double ynb = xn1 < xn2 ? yn1 : yn2;
1793 const double xnt = xn1 < xn2 ? xn2 : xn1;
1794 const double ynt = xn1 < xn2 ? yn2 : yn1;
1796 const double l1 = ynt - yp;
1797 const double l2 = yp - ynb;
1798 const double ln = ynt - ynb;
1800 const double lmean = 0.25 * ( l1 + l2 + ln);
1802 const double d1 = l1 - lmean;
1803 const double d2 = l2 - lmean;
1804 const double dn = 0.5 * ln - lmean;
1806 const double e1 = xp - xnt;
1807 const double e2 = xp - xnb;
1809 const double result = sqrt(d1 * d1 + d2 * d2 + dn * dn + e1 * e1 + e2 * e2);
1814 bug_if(appos == apneg);
1815 bug_if(ineg1 == ineg2);
1849static int visir_img_phot_flux(
1850 const cpl_image * combined,
1851 const cpl_image * weights_,
1852 const cpl_image * contrib,
1859 double * flux_snr_noise,
1860 int * flux_snr_radius,
1862 beamshape_t * beamshape)
1864 cpl_apertures * apert = NULL;
1866 cpl_image * bg_subtracted = NULL;
1867 cpl_vector * r0 = NULL;
1868 cpl_vector * fl = NULL;
1869 cpl_vector * fl_noise = NULL;
1870 cpl_vector * snr = NULL;
1872 double max_val = 0.0;
1876 int max_contrib = 1;
1877 cpl_image * weights = weights_ == NULL ?
1878 NULL : cpl_image_duplicate(weights_);
1881 if (cpl_error_get_code())
return cpl_error_get_code();
1883 cpl_ensure_code(combined != NULL, CPL_ERROR_NULL_INPUT);
1884 cpl_ensure_code(r0_max > 0, CPL_ERROR_ILLEGAL_INPUT);
1886 nx = cpl_image_get_size_x(combined);
1887 ny = cpl_image_get_size_y(combined);
1890 cpl_ensure_code(nx == cpl_image_get_size_x(weights) &&
1891 ny == cpl_image_get_size_y(weights),
1892 CPL_ERROR_ILLEGAL_INPUT);
1896 cpl_ensure_code(nx == cpl_image_get_size_x(contrib) &&
1897 ny == cpl_image_get_size_y(contrib),
1898 CPL_ERROR_ILLEGAL_INPUT);
1899 max_contrib = cpl_image_get_max(contrib);
1900 cpl_ensure_code(max_contrib >= 1, CPL_ERROR_ILLEGAL_INPUT);
1904 if ((labels = visir_create_ring_intimage(nx, ny,
1905 (
int)x_pos, (
int)y_pos, r1, r2)) == NULL) {
1906 cpl_msg_error(cpl_func,
"Could not create a ring image");
1910 apert = cpl_apertures_new_from_image(combined, labels);
1911 cpl_image_delete(labels);
1913 bg = cpl_apertures_get_median(apert, 1);
1914 cpl_apertures_delete(apert);
1916 cpl_msg_info(cpl_func,
"Background : %g", bg);
1919 if ((labels = visir_create_disk_intimage(nx, ny,
1920 (
int)x_pos, (
int)y_pos, r0_max)) == NULL) {
1921 cpl_msg_error(cpl_func,
"Could not create a disk image");
1927 bg_subtracted = cpl_image_subtract_scalar_create(combined, bg);
1931 cpl_image * scale = cpl_image_cast(contrib, CPL_TYPE_DOUBLE);
1932 cpl_image_power(scale, -1);
1933 cpl_image_multiply_scalar(scale, max_contrib);
1934 cpl_image_multiply(bg_subtracted, scale);
1936 cpl_image_multiply(weights, scale);
1937 cpl_image_delete(scale);
1940 apert = cpl_apertures_new_from_image(bg_subtracted, labels);
1941 cpl_image_delete(labels);
1943 *flux_tot = cpl_apertures_get_flux(apert, 1);
1944 cpl_apertures_delete(apert);
1946 cpl_msg_info(cpl_func,
"Star total flux (error): %g", *flux_tot);
1949 r0 = cpl_vector_new(r0_max);
1950 for (i=0 ; i<r0_max ; i++) cpl_vector_set(r0, i, i+1);
1953 fl = cpl_vector_new(r0_max);
1954 fl_noise = cpl_vector_new(r0_max);
1957 for (i=0 ; i<r0_max ; i++) {
1958 float fl_val = 0.f, fl_noise_val = 0.f;
1960 if ((labels = visir_create_disk_intimage(nx, ny,
1961 (
int)x_pos, (
int)y_pos, (
int)cpl_vector_get(r0, i))) == NULL) {
1962 cpl_msg_error(cpl_func,
"Could not create a disk image: %d", i);
1967 double sum = 0, esum = 0;
1969 for (
int ix = 1; ix < 1 + nx; ix++) {
1970 for (
int iy = 1; iy < 1 + ny; iy++) {
1971 if (!cpl_image_get(labels, ix, iy, &d) || d)
1974 sum += cpl_image_get(bg_subtracted, ix, iy, &d);
1977 esum += (1. / cpl_image_get(weights, ix, iy, &d));
1981 fl_noise_val = sqrt(esum);
1984 cpl_apertures * pert =
1985 cpl_apertures_new_from_image(bg_subtracted, labels);
1987 fl_val = cpl_apertures_get_flux(pert, 1);
1988 fl_noise_val = visir_img_phot_config.bg_sigma *
1989 sqrt((
double)cpl_apertures_get_npix(pert, 1));
1990 cpl_apertures_delete(pert);
1994 cpl_image_delete(labels);
1996 cpl_vector_set(fl, i, fl_val);
1997 cpl_vector_set(fl_noise, i, fl_noise_val);
2002 snr = cpl_vector_duplicate(fl);
2003 cpl_vector_divide(snr, fl_noise);
2004 for (i=0 ; i<r0_max ; i++) {
2005 if (i == 0 || max_val < cpl_vector_get(snr, i)) {
2006 max_val = cpl_vector_get(snr, i);
2010 *flux_snr = cpl_vector_get(fl, max_ind);
2011 *flux_snr_noise = cpl_vector_get(fl_noise, max_ind);
2012 *flux_snr_radius = (int)cpl_vector_get(r0, max_ind);
2013 cpl_msg_info(cpl_func,
"Best SNR star flux : %g (%g) for radius %d <= %d "
2014 " [pixel]", *flux_snr, *flux_snr_noise,
2015 (
int)cpl_vector_get(r0, max_ind),
2016 (
int)cpl_vector_get(r0, r0_max-1));
2018 if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
2019 cpl_matrix * mdump = cpl_matrix_new(1+r0_max, 3);
2020 for (i = 0; i < r0_max; i++) {
2021 cpl_matrix_set(mdump, i+1, 0, cpl_vector_get(fl, i));
2022 cpl_matrix_set(mdump, i+1, 1, cpl_vector_get(fl_noise, i));
2023 cpl_matrix_set(mdump, i+1, 2, cpl_vector_get(snr, i));
2025 cpl_msg_debug(cpl_func,
"Flux, flux-noise and S/N for radii out to %d",
2026 (
int)cpl_vector_get(r0, r0_max-1));
2028 cpl_matrix_dump(mdump, stdout);
2029 cpl_matrix_delete(mdump);
2032 *beamshape = (beamshape_t){.fwhm_x = -1., .fwhm_y = -1.,
2033 .peak = -1., .peak_err = 0.,
2034 .major = -1., .major_err = 0.,
2035 .minor = -1., .minor_err = 0.,
2036 .angle = -1., .angle_err = 0.};
2039 skip_if (cpl_image_get_fwhm(bg_subtracted, (
int)x_pos, (
int)y_pos, &beamshape->fwhm_x,
2040 &beamshape->fwhm_y));
2042 skip_if ( beamshape->fwhm_x <= 0.0 );
2043 skip_if ( beamshape->fwhm_y <= 0.0 );
2045 cpl_errorstate cleanstate = cpl_errorstate_get();
2047 if (fit_2d_gauss(bg_subtracted, weights, (cpl_size)x_pos, (cpl_size)y_pos,
2048 beamshape->fwhm_x, beamshape->fwhm_y,
2049 &beamshape->peak, &beamshape->peak_err,
2050 &beamshape->major, &beamshape->major_err,
2051 &beamshape->minor, &beamshape->minor_err,
2052 &beamshape->angle, &beamshape->angle_err) == CPL_ERROR_NONE) {
2053 cpl_msg_info(cpl_func,
"Peak: %g +- %g, FWHM : %g +- %g major ; %g +- %g minor, "
2054 "angle %g +- %g", beamshape->peak, beamshape->peak_err,
2055 beamshape->major, beamshape->major_err,
2056 beamshape->minor, beamshape->minor_err, beamshape->angle *
2057 CPL_MATH_DEG_RAD, beamshape->angle_err *
2061 cpl_msg_warning(cpl_func,
"2D gauss fit failed, approximate FWHM : %g"
2062 "in x ; %g in y ", beamshape->fwhm_x, beamshape->fwhm_y);
2063 cpl_errorstate_set(cleanstate);
2068 cpl_apertures_delete(apert);
2069 cpl_image_delete(labels);
2070 cpl_image_delete(bg_subtracted);
2071 cpl_image_delete(weights);
2073 cpl_vector_delete(r0);
2074 cpl_vector_delete(fl);
2075 cpl_vector_delete(snr);
2076 cpl_vector_delete(fl_noise);
2078 return cpl_error_get_code();
2094static cpl_error_code visir_get_filter_infos(
2103 cpl_ensure_code(f, CPL_ERROR_NULL_INPUT);
2104 cpl_ensure_code(pcwlen, CPL_ERROR_NULL_INPUT);
2105 cpl_ensure_code(pdwlen, CPL_ERROR_NULL_INPUT);
2107 skip_if (!strcmp(f,
"MV"));
2109 if (!strcmp(f,
"N-BAND") || !strcmp(f,
"N_BAND"))
2110 { cwlen = 10.56; dwlen = 5.37;}
2111 else if (!strcmp(f,
"SIC")) { cwlen = 11.848;dwlen = 2.34;}
2112 else if (!strcmp(f,
"PAH1_1")) { cwlen = 8.19;dwlen = 0.15;}
2113 else if (!strcmp(f,
"PAH1")) { cwlen = 8.586;dwlen = 0.421;}
2114 else if (!strcmp(f,
"ARIII")) { cwlen = 8.992;dwlen = 0.138;}
2115 else if (!strcmp(f,
"SIV_1")) { cwlen = 10.02;dwlen = 0.18;}
2116 else if (!strcmp(f,
"SIV")) { cwlen = 10.485;dwlen = 0.159;}
2117 else if (!strcmp(f,
"PAH2_1")) { cwlen = 10.76;dwlen = 0.69;}
2118 else if (!strcmp(f,
"SIV_2")) { cwlen = 11.1;dwlen = 0.19;}
2119 else if (!strcmp(f,
"PAH2")) { cwlen = 11.254;dwlen = 0.594;}
2120 else if (!strcmp(f,
"PAH2_2")) { cwlen = 12.13;dwlen = 0.37;}
2121 else if (!strcmp(f,
"NEII_1")) { cwlen = 12.51;dwlen = 0.18;}
2122 else if (!strcmp(f,
"NEII")) { cwlen = 12.805;dwlen = 0.21;}
2123 else if (!strcmp(f,
"NEII_2")) { cwlen = 13.036;dwlen = 0.219;}
2124 else if (!strcmp(f,
"Q0")) { cwlen = 16.554;dwlen = 0.398;}
2125 else if (!strcmp(f,
"QH2")) { cwlen = 17.11;dwlen = 0.398;}
2126 else if (!strcmp(f,
"Q1")) { cwlen = 17.653;dwlen = 0.83;}
2127 else if (!strcmp(f,
"Q2")) { cwlen = 18.718;dwlen = 0.878;}
2128 else if (!strcmp(f,
"Q3")) { cwlen = 19.5;dwlen = 0.4;}
2129 else if (!strcmp(f,
"Q4")) { cwlen = 20.5;dwlen = 1.0;}
2130 else if (!strcmp(f,
"Q7")) { cwlen = 23.1;dwlen = 0.8;}
2131 else if (!strcmp(f,
"Q8")) { cwlen = 24.5;dwlen = 0.8;}
2133 else if (!strcmp(f,
"10_5_4QP")) { cwlen = 10.5;dwlen =0.1;}
2134 else if (!strcmp(f,
"11_3_4QP")) { cwlen = 11.3;dwlen =0.1;}
2135 else if (!strcmp(f,
"12_4_AGP")) { cwlen = 12.4;dwlen =0.1;}
2136 else if (!strcmp(f,
"N-SW-spec") || !strcmp(f,
"N_SW_spec"))
2137 { cwlen = 8.85; dwlen = 2.7;}
2138 else if (!strcmp(f,
"H2S4-spec") || !strcmp(f,
"H2S4_spec"))
2139 { cwlen = 8.12; dwlen = 0.3;}
2140 else if (!strcmp(f,
"ARIII-spec") || !strcmp(f,
"ARIII_spec"))
2141 { cwlen = 8.44; dwlen = 0.78;}
2142 else if (!strcmp(f,
"NEII_2-spec") || !strcmp(f,
"NEII_2_spec"))
2143 { cwlen = 12.805; dwlen = 0.2;}
2144 else if (!strcmp(f,
"H2S3-spec") || !strcmp(f,
"H2S3_spec"))
2145 { cwlen = 9.62; dwlen = 0.2;}
2146 else if (!strcmp(f,
"H2S1-spec") || !strcmp(f,
"H2S1_spec"))
2147 { cwlen = 17.0;dwlen = 0.4;}
2148 else if (!strcmp(f,
"M-BAND") || !strcmp(f,
"M_BAND"))
2149 { cwlen = 4.82;dwlen = 0.35;}
2153 else if (!strcmp(f,
"J7.9") || !strcmp(f,
"J7_9"))
2154 { cwlen = (7.483 + 8.035)/2.0;
2155 dwlen = 8.035 - 7.483;}
2156 else if (!strcmp(f,
"J8.9") || !strcmp(f,
"J8_9"))
2157 { cwlen = (8.338 + 9.068)/2.0;
2158 dwlen = 9.068 - 8.338;}
2159 else if (!strcmp(f,
"J9.8") || !strcmp(f,
"J9_8"))
2160 { cwlen = (9.123 + 10.059)/2.0;
2161 dwlen = 10.059 - 9.123;}
2162 else if (!strcmp(f,
"J12.2") || !strcmp(f,
"J12_2"))
2163 { cwlen = (11.700 + 12.216)/2.0;
2164 dwlen = 12.216 - 11.700;}
2165 else if (!strcmp(f,
"B8.7") || !strcmp(f,
"B8_7"))
2166 { cwlen = (8.436 + 9.410)/2.0;
2167 dwlen = 9.410 - 8.436;}
2168 else if (!strcmp(f,
"B9.7") || !strcmp(f,
"B9_7"))
2169 { cwlen = (9.402 + 10.242)/2.0;
2170 dwlen = 10.242 - 9.402;}
2171 else if (!strcmp(f,
"B10.7") || !strcmp(f,
"B10_7"))
2172 { cwlen = (9.970 + 11.338)/2.0;
2173 dwlen = 11.338 - 9.970;}
2174 else if (!strcmp(f,
"B11.7") || !strcmp(f,
"B11_7"))
2175 { cwlen = (11.098 + 11.950)/2.0;
2176 dwlen = 11.950 - 11.098;}
2177 else if (!strcmp(f,
"B12.4") || !strcmp(f,
"B12_4"))
2178 { cwlen = (11.971 + 12.961)/2.0;
2179 dwlen = 12.961 - 11.971;}
2180 else if (!strcmp(f,
"L-BAND") || !strcmp(f,
"L_BAND"))
2182 dwlen = 4.0610 - 3.4195;}
2187 cpl_ensure_code(cwlen > 0, CPL_ERROR_DATA_NOT_FOUND);
2188 cpl_ensure_code(dwlen > 0, CPL_ERROR_DATA_NOT_FOUND);
2192 return cpl_error_get_code();
2204static cpl_error_code visir_img_phot_qc(cpl_propertylist * qclist,
2205 cpl_boolean drop_wcs,
2206 const irplib_framelist * rawframes)
2209 const cpl_propertylist * reflist
2210 = irplib_framelist_get_propertylist_const(rawframes, 0);
2214 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC EXPTIME",
2215 visir_img_phot_config.exptime));
2217 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC JYVAL",
2218 visir_img_phot_config.jy_val));
2220 bug_if (cpl_propertylist_append_string(qclist,
"ESO QC STARNAME",
2221 visir_img_phot_config.star_name));
2223 bug_if (cpl_propertylist_append_string(qclist,
"ESO QC FILTER",
2224 visir_img_phot_config.filter));
2227 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC NELEC",
2228 visir_img_phot_config.nelec));
2230 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC NPHOT",
2231 visir_img_phot_config.nphot));
2233 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC BACKGD SIGMA",
2234 visir_img_phot_config.bg_sigma));
2236 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FLUXTOT",
2237 visir_img_phot_config.flux_tot));
2239 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FLUXSNR",
2240 visir_img_phot_config.flux_snr));
2242 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FLUXSNR NOISE",
2243 visir_img_phot_config.flux_snr_noise));
2245 for (
int i = 0; i < 4; i++) {
2246 const int r = visir_img_phot_config.flux_snr_radius[i];
2248 sprintf(buffer,
"ESO QC FLUXSNR RADIUS%d", i + 1);
2249 bug_if (cpl_propertylist_append_int(qclist, buffer, r));
2252 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMX",
2253 visir_img_phot_config.beamshape.fwhm_x));
2255 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMY",
2256 visir_img_phot_config.beamshape.fwhm_y));
2257 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC GAUSSFIT FWHM_MAX",
2258 visir_img_phot_config.beamshape.major));
2259 cpl_propertylist_set_comment(qclist,
"ESO QC GAUSSFIT FWHM_MAX",
2260 "major axis [pix]");
2261 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC GAUSSFIT FWHM_MAX_ERR",
2262 visir_img_phot_config.beamshape.major_err));
2263 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC GAUSSFIT FWHM_MIN",
2264 visir_img_phot_config.beamshape.minor));
2265 cpl_propertylist_set_comment(qclist,
"ESO QC GAUSSFIT FWHM_MIN",
2266 "minor axis [pix]");
2267 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC GAUSSFIT FWHM_MIN_ERR",
2268 visir_img_phot_config.beamshape.minor_err));
2269 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC GAUSSFIT ANGLE",
2270 visir_img_phot_config.beamshape.angle * CPL_MATH_DEG_RAD));
2271 cpl_propertylist_set_comment(qclist,
"ESO QC GAUSSFIT ANGLE",
2273 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC GAUSSFIT ANGLE_ERR",
2274 visir_img_phot_config.beamshape.angle_err * CPL_MATH_DEG_RAD));
2275 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC GAUSSFIT PEAK",
2276 visir_img_phot_config.beamshape.peak));
2277 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC GAUSSFIT PEAK_ERR",
2278 visir_img_phot_config.beamshape.peak_err));
2280 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMX POS1",
2281 visir_img_phot_config.fwhm_x_pos1));
2283 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMY POS1",
2284 visir_img_phot_config.fwhm_y_pos1));
2286 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMX POS2",
2287 visir_img_phot_config.fwhm_x_pos2));
2289 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMY POS2",
2290 visir_img_phot_config.fwhm_y_pos2));
2292 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMX NEG1",
2293 visir_img_phot_config.fwhm_x_neg1));
2295 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMY NEG1",
2296 visir_img_phot_config.fwhm_y_neg1));
2298 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMX NEG2",
2299 visir_img_phot_config.fwhm_x_neg2));
2301 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC FWHMY NEG2",
2302 visir_img_phot_config.fwhm_y_neg2));
2304 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC SENSIT",
2305 visir_img_phot_config.sensitivity));
2307 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC AREA SENSIT",
2308 visir_img_phot_config.area_sensit));
2309 cpl_propertylist_set_comment(qclist,
"ESO QC AREA SENSIT",
2310 "scaled to noise of 1 arcsecond");
2312 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC CONVER",
2313 visir_img_phot_config.conversion));
2315 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC STREHL",
2316 visir_img_phot_config.strehl));
2318 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC STREHL ERROR",
2319 visir_img_phot_config.strehl_err));
2322 skip_if (visir_qc_append_capa(qclist, rawframes));
2325 cpl_propertylist * pcopy = cpl_propertylist_new();
2326 const cpl_error_code error
2327 = cpl_propertylist_copy_property_regexp(pcopy, reflist,
"^("
2328 IRPLIB_PFITS_WCS_REGEXP
2330 if (!error && cpl_propertylist_get_size(pcopy) > 0) {
2331 cpl_msg_warning(cpl_func,
"Combined image will have no WCS "
2334 cpl_propertylist_delete(pcopy);
2337 bug_if(cpl_propertylist_copy_property_regexp(qclist, reflist,
"^("
2338 VISIR_PFITS_IMG_PHOT_COPY
2341 bug_if(cpl_propertylist_copy_property_regexp(qclist, reflist,
"^("
2342 VISIR_PFITS_IMG_PHOT_COPY
2343 "|" IRPLIB_PFITS_WCS_REGEXP
2351 return cpl_error_get_code();
2368static cpl_error_code visir_img_phot_save(cpl_frameset * self,
2369 const cpl_parameterlist * parlist,
2370 const cpl_propertylist * qclist,
2371 const cpl_image * combined,
2372 const cpl_image * contrib,
2373 const cpl_image * beam1,
2374 const cpl_image * beam1i,
2375 const cpl_image * weights)
2378 cpl_propertylist * xtlist = cpl_propertylist_new();
2379 const char * procatg = VISIR_IMG_PHOT_COMBINED_PROCATG;
2384 const char * s = cpl_propertylist_get_string(qclist,
"ESO QC BEAMID");
2387 if (strcmp(s,
"COMBINED") == 0)
2388 procatg = VISIR_IMG_PHOT_COMBINED_PROCATG;
2390 procatg = VISIR_IMG_PHOT_ONEBEAM_PROCATG;
2394 skip_if (irplib_dfs_save_image(self, parlist, self, combined,
2395 CPL_BPP_IEEE_FLOAT, RECIPE_SAVE_STRING,
2396 procatg, qclist, NULL, visir_pipe_id,
2397 RECIPE_SAVE_STRING CPL_DFS_FITS));
2401 bug_if(cpl_propertylist_append_string(xtlist,
"EXTNAME",
2402 "Contribution Map"));
2403 skip_if (cpl_image_save(contrib, RECIPE_SAVE_STRING CPL_DFS_FITS,
2404 CPL_BPP_16_UNSIGNED, xtlist, CPL_IO_EXTEND));
2407 if (beam1 != NULL) {
2410 skip_if (irplib_dfs_save_image(self, parlist, self, beam1,
2411 CPL_BPP_IEEE_FLOAT, RECIPE_SAVE_STRING,
2412 VISIR_IMG_PHOT_ONEBEAM_PROCATG, qclist,
2413 NULL, visir_pipe_id,
2414 RECIPE_SAVE_STRING
"_onebeam" CPL_DFS_FITS));
2417 skip_if (cpl_image_save(beam1i, RECIPE_SAVE_STRING
"_onebeam" CPL_DFS_FITS,
2418 CPL_BPP_8_UNSIGNED, xtlist, CPL_IO_EXTEND));
2423 cpl_propertylist_delete(xtlist);
2425 return cpl_error_get_code();
2440static char * visir_img_phot_filter2label(
const char * self)
2443 char * label = NULL;
2446 bug_if(self == NULL);
2448 label = cpl_strdup(self);
2450 for (p = label; *p != (char)0; p++) {
2451 if (*p ==
'.' || *p ==
'-') *p =
'_';
cpl_error_code irplib_pfits_set_airmass(cpl_propertylist *self, const irplib_framelist *rawframes)
Update/Set the AIRMASS property.
cpl_error_code visir_dfs_check_framelist_tag(const irplib_framelist *self)
Check the tags in a frameset (group raw only)
int visir_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
const char * visir_parameterlist_get_string(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR string parameter.
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_dit(const cpl_propertylist *self)
The DIT.
double visir_pfits_get_ra(const cpl_propertylist *self)
The RA.
double visir_pfits_get_img_weight(const cpl_propertylist *self)
The relative weight of the image compared to the other images.
double visir_pfits_get_dec(const cpl_propertylist *self)
The DEC.
double visir_pfits_get_pixscale(const cpl_propertylist *self)
The pixel scale.
const char * visir_pfits_get_starname(const cpl_propertylist *self)
The std star name.
const char * visir_pfits_get_insmode(const cpl_propertylist *self)
The mode.
const char * visir_pfits_get_filter(const cpl_propertylist *self)
The filter.
const char * visir_pfits_get_chopnod_dir(const cpl_propertylist *self)
The chopping direction.