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,
640cpl_ensure_code(acqcam_imglist, CPL_ERROR_NULL_INPUT);
641cpl_ensure_code(
header, CPL_ERROR_NULL_INPUT);
642cpl_ensure_code(acqcam_table, CPL_ERROR_NULL_INPUT);
643cpl_ensure_code(o_header, CPL_ERROR_NULL_INPUT);
645cpl_size nx = cpl_image_get_size_x (cpl_imagelist_get (acqcam_imglist, 0));
646cpl_size ny = cpl_image_get_size_y (cpl_imagelist_get (acqcam_imglist, 0));
653const cpl_size ury = (ny>1100) ? 1200 : 745;
659 cpl_imagelist * pupilImage_filtered = cpl_imagelist_new ();
668 cpl_array * good_frames= cpl_array_new(cpl_imagelist_get_size(pupilImage_filtered),CPL_TYPE_INT);
669 cpl_imagelist * pupilImage_onFrames = cpl_imagelist_new ();
681 cpl_size nrow = cpl_imagelist_get_size(pupilImage_filtered);
682 cpl_size nrow_on = cpl_imagelist_get_size(pupilImage_onFrames);
684 if ((nrow_on<1)||(nrow<4))
687 cpl_array_fill_window_int (good_frames, 0, nrow_on, 0);
689 CPLCHECK_MSG(
"Cannot stor pupil offset values in OI_ACQ table");
691 cpl_imagelist_delete(pupilImage_onFrames);
692 cpl_imagelist_delete(pupilImage_filtered);
693 cpl_array_delete(good_frames);
694 cpl_msg_warning (cpl_func,
"Cannot reduce the %lli frames (not enough frames)",nrow);
696 return CPL_ERROR_NONE;
701 cpl_array * bad_frames_short= cpl_array_new(nrow_on,CPL_TYPE_INT);
702 cpl_array_fill_window_int (bad_frames_short, 0, nrow_on, 0);
704 cpl_bivector ** diode_pos_telescope = cpl_malloc (nrow_on *
sizeof(cpl_bivector *)) ;
705 cpl_bivector ** diode_pos_theoretical = cpl_malloc (nrow_on *
sizeof(cpl_bivector *)) ;
706 cpl_bivector ** diode_pos_offset = cpl_malloc (nrow_on *
sizeof(cpl_bivector *)) ;
707 cpl_imagelist ** pupilImage_shiftandadd = cpl_malloc (
GRAVI_SPOT_NTEL *
sizeof(cpl_imagelist *));
709 for (
int n = 0 ; n < nrow_on; n++)
717 pupilImage_shiftandadd[tel] = cpl_imagelist_new();
737 diode_pos_theoretical, nrow_on, ury);
738 CPLCHECK_MSG(
"Cannot get theoretical position of beacons");
745 diode_pos_offset, nrow_on);
746 CPLCHECK_MSG(
"Cannot find correct focus to shift and add pupil images");
759 CPLCHECK_MSG(
"Cannot stor pupil offset values in OI_ACQ table");
765 cpl_image * pupilImage_onFrames_collapse=cpl_imagelist_collapse_create (pupilImage_onFrames);
766 cpl_image * pupilImage_onFrames_1frame=cpl_imagelist_get (pupilImage_onFrames,0);
775 if (pupilImage_shiftandadd[tel] != NULL)
776 cpl_imagelist_delete( pupilImage_shiftandadd[tel]);
778FREE (cpl_free, pupilImage_shiftandadd);
781 for (
int n = 0 ; n < nrow_on; n++)
783 cpl_bivector_delete( diode_pos_telescope[n]);
784 cpl_bivector_delete( diode_pos_theoretical[n]);
785 cpl_bivector_delete( diode_pos_offset[n]);
787 FREE (cpl_free, diode_pos_telescope);
788 FREE (cpl_free, diode_pos_theoretical);
789 FREE (cpl_free, diode_pos_offset);
791 cpl_bivector_delete( diode_pos_subwindow);
793 cpl_imagelist_delete(pupilImage_onFrames);
794 cpl_imagelist_delete(pupilImage_filtered);
795 cpl_array_delete(good_frames);
796 cpl_array_delete(bad_frames_short);
797 cpl_vector_delete(scale_vector);
798 cpl_vector_delete(focus_value);
802return CPL_ERROR_NONE;
822 cpl_ensure_code(acqcam_imglist, CPL_ERROR_NULL_INPUT);
823 cpl_ensure_code(pupilImage_filtered, CPL_ERROR_NULL_INPUT);
824 cpl_ensure_code(ury, CPL_ERROR_NULL_INPUT);
827 cpl_size nrow = cpl_imagelist_get_size(acqcam_imglist);
829 cpl_size nx = cpl_image_get_size_x (cpl_imagelist_get (acqcam_imglist, 0));
830 cpl_size ny = cpl_image_get_size_y (cpl_imagelist_get (acqcam_imglist, 0));
832 cpl_imagelist * pupilImage = cpl_imagelist_new ();
834 for (cpl_size n = 0; n < nrow ; n++)
836 cpl_image * small_img_tmp = cpl_imagelist_get (acqcam_imglist, n);
837 cpl_image * small_img = cpl_image_extract( small_img_tmp, 1, ury, nx, ny);
838 cpl_imagelist_set(pupilImage, small_img,n);
841 nx=cpl_image_get_size_x (cpl_imagelist_get (pupilImage, 0));
842 ny=cpl_image_get_size_y (cpl_imagelist_get (pupilImage, 0));
844 cpl_image* pupilImageBackground = cpl_imagelist_collapse_minmax_create (pupilImage,(cpl_size)(nrow/8),(cpl_size)(5*nrow/8));
846 cpl_imagelist_subtract_image (pupilImage,pupilImageBackground);
850 cpl_matrix * kernel1 = cpl_matrix_new (Npref,Npref);
851 cpl_matrix * kernel2 = cpl_matrix_new (Npref,Npref);
852 for (cpl_size x =0;x< Npref; x++)
853 for (cpl_size y =0;y< Npref; y++)
855 double radius_square=(x-(Npref-1)/2)*(x-(Npref-1)/2)+(y-(Npref-1)/2)*(y-(Npref-1)/2);
856 cpl_matrix_set(kernel1,x,y,exp(- radius_square /30));
857 cpl_matrix_set(kernel2,x,y,exp(- radius_square /40));
860 cpl_matrix_divide_scalar (kernel1, cpl_matrix_get_mean (kernel1));
861 cpl_matrix_divide_scalar (kernel2, cpl_matrix_get_mean (kernel2));
862 cpl_matrix_subtract (kernel1,kernel2);
863 cpl_matrix_divide_scalar (kernel1, cpl_matrix_get_stdev (kernel1));
864 cpl_matrix_divide_scalar (kernel1, cpl_matrix_get_max (kernel1));
869 cpl_size fft_nx = nx + Npref - 1;
870 cpl_size fft_ny = ny + Npref - 1;
871 cpl_size half_kernel_w = (Npref - 1) / 2;
874 cpl_matrix_resize(kernel1, 0, ny-1, 0, nx-1);
875 cpl_image *kernel_image = cpl_image_wrap_double(fft_nx, fft_ny, cpl_matrix_get_data(kernel1));
878 cpl_image *kernel_fft = cpl_image_new(fft_nx, fft_ny, CPL_TYPE_DOUBLE_COMPLEX);
879 cpl_fft_image(kernel_fft, kernel_image, CPL_FFT_FORWARD);
882 cpl_imagelist *pupilImage_padded = cpl_imagelist_new();
883 for (cpl_size n = 0; n < nrow ; n++)
885 const cpl_image *small_img_tmp = cpl_imagelist_get_const(pupilImage, n);
886 cpl_image *padded_img_tmp = cpl_image_new(fft_nx, fft_ny, CPL_TYPE_DOUBLE);
887 cpl_image_copy(padded_img_tmp, small_img_tmp, 1, 1);
888 cpl_imagelist_set(pupilImage_padded, padded_img_tmp, n);
892 cpl_imagelist *pupilImage_fft = cpl_imagelist_new();
893 for (cpl_size n = 0; n < nrow; n++)
894 cpl_imagelist_set(pupilImage_fft, cpl_image_new(fft_nx, fft_ny, CPL_TYPE_DOUBLE_COMPLEX), n);
895 cpl_fft_imagelist(pupilImage_fft, pupilImage_padded, CPL_FFT_FORWARD | CPL_FFT_FIND_MEASURE);
898 cpl_imagelist_multiply_image(pupilImage_fft, kernel_fft);
901 cpl_imagelist *pupilImage_filtered_padded = cpl_imagelist_new();
902 for (cpl_size n = 0; n < nrow; n++)
903 cpl_imagelist_set(pupilImage_filtered_padded, cpl_image_new(fft_nx, fft_ny, CPL_TYPE_DOUBLE), n);
904 cpl_fft_imagelist(pupilImage_filtered_padded, pupilImage_fft, CPL_FFT_BACKWARD | CPL_FFT_FIND_MEASURE);
907 for (cpl_size n = 0; n < nrow; n++) {
908 const cpl_image *pad_filt_img_tmp = cpl_imagelist_get_const(pupilImage_filtered_padded, n);
909 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);
910 cpl_imagelist_set(pupilImage_filtered, trimmed_img, n);
913 cpl_matrix_delete(kernel1);
914 cpl_matrix_delete(kernel2);
916 cpl_image_unwrap(kernel_image);
920 cpl_imagelist_delete(pupilImage);
921 cpl_imagelist_delete(pupilImage_fft);
922 cpl_imagelist_delete(pupilImage_padded);
923 cpl_imagelist_delete(pupilImage_filtered_padded);
927 return CPL_ERROR_NONE;
952 cpl_ensure_code(pupilImage_filtered, CPL_ERROR_NULL_INPUT);
953 cpl_ensure_code(good_frames, CPL_ERROR_NULL_INPUT);
956 cpl_size nrow = cpl_imagelist_get_size(pupilImage_filtered);
957 cpl_size nx = cpl_image_get_size_x (cpl_imagelist_get (pupilImage_filtered, 0));
958 cpl_size ny = cpl_image_get_size_y (cpl_imagelist_get (pupilImage_filtered, 0));
960 cpl_vector * pupil_max = cpl_vector_new(4);
961 cpl_vector * pupil_mediam = cpl_vector_new(nrow);
962 cpl_array * back_frames= cpl_array_new(nrow,CPL_TYPE_INT);
964 for (cpl_size n = 0; n < nrow; n++)
967 cpl_image * image = cpl_imagelist_get (pupilImage_filtered,n);
968 cpl_vector_set(pupil_max, 0, cpl_image_get_max_window (image, 1, 1, 250, ny));
969 cpl_vector_set(pupil_max, 1, cpl_image_get_max_window (image, 251, 1, 500, ny));
970 cpl_vector_set(pupil_max, 2, cpl_image_get_max_window (image, 501, 1, 750, ny));
971 cpl_vector_set(pupil_max, 3, cpl_image_get_max_window (image, 751, 1, nx, ny));
972 cpl_vector_set(pupil_mediam, n, cpl_vector_get_median (pupil_max));
980 cpl_vector * pupil_mediam_sort = cpl_vector_duplicate (pupil_mediam);
981 cpl_vector_sort (pupil_mediam_sort,CPL_SORT_ASCENDING);
982 cpl_vector * pupil_median_down = cpl_vector_extract (pupil_mediam_sort, 0, (nrow-1)/2, 1);
983 cpl_vector * pupil_median_up = cpl_vector_extract (pupil_mediam_sort, nrow/2, nrow-1, 1);
984 double threshold_up = cpl_vector_get_median(pupil_median_up);
985 double threshold_down = cpl_vector_get_median(pupil_median_down);
986 double threshold=(threshold_up+threshold_down)/2.0;
988 CPLCHECK_MSG(
"Could not get median maximum of beacon flux ");
989 cpl_msg_info (cpl_func,
"Found threshold brightness level for beacon : %.5f ADU", threshold);
991 for (cpl_size n = 0; n < nrow; n++)
993 if (cpl_vector_get(pupil_mediam, n) >threshold *1.1)
994 cpl_array_set_int (good_frames,n,1);
996 cpl_array_set_int (good_frames,n,0);
997 if (cpl_vector_get(pupil_mediam, n) <threshold * 0.9)
998 cpl_array_set_int (back_frames,n,1);
1000 cpl_array_set_int (back_frames,n,0);
1003 cpl_size frames_background = 4;
1004 cpl_size n_goodFrames = 0;
1008 for (cpl_size n = 0; n < nrow; n++)
1009 if (cpl_array_get_int(good_frames,n,&nv) == 1)
1011 cpl_image * image = cpl_imagelist_get (pupilImage_filtered,n);
1014 cpl_size n_frames_background = 0;
1015 cpl_imagelist * pupilImage_offFrames = cpl_imagelist_new ();
1016 for (cpl_size b = 1; b < nrow; b++)
1019 if ((cpl_array_get_int(back_frames,n+b,&nv) == 1)&(n_frames_background<frames_background))
1021 cpl_image * image_background = cpl_imagelist_get (pupilImage_filtered,n+b);
1022 cpl_image * image_background_copy = cpl_image_duplicate (image_background);
1023 cpl_imagelist_set(pupilImage_offFrames, image_background_copy, n_frames_background);
1024 n_frames_background = n_frames_background + 1;
1027 if ((cpl_array_get_int(back_frames,n-b,&nv) == 1)&(n_frames_background<frames_background))
1029 cpl_image * image_background = cpl_imagelist_get (pupilImage_filtered,n-b);
1030 cpl_image * image_background_copy = cpl_image_duplicate (image_background);
1031 cpl_imagelist_set(pupilImage_offFrames, image_background_copy, n_frames_background);
1032 n_frames_background = n_frames_background + 1;
1036 cpl_image * image_background_mean = cpl_imagelist_collapse_create (pupilImage_offFrames);
1037 cpl_image * image_background_subtracted = cpl_image_subtract_create (image, image_background_mean);
1038 cpl_imagelist_set(pupilImage_onFrames, image_background_subtracted, n_goodFrames);
1041 cpl_imagelist_delete(pupilImage_offFrames);
1045 cpl_msg_info(cpl_func,
"Found %lli frames with pupil beacon ON (over %lli frames)",n_goodFrames, nrow);
1047 cpl_vector_delete(pupil_max);
1048 cpl_vector_delete(pupil_mediam);
1049 cpl_vector_delete(pupil_median_up);
1050 cpl_vector_delete(pupil_median_down);
1051 cpl_vector_delete(pupil_mediam_sort);
1052 cpl_array_delete(back_frames);
1056 return CPL_ERROR_NONE;
1076 cpl_ensure_code (
header, CPL_ERROR_NULL_INPUT);
1077 cpl_ensure_code (diode_pos_subwindow, CPL_ERROR_NULL_INPUT);
1079 cpl_size nsx = 0, nsy = 0, sx = 0, sy = 0;
1081 cpl_vector * x_pos_subwindow = cpl_bivector_get_x (diode_pos_subwindow);
1082 cpl_vector * y_pos_subwindow = cpl_bivector_get_y (diode_pos_subwindow);
1089 if ( cpl_propertylist_has (
header,
"ESO DET1 FRAMES NX") ) {
1092 nsx = cpl_propertylist_get_int (
header,
"ESO DET1 FRAMES NX");
1094 sx = cpl_propertylist_get_int (
header, name);
1096 nsy = cpl_propertylist_get_int (
header,
"ESO DET1 FRAMES NY");
1098 sy = cpl_propertylist_get_int (
header, name);
1103 cpl_msg_info (cpl_func,
"sub-window pupil %i sx= %lld sy = %lld", tel, sx, sy);
1112 cpl_vector_set( x_pos_subwindow, lens*
GRAVI_SPOT_NTEL+tel , xv - (sx - tel*nsx) - 1);
1113 cpl_vector_set( y_pos_subwindow, lens*
GRAVI_SPOT_NTEL+tel , yv - (sy - 3*nsy) - 1);
1121 return CPL_ERROR_NONE;
1144 cpl_array * good_frames,
1145 cpl_vector * scale_vector,
1146 cpl_bivector ** diode_pos_telescope,
1150 cpl_ensure_code (
header, CPL_ERROR_NULL_INPUT);
1151 cpl_ensure_code (good_frames, CPL_ERROR_NULL_INPUT);
1155 double parang1 = cpl_propertylist_get_double(
header,
"ESO ISS PARANG START");
1156 double parang2 = cpl_propertylist_get_double(
header,
"ESO ISS PARANG END");
1168 cpl_size nrow = cpl_array_get_size(good_frames);
1169 if (fabs(cpl_array_get_mean(good_frames)*nrow -nrow_on) > 1e-2)
1170 cpl_msg_error (cpl_func,
"Ratio of blinking frames different %f from %i",cpl_array_get_mean(good_frames)*nrow,nrow_on);
1179 if (!telname) cpl_msg_error (cpl_func,
"Cannot read the telescope name");
1180 cpl_ensure_code (telname, CPL_ERROR_ILLEGAL_INPUT);
1186 if (telname[0] ==
'U') {
1190 if ( tel == 0 ) scale = 16.83;
1191 if ( tel == 1 ) scale = 17.42;
1192 if ( tel == 2 ) scale = 16.85;
1193 if ( tel == 3 ) scale = 17.41;
1199 }
else if (telname[0] ==
'A') {
1207 return cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
1208 "Cannot get telescope name");
1210 cpl_vector_set(scale_vector,tel,scale);
1217 double northangle = 0;
1218 double zenithangle = 0;
1226 for (cpl_size n =0; n < nrow; n++)
1229 if (cpl_array_get_int(good_frames,n,&nv) ==1)
1231 double padif = parang2 - parang1;
1236 double parang= parang1 + padif*n/(nrow-1);
1243 angle = zenithangle - 45.;
1245 angle = northangle + parang + 45.;
1248 if (angle < 0) angle += 180;
1249 if (angle > 180) angle -= 180;
1250 double cang = cos(angle * CPL_MATH_RAD_DEG) * scale;
1251 double sang = sin(angle * CPL_MATH_RAD_DEG) * scale;
1255 cpl_vector * x_pos_telescope = cpl_bivector_get_x (diode_pos_telescope[n_on]);
1256 cpl_vector * y_pos_telescope = cpl_bivector_get_y (diode_pos_telescope[n_on]);
1258 cpl_vector_set(x_pos_telescope, 0*
GRAVI_SPOT_NTEL+tel, -cang * dx + sang * dy);
1259 cpl_vector_set(x_pos_telescope, 1*
GRAVI_SPOT_NTEL+tel, -cang * dx - sang * dy);
1260 cpl_vector_set(x_pos_telescope, 2*
GRAVI_SPOT_NTEL+tel, cang * dx - sang * dy);
1261 cpl_vector_set(x_pos_telescope, 3*
GRAVI_SPOT_NTEL+tel, cang * dx + sang * dy);
1263 cpl_vector_set(y_pos_telescope, 0*
GRAVI_SPOT_NTEL+tel, cang * dy + sang * dx);
1264 cpl_vector_set(y_pos_telescope, 1*
GRAVI_SPOT_NTEL+tel, -cang * dy + sang * dx);
1265 cpl_vector_set(y_pos_telescope, 2*
GRAVI_SPOT_NTEL+tel, -cang * dy - sang * dx);
1266 cpl_vector_set(y_pos_telescope, 3*
GRAVI_SPOT_NTEL+tel, cang * dy - sang * dx);
1272 cpl_msg_info (cpl_func,
"angle, parang %.2f, %.2f",angle,parang);
1273 cpl_msg_info (cpl_func,
"dx and dy %.2f, %.2f",cang,sang);
1281 CPLCHECK_MSG(
"Cannot determine diode position in telescope space");
1285 return CPL_ERROR_NONE;
1309 cpl_bivector ** diode_pos_telescope,
1310 cpl_bivector ** diode_pos_theoretical,
1311 cpl_size nrow_on,
int ury)
1315 cpl_ensure_code (diode_pos_subwindow, CPL_ERROR_NULL_INPUT);
1316 cpl_ensure_code (diode_pos_telescope, CPL_ERROR_NULL_INPUT);
1317 cpl_ensure_code (diode_pos_theoretical, CPL_ERROR_NULL_INPUT);
1319 cpl_vector * x_pos_subwindow = cpl_bivector_get_x (diode_pos_subwindow);
1320 cpl_vector * y_pos_subwindow = cpl_bivector_get_y (diode_pos_subwindow);
1324 double x_lenslet_mean=0.0;
1325 double y_lenslet_mean=0.0;
1332 cpl_msg_info (cpl_func,
"Reference pixel position for tel %d : X = %.2f, Y= %.2f", tel, x_lenslet_mean, y_lenslet_mean);
1337 double xlenslet=cpl_vector_get(x_pos_subwindow,lens*
GRAVI_SPOT_NTEL+tel)+
1339 double ylenslet=cpl_vector_get(y_pos_subwindow,lens*
GRAVI_SPOT_NTEL+tel)+
1343 for (cpl_size n_on = 0 ; n_on < nrow_on; n_on++)
1346 cpl_vector * x_pos_telescope = cpl_bivector_get_x (diode_pos_telescope[n_on]);
1347 cpl_vector * y_pos_telescope = cpl_bivector_get_y (diode_pos_telescope[n_on]);
1348 cpl_vector * x_pos_theoretical = cpl_bivector_get_x (diode_pos_theoretical[n_on]);
1349 cpl_vector * y_pos_theoretical = cpl_bivector_get_y (diode_pos_theoretical[n_on]);
1351 double x_theo = xlenslet + cpl_vector_get(x_pos_telescope,spot*
GRAVI_SPOT_NTEL+tel);
1352 double y_theo = ylenslet + cpl_vector_get(y_pos_telescope,spot*
GRAVI_SPOT_NTEL+tel)- ury +1;
1360CPLCHECK_MSG(
"Cannot compute the theoretical coordinates of spots");
1362return CPL_ERROR_NONE;
1383 cpl_ensure_code(mean_img, CPL_ERROR_NULL_INPUT);
1384 cpl_ensure_code(diode_pos_offset, CPL_ERROR_NULL_INPUT);
1385 cpl_ensure_code(diode_pos_theoretical, CPL_ERROR_NULL_INPUT);
1387 cpl_size nx = cpl_image_get_size_x (mean_img);
1388 cpl_size ny = cpl_image_get_size_y (mean_img);
1392 cpl_vector * x_pos_offset = cpl_bivector_get_x (diode_pos_offset[n_on]);
1393 cpl_vector * y_pos_offset = cpl_bivector_get_y (diode_pos_offset[n_on]);
1394 cpl_vector * x_pos_theoretical = cpl_bivector_get_x (diode_pos_theoretical[n_on]);
1395 cpl_vector * y_pos_theoretical = cpl_bivector_get_y (diode_pos_theoretical[n_on]);
1405 double x_off = cpl_vector_get(x_pos_offset,tel);
1406 double y_off = cpl_vector_get(y_pos_offset,tel)+ury;
1409 cpl_size xf = roundl(x_diode + x_off) + 1;
1410 cpl_size yf = roundl(y_diode + y_off) + 1;
1411 if (xf < 2 || xf > nx-2 || yf < 2 || yf > ny-2)
continue;
1412 cpl_image_set (mean_img, xf, yf, 0);
1413 cpl_image_set (mean_img, xf-1, yf, 0);
1414 cpl_image_set (mean_img, xf+1, yf, 0);
1415 cpl_image_set (mean_img, xf, yf+1, 0);
1416 cpl_image_set (mean_img, xf, yf-1, 0);
1417 CPLCHECK (
"Cannot imprint cross in image");
1420 CPLCHECK (
"Cannot imprint cross in image");
1422 return CPL_ERROR_NONE;
1461 cpl_vector * focus_value,
1462 cpl_bivector ** diode_pos_theoretical ,
1463 cpl_bivector ** diode_pos_offset, cpl_size nrow_on)
1467 cpl_ensure_code(pupilImage_onFrames, CPL_ERROR_NULL_INPUT);
1468 cpl_ensure_code(pupilImage_shiftandadd, CPL_ERROR_NULL_INPUT);
1469 cpl_ensure_code(good_frames, CPL_ERROR_NULL_INPUT);
1470 cpl_ensure_code(focus_value, CPL_ERROR_NULL_INPUT);
1471 cpl_ensure_code(diode_pos_theoretical, CPL_ERROR_NULL_INPUT);
1472 cpl_ensure_code(diode_pos_offset, CPL_ERROR_NULL_INPUT);
1473 cpl_ensure_code(nrow_on, CPL_ERROR_NULL_INPUT);
1475 if (cpl_imagelist_get_size(pupilImage_onFrames) != nrow_on)
1476 cpl_msg_error (cpl_func,
"Problem with number of blinking frames");
1483 cpl_imagelist * pupilImage_shifted= cpl_imagelist_new();
1484 cpl_size n_images = 0;
1485 for (cpl_size n = 0 ; n < nrow_on; n++)
1489 cpl_vector * x_pos_theoretical = cpl_bivector_get_x (diode_pos_theoretical[n]);
1490 cpl_vector * y_pos_theoretical = cpl_bivector_get_y (diode_pos_theoretical[n]);
1495 cpl_size x=(int) (x_theo + 0.5);
1496 cpl_size y=(int) (y_theo+ 0.5);
1497 cpl_image * verysmall_img_tmp = cpl_imagelist_get (pupilImage_onFrames, n);
1499 cpl_imagelist_set(pupilImage_shifted, verysmall_img, n_images);
1503 cpl_image * image_mean = cpl_imagelist_collapse_create (pupilImage_shifted);
1504 cpl_vector_set(focus_max, focus, cpl_image_get_max(image_mean));
1505 cpl_imagelist_delete(pupilImage_shifted);
1509 int focus_max_pos = cpl_vector_get_maxpos (focus_max);
1514 for (cpl_size n = 0 ; n < nrow_on; n++)
1516 cpl_vector * x_pos_theoretical = cpl_bivector_get_x (diode_pos_theoretical[n]);
1517 cpl_vector * y_pos_theoretical = cpl_bivector_get_y (diode_pos_theoretical[n]);
1518 cpl_imagelist * pupilImage_shifted= cpl_imagelist_new();
1521 cpl_size n_images = 0;
1527 int x= (int) (x_theo+ 0.5);
1528 int y= (int) (y_theo + 0.5);
1529 cpl_image * verysmall_img_tmp = cpl_imagelist_get (pupilImage_onFrames, n);
1539 cpl_imagelist_set(pupilImage_shifted, verysmall_img, n_images);
1540 cpl_vector_set (offs_x, n_images, (x-x_theo));
1541 cpl_vector_set (offs_y, n_images, (y-y_theo));
1546 cpl_bivector * offs = cpl_bivector_wrap_vectors (offs_x, offs_y);
1548 double ppos_x, ppos_y;
1549 cpl_image** cpl_image_combined = cpl_geom_img_offset_saa (pupilImage_shifted,offs,CPL_KERNEL_DEFAULT,
1550 0,0,CPL_GEOM_INTERSECT,&ppos_x,&ppos_y);
1553 cpl_vector * x_pos_offset = cpl_bivector_get_x (diode_pos_offset[n]);
1554 cpl_vector * y_pos_offset = cpl_bivector_get_y (diode_pos_offset[n]);
1558 cpl_vector_set(x_pos_offset, tel, ppos_x+3);
1559 cpl_vector_set(y_pos_offset, tel, ppos_y+3);
1561 cpl_imagelist_set(pupilImage_shiftandadd[tel], image_mean, n);
1562 CPLCHECK_MSG(
"Cannot add shift and added image to imagelist");
1564 if (cpl_image_combined[0] != NULL)
cpl_image_delete(cpl_image_combined[0]);
1565 if (cpl_image_combined[1] != NULL)
cpl_image_delete(cpl_image_combined[1]);
1566 cpl_free(cpl_image_combined);
1568 cpl_bivector_delete(offs);
1569 cpl_imagelist_delete(pupilImage_shifted);
1571 cpl_vector_delete(focus_max);
1574 CPLCHECK_MSG(
"Fail at running the shift and add ESO algorithm");
1577 return CPL_ERROR_NONE;
1603 cpl_array * bad_frames_short,
1604 cpl_bivector ** diode_pos_offset, cpl_propertylist * o_header,
1609 cpl_ensure_code(pupilImage_shiftandadd, CPL_ERROR_NULL_INPUT);
1610 cpl_ensure_code(bad_frames_short, CPL_ERROR_NULL_INPUT);
1611 cpl_ensure_code(diode_pos_offset, CPL_ERROR_NULL_INPUT);
1612 cpl_ensure_code(o_header, CPL_ERROR_NULL_INPUT);
1613 cpl_ensure_code(nrow_on, CPL_ERROR_NULL_INPUT);
1617 if (cpl_array_get_size(bad_frames_short)!= nrow_on)
1618 cpl_msg_error (cpl_func,
"Problem with number of blinking frames");
1622 double previous_xsc=0.0;
1623 double previous_ysc=0.0;
1624 double flux_sum=0.0;
1627 for (cpl_size n = 0 ; n < nrow_on; n++)
1629 cpl_image * image = cpl_imagelist_get (pupilImage_shiftandadd[tel], n);
1633 cpl_image_get_maxpos (image, &px, &py);
1636 double flux_max= cpl_image_get(image,px,py,&nv);
1637 double std = cpl_image_get_stdev (image);
1640 double xsc = (double) px;
1641 double ysc = (double) py;
1642 double exsc=3., eysc=3.;
1648 cpl_vector * x_pos_offset = cpl_bivector_get_x (diode_pos_offset[n]);
1649 cpl_vector * y_pos_offset = cpl_bivector_get_y (diode_pos_offset[n]);
1655 cpl_vector_set(x_pos_offset, tel, x_offset_final);
1656 cpl_vector_set(y_pos_offset, tel, y_offset_final);
1659 if ((flux_max/std < 4)||(exsc<0))
1661 previous = cpl_array_get_int (bad_frames_short,n,&nv);
1662 cpl_array_set_int (bad_frames_short,n,previous|(1<<tel));
1666 double distance=(xsc-previous_xsc)*(xsc-previous_xsc)+(ysc-previous_ysc)*(ysc-previous_ysc);
1667 if (distance > 10*10)
1669 previous = cpl_array_get_int (bad_frames_short,n-1,&nv);
1670 cpl_array_set_int (bad_frames_short,n-1,previous|(1<<(tel+4)));
1671 previous = cpl_array_get_int (bad_frames_short,n,&nv);
1672 cpl_array_set_int (bad_frames_short,n,previous|(1<<(tel+4)));
1680 CPLCHECK_MSG(
"Failure at testing bad pupil measurments");
1684 double flux_mean=flux_sum/(1e-7+n_sum);
1686 sprintf(qc_name,
"ESO QC ACQ PUP%i SPOT_FLUX", tel + 1);
1689 cpl_propertylist_set_comment(o_header, qc_name,
"[ADU] mean spot flux");
1694 CPLCHECK_MSG(
"Failure at fitting gaussian on diode position");
1697 return CPL_ERROR_NONE;
1728 cpl_vector* scale_vector, cpl_array * bad_frames_short, cpl_bivector ** diode_pos_offset, cpl_vector * focus_value,
gravi_data *static_param_data)
1734cpl_ensure_code(acqcam_table, CPL_ERROR_NULL_INPUT);
1735cpl_ensure_code(
header, CPL_ERROR_NULL_INPUT);
1736cpl_ensure_code(o_header, CPL_ERROR_NULL_INPUT);
1737cpl_ensure_code(good_frames, CPL_ERROR_NULL_INPUT);
1738cpl_size nrow = cpl_array_get_size(good_frames);
1755if (cpl_array_get_mean(good_frames)*nrow<.5)
1759 cpl_msg_info(cpl_func,
"No good pupil images ==> no good pupil position available");
1762 for (cpl_size row = 0; row < nrow; row++)
1764 cpl_table_set(acqcam_table,
"PUPIL_NSPOT", row *
GRAVI_SPOT_NTEL + tel, 0);
1765 CPLCHECK_MSG(
"Cannot put 0 in NSPOT data in the ACQ PUPIL");
1769 return CPL_ERROR_NONE;
1773cpl_ensure_code(scale_vector, CPL_ERROR_NULL_INPUT);
1774cpl_ensure_code(bad_frames_short, CPL_ERROR_NULL_INPUT);
1775cpl_ensure_code(diode_pos_offset, CPL_ERROR_NULL_INPUT);
1776cpl_ensure_code(focus_value, CPL_ERROR_NULL_INPUT);
1777cpl_ensure_code(static_param_data, CPL_ERROR_NULL_INPUT);
1779cpl_size nrow_on = cpl_array_get_size(bad_frames_short);
1781if (fabs(cpl_array_get_mean(good_frames)*nrow -nrow_on) > 1e-2)
1782 cpl_msg_error (cpl_func,
"Ratio of blinking frames different %f from %lli",cpl_array_get_mean(good_frames)*nrow,nrow_on);
1792 double cfangle = cos(northangle * CPL_MATH_RAD_DEG);
1793 double sfangle = sin(northangle * CPL_MATH_RAD_DEG);
1794 double scale = cpl_vector_get(scale_vector,tel);
1798 double r_shift = 0.0;
1803 double x_shift = 0.0;
1804 double y_shift = 0.0;
1805 double u_shift = 0.0;
1806 double v_shift = 0.0;
1807 double opd_pupil = 0.0;
1810 double x_shift_sum = 0.0;
1811 double y_shift_sum = 0.0;
1812 double u_shift_sum = 0.0;
1813 double v_shift_sum = 0.0;
1816 int n_bad_distance = 0;
1818 for (cpl_size row = 0; row < nrow; row++)
1822 if (cpl_array_get_int(good_frames,row,&nv) != 1)
1824 cpl_table_set(acqcam_table,
"PUPIL_NSPOT", row *
GRAVI_SPOT_NTEL + tel, 0);
1825 CPLCHECK_MSG(
"Cannot put 0 in NSPOT data in the ACQ PUPIL");
1830 int is_it_bad=cpl_array_get_int (bad_frames_short,n_on,&nv);
1832 cpl_vector * x_pos_offset = cpl_bivector_get_x (diode_pos_offset[n_on]);
1833 cpl_vector * y_pos_offset = cpl_bivector_get_y (diode_pos_offset[n_on]);
1834 CPLCHECK_MSG(
"Cannot put data from the offset bivector");
1836 x_shift = cpl_vector_get(x_pos_offset,tel);
1837 y_shift = cpl_vector_get(y_pos_offset,tel);
1840 u_shift = (cfangle * x_shift - sfangle * y_shift)
1842 v_shift = (sfangle * x_shift + cfangle * y_shift)
1844 opd_pupil = -(u_shift * sobj_x + v_shift * sobj_y)
1847 CPLCHECK_MSG(
"Cannot prepare data to be put in the ACQ PUPIL table");
1852 cpl_table_set(acqcam_table,
"PUPIL_NSPOT", row *
GRAVI_SPOT_NTEL + tel, 0);
1855 if (
CHECK_BIT(is_it_bad,tel )) n_bad_snr += 1;
1856 if (
CHECK_BIT(is_it_bad,tel+4)) n_bad_distance += 1;
1860 cpl_msg_info(cpl_func,
"Pupil image number%4lli is un-usable for tel %i",row,tel);
1864 cpl_table_set(acqcam_table,
"PUPIL_NSPOT", row *
GRAVI_SPOT_NTEL + tel,
1868 x_shift_sum += x_shift;
1869 y_shift_sum += y_shift;
1870 u_shift_sum += u_shift;
1871 v_shift_sum += v_shift;
1893 CPLCHECK_MSG(
"Cannot put data in the ACQ PUPIL table");
1897 CPLCHECK_MSG(
"Cannot put data in the ACQ PUPIL table");
1903 sprintf(qc_name,
"ESO QC ACQ FIELD%i NORTH_ANGLE", tel + 1);
1904 cpl_msg_info(cpl_func,
"%s = %f", qc_name, northangle);
1906 cpl_propertylist_set_comment(o_header, qc_name,
1907 "[deg] y->x, predicted North direction on ACQ");
1909 sprintf(qc_name,
"ESO QC ACQ PUP%i FRAMES", tel + 1);
1912 cpl_propertylist_set_comment(o_header, qc_name,
1913 "Good ACQ pupil frames");
1915 sprintf(qc_name,
"ESO QC ACQ PUP%i BADSNR", tel + 1);
1918 cpl_propertylist_set_comment(o_header, qc_name,
1919 "Frames with low SNR");
1921 sprintf(qc_name,
"ESO QC ACQ PUP%i JUMP", tel + 1);
1922 cpl_msg_info(cpl_func,
"%s = %i", qc_name, n_bad_distance);
1924 cpl_propertylist_set_comment(o_header, qc_name,
1925 "Frames with position jump");
1927 sprintf(qc_name,
"ESO QC ACQ PUP%i SCALE", tel + 1);
1930 cpl_propertylist_set_comment(o_header, qc_name,
1931 "[pix/m] diode scale on ACQ");
1933 sprintf(qc_name,
"ESO QC ACQ PUP%i FOCUS", tel + 1);
1935 cpl_propertylist_update_int(o_header, qc_name, z_shift);
1936 cpl_propertylist_set_comment(o_header, qc_name,
1937 "[pix] defocus of pupil plane");
1940 if (n_sum ==0) n_sum+=1;
1942 sprintf(qc_name,
"ESO QC ACQ PUP%i XPOS", tel + 1);
1943 cpl_msg_info(cpl_func,
"%s = %f", qc_name, x_shift_sum/n_sum);
1945 cpl_propertylist_set_comment(o_header, qc_name,
1946 "[pix] pupil x-shift in ACQ");
1948 sprintf(qc_name,
"ESO QC ACQ PUP%i YPOS", tel + 1);
1949 cpl_msg_info(cpl_func,
"%s = %f", qc_name, y_shift_sum/n_sum);
1951 cpl_propertylist_set_comment(o_header, qc_name,
1952 "[pix] pupil y-shift in ACQ");
1954 sprintf(qc_name,
"ESO QC ACQ PUP%i UPOS", tel + 1);
1955 cpl_msg_info(cpl_func,
"%s = %f", qc_name, u_shift_sum/n_sum);
1957 cpl_propertylist_set_comment(o_header, qc_name,
1958 "[m] pupil u-shift in ACQ");
1960 sprintf(qc_name,
"ESO QC ACQ PUP%i VPOS", tel + 1);
1961 cpl_msg_info(cpl_func,
"%s = %f", qc_name, v_shift_sum/n_sum);
1963 cpl_propertylist_set_comment(o_header, qc_name,
1964 "[m] pupil v-shift in ACQ");
1967 CPLCHECK_MSG(
"Cannot put data in the ACQ PUPIL table");
1974return CPL_ERROR_NONE;
2003 cpl_size nx = cpl_image_get_size_x (image_in);
2004 cpl_size ny = cpl_image_get_size_y (image_in);
2005 cpl_size llx_new,lly_new,urx_new,ury_new;
2006 cpl_size xpos, ypos;
2008 cpl_size nx_new=urx+1-llx;
2009 cpl_size ny_new=ury+1-lly;
2010 cpl_image * image_out= cpl_image_new (nx_new, ny_new, cpl_image_get_type(image_in));
2011 cpl_image_fill_window (image_out, 1, 1, nx_new, ny_new, 0.0);
2014 if ((llx >= nx)||(lly >= ny)||(urx <= 0)||(ury <= 0))
2016 cpl_msg_warning (cpl_func,
"Cutting at x=(%lli,%lli) y=(%lli,%lli) is outside the window bondaries", llx, urx, lly, ury);
2048 cpl_image * image_in_cut = cpl_image_extract(image_in,llx_new,lly_new,urx_new,ury_new);
2050 cpl_image_copy (image_out, image_in_cut, xpos, ypos);
2094 cpl_imagelist * acqcam_imglist,
2095 cpl_propertylist *
header,
2096 cpl_table * acqcam_table,
2097 cpl_propertylist * o_header,
2101 cpl_ensure_code (mean_img, CPL_ERROR_NULL_INPUT);
2102 cpl_ensure_code (acqcam_imglist, CPL_ERROR_NULL_INPUT);
2103 cpl_ensure_code (
header, CPL_ERROR_NULL_INPUT);
2104 cpl_ensure_code (acqcam_table, CPL_ERROR_NULL_INPUT);
2105 cpl_ensure_code (o_header, CPL_ERROR_NULL_INPUT);
2121 cpl_size nrow = cpl_imagelist_get_size (acqcam_imglist);
2148 double *roof_x = NULL;
2149 double *roof_y = NULL;
2154 double *spot_x = NULL;
2155 double *spot_y = NULL;
2159 double *roof_pos = NULL;
2162 CPLCHECK_MSG (
"STATIC_PARAM not available in the SOF. It is mandatory for acqcam reduction.");
2164 if ( cpl_table_has_column(roof_pos_table ,
"roof_x") ) {
2165 roof_x= cpl_table_get_data_double (roof_pos_table,
"roof_x");
2172 cpl_msg_warning(cpl_func,
"Cannot get the default values for roof_x ");
2175 if ( cpl_table_has_column(roof_pos_table ,
"roof_y") ) {
2176 roof_y= cpl_table_get_data_double (roof_pos_table,
"roof_y");
2183 cpl_msg_warning(cpl_func,
"Cannot get the default values for roof_y ");
2186 if ( cpl_table_has_column(roof_pos_table ,
"spot_x") ) {
2187 spot_x= cpl_table_get_data_double (roof_pos_table,
"spot_x");
2194 cpl_msg_warning(cpl_func,
"Cannot get the default values for spot_x ");
2197 if ( cpl_table_has_column(roof_pos_table ,
"spot_y") ) {
2198 spot_y= cpl_table_get_data_double (roof_pos_table,
"spot_y");
2205 cpl_msg_warning(cpl_func,
"Cannot get the default values for spot_y ");
2208 if ( cpl_table_has_column(roof_pos_table ,
"roof_pos") ) {
2209 roof_pos= cpl_table_get_data_double (roof_pos_table,
"roof_pos");
2210 cpl_msg_info(cpl_func,
"roof_pos [0] : %e", roof_pos[0] );
2211 cpl_msg_info(cpl_func,
"roof_pos [1] : %e", roof_pos[1] );
2212 cpl_msg_info(cpl_func,
"roof_pos [2] : %e", roof_pos[2] );
2213 cpl_msg_info(cpl_func,
"roof_pos [3] : %e", roof_pos[3] );
2216 cpl_msg_warning(cpl_func,
"Cannot get the default values for roof_pos ");
2234 double calib_dx[] = {0,0,0,0} ;
2235 double calib_dy[] = {0,0,0,0} ;
2240 if ( cpl_propertylist_has (
header,
"ESO DET1 FRAMES NX") ) {
2241 nsx = cpl_propertylist_get_int (
header,
"ESO DET1 FRAMES NX");
2250 double sobj_offx=0., sobj_offy=0, sobj_drho=0., sobj_dth=0.;
2251 if (cpl_propertylist_has(
header,
"ESO INS SOBJ OFFX")) {
2254 sobj_offx = cpl_propertylist_get_double (
header,
"ESO INS SOBJ OFFX");
2255 sobj_offy = cpl_propertylist_get_double (
header,
"ESO INS SOBJ OFFY");
2258 sobj_drho = sqrt(sobj_offx*sobj_offx+sobj_offy*sobj_offy);
2262 sobj_dth = atan2(sobj_offx, sobj_offy)*180./M_PI;
2267 double dx_in = sobj_x - sobj_offx;
2268 double dy_in = sobj_y - sobj_offy;
2269 double rho_in = sqrt(dx_in*dx_in + dy_in*dy_in);
2276 for (
int tel = 0; tel <
ntel; tel++) {
2278 double rp=roof_pos[tel];
2279 cpl_size sx=tel*512+1, sy=1;
2280 cpl_msg_info (cpl_func,
"Compute field position for beam %i", tel+1);
2283 sprintf (name,
"ESO INS DROTOFF%d", tel + 1);
2284 if ( cpl_propertylist_has (
header, name) ) {
2285 rp = cpl_propertylist_get_double(
header, name);
2289 cpl_msg_info (cpl_func,
"%s not in header, use %f", name, rp);
2293 double approx_PA = 270.-rp;
2299 if (!telname) cpl_msg_error (cpl_func,
"Cannot read the telescope name");
2300 cpl_ensure_code (telname, CPL_ERROR_ILLEGAL_INPUT);
2305 if (telname[0] ==
'U') {
2308 cpl_msg_info (cpl_func,
"PLATE SCALE UT is : %e",scale);
2309 }
else if (telname[0] ==
'A') {
2310 sprintf(telid,
"ESO PLATE SCALE AT%d", tel+1);
2312 cpl_msg_info (cpl_func,
"PLATE SCALE AT%d is : %e",tel+1, scale);
2327 double fiber_xft=0.;
2328 double fiber_yft=0.;
2329 double fiber_xsc=0.;
2330 double fiber_ysc=0.;
2331 sprintf (name,
"ESO ACQ FIBER FT%dX", tel + 1);
2332 if (cpl_propertylist_has(
header, name)) {
2333 fiber_xft=cpl_propertylist_get_double(
header, name);
2334 sprintf (name,
"ESO ACQ FIBER FT%dY", tel + 1);
2335 fiber_yft=cpl_propertylist_get_double(
header, name);
2336 sprintf (name,
"ESO ACQ FIBER SC%dX", tel + 1);
2337 fiber_xsc=cpl_propertylist_get_double(
header, name);
2338 sprintf (name,
"ESO ACQ FIBER SC%dY", tel + 1);
2339 fiber_ysc=cpl_propertylist_get_double(
header, name);
2341 double fiber_ft_sc_x=fiber_xsc-fiber_xft;
2342 double fiber_ft_sc_y=fiber_ysc-fiber_yft;
2350 double sobj_offx_cam = sobj_drho * sin((northangle+sobj_dth)/180.*M_PI);
2351 double sobj_offy_cam = sobj_drho * cos((northangle+sobj_dth)/180.*M_PI);
2355 sprintf (name,
"ESO DET1 FRAM%d STRX", tel + 1);
2356 sx = cpl_propertylist_get_int (
header, name);
2358 sprintf (name,
"ESO DET1 FRAM%d STRY", tel + 1);
2359 sy = cpl_propertylist_get_int (
header, name);
2364 cpl_msg_debug (cpl_func,
"sub-window field %i sx= %lld sy = %lld", tel, sx, sy);
2370 double xFT, yFT, xSC, ySC;
2376 xFT = spot_x[tel] - sx + nsx*tel + 1;
2377 yFT = spot_y[tel] - sy + 1;
2381 xFT = fiber_xft - sx + nsx*tel + 1;
2382 yFT = fiber_yft - sy + 1;
2383 xSC = fiber_xsc - sx + nsx*tel + 1;
2384 ySC = fiber_ysc - sy + 1;
2388 double cutout_roof_x = roof_x[tel] - sx + nsx*tel + 1;
2389 double cutout_roof_y = roof_y[tel] - sy + 1;
2391 cpl_msg_info (cpl_func,
" ROOF_X = %f", cutout_roof_x);
2392 cpl_msg_info (cpl_func,
" ROOF_Y = %f", cutout_roof_y);
2395 double approx_dx=0.5*rho_in*sin(approx_PA*M_PI/180.)/scale;
2396 double approx_dy=0.5*rho_in*cos(approx_PA*M_PI/180.)/scale;
2399 xFT = cutout_roof_x - approx_dx ;
2400 yFT = cutout_roof_y - approx_dy ;
2401 xSC = cutout_roof_x + approx_dx ;
2402 ySC = cutout_roof_y + approx_dy ;
2420 double xSCguess=xSC, ySCguess=ySC, xFTguess=xFT, yFTguess=yFT;
2431 sprintf (qc_name,
"ESO QC ACQ FIELD%i SC_X", tel+1);
2442 cpl_propertylist_set_comment (o_header, qc_name,
"[pixel] position in mean image");
2444 sprintf (qc_name,
"ESO QC ACQ FIELD%i SC_Y", tel+1);
2455 cpl_propertylist_set_comment (o_header, qc_name,
"[pixel] position in mean image");
2474 sprintf (qc_name,
"ESO QC ACQ FIELD%i FT_X", tel+1);
2485 cpl_propertylist_set_comment (o_header, qc_name,
"[pixel] position in mean image");
2487 sprintf (qc_name,
"ESO QC ACQ FIELD%i FT_Y", tel+1);
2498 cpl_propertylist_set_comment (o_header, qc_name,
"[pixel] position in mean image");
2505 sprintf (qc_name,
"ESO QC ACQ FIELD%i SCALE", tel+1);
2506 double sep = sqrt((ySC-yFT)*(ySC-yFT)+(xSC-xFT)*(xSC-xFT));
2508 double pscale = scale;
2509 if (sts_mode !=
DUAL_STS) pscale = sep ? rho_in/sep : scale;
2514 cpl_propertylist_set_comment (o_header, qc_name,
2515 "[mas/pixel] plate-scale in the "
2531 sprintf (qc_name,
"ESO QC ACQ FIELD%i SC_FIBER_DX", tel+1);
2534 qc_val = (xSC-xFT) + sobj_offx_cam/scale - fiber_ft_sc_x - calib_dx[tel];
2538 cpl_propertylist_set_comment (o_header, qc_name,
2539 "[pixel] dx from SC fiber to "
2542 sprintf (qc_name,
"ESO QC ACQ FIELD%i SC_FIBER_DY", tel+1);
2545 qc_val = (ySC-yFT) + sobj_offy_cam/scale - fiber_ft_sc_y - calib_dy[tel];
2549 cpl_propertylist_set_comment (o_header, qc_name,
2550 "[pixel] dx from SC fiber to "
2558 double max_on_average, strehl_on_average;
2568 if (cpl_error_get_code() != CPL_ERROR_NONE ) {
2569 cpl_msg_info (cpl_func,
"WARNING Filling STREHL due to NaN");
2571 strehl_on_average = 0.0;
2577 sprintf (qc_name,
"ESO QC ACQ FIELD%i STREHL", tel+1);
2578 cpl_msg_info (cpl_func,
"%s = %f", qc_name, strehl_on_average);
2580 cpl_propertylist_set_comment (o_header, qc_name,
"Average Strehl from stacked AcqCam images");
2592 if (cpl_error_get_code() != CPL_ERROR_NONE ) {
2593 cpl_msg_info (cpl_func,
"WARNING Filling STREHL SC due to NaN");
2595 strehl_on_average = 0.0;
2599 sprintf (qc_name,
"ESO QC ACQ FIELD%i STREHLSC", tel+1);
2600 cpl_msg_info (cpl_func,
"%s = %f", qc_name, strehl_on_average);
2602 cpl_propertylist_set_comment (o_header, qc_name,
"Average Strehl from stacked AcqCam images");
2609 for (cpl_size row = 0; row < nrow; row++) {
2610 if (row %10 == 0 || row == (nrow-1))
2611 cpl_msg_info_overwritable (cpl_func,
"Fit image %lld over %lld", row+1, nrow);
2614 cpl_image * img = cpl_imagelist_get (acqcam_imglist, row);
2620 double xsc = xSC, ysc = ySC, exsc=0., eysc=0.;
2624 if (xsc != 0.) xsc += sx - 1 - nsx*tel;
2625 if (ysc != 0.) ysc += sy - 1;
2626 cpl_table_set (acqcam_table,
"FIELD_SC_X", row*
ntel+tel, xsc);
2627 cpl_table_set (acqcam_table,
"FIELD_SC_Y", row*
ntel+tel, ysc);
2628 cpl_table_set (acqcam_table,
"FIELD_SC_XERR", row*
ntel+tel, exsc);
2629 cpl_table_set (acqcam_table,
"FIELD_SC_YERR", row*
ntel+tel, eysc);
2635 double xft = xFT, yft = yFT, exft=0., eyft=0.;
2640 if (xft != 0.) xft += sx - 1 - nsx*tel;
2641 if (yft != 0.) yft += sy - 1;
2648 cpl_table_set (acqcam_table,
"FIELD_FT_X", row*
ntel+tel, xft);
2649 cpl_table_set (acqcam_table,
"FIELD_FT_Y", row*
ntel+tel, yft);
2650 cpl_table_set (acqcam_table,
"FIELD_FT_XERR", row*
ntel+tel, exft);
2651 cpl_table_set (acqcam_table,
"FIELD_FT_YERR", row*
ntel+tel, eyft);
2657 double ft_sc_x = xsc - xft;
2658 double ft_sc_y = ysc - yft;
2659 double eft_sc_x = sqrt(exsc*exsc+exft*exft);
2660 double eft_sc_y = sqrt(eysc*eysc+eyft*eyft);
2661 double sep = sqrt(ft_sc_x*ft_sc_x+ft_sc_y*ft_sc_y);
2662 double pscale = scale;
2663 if (sts_mode !=
DUAL_STS) pscale = sep ? rho_in/sep : 0.;
2666 escale = rho_in/(sep*sep*sep)*
2667 (ft_sc_x*eft_sc_x+ft_sc_y*eft_sc_y) ;
2669 cpl_table_set (acqcam_table,
"FIELD_SCALE", row*
ntel+tel, pscale);
2670 cpl_table_set (acqcam_table,
"FIELD_SCALEERR", row*
ntel+tel, escale);
2681 double corrx=0, corry=0., ecorrx=0., ecorry=0.;
2683 corrx = ft_sc_x + sobj_offx_cam/pscale - fiber_ft_sc_x - calib_dx[tel];
2684 corry = ft_sc_y + sobj_offy_cam/pscale - fiber_ft_sc_y - calib_dy[tel];
2685 double tmp = escale/(pscale*pscale);
2687 ecorrx = sqrt(eft_sc_x*eft_sc_x + eft_sc_y*eft_sc_y + sobj_offx_cam*sobj_offx_cam*tmp);
2688 ecorry = sqrt(eft_sc_x*eft_sc_x + eft_sc_y*eft_sc_y + sobj_offy_cam*sobj_offy_cam*tmp);
2690 cpl_table_set (acqcam_table,
"FIELD_FIBER_DX", row*
ntel+tel, corrx);
2691 cpl_table_set (acqcam_table,
"FIELD_FIBER_DY", row*
ntel+tel, corry);
2692 cpl_table_set (acqcam_table,
"FIELD_FIBER_DXERR", row*
ntel+tel, ecorrx);
2693 cpl_table_set (acqcam_table,
"FIELD_FIBER_DYERR", row*
ntel+tel, ecorry);
2698 double max_on_frame;
2700 cpl_table_set (acqcam_table,
"FIELD_STREHL", row*
ntel+tel, strehl_on_average*(max_on_frame/max_on_average) );
2706 sprintf (qc_name,
"ESO QC ACQ FIELD%i SC_X STD", tel+1);
2708 cpl_propertylist_set_comment (o_header, qc_name,
"[pix] Std of field position of SC");
2711 sprintf (qc_name,
"ESO QC ACQ FIELD%i SC_Y STD", tel+1);
2713 cpl_propertylist_set_comment (o_header, qc_name,
"[pix] Std of field position of SC");
2716 sprintf (qc_name,
"ESO QC ACQ FIELD%i FT_X STD", tel+1);
2718 cpl_propertylist_set_comment (o_header, qc_name,
"[pix] Std of field position of FT");
2721 sprintf (qc_name,
"ESO QC ACQ FIELD%i FT_Y STD", tel+1);
2723 cpl_propertylist_set_comment (o_header, qc_name,
"[pix] Std of field position of FT");
2726 sprintf (qc_name,
"ESO QC ACQ FIELD%i STREHL STD", tel+1);
2728 cpl_propertylist_set_comment (o_header, qc_name,
"Std of FT strehl");
2733 return CPL_ERROR_NONE;
2770 cpl_ensure_code (output_data, CPL_ERROR_NULL_INPUT);
2771 cpl_ensure_code (input_data, CPL_ERROR_NULL_INPUT);
2776 return CPL_ERROR_NONE;
2780 cpl_propertylist *
header, * o_header;
2787 return CPL_ERROR_NONE;
2790 cpl_imagelist * acqcam_imglist;
2791 cpl_imagelist * acqcam_imglist_v2;
2798 cpl_size nrow = cpl_imagelist_get_size (acqcam_imglist);
2800 cpl_table * acqcam_table;
2801 acqcam_table = cpl_table_new (nrow *
ntel);
2804 cpl_table_new_column (acqcam_table,
"TIME", CPL_TYPE_INT);
2805 cpl_table_set_column_unit (acqcam_table,
"TIME",
"us");
2809 for (cpl_size row = 0; row < nrow; row++) {
2811 for (
int tel = 0; tel <
ntel; tel ++)
2812 cpl_table_set (acqcam_table,
"TIME", row*
ntel+tel, time);
2816 cpl_image * mean_img = cpl_imagelist_collapse_create (acqcam_imglist);
2817 cpl_image * mean_subtracted_img = NULL;
2821 cpl_image_subtract(mean_subtracted_img, mean_img);
2822 cpl_image_multiply_scalar(mean_subtracted_img, -1.0);
2823 }
else if (dark_data) {
2825 cpl_msg_warning(cpl_func,
"No SKY, using DARK for acquisition field subtraction");
2826 cpl_image_subtract(mean_subtracted_img, mean_img);
2827 cpl_image_multiply_scalar(mean_subtracted_img, -1.0);
2829 cpl_msg_warning(cpl_func,
"No SKY or DARK, skipping acquisition field subtraction");
2830 mean_subtracted_img = mean_img;
2835 acqcam_table, o_header, static_param_data);
2836 CPLCHECK_MSG (
"Cannot reduce acquisition field images");
2843 acqcam_table, o_header, static_param_data);
2847 cpl_propertylist * plist_acq_cam = cpl_propertylist_new ();
2848 cpl_propertylist_update_string (plist_acq_cam,
"INSNAME",
INSNAME_ACQ);
2857 FREE (cpl_table_delete, acqcam_table);
2862 return CPL_ERROR_NONE;
2889 cpl_msg_debug (cpl_func,
"ESO LENS Llambda is : %e", Llambda);
2895 cpl_msg_debug (cpl_func,
"ESO LENS D_pixel is : %e", D_pixel);
2901 cpl_msg_debug (cpl_func,
"ESO LENS D_lenslet is : %e", D_lenslet);
2905 longDef = 8 * (f_PT / D_lenslet) * (f_PT / D_lenslet) * 3.5 * D_pixel *
2906 D_beam / (f_PT * D_lenslet) * Llambda / CPL_MATH_2PI * PositionPixels;
2908 return f_lens * f_lens * longDef / (f_PT + longDef) / f_PT * (D_AT / D_lenslet);
2928 cpl_ensure_code (ia, CPL_ERROR_NULL_INPUT);
2929 cpl_ensure_code (ib, CPL_ERROR_NULL_INPUT);
2930 cpl_ensure_code (xd, CPL_ERROR_NULL_INPUT);
2931 cpl_ensure_code (yd, CPL_ERROR_NULL_INPUT);
2933 cpl_error_code error = CPL_ERROR_NONE;
2934 cpl_type type = cpl_image_get_type(ia);
2935 cpl_size nx = cpl_image_get_size_x(ia);
2936 cpl_size ny = cpl_image_get_size_y(ia);
2938 cpl_image * ic = cpl_image_new(nx, ny, type);
2939 cpl_image * fa = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX);
2940 cpl_image * fb = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX);
2941 cpl_image * fc = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX);
2943 cpl_imagelist * iab = cpl_imagelist_new();
2944 cpl_imagelist * fab = cpl_imagelist_new();
2947 error = cpl_imagelist_set(iab, ia, 0);
2950 error = cpl_imagelist_set(iab, ib, 1);
2953 error = cpl_imagelist_set(fab, fa, 0);
2956 error = cpl_imagelist_set(fab, fb, 1);
2959 error = cpl_fft_imagelist(fab, iab, CPL_FFT_FORWARD);
2962 error = cpl_image_conjugate(fc, fb);
2968 error = cpl_fft_image(ic, fc, CPL_FFT_BACKWARD | CPL_FFT_NOSCALE);
2971 error = cpl_image_get_maxpos(ic, xd, yd);
2974 if (*xd > nx/2) *xd = *xd - nx;
2975 if (*yd > ny/2) *yd = *yd - ny;
2986 FREE (cpl_imagelist_unwrap, iab);
2987 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_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_reduce_acqcam(gravi_data *output_data, gravi_data *input_data, gravi_data *sky_data, gravi_data *dark_data, gravi_data *static_param_data, int saveAcqTable)
Reduce the ACQ camera images.
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)