67 cpl_table * sky_table_avg, cpl_table * badft_table,
68 int n_region,
double gain,
const cpl_parameterlist * parlist);
71 cpl_imagelist * raw_imglist,
72 cpl_imagelist * rawVar_imglist,
76 cpl_table * wave_table,
77 cpl_table ** oiwave_tables,
78 cpl_table * detector_table,
79 cpl_table * specflat_table,
103 bad = cpl_image_get (bad_img, x, y, &nv);
127 cpl_ensure_code (imglist_sc, CPL_ERROR_NULL_INPUT);
128 cpl_ensure_code (bad_img, CPL_ERROR_NULL_INPUT);
131 int middel = 3, size = 7, nv, comp, badpix_comp;
132 cpl_vector * x = NULL;
134 cpl_size nrow = cpl_imagelist_get_size (imglist_sc);
135 cpl_size nx = cpl_image_get_size_x (bad_img);
136 cpl_size ny = cpl_image_get_size_y (bad_img);
139 if ((nx != cpl_image_get_size_x (cpl_imagelist_get (imglist_sc, 0))) ||
140 (ny != cpl_image_get_size_y (cpl_imagelist_get (imglist_sc, 0))) ){
141 return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
142 "The image lists have not the same size");
147 for (cpl_size k = 0; k < ny; k++)
148 for (cpl_size i = 0; i < nx; i++)
149 if (cpl_image_get (bad_img, i+1, k+1, &nv) != 0)
152 for (cpl_size row = 0; row < nrow; row ++) {
153 img = cpl_imagelist_get (imglist_sc, row);
154 cpl_mask * bpm = cpl_image_get_bpm (img);
155 cpl_mask_set (bpm, i + 1, k + 1, CPL_BINARY_1);
161 if (nbad > 0.25 * nx*ny) {
162 return cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
163 "Too many bad pixels (more than 25 percent)");
167 for (cpl_size row = 0; row < nrow; row ++){
169 img = cpl_imagelist_get (imglist_sc, row);
170 cpl_mask * bpm = cpl_image_get_bpm (img);
173 for (cpl_size k = 0; k < ny; k++){
174 for (cpl_size i = 0; i < nx; i++){
177 if (cpl_mask_get (bpm, i+1, k+1) != CPL_BINARY_0) {
179 x = cpl_vector_new (size-1);
181 if ((i - middel) < 0 ){
184 for (cpl_size j = 0; j < size; j++){
186 while (cpl_mask_get (bpm, i + badpix_comp, k + 1) != CPL_BINARY_0){
189 cpl_vector_set(x, comp, cpl_image_get (img, i + badpix_comp, k + 1, &nv));
195 else if ((i + middel) >= nx){
198 for (cpl_size j = 0; (j < size); j++){
200 while (cpl_mask_get (bpm, nx - (j + 1) + badpix_comp, k + 1) != CPL_BINARY_0){
204 cpl_vector_set(x, comp, cpl_image_get (img, nx - (j + 1) + badpix_comp, k + 1 , &nv));
213 int test1 = 0, test2 = 0;
214 for (cpl_size j = 0; j < size; j++){
216 if (i + j - middel + badpix_comp <= 1){
217 while (cpl_mask_get (bpm, i + j - middel + badpix_comp, k+1) != CPL_BINARY_0){
222 else if (i + j - middel + badpix_comp >= nx){
223 while (cpl_mask_get (bpm, i + j - middel + badpix_comp, k+1) != CPL_BINARY_0){
229 if ((test1 == 0) && (test2 == 0)){
240 cpl_vector_set(x, comp, cpl_image_get (img, i + j - middel + badpix_comp, k+1, &nv));
247 double mean = cpl_vector_get_median (x);
248 cpl_vector_delete (x);
249 cpl_image_set (img, i + 1, k + 1, mean);
255 cpl_mask_set (bpm, i + 1, k + 1, CPL_BINARY_0);
261 return CPL_ERROR_NONE;
284 cpl_table * skystd_table,
285 cpl_table * skyavg_table,
286 cpl_table * badft_table,
287 int n_region,
double gain,
const cpl_parameterlist * parlist)
291 cpl_ensure (pix_table, CPL_ERROR_NULL_INPUT, NULL);
292 cpl_ensure (skystd_table, CPL_ERROR_NULL_INPUT, NULL);
293 cpl_ensure (skyavg_table, CPL_ERROR_NULL_INPUT, NULL);
296 cpl_size nrow = cpl_table_get_nrow (pix_table);
297 cpl_table * output_table = cpl_table_new (nrow);
300 cpl_array ** arr_data = cpl_table_get_data_array (pix_table,
"PIX");
304 cpl_array ** arr_badft = cpl_table_get_data_array (badft_table,
"PIX");
308 cpl_size npix = cpl_table_get_column_depth (pix_table,
"PIX");
309 cpl_size sizex = cpl_table_get_column_dimension(pix_table,
"PIX", 0);
310 cpl_size sizey = cpl_table_get_column_dimension(pix_table,
"PIX", 1);
312 int npol = n_region > 24 ? 2 : 1;
313 cpl_size ny = sizey / npol;
320 cpl_msg_info (cpl_func,
"Option extra-pixel-ft applied, using %lld pixels", ny_out);
324 cpl_msg_info (cpl_func,
"Option extra-pixel-ft disabled, using %lld pixels", ny_out);
328 cpl_size n_output = 24;
329 cpl_size nx = sizex / n_output;
330 cpl_msg_info (cpl_func,
"Descramble %lld x %lld as %lld outputs x %lld pixels x %lld channels x %i pol",
331 sizex, sizey, n_output, nx, ny, npol);
334 if (cpl_table_has_column (pix_table,
"TIME")) {
335 cpl_table_duplicate_column (output_table,
"TIME", pix_table,
"TIME");
340 double * pSky = cpl_calloc (sizex * sizey,
sizeof(
double));
342 for (cpl_size pix = 0; pix < npix; pix++) {
349 double * pSkyVar = cpl_calloc (sizex * sizey,
sizeof(
double));
351 for (cpl_size pix = 0; pix < npix; pix++) {
353 pSkyVar[pix] = pow (pSkyVar[pix] / gain, 2.0);
360 for (cpl_size region = 0; region < n_output; region++) {
363 for (
int pol = 0; pol < npol; pol ++) {
366 if ( !(region+pol) || !((region*npol+pol+1)%6) )
367 cpl_msg_info_overwritable (cpl_func,
368 "Extract region of FT %lld over %lld (fast-no-cpl)",
369 (region*npol+pol+1), n_output*npol);
372 const char * data =
GRAVI_DATA[region*npol + pol];
373 cpl_table_new_column_array (output_table, data, CPL_TYPE_DOUBLE, ny_out);
374 cpl_array ** tData = cpl_table_get_data_array (output_table, data);
379 cpl_table_new_column_array (output_table, dataerr, CPL_TYPE_DOUBLE, ny_out);
380 cpl_array ** tDataErr = cpl_table_get_data_array (output_table, dataerr);
394 for (cpl_size row = 0; row < nrow; row ++) {
395 double *pData = cpl_malloc (ny_out *
sizeof(
double));
396 double *pDataErr = cpl_malloc (ny_out *
sizeof(
double));
397 for (cpl_size j = 0; j < ny_out; j++) {
398 long idx = sizex * (j + ny*pol) + region*nx;
401 if (cpl_array_get (arr_badft[0], idx, NULL) == 0) {
402 value += cpl_array_get (arr_data[row], idx, NULL) / gain - pSky[idx];
405 if (nx>1 && cpl_array_get (arr_badft[0], idx+1, NULL) == 0) {
406 value += cpl_array_get (arr_data[row], idx+1, NULL) / gain - pSky[idx+1];
407 var += pSkyVar[idx+1];
410 pDataErr[j] = sqrt (CPL_MAX (value,0.0) + var);
412 tData[row] = cpl_array_wrap_double (pData, ny_out);
413 tDataErr[row] = cpl_array_wrap_double (pDataErr, ny_out);
424 FREE (cpl_free, pSky);
425 FREE (cpl_free, pSkyVar);
459 cpl_imagelist * raw_imglist,
460 cpl_imagelist * rawVar_imglist,
466 cpl_ensure (profile_table, CPL_ERROR_NULL_INPUT, NULL);
467 cpl_ensure (raw_imglist, CPL_ERROR_NULL_INPUT, NULL);
468 cpl_ensure (rawVar_imglist, CPL_ERROR_NULL_INPUT, NULL);
472 cpl_size n_row = cpl_imagelist_get_size (raw_imglist);
473 cpl_ensure (n_row > 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
474 cpl_ensure (n_region==24 || n_region==48, CPL_ERROR_ILLEGAL_INPUT, NULL);
477 cpl_type type0 = cpl_image_get_type (cpl_imagelist_get (raw_imglist, 0));
478 cpl_type type1 = cpl_image_get_type (cpl_imagelist_get (rawVar_imglist, 0));
479 cpl_ensure (type0 == CPL_TYPE_DOUBLE, CPL_ERROR_ILLEGAL_INPUT, NULL);
480 cpl_ensure (type1 == CPL_TYPE_DOUBLE, CPL_ERROR_ILLEGAL_INPUT, NULL);
483 cpl_table * spectrum_table = cpl_table_new (n_row);
486 cpl_size nx = cpl_table_get_column_dimension (profile_table,
"DATA1",0);
487 cpl_size ny = cpl_table_get_column_dimension (profile_table,
"DATA1",1);
491 for (cpl_size region = 0; region < n_region; region++){
494 if ( !region || !((region+1)%6) )
495 cpl_msg_info_overwritable(cpl_func,
"Extract region of SC %lld over %lld",region+1,n_region);
498 const char * regionNameData =
GRAVI_DATA[region];
499 cpl_table_new_column_array (spectrum_table, regionNameData, CPL_TYPE_DOUBLE, nx);
503 cpl_table_new_column_array (spectrum_table, regionNameErr, CPL_TYPE_DOUBLE, nx);
507 cpl_image * profile_img = cpl_imagelist_get (profile_imglist, 0);
512 int xmin = 1, xmax = nx;
513 int ymin = ny, ymax = 0;
514 for (cpl_size jy = 1 ; jy <= ny ; jy++ ) {
515 for (cpl_size ix = 1 ; ix <= nx ; ix++ ) {
516 if ( !cpl_image_get (profile_img, ix, jy, &nv) )
continue;
517 if ( jy<ymin ) ymin=jy;
518 if ( jy>ymax ) ymax=jy;
524 cpl_msg_debug (cpl_func,
"Found limits: x=[%4d, %4d] y=[%4d, %4d] (nx=%lld,ny=%lld, FITS convention)",
525 xmin,xmax,ymin,ymax,nx,ny);
528 cpl_image * profile_crop = cpl_image_extract (profile_img, xmin, ymin, xmax, ymax);
532 cpl_array ** tData = cpl_table_get_data_array (spectrum_table, regionNameData);
533 cpl_array ** tDataErr = cpl_table_get_data_array (spectrum_table, regionNameErr);
536 for (cpl_size row = 0; row < n_row; row ++) {
540 cpl_image * rawFlux_profiled = cpl_image_extract (cpl_imagelist_get (raw_imglist, row),
541 xmin+startx-1, ymin, xmax+startx-1, ymax);
544 cpl_image *rawFlux = cpl_image_collapse_create (rawFlux_profiled,0);
550 cpl_image * rawVar_profiled = cpl_image_extract (cpl_imagelist_get (rawVar_imglist, row),
551 xmin+startx-1, ymin, xmax+startx-1, ymax);
555 cpl_image *rawErr = cpl_image_collapse_create (rawVar_profiled,0);
557 cpl_image_threshold (rawErr, 0.0, DBL_MAX, 0.0, DBL_MAX);
558 cpl_image_power (rawErr, 0.5);
562 tData[row] = cpl_array_wrap_double (cpl_image_get_data_double (rawFlux), nx);
565 tDataErr[row] = cpl_array_wrap_double (cpl_image_get_data_double (rawErr), nx);
568 FREE (cpl_image_unwrap, rawFlux);
569 FREE (cpl_image_unwrap, rawErr);
579 return spectrum_table;
617 const cpl_parameterlist * parlist,
621 cpl_ensure (raw_data, CPL_ERROR_NULL_INPUT, NULL);
622 cpl_ensure (profile_map, CPL_ERROR_NULL_INPUT, NULL);
623 cpl_ensure (bad_map, CPL_ERROR_NULL_INPUT, NULL);
624 cpl_ensure (dark_map || sky_map, CPL_ERROR_NULL_INPUT, NULL);
625 cpl_ensure (parlist, CPL_ERROR_NULL_INPUT, NULL);
636 cpl_propertylist_append (spectrum_header, raw_header);
657 cpl_table * skyavg_table = NULL, * skystd_table = NULL;
658 if (sky_map != NULL) {
659 cpl_msg_info (cpl_func,
"Extract FT spectra with SKY as background and variance");
663 else if (dark_map != NULL) {
667 cpl_msg_info (cpl_func,
"Extract FT spectra with DARK as background and variance");
671 cpl_error_set_message (cpl_func,CPL_ERROR_NULL_INPUT,
672 "DARK or SKY should be provided");
679 cpl_propertylist_set_comment (spectrum_header,
"ESO QC USEDGAIN FT",
"[adu/e-] value used for reduction");
687 cpl_table * spectrum_ft;
688 spectrum_ft =
gravi_table_ft_format (imaging_data_ft, skystd_table, skyavg_table, badft_table, n_region, gain_ft, parlist);
692 for (cpl_size reg=0; reg<n_region; reg++) {
693 cpl_table_set_column_unit (spectrum_ft,
GRAVI_DATA[reg],
"e");
694 cpl_table_set_column_unit (spectrum_ft,
GRAVI_DATAERR[reg],
"e");
698 cpl_propertylist * spectrum_plist = cpl_propertylist_new ();
700 cpl_propertylist_update_int (spectrum_plist,
PROFILE_NX, nx);
722 cpl_ensure (profile_table, CPL_ERROR_ILLEGAL_INPUT, NULL);
732 cpl_propertylist_set_comment (spectrum_header,
"ESO QC USEDGAIN SC",
"[adu/e-] value used for reduction");
739 cpl_image * skyavg_img;
740 if (sky_map != NULL){
742 int sky_map_usefull=1;
745 cpl_msg_warning (cpl_func,
"SC DIT is different from SKY SC DIT");
750 cpl_msg_warning (cpl_func,
"SC spectral resolution is different from SKY resolution :");
757 cpl_msg_warning (cpl_func,
"SC POLA is different from SKY POLA :");
762 if ((sky_map_usefull==1)||(dark_map == NULL))
764 cpl_msg_info (cpl_func,
"Extract SC spectra with SKY as background");
770 cpl_msg_info (cpl_func,
"Extract SC spectra with DARK as background");
773 }
else if (dark_map != NULL) {
777 cpl_msg_info (cpl_func,
"Extract SC spectra with DARK as background");
784 cpl_image * darkavg_img;
785 cpl_image * darkstd_img;
787 if (dark_map != NULL) {
788 cpl_msg_info (cpl_func,
"Extract SC photonic variance with DARK as background and variance");
792 else if (sky_map != NULL) {
793 gravi_pfits_add_check (spectrum_header,
"Extract SC photonic variance with SKY as background and variance");
800 CPLCHECK_NUL (
"The coordinate dimensions of the new window is missing");
804 cpl_imagelist * raw_imglist;
805 raw_imglist = cpl_imagelist_duplicate (imaging_data);
837 cpl_imagelist_subtract_image (raw_imglist, skyavg_img);
839 cpl_imagelist_divide_scalar (raw_imglist, gain_sc);
874 cpl_imagelist * rawVar_imglist;
875 rawVar_imglist = cpl_imagelist_duplicate (imaging_data);
876 cpl_imagelist_subtract_image (rawVar_imglist, darkavg_img);
877 cpl_imagelist_divide_scalar (rawVar_imglist, gain_sc);
882 cpl_image * darkvar_img = cpl_image_power_create (darkstd_img, 2.0);
883 cpl_image_divide_scalar (darkvar_img, gain_sc * gain_sc);
884 cpl_imagelist_add_image (rawVar_imglist, darkvar_img);
890 cpl_table * spectrum_table;
892 rawVar_imglist, startx);
895 cpl_size n_row = cpl_table_get_nrow (spectrum_table);
896 cpl_size n_region = cpl_table_get_ncol (profile_table);
899 for (cpl_size reg=0; reg<n_region; reg++) {
900 cpl_table_set_column_unit (spectrum_table,
GRAVI_DATA[reg],
"e");
901 cpl_table_set_column_unit (spectrum_table,
GRAVI_DATAERR[reg],
"e");
913 cpl_table_new_column (spectrum_table,
"TIME", CPL_TYPE_INT);
914 for (cpl_size row = 0; row < n_row; row ++) {
915 cpl_table_set_int (spectrum_table,
"TIME", row,
923 cpl_msg_info (cpl_func,
"Total flux in REGIONs: %.2e [e], in IMGs:%.2e [e] (ratio=%.5f)",
924 full_flux_reg,full_flux_img,full_flux_reg/full_flux_img);
927 cpl_propertylist_set_comment (spectrum_header,
"ESO QC TRANS PROFILE SC",
"[e/e] at profile extraction");
929 CPLCHECK_NUL (
"Cannot verify if extraction was flux-conservative");
932 cpl_propertylist * spectrum_plist = cpl_propertylist_new ();
934 cpl_propertylist_copy_property (spectrum_plist, profile_plist,
PROFILE_STARTX);
935 cpl_propertylist_copy_property (spectrum_plist, profile_plist,
PROFILE_NX);
945 cpl_table * spectrumflat_table;
952 cpl_propertylist * spectrumflat_plist = cpl_propertylist_new ();
957 FREE (cpl_imagelist_delete, raw_imglist);
958 FREE (cpl_imagelist_delete, rawVar_imglist);
962 return spectrum_data;
983 cpl_ensure_code (dark_map , CPL_ERROR_NULL_INPUT);
986 cpl_msg_warning (cpl_func,
"The DARK data has no METROLOGY extension");
995 const char * data_x=
"VOLT";
996 cpl_size nrow = cpl_table_get_nrow (met_data_table);
997 cpl_array ** met_data_array = cpl_table_get_data_array (met_data_table, data_x);
998 cpl_ensure_code (met_data_array, CPL_ERROR_ILLEGAL_INPUT);
999 cpl_array ** met_dark_array = cpl_table_get_data_array (met_dark_table, data_x);
1000 cpl_ensure_code (met_dark_array, CPL_ERROR_ILLEGAL_INPUT);
1004 for (cpl_size j = 0; j < nrow ; j++)
1006 cpl_array_subtract(met_data_array[j],met_dark_array[0]);
1009 cpl_msg_info (cpl_func,
"METROLOGY Volts have been subtracted from dark");
1013 return CPL_ERROR_NONE;
1039 cpl_table * wave_table,
1040 cpl_table ** oiwave_tables,
1041 cpl_table * detector_table,
1042 cpl_table * specflat_table,
1048 cpl_ensure_code (spectrum_table, CPL_ERROR_NULL_INPUT);
1049 cpl_ensure_code (wave_table, CPL_ERROR_NULL_INPUT);
1050 cpl_ensure_code (oiwave_tables, CPL_ERROR_NULL_INPUT);
1051 cpl_ensure_code (oiwave_tables[0], CPL_ERROR_NULL_INPUT);
1057 cpl_size nb_row = cpl_table_get_nrow (spectrum_table);
1058 cpl_size nb_oiwave = cpl_table_get_nrow (oiwave_tables[0]);
1062 cpl_ensure_code (oiwave_tables[1], CPL_ERROR_NULL_INPUT);
1063 cpl_ensure_code (cpl_table_get_nrow (oiwave_tables[0]) ==
1064 cpl_table_get_nrow (oiwave_tables[1]),
1065 CPL_ERROR_ILLEGAL_INPUT);
1069 cpl_ensure_code (nb_region == 24 || nb_region == 48,
1070 CPL_ERROR_ILLEGAL_INPUT);
1073 cpl_msg_info (cpl_func,
"nb_oiwave=%lld, nb_wave=%lld", nb_oiwave, nb_wave);
1074 cpl_ensure_code (nb_oiwave <= nb_wave, CPL_ERROR_ILLEGAL_INPUT);
1078 cpl_msg_info (cpl_func,
"Change the target wavelength because of FLAT");
1080 cpl_msg_info (cpl_func,
"Don't change the target wavelenght because of FLAT");
1085 double * xout = cpl_malloc (nb_oiwave *
sizeof(
double));
1086 double * yout = cpl_malloc (nb_oiwave *
sizeof(
double));
1087 cpl_size *
id = cpl_malloc (nb_oiwave *
sizeof(cpl_size));
1089 double * outputData = cpl_malloc (nb_oiwave *
sizeof(
double));
1090 double * outputErr = cpl_malloc (nb_oiwave *
sizeof(
double));
1093 for (
int pol = 0; pol < nb_pol; pol++) {
1096 double oiwave_min = cpl_table_get_column_min (oiwave_tables[pol],
"EFF_WAVE");
1097 double oiwave_max = cpl_table_get_column_max (oiwave_tables[pol],
"EFF_WAVE");
1099 cpl_msg_info(cpl_func,
"Reinterpolate pol %i: oiwave_min=%g, oiwave_max=%g [um]",
1100 pol, oiwave_min*1e6, oiwave_max*1e6);
1103 for (cpl_size reg = 0; reg < nb_region; reg++){
1113 int nbd = cpl_table_get_column_depth (spectrum_table, data_x);
1114 cpl_ensure_code (nbd == nb_wave, CPL_ERROR_ILLEGAL_INPUT);
1117 int nbw = cpl_table_get_column_depth (wave_table, data_x);
1119 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
1120 "Wavelength calibration is incompatible with the data. Make sure the \n"
1121 "calibration has been produced by the same version of the pipeline");
1122 cpl_ensure_code (nbw == nb_wave, CPL_ERROR_ILLEGAL_INPUT);
1127 cpl_ensure_code (wave_first < wave_last, CPL_ERROR_ILLEGAL_INPUT);
1138 cpl_array ** inputData = cpl_table_get_data_array (spectrum_table, data_x);
1139 cpl_array ** inputErr = cpl_table_get_data_array (spectrum_table, data_errx);
1140 const cpl_array * flat = NULL;
1141 if (specflat_table){
1142 flat = cpl_table_get_array (specflat_table, data_x, 0);
1144 cpl_array * wave = cpl_table_get_data_array(wave_table, data_x)[0];
1148 cpl_ensure_code ((cpl_array_get_type (inputData[0]) == CPL_TYPE_DOUBLE) &&
1149 (cpl_array_get_type (inputErr[0]) == CPL_TYPE_DOUBLE) &&
1150 (cpl_array_get_type (wave) == CPL_TYPE_DOUBLE),
1151 CPL_ERROR_ILLEGAL_INPUT);
1155 double * wave_ref = cpl_array_get_data_double (wave);
1167 if ( ( nb_oiwave <= 50 ) && ( type_data ==
GRAVI_SC) && (flat != NULL) ) {
1168 cpl_msg_info_overwritable (cpl_func,
"Reinterpolate (3 pixels) region %lld "
1169 "over %lld (%lld->%lld channels)",
1170 reg+1,nb_region,nb_wave,nb_oiwave);
1179 double * weight_m = cpl_malloc (nb_oiwave *
sizeof(
double));
1180 double * weight_i = cpl_malloc (nb_oiwave *
sizeof(
double));
1181 double * weight_p = cpl_malloc (nb_oiwave *
sizeof(
double));
1183 for (cpl_size iw = 0 ; iw < nb_oiwave ; iw ++)
1186 double l0=cpl_table_get (oiwave_tables[pol],
"EFF_WAVE", iw, NULL);
1192 if (iw == 0)
id[iw] = 1;
1193 else id[iw] =
id[iw-1];
1194 while ( (1./l0 < 0.5/wave_ref[
id[iw]]+0.5/wave_ref[
id[iw]+1]) && (
id[iw] < nb_wave-2 ) ){
1200 double xm=l0/wave_ref[
id[iw]-1]-1.;
1201 double xi=l0/wave_ref[
id[iw]]-1.;
1202 double xp=l0/wave_ref[
id[iw]+1]-1.;
1203 double xT=(xp-xm)/2;
1211 Fm=cpl_array_get (flat,
id[iw]-1, NULL);
1212 Fi=cpl_array_get (flat,
id[iw], NULL);
1213 Fp=cpl_array_get (flat,
id[iw]+1, NULL);
1224 double fluxLimit = 40 ;
1225 if ( (Fi > fluxLimit) && (Fp > fluxLimit) && (Fm > fluxLimit) && (xm-xi>1e-4) && (xi-xp>1e-4) )
1238 weight_p[iw]= (xT-2*xi)/(4*xp) ;
1240 weight_m[iw]= -(xT+2*xi)/(4*xm);
1249 else if ((Fi > fluxLimit) && (Fp > fluxLimit) && (xi>1e-4) && (xi-xp>1e-4) )
1251 weight_p[iw]= -xi/xp ;
1262 else if ( (Fm > fluxLimit) && (Fi > fluxLimit) && (xi<1e-4) && (xm-xi>1e-4))
1267 weight_m[iw]= -xi/xm ;
1281 norm = weight_m[iw] + weight_i[iw] + weight_p[iw];
1298 for (cpl_size j = 0; j < nb_row; j++){
1304 yref = cpl_array_get_data_double (inputData[j]);
1306 for (cpl_size iw=0 ; iw < nb_oiwave ; iw ++) {
1307 outputData[iw]=yref[
id[iw]-1]*weight_m[iw] + yref[
id[iw]]*weight_i[iw] + yref[
id[iw]+1]*weight_p[iw];
1310 for (cpl_size iw = 0 ; iw < nb_oiwave ; iw ++){
1311 yref[iw]=outputData[iw];
1317 yref = cpl_array_get_data_double (inputErr[j]);
1319 for (cpl_size iw=0 ; iw < nb_oiwave ; iw ++) {
1320 outputErr[iw]=sqrt(pow(yref[
id[iw]-1]*weight_m[iw],2) + pow(yref[
id[iw]]*weight_i[iw],2) + pow(yref[
id[iw]+1]*weight_p[iw],2));
1323 for (cpl_size iw = 0 ; iw < nb_oiwave ; iw ++){
1324 yref[iw]=outputErr[iw];
1329 FREE (cpl_free, weight_m);
1330 FREE (cpl_free, weight_i);
1331 FREE (cpl_free, weight_p);
1338 cpl_msg_info_overwritable (cpl_func,
"Reinterpolate region %lld "
1339 "over %lld (%lld->%lld channels)",
1340 reg+1,nb_region,nb_wave,nb_oiwave);
1348 double * weight_m = cpl_malloc (nb_oiwave *
sizeof(
double));
1349 double * weight_p = cpl_malloc (nb_oiwave *
sizeof(
double));
1351 for (cpl_size iw = 0 ; iw < nb_oiwave ; iw ++)
1354 double l0=cpl_table_get (oiwave_tables[pol],
"EFF_WAVE", iw, NULL);
1360 if (iw == 0)
id[iw] = 1;
1361 else id[iw] =
id[iw-1];
1362 while ( (1./l0 < 1./wave_ref[
id[iw]]) && (
id[iw] < nb_wave-1 ) ){
1368 double xm=l0/wave_ref[
id[iw]-1]-1.;
1369 double xp=l0/wave_ref[
id[iw]]-1.;
1377 Fm=cpl_array_get (flat,
id[iw]-1, NULL);
1378 Fp=cpl_array_get (flat,
id[iw], NULL);
1388 if ( (Fp>1e-4) && (Fm>1e-4) && (xm>=0.0) && (xp<=0.0) )
1406 norm = weight_m[iw]+ weight_p[iw];
1423 for (cpl_size j = 0; j < nb_row; j++){
1429 yref = cpl_array_get_data_double (inputData[j]);
1431 for (cpl_size iw=0 ; iw < nb_oiwave ; iw ++) {
1432 outputData[iw]=yref[
id[iw]-1]*weight_m[iw] + yref[
id[iw]]*weight_p[iw];
1435 for (cpl_size iw = 0 ; iw < nb_oiwave ; iw ++){
1436 yref[iw]=outputData[iw];
1442 yref = cpl_array_get_data_double (inputErr[j]);
1444 for (cpl_size iw=0 ; iw < nb_oiwave ; iw ++) {
1445 outputErr[iw]=sqrt(pow(yref[
id[iw]-1]*weight_m[iw],2) + pow(yref[
id[iw]]*weight_p[iw],2));
1448 for (cpl_size iw = 0 ; iw < nb_oiwave ; iw ++){
1449 yref[iw]=outputErr[iw];
1454 FREE (cpl_free, weight_m);
1455 FREE (cpl_free, weight_p);
1461 if (nb_wave > nb_oiwave) {
1462 cpl_msg_debug (cpl_func,
"Modify depth of column %s (%lld->%lld)", data_x, nb_wave, nb_oiwave);
1463 cpl_table_set_column_depth (spectrum_table, data_x, nb_oiwave);
1464 cpl_table_set_column_depth (spectrum_table, data_errx, nb_oiwave);
1473 FREE (cpl_free, yout);
1474 FREE (cpl_free, xout);
1477 FREE (cpl_free,
id);
1478 FREE (cpl_free, outputData);
1479 FREE (cpl_free, outputErr);
1483 return CPL_ERROR_NONE;
1519 cpl_ensure_code (spectrum_data, CPL_ERROR_NULL_INPUT);
1520 cpl_ensure_code (wave_map, CPL_ERROR_NULL_INPUT);
1521 cpl_ensure_code (p2vm_map, CPL_ERROR_NULL_INPUT);
1526 CPLCHECK_MSG (
"Cannot copy OI_WAVELENGTH extention(s)");
1529 int init_type_data = 1;
1530 int end_type_data = 1;
1537 for (
int type_data = init_type_data; type_data <= end_type_data; type_data++ ) {
1549 cpl_table * spectrum_table, * wave_table, * detector_table;
1554 cpl_table * specflat_table;
1558 specflat_table = NULL;
1578 FREE (cpl_free, oiwave_tables);
1589 cpl_propertylist_erase (spectrum_plist,
PROFILE_NX);
1590 cpl_propertylist_update_int (spectrum_plist,
"NWAVE", nwave);
1594 cpl_msg_info (cpl_func,
"Total flux in REGION1s: %.2e [e], in REGION0s:%.2e [e] (ratio=%.5f)",
1595 full_flux_reg1,full_flux_reg0,full_flux_reg1/full_flux_reg0);
1599 sprintf (qc_name,
"ESO QC TRANS INTERP %s",
GRAVI_TYPE(type_data));
1601 cpl_propertylist_set_comment (spectrum_header, qc_name,
"[e/e] at interpolation");
1607 return CPL_ERROR_NONE;
#define gravi_table_get_value(table, name, row, value)
typedefCPL_BEGIN_DECLS struct _gravi_data_ gravi_data
#define gravi_data_get_spectrum_data(data, type)
#define gravi_data_is_internal(data)
#define gravi_data_get_wave_data(data, type)
#define gravi_data_get_spectrum_data_plist(data, type)
#define gravi_data_get_header(data)
#define gravi_data_has_spectrum(data, type)
#define gravi_data_has_detector(data, type)
#define gravi_data_get_imaging_detector(data, type)
#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_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_IMAGING_DETECTOR_FT_EXT
#define GRAVI_SPECTRUMFLAT_DATA_SC_EXT
#define GRAVI_PROFILE_DATA_EXT
#define PROFILE_FULLSTARTX
#define GRAVI_IMAGING_DATA_FT_EXT
#define GRAVI_IMAGING_ERR_FT_EXT
#define GRAVI_IMAGING_DATA_SC_EXT
#define GRAVI_SPECTRUM_DATA_FT_EXT
#define GRAVI_IMAGING_ERR_SC_EXT
#define GRAVI_IMAGING_DETECTOR_SC_EXT
#define GRAVI_METROLOGY_EXT
#define GRAVI_OI_WAVELENGTH_EXT
#define GRAVI_SPECTRUM_DATA_SC_EXT
#define gravi_spectrum_get_npol(table)
#define gravi_msg_function_exit(flag)
#define FREE(function, variable)
#define CPLCHECK_NUL(msg)
#define gravi_msg_function_start(flag)
#define CPLCHECK_MSG(msg)
cpl_imagelist * gravi_imagelist_wrap_column(cpl_table *table_data, const char *data_x)
Wrap a column array of a table into an imagelist.
cpl_error_code gravi_imagelist_unwrap_images(cpl_imagelist *imglist)
Unwrap an imagelist an all its images.
cpl_propertylist * gravi_data_get_plist(gravi_data *self, const char *extname)
Get the propertylist from EXTNAME.
gravi_data * gravi_data_new(int nb_ext)
Create an empty gravi_data.
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_table ** gravi_data_get_oiwave_tables(gravi_data *data, int type_data, int npol)
Get pointer to the OI_WAVELENGTH tables of both polarisations.
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.
cpl_error_code gravi_data_copy_ext(gravi_data *output, gravi_data *input, const char *name)
Copy extensions from one data to another.
int gravi_param_get_bool(const cpl_parameterlist *parlist, const char *name)
int gravi_param_get_int_default(const cpl_parameterlist *parlist, const char *name, int def)
int gravi_pfits_get_startx(const cpl_propertylist *plist)
find out the name of the propertylist
const char * gravi_pfits_get_pola_mode(const cpl_propertylist *plist, int type_data)
cpl_error_code gravi_pfits_add_check(cpl_propertylist *header, const char *msg)
Add a QC.CHECK keyword to the header.
const char * gravi_pfits_get_spec_res(const cpl_propertylist *plist)
double gravi_pfits_get_dit_sc(const cpl_propertylist *plist)
double gravi_pfits_get_ft_gain(const cpl_propertylist *plist)
FT system gain in [ADU/e].
double gravi_pfits_get_time_sc(const cpl_propertylist *header, cpl_size row)
Time of the middle of the SC exposure row in [us], counted from PRC.ACQ.START.
double gravi_pfits_get_sc_gain(const cpl_propertylist *plist)
SC system gain in [ADU/e].
int gravi_pixel_is_good(cpl_image *bad_img, int x, int y)
Check if the pixel in the BADPIX map is a good pixel.
cpl_error_code gravi_interpolate_spectrum_table(cpl_table *spectrum_table, cpl_table *wave_table, cpl_table **oiwave_tables, cpl_table *detector_table, cpl_table *specflat_table, int type_data)
Re-interpolate in-place a spectrum table.
cpl_error_code gravi_align_spectrum(gravi_data *spectrum_data, gravi_data *wave_map, gravi_data *p2vm_map, enum gravi_detector_type det_type)
Regrid the regions into a common wavelength (in-place)
cpl_error_code gravi_remove_badpixel_sc(cpl_imagelist *imglist_sc, cpl_image *bad_img)
Remove the badpixel of the SC.
gravi_data * gravi_extract_spectrum(gravi_data *raw_data, gravi_data *profile_map, gravi_data *dark_map, gravi_data *bad_map, gravi_data *sky_map, const cpl_parameterlist *parlist, enum gravi_detector_type det_type)
Create the SPECTRUM gravi_data with extracted spectrum per region.
cpl_table * gravi_table_ft_format(cpl_table *table_ft, cpl_table *sky_table_std, cpl_table *sky_table_avg, cpl_table *badft_table, int n_region, double gain, const cpl_parameterlist *parlist)
Extract FT spectrum from PIX column.
cpl_error_code gravi_subtract_met_dark(gravi_data *preproc_data, gravi_data *dark_map)
Substract metrology dark.
cpl_table * gravi_imglist_sc_collapse(cpl_table *profile_table, cpl_imagelist *raw_imglist, cpl_imagelist *rawVar_imglist, cpl_size startx)
Extract the SC spectrum with profile.
cpl_error_code gravi_msg_warning(const char *component, const char *msg)
int gravi_region_get_pol(cpl_table *imaging_detector, int region)
Return the polarisation id of a region.
double gravi_imagelist_get_flux(const cpl_imagelist *imglist)
Return the total flux in imagelist.
cpl_size gravi_spectrum_get_nwave(const cpl_table *table)
double gravi_spectrum_get_flux(const cpl_table *table)
Return the total flux in DATA# regions.
char GRAVI_DATAERR[50][10]
cpl_size gravi_spectrum_get_nregion(const cpl_table *table)