64#include <hdrl_strehl.h>
82#define GRAVI_SPOT_NTEL 4
83#define GRAVI_SPOT_NLENS 4
84#define GRAVI_SPOT_NSPOT 4
85#define GRAVI_SPOT_NFOCUS 21
86#define GRAVI_SPOT_NSEARCH 45
87#define GRAVI_SPOT_SWINDOW 28
89#define GRAVI_SPOT_NA 30
90#define GRAVI_SPOT_SUB 0
91#define GRAVI_SPOT_ANGLE 8
92#define GRAVI_SPOT_SCALE 9
93#define GRAVI_SPOT_DIODE 10
94#define GRAVI_SPOT_FWHM 13
95#define GRAVI_SPOT_FLUX 14
97#define GRAVI_ACQ_PUP_FLUX 1e6
99#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
105double exp1 (
double x);
106double sin1 (
double x);
115 cpl_imagelist * acqcam_imglist,
116 cpl_propertylist *
header,
117 cpl_table * acqcam_table,
118 cpl_propertylist * o_header,
122 cpl_imagelist * acqcam_imglist,
123 cpl_propertylist *
header,
124 cpl_table * acqcam_table,
125 cpl_propertylist * o_header,
129 double *ex,
double *ey, cpl_size size);
132 double pscale,
double *SR, cpl_propertylist *
header);
134cpl_error_code
gravi_acq_measure_max(cpl_image * img,
double x,
double y,
double size,
double * img_max);
139 cpl_imagelist * acqcam_imglist,
140 cpl_propertylist *
header,
141 cpl_table * acqcam_table,
142 cpl_propertylist * o_header,
145cpl_error_code
gravi_acqcam_clean_pupil_v2(cpl_imagelist * acqcam_imglist, cpl_imagelist * pupilImage_filtered,
const cpl_size ury);
150 cpl_bivector * diode_pos_subwindow);
153 cpl_array * good_frames,
154 cpl_vector * scale_vector,
155 cpl_bivector ** diode_pos_telescope,
159 cpl_bivector ** diode_pos_telescope,
160 cpl_bivector ** diode_pos_theoretical,
161 cpl_size nrow_on,
int ury);
163cpl_error_code
gravi_acqcam_spot_imprint_v2(cpl_image *mean_img, cpl_bivector ** diode_pos_offset, cpl_bivector ** diode_pos_theoretical,
int ury);
167 cpl_vector * focus_value,
168 cpl_bivector ** diode_pos_theoretical,
169 cpl_bivector ** diode_pos_offset, cpl_size nrow_on);
172 cpl_array * good_frames,
173 cpl_bivector ** diode_pos_offset, cpl_propertylist * o_header,
177 cpl_vector* scale_vector, cpl_array * bad_frames_short, cpl_bivector ** diode_pos_offset , cpl_vector * focus_value,
gravi_data *static_param_data);
179cpl_image *
gravi_image_extract(cpl_image * image_in, cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury);
213 cpl_ensure_code (output_data, CPL_ERROR_NULL_INPUT);
214 cpl_ensure_code (input_data, CPL_ERROR_NULL_INPUT);
219 return CPL_ERROR_NONE;
223 return CPL_ERROR_NONE;
231 cpl_imagelist * imglist;
236 cpl_image * image0 = cpl_imagelist_get (imglist, 0);
237 if ( (cpl_image_get_size_x (image0) != cpl_image_get_size_x (badpix_img) ) ||
238 (cpl_image_get_size_y (image0) != cpl_image_get_size_y (badpix_img) ) ) {
239 gravi_msg_warning (cpl_func,
"Cannot preproc the ACQCAM. Bad pixel mask does not have correct size.");
240 return CPL_ERROR_NONE;
244 cpl_mask * badpix_mask = cpl_mask_threshold_image_create (badpix_img, 0.5, 10000);
247 imglist = cpl_imagelist_duplicate (imglist);
253 cpl_size nrow = cpl_imagelist_get_size (imglist);
254 for (cpl_size row = 0; row < nrow; row++) {
257 cpl_image * img = cpl_imagelist_get (imglist, row);
260 cpl_image_reject_from_mask (img, badpix_mask);
261 cpl_detector_interpolate_rejected (img);
265 FREE (cpl_mask_delete, badpix_mask);
270 return CPL_ERROR_NONE;
279 while (x >= CPL_MATH_PI) x -= CPL_MATH_2PI;
280 while (x <= -CPL_MATH_PI) x += CPL_MATH_2PI;
283 if (x > CPL_MATH_PI_2) x = CPL_MATH_PI - x;
284 if (x < -CPL_MATH_PI_2) x = -CPL_MATH_PI - x;
286 double x2 = x*x, x3 = x2*x, x5 = x3*x2;
287 return 0.9996949 * x - 0.1656700 * x3 + 0.0075134 * x5;
293 x *= x; x *= x; x *= x; x *= x;
294 x *= x; x *= x; x *= x; x *= x;
312 xd[0] = -cang * dx + sang * dy;
313 xd[1] = -cang * dx - sang * dy;
314 xd[2] = cang * dx - sang * dy;
315 xd[3] = cang * dx + sang * dy;
317 yd[0] = cang * dy + sang * dx;
318 yd[1] = -cang * dy + sang * dx;
319 yd[2] = -cang * dy - sang * dx;
320 yd[3] = cang * dy - sang * dx;
327static int gravi_acqcam_xy_sub (
const double v[],
double *xsub,
double *ysub)
331 xsub[0] = vd[0] + vd[1] + vd[2] + vd[3];
332 xsub[1] = vd[0] - vd[1] + vd[2] - vd[3];
333 xsub[2] = vd[0] + vd[1] - vd[2] - vd[3];
334 xsub[3] = vd[0] - vd[1] - vd[2] + vd[3];
336 ysub[0] = vd[4] + vd[5] + vd[6] + vd[7];
337 ysub[1] = vd[4] - vd[5] + vd[6] - vd[7];
338 ysub[2] = vd[4] + vd[5] - vd[6] - vd[7];
339 ysub[3] = vd[4] - vd[5] - vd[6] + vd[7];
346static int gravi_acqcam_spot (
const double x_in[],
const double v[],
double *result)
351 double xd[4], yd[4], xsub[4], ysub[4];
353 gravi_acqcam_xy_sub (v, xsub, ysub);
359 for (
int diode = 0; diode < 4 ; diode++) {
360 for (
int sub = 0; sub < 4 ; sub++) {
361 double xf = (x_in[0] - xsub[sub] - xd[diode]);
362 double yf = (x_in[1] - ysub[sub] - yd[diode]);
363 double dist = (xf*xf + yf*yf) / fwhm2;
372static int gravi_acqcam_spot_dfda (
const double x_in[],
const double v[],
double result[])
374 double next = 0.0, here = 0.0, epsilon = 1e-8;
380 gravi_acqcam_spot (x_in, vlocal, &here);
390 vlocal[a] += epsilon;
391 gravi_acqcam_spot (x_in, vlocal, &next);
392 vlocal[a] -= epsilon;
393 result[a] = (next - here) / epsilon;
400 result[a] = here / v[a];
424 double pscale,
double *SR,
425 cpl_propertylist *
header)
428 cpl_ensure_code (img, CPL_ERROR_NULL_INPUT);
429 cpl_ensure_code (SR, CPL_ERROR_NULL_INPUT);
430 cpl_ensure_code (
header, CPL_ERROR_NULL_INPUT);
431 cpl_ensure_code (pscale > 0, CPL_ERROR_ILLEGAL_INPUT);
434 cpl_ensure_code (x > hw, CPL_ERROR_ILLEGAL_INPUT);
435 cpl_ensure_code (y > hw, CPL_ERROR_ILLEGAL_INPUT);
439 hdrl_parameter * strehl_params;
443 CPLCHECK (
"Cannot get telescope name");
445 if (telname[0] ==
'U') {
447 hdrl_strehl_parameter_create (1.8e-6, 8.0/2.0, 1.126/2.0,
448 pscale*1e-3, pscale*1e-3,
450 }
else if (telname[0] ==
'A') {
452 hdrl_strehl_parameter_create (1.8e-6, 1.8/2.0, 0.138/2.0,
453 pscale*1e-3, pscale*1e-3,
456 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
457 "Cannot recognise the telescope");
458 return CPL_ERROR_ILLEGAL_INPUT;
462 cpl_image * sub_image = cpl_image_extract (img, x-hw, y-hw, x+hw, y+hw);
463 hdrl_image * sub_hdrl = hdrl_image_create (sub_image, NULL);
466 hdrl_strehl_result strehl;
467 strehl = hdrl_strehl_compute (sub_hdrl, strehl_params);
468 *SR = (double) strehl.strehl_value.data;
472 FREE (hdrl_image_delete, sub_hdrl);
473 FREE (hdrl_parameter_delete, strehl_params);
476 return CPL_ERROR_NONE;
488 cpl_ensure_code (img, CPL_ERROR_NULL_INPUT);
489 cpl_ensure_code (img_max, CPL_ERROR_NULL_INPUT);
491 cpl_image * small_img = cpl_image_extract(img, x-size, y-size, x+size, y+size);
492 *img_max = cpl_image_get_max(small_img);
496 return CPL_ERROR_NONE;
517 double *ex,
double *ey, cpl_size size)
520 cpl_ensure_code (img, CPL_ERROR_NULL_INPUT);
521 cpl_ensure_code (x, CPL_ERROR_NULL_INPUT);
522 cpl_ensure_code (y, CPL_ERROR_NULL_INPUT);
523 cpl_ensure_code (ex, CPL_ERROR_NULL_INPUT);
524 cpl_ensure_code (ey, CPL_ERROR_NULL_INPUT);
527 cpl_array * parameters = cpl_array_new (7, CPL_TYPE_DOUBLE);
528 cpl_array_fill_window_invalid (parameters, 0, 7);
529 cpl_array_set (parameters, 2, 0);
530 cpl_array_set (parameters, 3, *x);
531 cpl_array_set (parameters, 4, *y);
532 cpl_array_set (parameters, 5, 3);
533 cpl_array_set (parameters, 6, 3);
536 cpl_size x_med_min=(cpl_size)(*x)-size;
537 cpl_size x_med_max=(cpl_size)(*x)+size;
538 cpl_size y_med_min=(cpl_size)(*y)-size;
539 cpl_size y_med_max=(cpl_size)(*y)+size;
540 cpl_size nx = cpl_image_get_size_x (img);
541 cpl_size ny = cpl_image_get_size_y (img);
542 if (x_med_min <1) x_med_min=1;
543 if (y_med_min <1) y_med_min=1;
544 if (x_med_max > nx) x_med_max=nx;
545 if (y_med_max > ny) y_med_max=ny;
547 double med = cpl_image_get_median_window (img,
548 x_med_min, y_med_min,
549 x_med_max, y_med_max);
550 cpl_array_set (parameters, 0, med);
556 cpl_error_code fit_converged = cpl_fit_image_gaussian (img, NULL, (cpl_size)(*x), (cpl_size)(*y),
557 size, size, parameters,
558 NULL, NULL, &rms, NULL, NULL,
559 NULL, NULL, NULL, NULL);
561 if (fit_converged == CPL_ERROR_NONE)
564 *x = cpl_array_get (parameters,3,NULL);
565 *y = cpl_array_get (parameters,4,NULL);
573 double A = cpl_array_get (parameters, 1, NULL);
574 double rho = cpl_array_get (parameters, 2, NULL);
575 double sx = cpl_array_get (parameters, 5, NULL);
576 double sy = cpl_array_get (parameters, 6, NULL);
579 double cst = 2. * sqrt(2. * M_PI * (1. - rho*rho) * sx * sy) * rms / A;
585 cpl_msg_info (cpl_func,
"rejecting fit: x=%g, y=%g, SNR=%g, sx=%g, sy=%g",
586 *x, *y, A/(rms * 2.*M_PI*sx*sy*sqrt(1-rho*rho)), sx, sy);
592 CPLCHECK_MSG(
"Error checking significance of fit result");
594 cpl_msg_warning (cpl_func,
"fit of pupil beacon did not converge");
610 FREE (cpl_array_delete, parameters);
613 return CPL_ERROR_NONE;
635 cpl_table * acqcam_table, cpl_propertylist * o_header,
639cpl_ensure_code(acqcam_imglist, CPL_ERROR_NULL_INPUT);
640cpl_ensure_code(
header, CPL_ERROR_NULL_INPUT);
641cpl_ensure_code(acqcam_table, CPL_ERROR_NULL_INPUT);
642cpl_ensure_code(o_header, CPL_ERROR_NULL_INPUT);
644cpl_size nx = cpl_image_get_size_x (cpl_imagelist_get (acqcam_imglist, 0));
645cpl_size ny = cpl_image_get_size_y (cpl_imagelist_get (acqcam_imglist, 0));
652const cpl_size ury = (ny>1100) ? 1200 : 745;
658 cpl_imagelist * pupilImage_filtered = cpl_imagelist_new ();
667 cpl_array * good_frames= cpl_array_new(cpl_imagelist_get_size(pupilImage_filtered),CPL_TYPE_INT);
668 cpl_imagelist * pupilImage_onFrames = cpl_imagelist_new ();
680 cpl_size nrow = cpl_imagelist_get_size(pupilImage_filtered);
681 cpl_size nrow_on = cpl_imagelist_get_size(pupilImage_onFrames);
683 if ((nrow_on<1)||(nrow<4))
686 cpl_array_fill_window_int (good_frames, 0, nrow_on, 0);
688 CPLCHECK_MSG(
"Cannot stor pupil offset values in OI_ACQ table");
690 cpl_imagelist_delete(pupilImage_onFrames);
691 cpl_imagelist_delete(pupilImage_filtered);
692 cpl_array_delete(good_frames);
693 cpl_msg_warning (cpl_func,
"Cannot reduce the %lli frames (not enough frames)",nrow);
695 return CPL_ERROR_NONE;
700 cpl_array * bad_frames_short= cpl_array_new(nrow_on,CPL_TYPE_INT);
701 cpl_array_fill_window_int (bad_frames_short, 0, nrow_on, 0);
703 cpl_bivector ** diode_pos_telescope = cpl_malloc (nrow_on *
sizeof(cpl_bivector *)) ;
704 cpl_bivector ** diode_pos_theoretical = cpl_malloc (nrow_on *
sizeof(cpl_bivector *)) ;
705 cpl_bivector ** diode_pos_offset = cpl_malloc (nrow_on *
sizeof(cpl_bivector *)) ;
706 cpl_imagelist ** pupilImage_shiftandadd = cpl_malloc (
GRAVI_SPOT_NTEL *
sizeof(cpl_imagelist *));
708 for (
int n = 0 ; n < nrow_on; n++)
716 pupilImage_shiftandadd[tel] = cpl_imagelist_new();
736 diode_pos_theoretical, nrow_on, ury);
737 CPLCHECK_MSG(
"Cannot get theoretical position of beacons");
744 diode_pos_offset, nrow_on);
745 CPLCHECK_MSG(
"Cannot find correct focus to shift and add pupil images");
758 CPLCHECK_MSG(
"Cannot stor pupil offset values in OI_ACQ table");
764 cpl_image * pupilImage_onFrames_collapse=cpl_imagelist_collapse_create (pupilImage_onFrames);
765 cpl_image * pupilImage_onFrames_1frame=cpl_imagelist_get (pupilImage_onFrames,0);
774 if (pupilImage_shiftandadd[tel] != NULL)
775 cpl_imagelist_delete( pupilImage_shiftandadd[tel]);
777FREE (cpl_free, pupilImage_shiftandadd);
780 for (
int n = 0 ; n < nrow_on; n++)
782 cpl_bivector_delete( diode_pos_telescope[n]);
783 cpl_bivector_delete( diode_pos_theoretical[n]);
784 cpl_bivector_delete( diode_pos_offset[n]);
786 FREE (cpl_free, diode_pos_telescope);
787 FREE (cpl_free, diode_pos_theoretical);
788 FREE (cpl_free, diode_pos_offset);
790 cpl_bivector_delete( diode_pos_subwindow);
792 cpl_imagelist_delete(pupilImage_onFrames);
793 cpl_imagelist_delete(pupilImage_filtered);
794 cpl_array_delete(good_frames);
795 cpl_array_delete(bad_frames_short);
796 cpl_vector_delete(scale_vector);
797 cpl_vector_delete(focus_value);
801return CPL_ERROR_NONE;
821 cpl_ensure_code(acqcam_imglist, CPL_ERROR_NULL_INPUT);
822 cpl_ensure_code(pupilImage_filtered, CPL_ERROR_NULL_INPUT);
823 cpl_ensure_code(ury, CPL_ERROR_NULL_INPUT);
826 cpl_size nrow = cpl_imagelist_get_size(acqcam_imglist);
828 cpl_size nx = cpl_image_get_size_x (cpl_imagelist_get (acqcam_imglist, 0));
829 cpl_size ny = cpl_image_get_size_y (cpl_imagelist_get (acqcam_imglist, 0));
831 cpl_imagelist * pupilImage = cpl_imagelist_new ();
833 for (cpl_size n = 0; n < nrow ; n++)
835 cpl_image * small_img_tmp = cpl_imagelist_get (acqcam_imglist, n);
836 cpl_image * small_img = cpl_image_extract( small_img_tmp, 1, ury, nx, ny);
837 cpl_imagelist_set(pupilImage, small_img,n);
840 nx=cpl_image_get_size_x (cpl_imagelist_get (pupilImage, 0));
841 ny=cpl_image_get_size_y (cpl_imagelist_get (pupilImage, 0));
843 cpl_image* pupilImageBackground = cpl_imagelist_collapse_minmax_create (pupilImage,(cpl_size)(nrow/8),(cpl_size)(5*nrow/8));
845 cpl_imagelist_subtract_image (pupilImage,pupilImageBackground);
849 cpl_matrix * kernel1 = cpl_matrix_new (Npref,Npref);
850 cpl_matrix * kernel2 = cpl_matrix_new (Npref,Npref);
851 for (cpl_size x =0;x< Npref; x++)
852 for (cpl_size y =0;y< Npref; y++)
854 double radius_square=(x-(Npref-1)/2)*(x-(Npref-1)/2)+(y-(Npref-1)/2)*(y-(Npref-1)/2);
855 cpl_matrix_set(kernel1,x,y,exp(- radius_square /30));
856 cpl_matrix_set(kernel2,x,y,exp(- radius_square /40));
859 cpl_matrix_divide_scalar (kernel1, cpl_matrix_get_mean (kernel1));
860 cpl_matrix_divide_scalar (kernel2, cpl_matrix_get_mean (kernel2));
861 cpl_matrix_subtract (kernel1,kernel2);
862 cpl_matrix_divide_scalar (kernel1, cpl_matrix_get_stdev (kernel1));
863 cpl_matrix_divide_scalar (kernel1, cpl_matrix_get_max (kernel1));
868 cpl_size fft_nx = nx + Npref - 1;
869 cpl_size fft_ny = ny + Npref - 1;
870 cpl_size half_kernel_w = (Npref - 1) / 2;
873 cpl_matrix_resize(kernel1, 0, ny-1, 0, nx-1);
874 cpl_image *kernel_image = cpl_image_wrap_double(fft_nx, fft_ny, cpl_matrix_get_data(kernel1));
877 cpl_image *kernel_fft = cpl_image_new(fft_nx, fft_ny, CPL_TYPE_DOUBLE_COMPLEX);
878 cpl_fft_image(kernel_fft, kernel_image, CPL_FFT_FORWARD);
881 cpl_imagelist *pupilImage_padded = cpl_imagelist_new();
882 for (cpl_size n = 0; n < nrow ; n++)
884 const cpl_image *small_img_tmp = cpl_imagelist_get_const(pupilImage, n);
885 cpl_image *padded_img_tmp = cpl_image_new(fft_nx, fft_ny, CPL_TYPE_DOUBLE);
886 cpl_image_copy(padded_img_tmp, small_img_tmp, 1, 1);
887 cpl_imagelist_set(pupilImage_padded, padded_img_tmp, n);
891 cpl_imagelist *pupilImage_fft = cpl_imagelist_new();
892 for (cpl_size n = 0; n < nrow; n++)
893 cpl_imagelist_set(pupilImage_fft, cpl_image_new(fft_nx, fft_ny, CPL_TYPE_DOUBLE_COMPLEX), n);
894 cpl_fft_imagelist(pupilImage_fft, pupilImage_padded, CPL_FFT_FORWARD | CPL_FFT_FIND_MEASURE);
897 cpl_imagelist_multiply_image(pupilImage_fft, kernel_fft);
900 cpl_imagelist *pupilImage_filtered_padded = cpl_imagelist_new();
901 for (cpl_size n = 0; n < nrow; n++)
902 cpl_imagelist_set(pupilImage_filtered_padded, cpl_image_new(fft_nx, fft_ny, CPL_TYPE_DOUBLE), n);
903 cpl_fft_imagelist(pupilImage_filtered_padded, pupilImage_fft, CPL_FFT_BACKWARD | CPL_FFT_FIND_MEASURE);
906 for (cpl_size n = 0; n < nrow; n++) {
907 const cpl_image *pad_filt_img_tmp = cpl_imagelist_get_const(pupilImage_filtered_padded, n);
908 cpl_image *trimmed_img = cpl_image_extract(pad_filt_img_tmp, half_kernel_w+1, half_kernel_w+1, fft_nx-half_kernel_w, fft_ny-half_kernel_w);
909 cpl_imagelist_set(pupilImage_filtered, trimmed_img, n);
912 cpl_matrix_delete(kernel1);
913 cpl_matrix_delete(kernel2);
915 cpl_image_unwrap(kernel_image);
919 cpl_imagelist_delete(pupilImage);
920 cpl_imagelist_delete(pupilImage_fft);
921 cpl_imagelist_delete(pupilImage_padded);
922 cpl_imagelist_delete(pupilImage_filtered_padded);
926 return CPL_ERROR_NONE;
951 cpl_ensure_code(pupilImage_filtered, CPL_ERROR_NULL_INPUT);
952 cpl_ensure_code(good_frames, CPL_ERROR_NULL_INPUT);
955 cpl_size nrow = cpl_imagelist_get_size(pupilImage_filtered);
956 cpl_size nx = cpl_image_get_size_x (cpl_imagelist_get (pupilImage_filtered, 0));
957 cpl_size ny = cpl_image_get_size_y (cpl_imagelist_get (pupilImage_filtered, 0));
959 cpl_vector * pupil_max = cpl_vector_new(4);
960 cpl_vector * pupil_mediam = cpl_vector_new(nrow);
961 cpl_array * back_frames= cpl_array_new(nrow,CPL_TYPE_INT);
963 for (cpl_size n = 0; n < nrow; n++)
966 cpl_image * image = cpl_imagelist_get (pupilImage_filtered,n);
967 cpl_vector_set(pupil_max, 0, cpl_image_get_max_window (image, 1, 1, 250, ny));
968 cpl_vector_set(pupil_max, 1, cpl_image_get_max_window (image, 251, 1, 500, ny));
969 cpl_vector_set(pupil_max, 2, cpl_image_get_max_window (image, 501, 1, 750, ny));
970 cpl_vector_set(pupil_max, 3, cpl_image_get_max_window (image, 751, 1, nx, ny));
971 cpl_vector_set(pupil_mediam, n, cpl_vector_get_median (pupil_max));
979 cpl_vector * pupil_mediam_sort = cpl_vector_duplicate (pupil_mediam);
980 cpl_vector_sort (pupil_mediam_sort,CPL_SORT_ASCENDING);
981 cpl_vector * pupil_median_down = cpl_vector_extract (pupil_mediam_sort, 0, (nrow-1)/2, 1);
982 cpl_vector * pupil_median_up = cpl_vector_extract (pupil_mediam_sort, nrow/2, nrow-1, 1);
983 double threshold_up = cpl_vector_get_median(pupil_median_up);
984 double threshold_down = cpl_vector_get_median(pupil_median_down);
985 double threshold=(threshold_up+threshold_down)/2.0;
987 CPLCHECK_MSG(
"Could not get median maximum of beacon flux ");
988 cpl_msg_info (cpl_func,
"Found threshold brightness level for beacon : %.5f ADU", threshold);
990 for (cpl_size n = 0; n < nrow; n++)
992 if (cpl_vector_get(pupil_mediam, n) >threshold *1.1)
993 cpl_array_set_int (good_frames,n,1);
995 cpl_array_set_int (good_frames,n,0);
996 if (cpl_vector_get(pupil_mediam, n) <threshold * 0.9)
997 cpl_array_set_int (back_frames,n,1);
999 cpl_array_set_int (back_frames,n,0);
1002 cpl_size frames_background = 4;
1003 cpl_size n_goodFrames = 0;
1007 for (cpl_size n = 0; n < nrow; n++)
1008 if (cpl_array_get_int(good_frames,n,&nv) == 1)
1010 cpl_image * image = cpl_imagelist_get (pupilImage_filtered,n);
1013 cpl_size n_frames_background = 0;
1014 cpl_imagelist * pupilImage_offFrames = cpl_imagelist_new ();
1015 for (cpl_size b = 1; b < nrow; b++)
1018 if ((cpl_array_get_int(back_frames,n+b,&nv) == 1)&(n_frames_background<frames_background))
1020 cpl_image * image_background = cpl_imagelist_get (pupilImage_filtered,n+b);
1021 cpl_image * image_background_copy = cpl_image_duplicate (image_background);
1022 cpl_imagelist_set(pupilImage_offFrames, image_background_copy, n_frames_background);
1023 n_frames_background = n_frames_background + 1;
1026 if ((cpl_array_get_int(back_frames,n-b,&nv) == 1)&(n_frames_background<frames_background))
1028 cpl_image * image_background = cpl_imagelist_get (pupilImage_filtered,n-b);
1029 cpl_image * image_background_copy = cpl_image_duplicate (image_background);
1030 cpl_imagelist_set(pupilImage_offFrames, image_background_copy, n_frames_background);
1031 n_frames_background = n_frames_background + 1;
1035 cpl_image * image_background_mean = cpl_imagelist_collapse_create (pupilImage_offFrames);
1036 cpl_image * image_background_subtracted = cpl_image_subtract_create (image, image_background_mean);
1037 cpl_imagelist_set(pupilImage_onFrames, image_background_subtracted, n_goodFrames);
1040 cpl_imagelist_delete(pupilImage_offFrames);
1044 cpl_msg_info(cpl_func,
"Found %lli frames with pupil beacon ON (over %lli frames)",n_goodFrames, nrow);
1046 cpl_vector_delete(pupil_max);
1047 cpl_vector_delete(pupil_mediam);
1048 cpl_vector_delete(pupil_median_up);
1049 cpl_vector_delete(pupil_median_down);
1050 cpl_vector_delete(pupil_mediam_sort);
1051 cpl_array_delete(back_frames);
1055 return CPL_ERROR_NONE;
1075 cpl_ensure_code (
header, CPL_ERROR_NULL_INPUT);
1076 cpl_ensure_code (diode_pos_subwindow, CPL_ERROR_NULL_INPUT);
1078 cpl_size nsx = 0, nsy = 0, sx = 0, sy = 0;
1080 cpl_vector * x_pos_subwindow = cpl_bivector_get_x (diode_pos_subwindow);
1081 cpl_vector * y_pos_subwindow = cpl_bivector_get_y (diode_pos_subwindow);
1088 if ( cpl_propertylist_has (
header,
"ESO DET1 FRAMES NX") ) {
1091 nsx = cpl_propertylist_get_int (
header,
"ESO DET1 FRAMES NX");
1093 sx = cpl_propertylist_get_int (
header, name);
1095 nsy = cpl_propertylist_get_int (
header,
"ESO DET1 FRAMES NY");
1097 sy = cpl_propertylist_get_int (
header, name);
1102 cpl_msg_info (cpl_func,
"sub-window pupil %i sx= %lld sy = %lld", tel, sx, sy);
1111 cpl_vector_set( x_pos_subwindow, lens*
GRAVI_SPOT_NTEL+tel , xv - (sx - tel*nsx) - 1);
1112 cpl_vector_set( y_pos_subwindow, lens*
GRAVI_SPOT_NTEL+tel , yv - (sy - 3*nsy) - 1);
1120 return CPL_ERROR_NONE;
1143 cpl_array * good_frames,
1144 cpl_vector * scale_vector,
1145 cpl_bivector ** diode_pos_telescope,
1149 cpl_ensure_code (
header, CPL_ERROR_NULL_INPUT);
1150 cpl_ensure_code (good_frames, CPL_ERROR_NULL_INPUT);
1154 double parang1 = cpl_propertylist_get_double(
header,
"ESO ISS PARANG START");
1155 double parang2 = cpl_propertylist_get_double(
header,
"ESO ISS PARANG END");
1167 cpl_size nrow = cpl_array_get_size(good_frames);
1168 if (fabs(cpl_array_get_mean(good_frames)*nrow -nrow_on) > 1e-2)
1169 cpl_msg_error (cpl_func,
"Ratio of blinking frames different %f from %i",cpl_array_get_mean(good_frames)*nrow,nrow_on);
1178 if (!telname) cpl_msg_error (cpl_func,
"Cannot read the telescope name");
1179 cpl_ensure_code (telname, CPL_ERROR_ILLEGAL_INPUT);
1185 if (telname[0] ==
'U') {
1189 if ( tel == 0 ) scale = 16.83;
1190 if ( tel == 1 ) scale = 17.42;
1191 if ( tel == 2 ) scale = 16.85;
1192 if ( tel == 3 ) scale = 17.41;
1198 }
else if (telname[0] ==
'A') {
1206 return cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
1207 "Cannot get telescope name");
1209 cpl_vector_set(scale_vector,tel,scale);
1216 double northangle = 0;
1217 double zenithangle = 0;
1225 for (cpl_size n =0; n < nrow; n++)
1228 if (cpl_array_get_int(good_frames,n,&nv) ==1)
1230 double padif = parang2 - parang1;
1235 double parang= parang1 + padif*n/(nrow-1);
1242 angle = zenithangle - 45.;
1244 angle = northangle + parang + 45.;
1247 if (angle < 0) angle += 180;
1248 if (angle > 180) angle -= 180;
1249 double cang = cos(angle * CPL_MATH_RAD_DEG) * scale;
1250 double sang = sin(angle * CPL_MATH_RAD_DEG) * scale;
1254 cpl_vector * x_pos_telescope = cpl_bivector_get_x (diode_pos_telescope[n_on]);
1255 cpl_vector * y_pos_telescope = cpl_bivector_get_y (diode_pos_telescope[n_on]);
1257 cpl_vector_set(x_pos_telescope, 0*
GRAVI_SPOT_NTEL+tel, -cang * dx + sang * dy);
1258 cpl_vector_set(x_pos_telescope, 1*
GRAVI_SPOT_NTEL+tel, -cang * dx - sang * dy);
1259 cpl_vector_set(x_pos_telescope, 2*
GRAVI_SPOT_NTEL+tel, cang * dx - sang * dy);
1260 cpl_vector_set(x_pos_telescope, 3*
GRAVI_SPOT_NTEL+tel, cang * dx + sang * dy);
1262 cpl_vector_set(y_pos_telescope, 0*
GRAVI_SPOT_NTEL+tel, cang * dy + sang * dx);
1263 cpl_vector_set(y_pos_telescope, 1*
GRAVI_SPOT_NTEL+tel, -cang * dy + sang * dx);
1264 cpl_vector_set(y_pos_telescope, 2*
GRAVI_SPOT_NTEL+tel, -cang * dy - sang * dx);
1265 cpl_vector_set(y_pos_telescope, 3*
GRAVI_SPOT_NTEL+tel, cang * dy - sang * dx);
1271 cpl_msg_info (cpl_func,
"angle, parang %.2f, %.2f",angle,parang);
1272 cpl_msg_info (cpl_func,
"dx and dy %.2f, %.2f",cang,sang);
1280 CPLCHECK_MSG(
"Cannot determine diode position in telescope space");
1284 return CPL_ERROR_NONE;
1308 cpl_bivector ** diode_pos_telescope,
1309 cpl_bivector ** diode_pos_theoretical,
1310 cpl_size nrow_on,
int ury)
1314 cpl_ensure_code (diode_pos_subwindow, CPL_ERROR_NULL_INPUT);
1315 cpl_ensure_code (diode_pos_telescope, CPL_ERROR_NULL_INPUT);
1316 cpl_ensure_code (diode_pos_theoretical, CPL_ERROR_NULL_INPUT);
1318 cpl_vector * x_pos_subwindow = cpl_bivector_get_x (diode_pos_subwindow);
1319 cpl_vector * y_pos_subwindow = cpl_bivector_get_y (diode_pos_subwindow);
1323 double x_lenslet_mean=0.0;
1324 double y_lenslet_mean=0.0;
1331 cpl_msg_info (cpl_func,
"Reference pixel position for tel %d : X = %.2f, Y= %.2f", tel, x_lenslet_mean, y_lenslet_mean);
1336 double xlenslet=cpl_vector_get(x_pos_subwindow,lens*
GRAVI_SPOT_NTEL+tel)+
1338 double ylenslet=cpl_vector_get(y_pos_subwindow,lens*
GRAVI_SPOT_NTEL+tel)+
1342 for (cpl_size n_on = 0 ; n_on < nrow_on; n_on++)
1345 cpl_vector * x_pos_telescope = cpl_bivector_get_x (diode_pos_telescope[n_on]);
1346 cpl_vector * y_pos_telescope = cpl_bivector_get_y (diode_pos_telescope[n_on]);
1347 cpl_vector * x_pos_theoretical = cpl_bivector_get_x (diode_pos_theoretical[n_on]);
1348 cpl_vector * y_pos_theoretical = cpl_bivector_get_y (diode_pos_theoretical[n_on]);
1350 double x_theo = xlenslet + cpl_vector_get(x_pos_telescope,spot*
GRAVI_SPOT_NTEL+tel);
1351 double y_theo = ylenslet + cpl_vector_get(y_pos_telescope,spot*
GRAVI_SPOT_NTEL+tel)- ury +1;
1359CPLCHECK_MSG(
"Cannot compute the theoretical coordinates of spots");
1361return CPL_ERROR_NONE;
1382 cpl_ensure_code(mean_img, CPL_ERROR_NULL_INPUT);
1383 cpl_ensure_code(diode_pos_offset, CPL_ERROR_NULL_INPUT);
1384 cpl_ensure_code(diode_pos_theoretical, CPL_ERROR_NULL_INPUT);
1386 cpl_size nx = cpl_image_get_size_x (mean_img);
1387 cpl_size ny = cpl_image_get_size_y (mean_img);
1391 cpl_vector * x_pos_offset = cpl_bivector_get_x (diode_pos_offset[n_on]);
1392 cpl_vector * y_pos_offset = cpl_bivector_get_y (diode_pos_offset[n_on]);
1393 cpl_vector * x_pos_theoretical = cpl_bivector_get_x (diode_pos_theoretical[n_on]);
1394 cpl_vector * y_pos_theoretical = cpl_bivector_get_y (diode_pos_theoretical[n_on]);
1404 double x_off = cpl_vector_get(x_pos_offset,tel);
1405 double y_off = cpl_vector_get(y_pos_offset,tel)+ury;
1408 cpl_size xf = roundl(x_diode + x_off) + 1;
1409 cpl_size yf = roundl(y_diode + y_off) + 1;
1410 if (xf < 2 || xf > nx-2 || yf < 2 || yf > ny-2)
continue;
1411 cpl_image_set (mean_img, xf, yf, 0);
1412 cpl_image_set (mean_img, xf-1, yf, 0);
1413 cpl_image_set (mean_img, xf+1, yf, 0);
1414 cpl_image_set (mean_img, xf, yf+1, 0);
1415 cpl_image_set (mean_img, xf, yf-1, 0);
1416 CPLCHECK (
"Cannot imprint cross in image");
1419 CPLCHECK (
"Cannot imprint cross in image");
1421 return CPL_ERROR_NONE;
1460 cpl_vector * focus_value,
1461 cpl_bivector ** diode_pos_theoretical ,
1462 cpl_bivector ** diode_pos_offset, cpl_size nrow_on)
1466 cpl_ensure_code(pupilImage_onFrames, CPL_ERROR_NULL_INPUT);
1467 cpl_ensure_code(pupilImage_shiftandadd, CPL_ERROR_NULL_INPUT);
1468 cpl_ensure_code(good_frames, CPL_ERROR_NULL_INPUT);
1469 cpl_ensure_code(focus_value, CPL_ERROR_NULL_INPUT);
1470 cpl_ensure_code(diode_pos_theoretical, CPL_ERROR_NULL_INPUT);
1471 cpl_ensure_code(diode_pos_offset, CPL_ERROR_NULL_INPUT);
1472 cpl_ensure_code(nrow_on, CPL_ERROR_NULL_INPUT);
1474 if (cpl_imagelist_get_size(pupilImage_onFrames) != nrow_on)
1475 cpl_msg_error (cpl_func,
"Problem with number of blinking frames");
1482 cpl_imagelist * pupilImage_shifted= cpl_imagelist_new();
1483 cpl_size n_images = 0;
1484 for (cpl_size n = 0 ; n < nrow_on; n++)
1488 cpl_vector * x_pos_theoretical = cpl_bivector_get_x (diode_pos_theoretical[n]);
1489 cpl_vector * y_pos_theoretical = cpl_bivector_get_y (diode_pos_theoretical[n]);
1494 cpl_size x=(int) (x_theo + 0.5);
1495 cpl_size y=(int) (y_theo+ 0.5);
1496 cpl_image * verysmall_img_tmp = cpl_imagelist_get (pupilImage_onFrames, n);
1498 cpl_imagelist_set(pupilImage_shifted, verysmall_img, n_images);
1502 cpl_image * image_mean = cpl_imagelist_collapse_create (pupilImage_shifted);
1503 cpl_vector_set(focus_max, focus, cpl_image_get_max(image_mean));
1504 cpl_imagelist_delete(pupilImage_shifted);
1508 int focus_max_pos = cpl_vector_get_maxpos (focus_max);
1513 for (cpl_size n = 0 ; n < nrow_on; n++)
1515 cpl_vector * x_pos_theoretical = cpl_bivector_get_x (diode_pos_theoretical[n]);
1516 cpl_vector * y_pos_theoretical = cpl_bivector_get_y (diode_pos_theoretical[n]);
1517 cpl_imagelist * pupilImage_shifted= cpl_imagelist_new();
1520 cpl_size n_images = 0;
1526 int x= (int) (x_theo+ 0.5);
1527 int y= (int) (y_theo + 0.5);
1528 cpl_image * verysmall_img_tmp = cpl_imagelist_get (pupilImage_onFrames, n);
1538 cpl_imagelist_set(pupilImage_shifted, verysmall_img, n_images);
1539 cpl_vector_set (offs_x, n_images, (x-x_theo));
1540 cpl_vector_set (offs_y, n_images, (y-y_theo));
1545 cpl_bivector * offs = cpl_bivector_wrap_vectors (offs_x, offs_y);
1547 double ppos_x, ppos_y;
1548 cpl_image** cpl_image_combined = cpl_geom_img_offset_saa (pupilImage_shifted,offs,CPL_KERNEL_DEFAULT,
1549 0,0,CPL_GEOM_INTERSECT,&ppos_x,&ppos_y);
1552 cpl_vector * x_pos_offset = cpl_bivector_get_x (diode_pos_offset[n]);
1553 cpl_vector * y_pos_offset = cpl_bivector_get_y (diode_pos_offset[n]);
1557 cpl_vector_set(x_pos_offset, tel, ppos_x+3);
1558 cpl_vector_set(y_pos_offset, tel, ppos_y+3);
1560 cpl_imagelist_set(pupilImage_shiftandadd[tel], image_mean, n);
1561 CPLCHECK_MSG(
"Cannot add shift and added image to imagelist");
1563 if (cpl_image_combined[0] != NULL)
cpl_image_delete(cpl_image_combined[0]);
1564 if (cpl_image_combined[1] != NULL)
cpl_image_delete(cpl_image_combined[1]);
1565 cpl_free(cpl_image_combined);
1567 cpl_bivector_delete(offs);
1568 cpl_imagelist_delete(pupilImage_shifted);
1570 cpl_vector_delete(focus_max);
1573 CPLCHECK_MSG(
"Fail at running the shift and add ESO algorithm");
1576 return CPL_ERROR_NONE;
1602 cpl_array * bad_frames_short,
1603 cpl_bivector ** diode_pos_offset, cpl_propertylist * o_header,
1608 cpl_ensure_code(pupilImage_shiftandadd, CPL_ERROR_NULL_INPUT);
1609 cpl_ensure_code(bad_frames_short, CPL_ERROR_NULL_INPUT);
1610 cpl_ensure_code(diode_pos_offset, CPL_ERROR_NULL_INPUT);
1611 cpl_ensure_code(o_header, CPL_ERROR_NULL_INPUT);
1612 cpl_ensure_code(nrow_on, CPL_ERROR_NULL_INPUT);
1616 if (cpl_array_get_size(bad_frames_short)!= nrow_on)
1617 cpl_msg_error (cpl_func,
"Problem with number of blinking frames");
1621 double previous_xsc=0.0;
1622 double previous_ysc=0.0;
1623 double flux_sum=0.0;
1626 for (cpl_size n = 0 ; n < nrow_on; n++)
1628 cpl_image * image = cpl_imagelist_get (pupilImage_shiftandadd[tel], n);
1632 cpl_image_get_maxpos (image, &px, &py);
1635 double flux_max= cpl_image_get(image,px,py,&nv);
1636 double std = cpl_image_get_stdev (image);
1639 double xsc = (double) px;
1640 double ysc = (double) py;
1641 double exsc=3., eysc=3.;
1647 cpl_vector * x_pos_offset = cpl_bivector_get_x (diode_pos_offset[n]);
1648 cpl_vector * y_pos_offset = cpl_bivector_get_y (diode_pos_offset[n]);
1654 cpl_vector_set(x_pos_offset, tel, x_offset_final);
1655 cpl_vector_set(y_pos_offset, tel, y_offset_final);
1658 if ((flux_max/std < 4)||(exsc<0))
1660 previous = cpl_array_get_int (bad_frames_short,n,&nv);
1661 cpl_array_set_int (bad_frames_short,n,previous|(1<<tel));
1665 double distance=(xsc-previous_xsc)*(xsc-previous_xsc)+(ysc-previous_ysc)*(ysc-previous_ysc);
1666 if (distance > 10*10)
1668 previous = cpl_array_get_int (bad_frames_short,n-1,&nv);
1669 cpl_array_set_int (bad_frames_short,n-1,previous|(1<<(tel+4)));
1670 previous = cpl_array_get_int (bad_frames_short,n,&nv);
1671 cpl_array_set_int (bad_frames_short,n,previous|(1<<(tel+4)));
1679 CPLCHECK_MSG(
"Failure at testing bad pupil measurments");
1683 double flux_mean=flux_sum/(1e-7+n_sum);
1685 sprintf(qc_name,
"ESO QC ACQ PUP%i SPOT_FLUX", tel + 1);
1688 cpl_propertylist_set_comment(o_header, qc_name,
"[ADU] mean spot flux");
1693 CPLCHECK_MSG(
"Failure at fitting gaussian on diode position");
1696 return CPL_ERROR_NONE;
1727 cpl_vector* scale_vector, cpl_array * bad_frames_short, cpl_bivector ** diode_pos_offset, cpl_vector * focus_value,
gravi_data *static_param_data)
1733cpl_ensure_code(acqcam_table, CPL_ERROR_NULL_INPUT);
1734cpl_ensure_code(
header, CPL_ERROR_NULL_INPUT);
1735cpl_ensure_code(o_header, CPL_ERROR_NULL_INPUT);
1736cpl_ensure_code(good_frames, CPL_ERROR_NULL_INPUT);
1737cpl_size nrow = cpl_array_get_size(good_frames);
1754if (cpl_array_get_mean(good_frames)*nrow<.5)
1758 cpl_msg_info(cpl_func,
"No good pupil images ==> no good pupil position available");
1761 for (cpl_size row = 0; row < nrow; row++)
1763 cpl_table_set(acqcam_table,
"PUPIL_NSPOT", row *
GRAVI_SPOT_NTEL + tel, 0);
1764 CPLCHECK_MSG(
"Cannot put 0 in NSPOT data in the ACQ PUPIL");
1768 return CPL_ERROR_NONE;
1772cpl_ensure_code(scale_vector, CPL_ERROR_NULL_INPUT);
1773cpl_ensure_code(bad_frames_short, CPL_ERROR_NULL_INPUT);
1774cpl_ensure_code(diode_pos_offset, CPL_ERROR_NULL_INPUT);
1775cpl_ensure_code(focus_value, CPL_ERROR_NULL_INPUT);
1776cpl_ensure_code(static_param_data, CPL_ERROR_NULL_INPUT);
1778cpl_size nrow_on = cpl_array_get_size(bad_frames_short);
1780if (fabs(cpl_array_get_mean(good_frames)*nrow -nrow_on) > 1e-2)
1781 cpl_msg_error (cpl_func,
"Ratio of blinking frames different %f from %lli",cpl_array_get_mean(good_frames)*nrow,nrow_on);
1791 double cfangle = cos(northangle * CPL_MATH_RAD_DEG);
1792 double sfangle = sin(northangle * CPL_MATH_RAD_DEG);
1793 double scale = cpl_vector_get(scale_vector,tel);
1797 double r_shift = 0.0;
1802 double x_shift = 0.0;
1803 double y_shift = 0.0;
1804 double u_shift = 0.0;
1805 double v_shift = 0.0;
1806 double opd_pupil = 0.0;
1809 double x_shift_sum = 0.0;
1810 double y_shift_sum = 0.0;
1811 double u_shift_sum = 0.0;
1812 double v_shift_sum = 0.0;
1815 int n_bad_distance = 0;
1817 for (cpl_size row = 0; row < nrow; row++)
1821 if (cpl_array_get_int(good_frames,row,&nv) != 1)
1823 cpl_table_set(acqcam_table,
"PUPIL_NSPOT", row *
GRAVI_SPOT_NTEL + tel, 0);
1824 CPLCHECK_MSG(
"Cannot put 0 in NSPOT data in the ACQ PUPIL");
1829 int is_it_bad=cpl_array_get_int (bad_frames_short,n_on,&nv);
1831 cpl_vector * x_pos_offset = cpl_bivector_get_x (diode_pos_offset[n_on]);
1832 cpl_vector * y_pos_offset = cpl_bivector_get_y (diode_pos_offset[n_on]);
1833 CPLCHECK_MSG(
"Cannot put data from the offset bivector");
1835 x_shift = cpl_vector_get(x_pos_offset,tel);
1836 y_shift = cpl_vector_get(y_pos_offset,tel);
1839 u_shift = (cfangle * x_shift - sfangle * y_shift)
1841 v_shift = (sfangle * x_shift + cfangle * y_shift)
1843 opd_pupil = -(u_shift * sobj_x + v_shift * sobj_y)
1846 CPLCHECK_MSG(
"Cannot prepare data to be put in the ACQ PUPIL table");
1851 cpl_table_set(acqcam_table,
"PUPIL_NSPOT", row *
GRAVI_SPOT_NTEL + tel, 0);
1854 if (
CHECK_BIT(is_it_bad,tel )) n_bad_snr += 1;
1855 if (
CHECK_BIT(is_it_bad,tel+4)) n_bad_distance += 1;
1859 cpl_msg_info(cpl_func,
"Pupil image number%4lli is un-usable for tel %i",row,tel);
1863 cpl_table_set(acqcam_table,
"PUPIL_NSPOT", row *
GRAVI_SPOT_NTEL + tel,
1867 x_shift_sum += x_shift;
1868 y_shift_sum += y_shift;
1869 u_shift_sum += u_shift;
1870 v_shift_sum += v_shift;
1892 CPLCHECK_MSG(
"Cannot put data in the ACQ PUPIL table");
1896 CPLCHECK_MSG(
"Cannot put data in the ACQ PUPIL table");
1902 sprintf(qc_name,
"ESO QC ACQ FIELD%i NORTH_ANGLE", tel + 1);
1903 cpl_msg_info(cpl_func,
"%s = %f", qc_name, northangle);
1905 cpl_propertylist_set_comment(o_header, qc_name,
1906 "[deg] y->x, predicted North direction on ACQ");
1908 sprintf(qc_name,
"ESO QC ACQ PUP%i FRAMES", tel + 1);
1911 cpl_propertylist_set_comment(o_header, qc_name,
1912 "Good ACQ pupil frames");
1914 sprintf(qc_name,
"ESO QC ACQ PUP%i BADSNR", tel + 1);
1917 cpl_propertylist_set_comment(o_header, qc_name,
1918 "Frames with low SNR");
1920 sprintf(qc_name,
"ESO QC ACQ PUP%i JUMP", tel + 1);
1921 cpl_msg_info(cpl_func,
"%s = %i", qc_name, n_bad_distance);
1923 cpl_propertylist_set_comment(o_header, qc_name,
1924 "Frames with position jump");
1926 sprintf(qc_name,
"ESO QC ACQ PUP%i SCALE", tel + 1);
1929 cpl_propertylist_set_comment(o_header, qc_name,
1930 "[pix/m] diode scale on ACQ");
1932 sprintf(qc_name,
"ESO QC ACQ PUP%i FOCUS", tel + 1);
1934 cpl_propertylist_update_int(o_header, qc_name, z_shift);
1935 cpl_propertylist_set_comment(o_header, qc_name,
1936 "[pix] defocus of pupil plane");
1939 if (n_sum ==0) n_sum+=1;
1941 sprintf(qc_name,
"ESO QC ACQ PUP%i XPOS", tel + 1);
1942 cpl_msg_info(cpl_func,
"%s = %f", qc_name, x_shift_sum/n_sum);
1944 cpl_propertylist_set_comment(o_header, qc_name,
1945 "[pix] pupil x-shift in ACQ");
1947 sprintf(qc_name,
"ESO QC ACQ PUP%i YPOS", tel + 1);
1948 cpl_msg_info(cpl_func,
"%s = %f", qc_name, y_shift_sum/n_sum);
1950 cpl_propertylist_set_comment(o_header, qc_name,
1951 "[pix] pupil y-shift in ACQ");
1953 sprintf(qc_name,
"ESO QC ACQ PUP%i UPOS", tel + 1);
1954 cpl_msg_info(cpl_func,
"%s = %f", qc_name, u_shift_sum/n_sum);
1956 cpl_propertylist_set_comment(o_header, qc_name,
1957 "[m] pupil u-shift in ACQ");
1959 sprintf(qc_name,
"ESO QC ACQ PUP%i VPOS", tel + 1);
1960 cpl_msg_info(cpl_func,
"%s = %f", qc_name, v_shift_sum/n_sum);
1962 cpl_propertylist_set_comment(o_header, qc_name,
1963 "[m] pupil v-shift in ACQ");
1966 CPLCHECK_MSG(
"Cannot put data in the ACQ PUPIL table");
1973return CPL_ERROR_NONE;
2002 cpl_size nx = cpl_image_get_size_x (image_in);
2003 cpl_size ny = cpl_image_get_size_y (image_in);
2004 cpl_size llx_new,lly_new,urx_new,ury_new;
2005 cpl_size xpos, ypos;
2007 cpl_size nx_new=urx+1-llx;
2008 cpl_size ny_new=ury+1-lly;
2009 cpl_image * image_out= cpl_image_new (nx_new, ny_new, cpl_image_get_type(image_in));
2010 cpl_image_fill_window (image_out, 1, 1, nx_new, ny_new, 0.0);
2013 if ((llx >= nx)||(lly >= ny)||(urx <= 0)||(ury <= 0))
2015 cpl_msg_warning (cpl_func,
"Cutting at x=(%lli,%lli) y=(%lli,%lli) is outside the window bondaries", llx, urx, lly, ury);
2047 cpl_image * image_in_cut = cpl_image_extract(image_in,llx_new,lly_new,urx_new,ury_new);
2049 cpl_image_copy (image_out, image_in_cut, xpos, ypos);
2093 cpl_imagelist * acqcam_imglist,
2094 cpl_propertylist *
header,
2095 cpl_table * acqcam_table,
2096 cpl_propertylist * o_header,
2100 cpl_ensure_code (mean_img, CPL_ERROR_NULL_INPUT);
2101 cpl_ensure_code (acqcam_imglist, CPL_ERROR_NULL_INPUT);
2102 cpl_ensure_code (
header, CPL_ERROR_NULL_INPUT);
2103 cpl_ensure_code (acqcam_table, CPL_ERROR_NULL_INPUT);
2104 cpl_ensure_code (o_header, CPL_ERROR_NULL_INPUT);
2120 cpl_size nrow = cpl_imagelist_get_size (acqcam_imglist);
2147 double *roof_x = NULL;
2148 double *roof_y = NULL;
2153 double *spot_x = NULL;
2154 double *spot_y = NULL;
2158 double *roof_pos = NULL;
2161 CPLCHECK_MSG (
"STATIC_PARAM not available in the SOF. It is mandatory for acqcam reduction.");
2163 if ( cpl_table_has_column(roof_pos_table ,
"roof_x") ) {
2164 roof_x= cpl_table_get_data_double (roof_pos_table,
"roof_x");
2171 cpl_msg_warning(cpl_func,
"Cannot get the default values for roof_x ");
2174 if ( cpl_table_has_column(roof_pos_table ,
"roof_y") ) {
2175 roof_y= cpl_table_get_data_double (roof_pos_table,
"roof_y");
2182 cpl_msg_warning(cpl_func,
"Cannot get the default values for roof_y ");
2185 if ( cpl_table_has_column(roof_pos_table ,
"spot_x") ) {
2186 spot_x= cpl_table_get_data_double (roof_pos_table,
"spot_x");
2193 cpl_msg_warning(cpl_func,
"Cannot get the default values for spot_x ");
2196 if ( cpl_table_has_column(roof_pos_table ,
"spot_y") ) {
2197 spot_y= cpl_table_get_data_double (roof_pos_table,
"spot_y");
2204 cpl_msg_warning(cpl_func,
"Cannot get the default values for spot_y ");
2207 if ( cpl_table_has_column(roof_pos_table ,
"roof_pos") ) {
2208 roof_pos= cpl_table_get_data_double (roof_pos_table,
"roof_pos");
2209 cpl_msg_info(cpl_func,
"roof_pos [0] : %e", roof_pos[0] );
2210 cpl_msg_info(cpl_func,
"roof_pos [1] : %e", roof_pos[1] );
2211 cpl_msg_info(cpl_func,
"roof_pos [2] : %e", roof_pos[2] );
2212 cpl_msg_info(cpl_func,
"roof_pos [3] : %e", roof_pos[3] );
2215 cpl_msg_warning(cpl_func,
"Cannot get the default values for roof_pos ");
2233 double calib_dx[] = {0,0,0,0} ;
2234 double calib_dy[] = {0,0,0,0} ;
2239 if ( cpl_propertylist_has (
header,
"ESO DET1 FRAMES NX") ) {
2240 nsx = cpl_propertylist_get_int (
header,
"ESO DET1 FRAMES NX");
2249 double sobj_offx=0., sobj_offy=0, sobj_drho=0., sobj_dth=0.;
2250 if (cpl_propertylist_has(
header,
"ESO INS SOBJ OFFX")) {
2253 sobj_offx = cpl_propertylist_get_double (
header,
"ESO INS SOBJ OFFX");
2254 sobj_offy = cpl_propertylist_get_double (
header,
"ESO INS SOBJ OFFY");
2257 sobj_drho = sqrt(sobj_offx*sobj_offx+sobj_offy*sobj_offy);
2261 sobj_dth = atan2(sobj_offx, sobj_offy)*180./M_PI;
2266 double dx_in = sobj_x - sobj_offx;
2267 double dy_in = sobj_y - sobj_offy;
2268 double rho_in = sqrt(dx_in*dx_in + dy_in*dy_in);
2275 for (
int tel = 0; tel <
ntel; tel++) {
2277 double rp=roof_pos[tel];
2278 cpl_size sx=tel*512+1, sy=1;
2279 cpl_msg_info (cpl_func,
"Compute field position for beam %i", tel+1);
2282 sprintf (name,
"ESO INS DROTOFF%d", tel + 1);
2283 if ( cpl_propertylist_has (
header, name) ) {
2284 rp = cpl_propertylist_get_double(
header, name);
2288 cpl_msg_info (cpl_func,
"%s not in header, use %f", name, rp);
2292 double approx_PA = 270.-rp;
2298 if (!telname) cpl_msg_error (cpl_func,
"Cannot read the telescope name");
2299 cpl_ensure_code (telname, CPL_ERROR_ILLEGAL_INPUT);
2304 if (telname[0] ==
'U') {
2307 cpl_msg_info (cpl_func,
"PLATE SCALE UT is : %e",scale);
2308 }
else if (telname[0] ==
'A') {
2309 sprintf(telid,
"ESO PLATE SCALE AT%d", tel+1);
2311 cpl_msg_info (cpl_func,
"PLATE SCALE AT%d is : %e",tel+1, scale);
2326 double fiber_xft=0.;
2327 double fiber_yft=0.;
2328 double fiber_xsc=0.;
2329 double fiber_ysc=0.;
2330 sprintf (name,
"ESO ACQ FIBER FT%dX", tel + 1);
2331 if (cpl_propertylist_has(
header, name)) {
2332 fiber_xft=cpl_propertylist_get_double(
header, name);
2333 sprintf (name,
"ESO ACQ FIBER FT%dY", tel + 1);
2334 fiber_yft=cpl_propertylist_get_double(
header, name);
2335 sprintf (name,
"ESO ACQ FIBER SC%dX", tel + 1);
2336 fiber_xsc=cpl_propertylist_get_double(
header, name);
2337 sprintf (name,
"ESO ACQ FIBER SC%dY", tel + 1);
2338 fiber_ysc=cpl_propertylist_get_double(
header, name);
2340 double fiber_ft_sc_x=fiber_xsc-fiber_xft;
2341 double fiber_ft_sc_y=fiber_ysc-fiber_yft;
2349 double sobj_offx_cam = sobj_drho * sin((northangle+sobj_dth)/180.*M_PI);
2350 double sobj_offy_cam = sobj_drho * cos((northangle+sobj_dth)/180.*M_PI);
2354 sprintf (name,
"ESO DET1 FRAM%d STRX", tel + 1);
2355 sx = cpl_propertylist_get_int (
header, name);
2357 sprintf (name,
"ESO DET1 FRAM%d STRY", tel + 1);
2358 sy = cpl_propertylist_get_int (
header, name);
2363 cpl_msg_debug (cpl_func,
"sub-window field %i sx= %lld sy = %lld", tel, sx, sy);
2369 double xFT, yFT, xSC, ySC;
2375 xFT = spot_x[tel] - sx + nsx*tel + 1;
2376 yFT = spot_y[tel] - sy + 1;
2380 xFT = fiber_xft - sx + nsx*tel + 1;
2381 yFT = fiber_yft - sy + 1;
2382 xSC = fiber_xsc - sx + nsx*tel + 1;
2383 ySC = fiber_ysc - sy + 1;
2387 double cutout_roof_x = roof_x[tel] - sx + nsx*tel + 1;
2388 double cutout_roof_y = roof_y[tel] - sy + 1;
2390 cpl_msg_info (cpl_func,
" ROOF_X = %f", cutout_roof_x);
2391 cpl_msg_info (cpl_func,
" ROOF_Y = %f", cutout_roof_y);
2394 double approx_dx=0.5*rho_in*sin(approx_PA*M_PI/180.)/scale;
2395 double approx_dy=0.5*rho_in*cos(approx_PA*M_PI/180.)/scale;
2398 xFT = cutout_roof_x - approx_dx ;
2399 yFT = cutout_roof_y - approx_dy ;
2400 xSC = cutout_roof_x + approx_dx ;
2401 ySC = cutout_roof_y + approx_dy ;
2419 double xSCguess=xSC, ySCguess=ySC, xFTguess=xFT, yFTguess=yFT;
2430 sprintf (qc_name,
"ESO QC ACQ FIELD%i SC_X", tel+1);
2441 cpl_propertylist_set_comment (o_header, qc_name,
"[pixel] position in mean image");
2443 sprintf (qc_name,
"ESO QC ACQ FIELD%i SC_Y", tel+1);
2454 cpl_propertylist_set_comment (o_header, qc_name,
"[pixel] position in mean image");
2473 sprintf (qc_name,
"ESO QC ACQ FIELD%i FT_X", tel+1);
2484 cpl_propertylist_set_comment (o_header, qc_name,
"[pixel] position in mean image");
2486 sprintf (qc_name,
"ESO QC ACQ FIELD%i FT_Y", tel+1);
2497 cpl_propertylist_set_comment (o_header, qc_name,
"[pixel] position in mean image");
2504 sprintf (qc_name,
"ESO QC ACQ FIELD%i SCALE", tel+1);
2505 double sep = sqrt((ySC-yFT)*(ySC-yFT)+(xSC-xFT)*(xSC-xFT));
2507 double pscale = scale;
2508 if (sts_mode !=
DUAL_STS) pscale = sep ? rho_in/sep : scale;
2513 cpl_propertylist_set_comment (o_header, qc_name,
2514 "[mas/pixel] plate-scale in the "
2530 sprintf (qc_name,
"ESO QC ACQ FIELD%i SC_FIBER_DX", tel+1);
2533 qc_val = (xSC-xFT) + sobj_offx_cam/scale - fiber_ft_sc_x - calib_dx[tel];
2537 cpl_propertylist_set_comment (o_header, qc_name,
2538 "[pixel] dx from SC fiber to "
2541 sprintf (qc_name,
"ESO QC ACQ FIELD%i SC_FIBER_DY", tel+1);
2544 qc_val = (ySC-yFT) + sobj_offy_cam/scale - fiber_ft_sc_y - calib_dy[tel];
2548 cpl_propertylist_set_comment (o_header, qc_name,
2549 "[pixel] dx from SC fiber to "
2557 double max_on_average, strehl_on_average;
2567 if (cpl_error_get_code() != CPL_ERROR_NONE ) {
2568 cpl_msg_info (cpl_func,
"WARNING Filling STREHL due to NaN");
2570 strehl_on_average = 0.0;
2576 sprintf (qc_name,
"ESO QC ACQ FIELD%i STREHL", tel+1);
2577 cpl_msg_info (cpl_func,
"%s = %f", qc_name, strehl_on_average);
2579 cpl_propertylist_set_comment (o_header, qc_name,
"Average Strehl from stacked AcqCam images");
2591 if (cpl_error_get_code() != CPL_ERROR_NONE ) {
2592 cpl_msg_info (cpl_func,
"WARNING Filling STREHL SC due to NaN");
2594 strehl_on_average = 0.0;
2598 sprintf (qc_name,
"ESO QC ACQ FIELD%i STREHLSC", tel+1);
2599 cpl_msg_info (cpl_func,
"%s = %f", qc_name, strehl_on_average);
2601 cpl_propertylist_set_comment (o_header, qc_name,
"Average Strehl from stacked AcqCam images");
2608 for (cpl_size row = 0; row < nrow; row++) {
2609 if (row %10 == 0 || row == (nrow-1))
2610 cpl_msg_info_overwritable (cpl_func,
"Fit image %lld over %lld", row+1, nrow);
2613 cpl_image * img = cpl_imagelist_get (acqcam_imglist, row);
2619 double xsc = xSC, ysc = ySC, exsc=0., eysc=0.;
2623 if (xsc != 0.) xsc += sx - 1 - nsx*tel;
2624 if (ysc != 0.) ysc += sy - 1;
2625 cpl_table_set (acqcam_table,
"FIELD_SC_X", row*
ntel+tel, xsc);
2626 cpl_table_set (acqcam_table,
"FIELD_SC_Y", row*
ntel+tel, ysc);
2627 cpl_table_set (acqcam_table,
"FIELD_SC_XERR", row*
ntel+tel, exsc);
2628 cpl_table_set (acqcam_table,
"FIELD_SC_YERR", row*
ntel+tel, eysc);
2634 double xft = xFT, yft = yFT, exft=0., eyft=0.;
2639 if (xft != 0.) xft += sx - 1 - nsx*tel;
2640 if (yft != 0.) yft += sy - 1;
2647 cpl_table_set (acqcam_table,
"FIELD_FT_X", row*
ntel+tel, xft);
2648 cpl_table_set (acqcam_table,
"FIELD_FT_Y", row*
ntel+tel, yft);
2649 cpl_table_set (acqcam_table,
"FIELD_FT_XERR", row*
ntel+tel, exft);
2650 cpl_table_set (acqcam_table,
"FIELD_FT_YERR", row*
ntel+tel, eyft);
2656 double ft_sc_x = xsc - xft;
2657 double ft_sc_y = ysc - yft;
2658 double eft_sc_x = sqrt(exsc*exsc+exft*exft);
2659 double eft_sc_y = sqrt(eysc*eysc+eyft*eyft);
2660 double sep = sqrt(ft_sc_x*ft_sc_x+ft_sc_y*ft_sc_y);
2661 double pscale = scale;
2662 if (sts_mode !=
DUAL_STS) pscale = sep ? rho_in/sep : 0.;
2665 escale = rho_in/(sep*sep*sep)*
2666 (ft_sc_x*eft_sc_x+ft_sc_y*eft_sc_y) ;
2668 cpl_table_set (acqcam_table,
"FIELD_SCALE", row*
ntel+tel, pscale);
2669 cpl_table_set (acqcam_table,
"FIELD_SCALEERR", row*
ntel+tel, escale);
2680 double corrx=0, corry=0., ecorrx=0., ecorry=0.;
2682 corrx = ft_sc_x + sobj_offx_cam/pscale - fiber_ft_sc_x - calib_dx[tel];
2683 corry = ft_sc_y + sobj_offy_cam/pscale - fiber_ft_sc_y - calib_dy[tel];
2684 double tmp = escale/(pscale*pscale);
2686 ecorrx = sqrt(eft_sc_x*eft_sc_x + eft_sc_y*eft_sc_y + sobj_offx_cam*sobj_offx_cam*tmp);
2687 ecorry = sqrt(eft_sc_x*eft_sc_x + eft_sc_y*eft_sc_y + sobj_offy_cam*sobj_offy_cam*tmp);
2689 cpl_table_set (acqcam_table,
"FIELD_FIBER_DX", row*
ntel+tel, corrx);
2690 cpl_table_set (acqcam_table,
"FIELD_FIBER_DY", row*
ntel+tel, corry);
2691 cpl_table_set (acqcam_table,
"FIELD_FIBER_DXERR", row*
ntel+tel, ecorrx);
2692 cpl_table_set (acqcam_table,
"FIELD_FIBER_DYERR", row*
ntel+tel, ecorry);
2697 double max_on_frame;
2699 cpl_table_set (acqcam_table,
"FIELD_STREHL", row*
ntel+tel, strehl_on_average*(max_on_frame/max_on_average) );
2705 sprintf (qc_name,
"ESO QC ACQ FIELD%i SC_X STD", tel+1);
2707 cpl_propertylist_set_comment (o_header, qc_name,
"[pix] Std of field position of SC");
2710 sprintf (qc_name,
"ESO QC ACQ FIELD%i SC_Y STD", tel+1);
2712 cpl_propertylist_set_comment (o_header, qc_name,
"[pix] Std of field position of SC");
2715 sprintf (qc_name,
"ESO QC ACQ FIELD%i FT_X STD", tel+1);
2717 cpl_propertylist_set_comment (o_header, qc_name,
"[pix] Std of field position of FT");
2720 sprintf (qc_name,
"ESO QC ACQ FIELD%i FT_Y STD", tel+1);
2722 cpl_propertylist_set_comment (o_header, qc_name,
"[pix] Std of field position of FT");
2725 sprintf (qc_name,
"ESO QC ACQ FIELD%i STREHL STD", tel+1);
2727 cpl_propertylist_set_comment (o_header, qc_name,
"Std of FT strehl");
2732 return CPL_ERROR_NONE;
2761 cpl_ensure_code (output_data, CPL_ERROR_NULL_INPUT);
2762 cpl_ensure_code (input_data, CPL_ERROR_NULL_INPUT);
2767 return CPL_ERROR_NONE;
2771 cpl_propertylist *
header, * o_header;
2778 return CPL_ERROR_NONE;
2781 cpl_imagelist * acqcam_imglist;
2782 cpl_imagelist * acqcam_imglist_v2;
2789 cpl_size nrow = cpl_imagelist_get_size (acqcam_imglist);
2791 cpl_table * acqcam_table;
2792 acqcam_table = cpl_table_new (nrow *
ntel);
2795 cpl_table_new_column (acqcam_table,
"TIME", CPL_TYPE_INT);
2796 cpl_table_set_column_unit (acqcam_table,
"TIME",
"us");
2800 for (cpl_size row = 0; row < nrow; row++) {
2802 for (
int tel = 0; tel <
ntel; tel ++)
2803 cpl_table_set (acqcam_table,
"TIME", row*
ntel+tel, time);
2807 cpl_image * mean_img = cpl_imagelist_collapse_create (acqcam_imglist);
2808 cpl_image * mean_subtracted_img = NULL;
2812 cpl_image_subtract(mean_subtracted_img, mean_img);
2813 cpl_image_multiply_scalar(mean_subtracted_img, -1.0);
2814 }
else if (dark_data) {
2816 cpl_msg_warning(cpl_func,
"No SKY, using DARK for acquisition field subtraction");
2817 cpl_image_subtract(mean_subtracted_img, mean_img);
2818 cpl_image_multiply_scalar(mean_subtracted_img, -1.0);
2820 cpl_msg_warning(cpl_func,
"No SKY or DARK, skipping acquisition field subtraction");
2821 mean_subtracted_img = mean_img;
2826 acqcam_table, o_header, static_param_data);
2827 CPLCHECK_MSG (
"Cannot reduce acquisition field images");
2831 acqcam_table, o_header, static_param_data);
2835 cpl_propertylist * plist_acq_cam = cpl_propertylist_new ();
2836 cpl_propertylist_update_string (plist_acq_cam,
"INSNAME",
INSNAME_ACQ);
2844 return CPL_ERROR_NONE;
2871 cpl_msg_debug (cpl_func,
"ESO LENS Llambda is : %e", Llambda);
2877 cpl_msg_debug (cpl_func,
"ESO LENS D_pixel is : %e", D_pixel);
2883 cpl_msg_debug (cpl_func,
"ESO LENS D_lenslet is : %e", D_lenslet);
2887 longDef = 8 * (f_PT / D_lenslet) * (f_PT / D_lenslet) * 3.5 * D_pixel *
2888 D_beam / (f_PT * D_lenslet) * Llambda / CPL_MATH_2PI * PositionPixels;
2890 return f_lens * f_lens * longDef / (f_PT + longDef) / f_PT * (D_AT / D_lenslet);
2910 cpl_ensure_code (ia, CPL_ERROR_NULL_INPUT);
2911 cpl_ensure_code (ib, CPL_ERROR_NULL_INPUT);
2912 cpl_ensure_code (xd, CPL_ERROR_NULL_INPUT);
2913 cpl_ensure_code (yd, CPL_ERROR_NULL_INPUT);
2915 cpl_error_code error = CPL_ERROR_NONE;
2916 cpl_type type = cpl_image_get_type(ia);
2917 cpl_size nx = cpl_image_get_size_x(ia);
2918 cpl_size ny = cpl_image_get_size_y(ia);
2920 cpl_image * ic = cpl_image_new(nx, ny, type);
2921 cpl_image * fa = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX);
2922 cpl_image * fb = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX);
2923 cpl_image * fc = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX);
2925 cpl_imagelist * iab = cpl_imagelist_new();
2926 cpl_imagelist * fab = cpl_imagelist_new();
2929 error = cpl_imagelist_set(iab, ia, 0);
2932 error = cpl_imagelist_set(iab, ib, 1);
2935 error = cpl_imagelist_set(fab, fa, 0);
2938 error = cpl_imagelist_set(fab, fb, 1);
2941 error = cpl_fft_imagelist(fab, iab, CPL_FFT_FORWARD);
2944 error = cpl_image_conjugate(fc, fb);
2950 error = cpl_fft_image(ic, fc, CPL_FFT_BACKWARD | CPL_FFT_NOSCALE);
2953 error = cpl_image_get_maxpos(ic, xd, yd);
2956 if (*xd > nx/2) *xd = *xd - nx;
2957 if (*yd > ny/2) *yd = *yd - ny;
2968 FREE (cpl_imagelist_unwrap, iab);
2969 FREE (cpl_imagelist_unwrap, fab);
#define GRAVI_PRIMARY_HDR_EXT
typedefCPL_BEGIN_DECLS struct _gravi_data_ gravi_data
#define gravi_data_get_header(data)
#define gravi_data_get_img(data, ext)
cpl_image_multiply(flat_profiled, profile_crop)
cpl_msg_debug(cpl_func, "Spectra has <50 pixels -> don't flat")
cpl_propertylist * header
cpl_msg_info(cpl_func, "Compute WAVE_SCAN for %s", GRAVI_TYPE(type_data))
cpl_propertylist_update_double(header, "ESO QC MINWAVE SC", cpl_propertylist_get_double(plist, "ESO QC MINWAVE SC"))
cpl_image_delete(flat_profiled)
#define GRAVI_OI_VIS_ACQ_EXT
#define GRAVI_IMAGING_DATA_ACQ_EXT
#define gravi_msg_function_exit(flag)
#define FREE(function, variable)
#define gravi_msg_function_start(flag)
#define CPLCHECK_MSG(msg)
#define GRAVI_MATH_RAD_MAS
cpl_error_code gravi_image_fft_correlate(cpl_image *ia, cpl_image *ib, cpl_size *xd, cpl_size *yd)
Correlate two images using FFT.
cpl_image * gravi_image_extract(cpl_image *image_in, cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury)
extract sub window of image (similar to cpl_image_extract)
#define GRAVI_SPOT_NSEARCH
int gravi_acqcam_xy_diode(const double v[], double *xd, double *yd)
cpl_error_code gravi_acqcam_set_pupil_table_v2(cpl_table *acqcam_table, cpl_propertylist *header, cpl_propertylist *o_header, cpl_array *good_frames, cpl_vector *scale_vector, cpl_array *bad_frames_short, cpl_bivector **diode_pos_offset, cpl_vector *focus_value, gravi_data *static_param_data)
store the pupil offset in the table, and create QC parameters.
#define GRAVI_SPOT_SWINDOW
cpl_error_code gravi_reduce_acqcam(gravi_data *output_data, gravi_data *input_data, gravi_data *sky_data, gravi_data *dark_data, gravi_data *static_param_data)
Reduce the ACQ camera images.
cpl_error_code gravi_acq_measure_max(cpl_image *img, double x, double y, double size, double *img_max)
cpl_error_code gravi_acq_fit_gaussian(cpl_image *img, double *x, double *y, double *ex, double *ey, cpl_size size)
Fit a Gaussian into an image, and mark the position.
#define GRAVI_SPOT_NFOCUS
cpl_error_code gravi_acqcam_field(cpl_image *mean_img, cpl_imagelist *acqcam_imglist, cpl_propertylist *header, cpl_table *acqcam_table, cpl_propertylist *o_header, gravi_data *static_param_data)
Reduce the images of field from ACQ.
cpl_error_code gravi_acqcam_get_diode_ref_v2(cpl_propertylist *header, cpl_array *good_frames, cpl_vector *scale_vector, cpl_bivector **diode_pos_telescope, int nrow_on)
Get the position of the telescope diodes in pixels.
#define CHECK_BIT(var, pos)
const int * GRAVI_LVMQ_FREE
cpl_error_code gravi_acqcam_select_good_frames_v2(cpl_imagelist *acqcam_imglist, cpl_imagelist *pupilImage_onFrames, cpl_array *good_frames)
select pupil frames with pupil beacon on. Clean pupil frames by substraction of images with pupil bea...
cpl_error_code gravi_acqcam_get_pup_ref_v2(cpl_propertylist *header, cpl_bivector *diode_pos_subwindow)
Get the reference pixels for the pupil guiding on the acquisition camera.
cpl_error_code gravi_acqcam_spot_imprint_v2(cpl_image *mean_img, cpl_bivector **diode_pos_offset, cpl_bivector **diode_pos_theoretical, int ury)
imprint zeros at the postion of the detected pupil spots
cpl_error_code gravi_acqcam_perform_shiftandadd_v2(cpl_imagelist *pupilImage_onFrames, cpl_imagelist **pupilImage_shiftandadd, cpl_array *good_frames, cpl_vector *focus_value, cpl_bivector **diode_pos_theoretical, cpl_bivector **diode_pos_offset, cpl_size nrow_on)
perform shift and add of the pupil image according to the theoretical positions
double gravi_acqcam_z2meter(double PositionPixels, gravi_data *static_param_data)
Convert z_shift from [pixel] to [meters] Formula extracted from gvacqPupilTracker....
cpl_error_code gravi_acqcam_get_diode_theoretical_v2(cpl_bivector *diode_pos_subwindow, cpl_bivector **diode_pos_telescope, cpl_bivector **diode_pos_theoretical, cpl_size nrow_on, int ury)
Get the position of the telescope diodes in pixels.
cpl_error_code gravi_preproc_acqcam(gravi_data *output_data, gravi_data *input_data, gravi_data *bad_map)
Preprocess the ACQ images: correct bad pixels, clean from pupil background via blinking,...
cpl_error_code gravi_acqcam_clean_pupil_v2(cpl_imagelist *acqcam_imglist, cpl_imagelist *pupilImage_filtered, const cpl_size ury)
Cleaning pupil images by cross-correlation with gaussian function.
cpl_error_code gravi_acq_measure_strehl(cpl_image *img, double x, double y, double pscale, double *SR, cpl_propertylist *header)
measure Strehl Ratio of the source at the given location
cpl_error_code gravi_acqcam_pupil(cpl_image *mean_img, cpl_imagelist *acqcam_imglist, cpl_propertylist *header, cpl_table *acqcam_table, cpl_propertylist *o_header, gravi_data *static_param_data)
cpl_error_code gravi_acqcam_get_pupil_offset_v2(cpl_imagelist **pupilImage_shiftandadd, cpl_array *good_frames, cpl_bivector **diode_pos_offset, cpl_propertylist *o_header, cpl_size nrow_on)
on the images shift and added, find maximum and perform gaussian fit
double gravi_acqcam_defocus_scaling(int focus)
gives focus value as in a list of value
cpl_error_code gravi_acqcam_pupil_v2(cpl_image *mean_img, cpl_imagelist *acqcam_imglist, cpl_propertylist *header, cpl_table *acqcam_table, cpl_propertylist *o_header, gravi_data *static_param_data)
Reduce the images of pupil from ACQ V2.0.
cpl_error_code gravi_table_new_column(cpl_table *table, const char *name, const char *unit, cpl_type type)
cpl_error_code gravi_image_replace_window(cpl_image *img1, const cpl_image *img2, cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury, cpl_size llx2, cpl_size lly2)
double gravi_table_get_column_std(cpl_table *table, const char *name, int base, int nbase)
cpl_error_code gravi_data_add_cube(gravi_data *self, cpl_propertylist *plist, const char *extname, cpl_imagelist *imglist)
Add an IMAGE (imagelist) extension in gravi_data.
cpl_propertylist * gravi_data_get_plist(gravi_data *self, const char *extname)
Get the propertylist from EXTNAME.
cpl_error_code gravi_data_add_table(gravi_data *self, cpl_propertylist *plist, const char *extname, cpl_table *table)
Add a BINTABLE extension in gravi_data.
cpl_error_code gravi_data_add_img(gravi_data *self, cpl_propertylist *plist, const char *extname, cpl_image *image)
Add an IMAGE (single image) extension in gravi_data.
cpl_imagelist * gravi_data_get_cube(gravi_data *self, const char *extname)
Return a pointer on an IMAGE extension by its EXTNAME.
int gravi_data_has_extension(gravi_data *raw_calib, const char *ext_name)
Check if data has extension with given EXTNAME.
cpl_table * gravi_data_get_table(gravi_data *self, const char *extname)
Return a pointer on a table extension by its EXTNAME.
double gravi_pfits_get_zenithangle_beamb_acqcam(const cpl_propertylist *plist, int tel, int n, int nrow)
double gravi_pfits_get_sobj_y(const cpl_propertylist *plist)
int gravi_pfits_get_mode(const cpl_propertylist *plist)
double gravi_pfits_get_northangle_acqcam(const cpl_propertylist *plist, int tel)
int gravi_pfits_get_axis(const cpl_propertylist *plist)
const char * gravi_pfits_get_feed(const cpl_propertylist *plist)
double gravi_pfits_get_sobj_x(const cpl_propertylist *plist)
double gravi_pfits_get_time_acqcam(const cpl_propertylist *header, cpl_size row)
Time of the middle of the ACQCAM exposure row in [us], counted from PRC.ACQ.START.
double gravi_pfits_get_ptfc_acqcam(const cpl_propertylist *plist, int spot)
cpl_error_code gravi_msg_warning(const char *component, const char *msg)
const char * gravi_conf_get_telname(int gravi_beam, cpl_propertylist *header)