62#define GRAVI_DATA_SIZE 30
113 cpl_ensure (nb_ext==0, CPL_ERROR_ILLEGAL_INPUT, NULL);
116 self->primary_hdr = cpl_propertylist_new ();
117 self->extra_primary_hdr = cpl_propertylist_new ();
120 self->exts_hdrs = cpl_malloc (
GRAVI_DATA_SIZE *
sizeof(cpl_propertylist*));
122 self->exts_imgl = cpl_malloc (
GRAVI_DATA_SIZE *
sizeof(cpl_imagelist*));
125 self->exts_tbs[i] = NULL;
126 self->exts_hdrs[i] = NULL;
127 self->exts_imgl[i] = NULL;
152 FREE (cpl_propertylist_delete, self->primary_hdr);
158 if(self->extra_primary_hdr != NULL)
159 FREE (cpl_propertylist_delete, self->extra_primary_hdr);
161 FREE (cpl_free, self);
176 if (hdr==NULL) {
return 0; }
177 if (!cpl_propertylist_has (hdr,
"EXTNAME")) {
return 0; }
200 cpl_ensure_code (hdr, CPL_ERROR_NULL_INPUT);
201 cpl_ensure_code (oi_table, CPL_ERROR_NULL_INPUT);
206 if ( cpl_table_has_column (oi_table,
"FLAG") ) {
207 cpl_table_set_column_savetype(oi_table,
"FLAG", CPL_TYPE_BOOL);
209 if ( cpl_table_has_column (oi_table,
"VISREFMAP") ) {
210 cpl_table_set_column_savetype(oi_table,
"VISREFMAP", CPL_TYPE_BOOL);
212 if ( cpl_table_has_column (oi_table,
"STA_INDEX") ) {
213 cpl_table_set_column_savetype(oi_table,
"STA_INDEX", CPL_TYPE_SHORT);
216 if ( cpl_table_has_column (oi_table,
"TARGET_ID") ) {
217 cpl_table_set_column_savetype(oi_table,
"TARGET_ID", CPL_TYPE_SHORT);
220 if ( cpl_table_has_column (oi_table,
"MNT_STA") ) {
221 cpl_table_set_column_savetype(oi_table,
"MNT_STA", CPL_TYPE_SHORT);
225 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
226 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
227 "Cannot reinstall the savetypes");
228 return cpl_error_get_code();
231 return CPL_ERROR_NONE;
253 cpl_ensure (self, CPL_ERROR_NULL_INPUT, NULL);
256 copy->nb_ext = self->nb_ext;
258 if (self->primary_hdr) {
259 cpl_propertylist_delete (copy->primary_hdr);
260 copy->primary_hdr = cpl_propertylist_duplicate(self->primary_hdr);
262 cpl_msg_warning (cpl_func,
"a data without header shall not exist");
267 for (
int i = 0; i < copy->nb_ext ; i++){
268 if (self->exts_hdrs[i])
269 copy->exts_hdrs[i] = cpl_propertylist_duplicate(self->exts_hdrs[i]);
270 if (self->exts_tbs[i]) {
271 copy->exts_tbs[i] = cpl_table_duplicate(self->exts_tbs[i]);
274 if (self->exts_imgl[i])
275 copy->exts_imgl[i] = cpl_imagelist_duplicate(self->exts_imgl[i]);
280 if (self->extra_primary_hdr) {
281 cpl_propertylist_delete (copy->extra_primary_hdr);
282 copy->extra_primary_hdr = cpl_propertylist_duplicate(self->extra_primary_hdr);
311 cpl_ensure_code (first, CPL_ERROR_NULL_INPUT);
312 cpl_ensure_code (second, CPL_ERROR_NULL_INPUT);
313 cpl_ensure_code (first->nb_ext > 1, CPL_ERROR_INCOMPATIBLE_INPUT);
314 cpl_ensure_code (second->nb_ext > 1, CPL_ERROR_INCOMPATIBLE_INPUT);
316 cpl_msg_warning (cpl_func,
"Append data: keep only the HEADER of the first data");
317 cpl_msg_warning (cpl_func,
"Append data: FIXME: only works for OIFITS data");
319 cpl_size nb_ext = CPL_MIN(first->nb_ext, second->nb_ext);
320 for (
int i = 0; i < nb_ext ; i++) {
325 cpl_ensure_code (!strcmp (name1, name2), CPL_ERROR_INCOMPATIBLE_INPUT);
328 if ( !strcmp (name1,
"OI_WAVELENGTH") ||
329 !strcmp (name1,
"OI_TARGET") ||
330 !strcmp (name1,
"OI_ARRAY") ||
331 !strcmp (name1,
"IMAGING_DETECTOR_SC") ||
332 !strcmp (name1,
"IMAGING_DETECTOR_FT") ||
333 !strcmp (name1,
"ARRAY_DESCRIPTION") ||
334 !strcmp (name1,
"ARRAY_GEOMETRY") ||
335 !strcmp (name1,
"OPTICAL_TRAIN") ) {
343 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
"Tables %s are different", name1);
350 if ( first->exts_tbs[i] != NULL ) {
352 cpl_table_insert (first->exts_tbs[i], second->exts_tbs[i], CPL_SIZE_MAX);
359 if ( first->exts_imgl[i] != NULL ) {
361 cpl_size n_first = cpl_imagelist_get_size (first->exts_imgl[i]);
362 cpl_size n_second = cpl_imagelist_get_size (second->exts_imgl[i]);
365 for (cpl_size iimg = 0; iimg < n_second; iimg++) {
366 cpl_image * img = cpl_image_duplicate (cpl_imagelist_get (second->exts_imgl[i], iimg));
367 cpl_imagelist_set (first->exts_imgl[i], img, n_first + iimg);
378 for (
int i = nb_ext; i < second->nb_ext; i++)
384 return CPL_ERROR_NONE;
405 cpl_ensure (filename, CPL_ERROR_NULL_INPUT, NULL);
410 int nb_ext = cpl_fits_count_extensions (filename);
412 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
"no extension in this file");
420 cpl_propertylist *
header = cpl_propertylist_load (filename, 0);
421 cpl_propertylist_append (self->primary_hdr,
header);
425 for (
int i = 0; i < nb_ext ; i++ ){
428 self->exts_hdrs[i] = cpl_propertylist_load (filename, i+1);
433 self->exts_tbs[i] = cpl_table_load (filename, i+1, 0);
439 self->exts_imgl[i] = cpl_imagelist_load (filename,CPL_TYPE_DOUBLE,i+1);
444 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
"The dimension of the extension is wrong");
475 const char * extensions_regexp)
478 cpl_ensure (filename, CPL_ERROR_NULL_INPUT, NULL);
483 int nb_ext = cpl_fits_count_extensions (filename);
485 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
"no extension in this file");
493 cpl_propertylist *
header = cpl_propertylist_load (filename, 0);
494 cpl_propertylist_append (self->primary_hdr,
header);
499 int status = regcomp(&filter, extensions_regexp, REG_EXTENDED | REG_NOSUB);
501 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
502 "Cannot interpret extension regular expression");
508 for (
int i = 0; i < nb_ext ; i++ ){
511 cpl_propertylist *proplist = cpl_propertylist_load (filename, i+1);
512 const char *extname = cpl_propertylist_get_string (proplist,
"EXTNAME");
516 if (regexec(&filter, extname, 0, NULL, 0) == REG_NOMATCH)
518 cpl_propertylist_delete(proplist);
522 self->exts_hdrs[iext] = proplist;
526 self->exts_tbs[iext] = cpl_table_load (filename, i+1, 0);
532 self->exts_imgl[iext] = cpl_imagelist_load (filename,CPL_TYPE_DOUBLE,i+1);
537 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
"The dimension of the extension is wrong");
567 cpl_ensure_code (data, CPL_ERROR_NULL_INPUT);
568 cpl_errorstate prestate = cpl_errorstate_get();
576 if (cpl_errorstate_is_equal(prestate)) {
577 cpl_msg_info (cpl_func,
"(insmode: %s %s %s)", res, scpol, ftpol);
579 cpl_errorstate_set (prestate);
582 return CPL_ERROR_NONE;
600 cpl_frameset * used_frameset)
602 cpl_ensure (frame, CPL_ERROR_NULL_INPUT, NULL);
604 const char * filename = cpl_frame_get_filename (frame);
608 if (used_frameset) cpl_frameset_insert (used_frameset, cpl_frame_duplicate (frame));
636 cpl_frameset * patch_frameset)
638 cpl_ensure (file_to_patch, CPL_ERROR_NULL_INPUT, 0);
640 cpl_frame * patch_frame = NULL;
642 if ( !cpl_frameset_is_empty (patch_frameset) )
643 patch_frame = cpl_frameset_get_position(patch_frameset, 0);
646 const char * filename = cpl_frame_get_filename (patch_frame);
649 cpl_propertylist * plist_patch = cpl_propertylist_load (filename, 0);
654 for (
int i=0; i<cpl_propertylist_get_size(plist_patch); i++){
655 cpl_property * keyword = cpl_propertylist_get(plist_patch, i);
656 cpl_type type = cpl_property_get_type(keyword);
657 const char * p_name = cpl_property_get_name (keyword);
658 if ( (strstr(p_name,
" QC ") != NULL) ||
659 (strstr(p_name,
" TPL ") != NULL) ||
660 (strstr(p_name,
" OCS ") != NULL) ||
661 (strstr(p_name,
" OBS ") != NULL) ||
662 (strstr(p_name,
" MET ") != NULL) ||
663 (strstr(p_name,
" ISS ") != NULL) ||
664 (strstr(p_name,
" INS ") != NULL) ||
665 (strstr(p_name,
" FT ") != NULL) ||
666 (strstr(p_name,
" FDDL ") != NULL) ||
667 (strstr(p_name,
" ACQ ") != NULL) ) {
668 cpl_msg_info (cpl_func,
"Patch the keyword %s", p_name);
670 case CPL_TYPE_FLOAT :
671 cpl_propertylist_update_float(plist_file_to_patch, p_name, cpl_property_get_float(keyword));
673 case CPL_TYPE_DOUBLE :
677 cpl_propertylist_update_int(plist_file_to_patch, p_name, cpl_property_get_int(keyword));
679 case CPL_TYPE_STRING :
680 cpl_propertylist_update_string(plist_file_to_patch, p_name, cpl_property_get_string(keyword));
683 cpl_propertylist_update_char(plist_file_to_patch, p_name, cpl_property_get_char(keyword));
686 cpl_propertylist_update_bool(plist_file_to_patch, p_name, cpl_property_get_bool(keyword));
689 cpl_msg_error (cpl_func,
"'%s' is an invalid type of property",p_name);
690 cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
691 "invalid type of property");
696 FREE (cpl_propertylist_delete, plist_patch);
717 cpl_frameset * used_frameset)
719 cpl_ensure (frame, CPL_ERROR_NULL_INPUT, NULL);
721 const char * filename = cpl_frame_get_filename (frame);
724 if (used_frameset) cpl_frameset_insert (used_frameset, cpl_frame_duplicate (frame));
761 cpl_frameset * used_frameset,
762 const char * extensions_regexp)
764 cpl_ensure (frame, CPL_ERROR_NULL_INPUT, NULL);
766 const char * filename = cpl_frame_get_filename (frame);
769 if (used_frameset) cpl_frameset_insert (used_frameset, cpl_frame_duplicate (frame));
798 cpl_ensure_code (self, CPL_ERROR_NULL_INPUT);
802 cpl_msg_info (cpl_func,
"HEADER: %p", self->primary_hdr);
805 for (
int i=0; i<self->nb_ext; i++){
814 return CPL_ERROR_NONE;
830 cpl_ensure (self, CPL_ERROR_ILLEGAL_INPUT, 0L);
831 return (
int)self->nb_ext;
857 const char * filename,
860 cpl_ensure_code (self, CPL_ERROR_NULL_INPUT);
861 cpl_ensure_code (filename, CPL_ERROR_NULL_INPUT);
863 cpl_propertylist *prim_hdr = cpl_propertylist_duplicate(self->primary_hdr);
864 if(self->extra_primary_hdr != NULL)
865 cpl_propertylist_append(prim_hdr, self->extra_primary_hdr);
868 if (self->exts_tbs[0] != NULL)
870 self->exts_hdrs[0], filename, mode);
871 else if (self->exts_imgl[0] != NULL){
872 cpl_propertylist_save (prim_hdr, filename, mode);
873 cpl_imagelist_save (self->exts_imgl[0], filename,
874 CPL_TYPE_DOUBLE, self->exts_hdrs[0], CPL_IO_EXTEND);
877 cpl_error_set_message(cpl_func, CPL_ERROR_NULL_INPUT,
878 "one of the inputs at least is NULL");
879 return CPL_ERROR_NULL_INPUT;
884 for (
int i = 1; i < self->nb_ext; i++){
888 self->exts_hdrs[i], filename, CPL_IO_EXTEND);
890 cpl_imagelist_save (self->exts_imgl[i], filename,
891 CPL_TYPE_DOUBLE, self->exts_hdrs[i], CPL_IO_EXTEND);
893 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
894 "The dimension of the extension is wrong");
896 return CPL_ERROR_ILLEGAL_INPUT;
900 return CPL_ERROR_NONE;
926 cpl_frameset * allframes,
927 const char * filename,
929 const cpl_parameterlist * parlist,
930 cpl_frameset * usedframes,
933 cpl_propertylist * applist,
934 const char * proCatg)
937 cpl_ensure_code (filename || frame, CPL_ERROR_NULL_INPUT);
938 cpl_ensure_code (self, CPL_ERROR_NULL_INPUT);
939 cpl_ensure_code (proCatg, CPL_ERROR_NULL_INPUT);
941 cpl_frameset * frameset;
942 int ext, i = 0, j = 0;
946 if (applist == NULL) {
951 if(self->extra_primary_hdr != NULL)
952 cpl_propertylist_append(applist, self->extra_primary_hdr);
955 applist = cpl_propertylist_duplicate (applist);
959 cpl_propertylist_append_string (applist, CPL_DFS_PRO_CATG, proCatg);
968 if ( cpl_propertylist_has (hdr,
"DATE-OBS") ) {
969 cpl_propertylist_copy_property (applist, hdr,
"DATE-OBS");
974 if (strstr (proCatg,
"VIS") || strstr (proCatg,
"TF")) {
976 cpl_propertylist_append (applist, tmp);
977 FREE (cpl_propertylist_delete, tmp);
985 for(i = 0; proCatg[i]; i++)
if (proCatg[i]!=
'_') { catg_ext[j] = tolower(proCatg[i]); j++; }
990 if (filename == NULL && frame != NULL) {
991 filename = cpl_frame_get_filename (frame);
992 }
else if (filename == NULL && frame == NULL) {
993 cpl_error_set_message(cpl_func, CPL_ERROR_NULL_INPUT,
"Need a frame if filename is void");
994 return CPL_ERROR_NULL_INPUT;
998 char * product_name = NULL;
1000 if ( cpl_parameterlist_find_const (parlist,
"gravity.dfs.static-name") &&
1005 product_name = cpl_sprintf (
"%s_%s_%s.fits", recipe, catg_ext, suffix);
1007 product_name = cpl_sprintf (
"%s_%s.fits", recipe, catg_ext);
1012 char * filenoext = cpl_strdup (
FILESHORT(filename));
1013 char * lastdot = strrchr (filenoext,
'.');
1014 if (lastdot != NULL) *lastdot =
'\0';
1015 product_name = cpl_sprintf (
"%s_%s.fits", filenoext, catg_ext);
1016 FREE (cpl_free, filenoext);
1019 cpl_msg_info (cpl_func,
"Save file to %s", product_name);
1021 if (usedframes && frame==NULL) {
1023 frameset = cpl_frameset_duplicate (usedframes);
1025 else if (usedframes && frame) {
1028 frameset = cpl_frameset_new ();
1029 cpl_frameset_insert (frameset, cpl_frame_duplicate (frame));
1030 for (
int f = 0; f < cpl_frameset_get_size (usedframes); f++)
1031 if (strcmp (cpl_frame_get_filename (cpl_frameset_get_position (usedframes, f)), cpl_frame_get_filename (frame)))
1032 cpl_frameset_insert (frameset, cpl_frame_duplicate (cpl_frameset_get_position (usedframes, f)));
1034 else if (usedframes==NULL && frame) {
1036 frameset = cpl_frameset_new ();
1037 cpl_frameset_insert (frameset, cpl_frame_duplicate (frame));
1041 cpl_error_set_message(cpl_func, CPL_ERROR_NULL_INPUT,
"Bug: need a frame or a usedframes");
1042 return CPL_ERROR_NULL_INPUT;
1046 for (
int i = 0; i < cpl_propertylist_get_size(applist); i++) {
1047 cpl_property *p = cpl_propertylist_get(applist, i);
1048 if (cpl_property_get_type(p) == CPL_TYPE_FLOAT) {
1049 const char *name = cpl_property_get_name(p);
1050 const float value = cpl_property_get_float(p);
1051 if (!isfinite(value)) {
1052 cpl_msg_error(cpl_func,
"Card %s has invalid value %f", name, value);
1054 }
else if(cpl_property_get_type(p) == CPL_TYPE_DOUBLE) {
1055 const char *name = cpl_property_get_name(p);
1056 const double value = cpl_property_get_double(p);
1057 if (!isfinite(value)) {
1058 cpl_msg_error(cpl_func,
"Card %s has invalid value %f", name, value);
1064 cpl_dfs_save_propertylist (allframes, NULL, parlist,
1065 frameset, frame, recipe, applist,
1066 NULL, PACKAGE_STRING, product_name);
1067 CPLCHECK_MSG(
"Cannot save the first extension primary header");
1070 for (ext = 0; ext < self->nb_ext; ext ++)
1072 if (self->exts_tbs[ext] != NULL)
1074 self->exts_hdrs[ext], product_name, CPL_IO_EXTEND);
1075 else if (self->exts_imgl[ext] != NULL)
1076 cpl_imagelist_save (self->exts_imgl[ext], product_name,
1077 cpl_image_get_type (cpl_imagelist_get (self->exts_imgl[ext], 0)),
1078 self->exts_hdrs[ext], CPL_IO_EXTEND);
1082 FREE (cpl_frameset_delete, frameset);
1083 FREE (cpl_free, product_name);
1084 FREE (cpl_propertylist_delete, applist);
1087 return CPL_ERROR_NONE;
1104 cpl_ensure_code (detector_table, CPL_ERROR_NULL_INPUT);
1112 return (ref0_y+ref1_y)/2;
1132 cpl_size nx, cpl_size ny)
1135 cpl_ensure (detector_table, CPL_ERROR_NULL_INPUT, NULL);
1136 cpl_ensure (nx > 2, CPL_ERROR_ILLEGAL_INPUT, NULL);
1137 cpl_ensure (ny > 2, CPL_ERROR_ILLEGAL_INPUT, NULL);
1140 cpl_size nreg = cpl_table_get_nrow (detector_table);
1141 cpl_ensure (nreg == 24 || nreg == 48, CPL_ERROR_ILLEGAL_INPUT, NULL);
1144 cpl_mask * mask = cpl_mask_new (nx, ny);
1146 cpl_msg_info (cpl_func,
"Create mask with size nx = %lli, ny = %lli", nx, ny);
1150 cpl_size mindeg = 0, maxdeg, hw;
1151 if (nx < 150) {maxdeg = 0; hw = 4;}
1152 else if (nx < 400) {maxdeg = 0; hw = 4;}
1153 else {maxdeg = 2; hw = 6;}
1157 const char * names[] = {
"LEFT",
"HALFLEFT",
"CENTER",
"HALFRIGHT",
"RIGHT"};
1160 for (
int n = 0; n < nnames; n++) {
1162 if (cpl_table_has_column (detector_table, names[n]) == 0) {
1163 CPLCHECK_NUL (
"Missing LEFT,HALFLEFT,CENTER,HALFRIGHT,RIGHT "
1164 "column in detector table (old data?), use another bias-method");
1169 cpl_polynomial * fit = cpl_polynomial_new (1);
1170 cpl_matrix * xp = cpl_matrix_new (1,nnames);
1171 cpl_vector * yp = cpl_vector_new (nnames);
1174 for (cpl_size reg = 0; reg < nreg; reg++) {
1177 for (
int n = 0; n < nnames; n++) {
1180 cpl_matrix_set (xp, 0, n, x0);
1181 cpl_vector_set (yp, n, y0);
1186 cpl_polynomial_fit (fit, xp, NULL, yp, NULL, CPL_FALSE, &mindeg, &maxdeg);
1187 CPLCHECK_NUL (
"Cannot fit the expected position from table");
1191 for (cpl_size x = 0; x < nx ; x++) {
1192 cpl_size y0 = cpl_polynomial_eval_1d (fit, x, NULL);
1193 for (cpl_size y = y0-hw; y <= y0+hw; y++) {
1194 if ((y >= 0) && (y < ny))
1195 cpl_mask_set (mask, x+1, y+1, CPL_BINARY_1);
1202 FREE (cpl_polynomial_delete, fit);
1203 FREE (cpl_matrix_delete, xp);
1204 FREE (cpl_vector_delete, yp);
1233 const cpl_parameterlist * parlist)
1236 cpl_ensure_code (data, CPL_ERROR_NULL_INPUT);
1243 cpl_size nreg = cpl_table_get_nrow (detector_table);
1250 cpl_size nframe = cpl_imagelist_get_size (imglist);
1251 cpl_size nx = cpl_image_get_size_x (cpl_imagelist_get (imglist, 0));
1252 cpl_size ny = cpl_image_get_size_y (cpl_imagelist_get (imglist, 0));
1264 cpl_msg_info (cpl_func,
"Skip gravi_remove_cosmicrays_sc");
1268 cpl_vector * bias_list = cpl_vector_new (nframe);
1271 cpl_size nx_bias_hr = 4;
1272 cpl_size ny_reg_mr = (ny - 1) / nreg;
1273 cpl_size n_bias_line = 5;
1282 "gravity.preproc.bias-method",
"AUTO");
1290 if (cpl_table_has_column(detector_table,
"LEFT") )
1292 bias_method =
"MASKED_MEDIAN_PER_COLUMN";
1294 "Using MASKED_MEDIAN_PER_COLUMNM bias method");
1298 bias_method =
"MEDIAN";
1300 "Using MEDIAN bias method");
1303 if ( !strcmp (bias_method,
"MASKED_MEDIAN_PER_COLUMN")) {
1312 cpl_image * mask_img = cpl_image_new_from_mask (mask);
1316 for (cpl_size f = 0; f < nframe; f++) {
1317 cpl_image * frame = cpl_imagelist_get (imglist, f);
1333 cpl_mask * thismask = cpl_mask_duplicate (mask);
1334 cpl_mask * bpm = cpl_image_set_bpm (frame, thismask);
1335 FREE (cpl_mask_delete, bpm);
1338 cpl_image * collapse_y;
1339 collapse_y = cpl_image_collapse_median_create (frame, 0, 0, 0);
1343 thismask = cpl_image_set_bpm (frame, bpm);
1344 FREE (cpl_mask_delete, thismask);
1356 cpl_vector_set (bias_list, f, cpl_image_get_mean (collapse_y));
1365 FREE (cpl_mask_delete, mask);
1369 else if ( !strcmp(resolution,
"HIGH") && !strcmp (bias_method,
1370 "MEDIAN_PER_COLUMN")) {
1377 cpl_vector * bias = cpl_vector_new (nx);
1378 cpl_vector * bias_column = cpl_vector_new (n_bias_line*2);
1381 for (cpl_size f = 0; f < nframe; f++) {
1382 cpl_image * frame = cpl_imagelist_get (imglist, f);
1385 for (cpl_size x = 0; x < nx; x++) {
1386 cpl_size bias_index=0;
1389 for (cpl_size y = 0; y < n_bias_line; y++) {
1390 double value = cpl_image_get (frame, x+1, y+1, &nv);
1391 cpl_vector_set (bias_column, bias_index++, value);
1396 for (cpl_size y = 0; y < n_bias_line; y++) {
1397 double value = cpl_image_get (frame, x+1, ny-y, &nv);
1398 cpl_vector_set (bias_column, bias_index++, value);
1403 double bias_med = cpl_vector_get_median (bias_column);
1404 cpl_vector_set (bias, x, bias_med);
1407 for (cpl_size y = 0; y < ny; y++) {
1408 double value = cpl_image_get (frame, x+1, y+1, &nv);
1409 cpl_image_set (frame, x+1, y+1, value - bias_med);
1415 double bias_mean = cpl_vector_get_mean (bias);
1416 cpl_vector_set (bias_list, f, bias_mean);
1418 FREE (cpl_vector_delete, bias);
1419 FREE (cpl_vector_delete, bias_column);
1423 else if ( !strcmp(resolution,
"HIGH") ) {
1428 cpl_vector * bias = cpl_vector_new (nx_bias_hr * ny);
1431 for (cpl_size f = 0; f < nframe; f++) {
1432 cpl_image * frame = cpl_imagelist_get (imglist, f);
1435 for (cpl_size x = 0; x < nx_bias_hr; x++)
1436 for (cpl_size y = 0; y < ny; y++) {
1437 cpl_vector_set (bias, x * ny + y, cpl_image_get (frame, x+1, y+1, &nv));
1442 double bias_med = cpl_vector_get_median (bias);
1443 cpl_vector_set (bias_list, f, bias_med);
1444 cpl_image_subtract_scalar (frame, bias_med);
1447 FREE (cpl_vector_delete, bias);
1451 else if ( !strcmp (bias_method,
1452 "MEDIAN_PER_COLUMN")) {
1457 gravi_msg_warning (
"FIXME",
"Remove bias per column is experimental (LOW, MEDIUM)");
1459 cpl_vector * bias = cpl_vector_new (nx);
1461 cpl_vector * bias_column = cpl_vector_new ((nreg-1)*n_bias_line);
1462 cpl_vector * bias_coord = cpl_vector_new ((nreg-1)*n_bias_line);
1465 for (cpl_size f = 0; f < nframe; f++) {
1466 cpl_image * frame = cpl_imagelist_get (imglist, f);
1469 for (cpl_size x = 0; x < nx; x++) {
1470 cpl_size bias_index=0;
1480 for (cpl_size reg = 0; reg < nreg-1; reg++) {
1482 for (cpl_size y = 0; y < n_bias_line; y++){
1483 double value = cpl_image_get (frame, x+1, starty+y+1, &nv);
1484 cpl_vector_set (bias_column, bias_index, value);
1485 cpl_vector_set (bias_coord, bias_index++, starty+y);
1492 cpl_vector_set (bias, x, bias_med);
1495 for (cpl_size y = 0; y < ny; y++) {
1496 double value = cpl_image_get (frame, x+1, y+1, &nv);
1497 cpl_image_set (frame, x+1, y+1, value - bias_med);
1503 double bias_mean = cpl_vector_get_mean (bias);
1504 cpl_vector_set (bias_list, f, bias_mean);
1506 FREE (cpl_vector_delete, bias);
1507 FREE (cpl_vector_delete, bias_column);
1515 cpl_vector * bias = cpl_vector_new (nx * nreg);
1518 for (cpl_size f = 0; f < nframe; f++) {
1519 cpl_image * frame = cpl_imagelist_get (imglist, f);
1522 for (cpl_size x = 0; x < nx; x++)
1523 for (cpl_size y = 0; y < nreg; y++) {
1524 cpl_vector_set (bias, x * nreg + y, cpl_image_get (frame, x+1, (y+1)*ny_reg_mr+1, &nv));
1529 double bias_med = cpl_vector_get_median (bias);
1530 cpl_vector_set (bias_list, f, bias_med);
1531 cpl_image_subtract_scalar (frame, bias_med);
1534 FREE (cpl_vector_delete, bias);
1545 cpl_propertylist_set_comment (
header,
"ESO QC PIXBIAS AVG",
"[adu] avg over the bias pixel");
1548 cpl_propertylist_set_comment (
header,
"ESO QC PIXBIAS RMS",
"[adu] rms over frames");
1549 cpl_vector_delete (bias_list);
1552 return CPL_ERROR_NONE;
1561 while (ext < self->nb_ext){
1562 cpl_propertylist *p = self->exts_hdrs[ext];
1563 const char *key = cpl_propertylist_get_string (p,
"EXTNAME");
1564 if (strcmp(key, name) == 0)
break;
1590 const char * insname)
1592 cpl_ensure_code (output, CPL_ERROR_NULL_INPUT);
1593 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1594 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
1595 cpl_ensure_code (insname, CPL_ERROR_NULL_INPUT);
1598 for (
int j = 0; j < n; j++){
1602 if (!cpl_propertylist_has (
plist,
"EXTNAME"))
continue;
1603 if (!cpl_propertylist_has (
plist,
"INSNAME"))
continue;
1610 if (plist_name == NULL)
continue;
1612 if (!(strcmp (plist_name, name)) &&
1613 !(strcmp (plist_insname, insname))) {
1616 if (type_data == 2) {
1620 else if (type_data == 3) {
1629 return CPL_ERROR_NONE;
1651 cpl_ensure_code (output, CPL_ERROR_NULL_INPUT);
1652 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1653 cpl_ensure_code (num>=0, CPL_ERROR_ILLEGAL_INPUT);
1654 cpl_ensure_code (num<input->nb_ext, CPL_ERROR_ILLEGAL_INPUT);
1664 else if (type_data == 3)
1672 return CPL_ERROR_NONE;
1694 cpl_ensure_code (output, CPL_ERROR_NULL_INPUT);
1695 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1696 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
1699 for (
int j = 0; j < n; j++){
1706 if (plist_name == NULL)
continue;
1708 if (!(strcmp (plist_name, name))) {
1711 if (type_data == 2) {
1715 else if (type_data == 3) {
1724 return CPL_ERROR_NONE;
1746 cpl_ensure_code (output, CPL_ERROR_NULL_INPUT);
1747 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1748 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
1753 for (
int j = 0; j < n; j++){
1760 if ( (plist_name!=NULL) &&
1761 !(strcmp (plist_name, name))) {
1763 cpl_msg_info (cpl_func,
"Move extension %s", plist_name);
1765 if (type_data == 2) {
1769 else if (type_data == 3) {
1778 input->exts_hdrs[jnew] = input->exts_hdrs[j];
1779 input->exts_imgl[jnew] = input->exts_imgl[j];
1780 input->exts_tbs[jnew] = input->exts_tbs[j];
1787 input->nb_ext = jnew;
1789 input->exts_hdrs[j] = NULL;
1790 input->exts_imgl[j] = NULL;
1791 input->exts_tbs[j] = NULL;
1795 return CPL_ERROR_NONE;
1810 cpl_ensure (raw_calib, CPL_ERROR_NULL_INPUT, 0);
1811 cpl_ensure (ext_name, CPL_ERROR_NULL_INPUT, 0);
1816 if (ext == raw_calib->nb_ext) {
1835 cpl_ensure (self, CPL_ERROR_NULL_INPUT, -1);
1836 cpl_ensure (type, CPL_ERROR_NULL_INPUT, -1);
1837 cpl_ensure (strlen (type)>1, CPL_ERROR_ILLEGAL_INPUT, -1);
1848 if ( (cpl_propertylist_has (
plist,
"INSNAME") &&
1850 (cpl_propertylist_has (
plist,
"EXTNAME") &&
1878 cpl_ensure (self, CPL_ERROR_NULL_INPUT, NULL);
1879 cpl_ensure (i>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
1880 cpl_ensure (i<self->nb_ext, CPL_ERROR_ILLEGAL_INPUT, NULL);
1882 return self->exts_hdrs[i];
1903 cpl_ensure (self, CPL_ERROR_NULL_INPUT, NULL);
1904 cpl_ensure (i>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
1905 cpl_ensure (i<self->nb_ext, CPL_ERROR_ILLEGAL_INPUT, NULL);
1907 return self->exts_tbs[i];
1928 cpl_ensure (self, CPL_ERROR_NULL_INPUT, NULL);
1929 cpl_ensure (i>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
1930 cpl_ensure (i<self->nb_ext, CPL_ERROR_ILLEGAL_INPUT, NULL);
1932 return self->exts_imgl[i];
1953 const char * extname,
1954 const char * insname)
1956 cpl_ensure (self, CPL_ERROR_NULL_INPUT, NULL);
1957 cpl_ensure (extname, CPL_ERROR_NULL_INPUT, NULL);
1958 cpl_ensure (insname, CPL_ERROR_NULL_INPUT, NULL);
1960 int nb_ext = self->nb_ext;
1962 for (
int i = 0; i < nb_ext; i++){
1964 if (cpl_propertylist_has (self->exts_hdrs[i],
"INSNAME")){
1974 cpl_msg_warning(cpl_func,
"The extention %s doesn't exist "
1975 "with the insname %s",
1980 return self->exts_tbs[pos];
2002 const char * extname,
2003 const char * insname)
2005 cpl_ensure (self, CPL_ERROR_NULL_INPUT, NULL);
2006 cpl_ensure (extname, CPL_ERROR_NULL_INPUT, NULL);
2007 cpl_ensure (insname, CPL_ERROR_NULL_INPUT, NULL);
2009 int nb_ext = self->nb_ext;
2011 for (
int i = 0; i < nb_ext; i++){
2012 if (cpl_propertylist_has (self->exts_hdrs[i],
"INSNAME")){
2022 cpl_msg_warning(cpl_func,
"The extention %s doesn't exist "
2023 "with the insname %s",
2028 return self->exts_hdrs[pos];
2050 const char * extname)
2052 cpl_ensure (self, CPL_ERROR_NULL_INPUT, NULL);
2053 cpl_ensure (extname, CPL_ERROR_NULL_INPUT, NULL);
2056 return self->primary_hdr;
2060 cpl_ensure (pos<self->nb_ext, CPL_ERROR_ILLEGAL_INPUT, NULL);
2062 return self->exts_hdrs[pos];
2076 cpl_ensure (self, CPL_ERROR_NULL_INPUT, NULL);
2077 return self->extra_primary_hdr;
2098 cpl_ensure (self, CPL_ERROR_NULL_INPUT, NULL);
2099 cpl_ensure (extname, CPL_ERROR_NULL_INPUT, NULL);
2103 cpl_ensure (pos<self->nb_ext, CPL_ERROR_ILLEGAL_INPUT, NULL);
2105 if ((self->exts_tbs[pos] == NULL) ||
2107 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
2108 "No BINTABLE at the extension %s", extname);
2112 return self->exts_tbs[pos];
2133 cpl_ensure (self, CPL_ERROR_NULL_INPUT, NULL);
2134 cpl_ensure (extname, CPL_ERROR_NULL_INPUT, NULL);
2138 cpl_ensure (pos<self->nb_ext, CPL_ERROR_ILLEGAL_INPUT, NULL);
2140 if ((self->exts_imgl[pos] == NULL) ||
2142 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
2143 "No IMAGE at the extension %s", extname);
2147 return self->exts_imgl[pos];
2163 cpl_ensure_code (self, CPL_ERROR_NULL_INPUT);
2164 cpl_ensure_code (pos>-1, CPL_ERROR_ILLEGAL_INPUT);
2168 for (
int i = 0; i < self->nb_ext; i++) {
2170 self->exts_hdrs[comp] = self->exts_hdrs[i];
2171 self->exts_tbs[comp] = self->exts_tbs[i];
2172 self->exts_imgl[comp] = self->exts_imgl[i];
2177 FREE (cpl_table_delete, self->exts_tbs[i]);
2179 FREE (cpl_imagelist_delete, self->exts_imgl[i]);
2182 FREE (cpl_propertylist_delete, self->exts_hdrs[i]);
2189 self->exts_hdrs[i] = NULL;
2190 self->exts_tbs[i] = NULL;
2191 self->exts_imgl[i] = NULL;
2195 self->nb_ext = comp;
2197 return CPL_ERROR_NONE;
2214 cpl_ensure_code (self, CPL_ERROR_NULL_INPUT);
2215 cpl_ensure_code (extname, CPL_ERROR_NULL_INPUT);
2221 if (pos == self->nb_ext) {
2222 cpl_msg_info (cpl_func,
"Cannot delete '%s' (not found)",extname);
2223 return CPL_ERROR_NONE;
2225 cpl_msg_info (cpl_func,
"Delete '%s' found in ext[%i] (over %i) ",extname, pos, self->nb_ext);
2232 return CPL_ERROR_NONE;
2249 cpl_ensure_code (self, CPL_ERROR_NULL_INPUT);
2250 cpl_ensure_code (type, CPL_ERROR_NULL_INPUT);
2251 cpl_ensure_code (strlen (type)>1, CPL_ERROR_ILLEGAL_INPUT);
2260 if ( (cpl_propertylist_has (
plist,
"INSNAME") &&
2262 (cpl_propertylist_has (
plist,
"EXTNAME") &&
2272 return CPL_ERROR_NONE;
2290 cpl_propertylist *
plist,
2291 const char * extname,
2294 cpl_ensure_code (self, CPL_ERROR_NULL_INPUT);
2295 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
2298 if (
plist == NULL)
plist = cpl_propertylist_new ();
2299 if (extname != NULL) cpl_propertylist_update_string (
plist,
"EXTNAME", extname);
2302 cpl_propertylist_update_string (
plist,
"XTENSION",
"BINTABLE");
2303 self->exts_hdrs[self->nb_ext] =
plist;
2306 if (!cpl_propertylist_has(
plist,
"EXTNAME") ) {
2307 cpl_msg_error (cpl_func,
"FIXME: set a table without EXTNAME !!");
2308 cpl_propertylist_update_string (
plist,
"EXTNAME",
"UNKNOWN");
2312 const char * plist_name = 0;
2313 if (cpl_propertylist_has (
plist,
"EXTNAME"))
2322 cpl_propertylist_update_int (
plist,
"OI_REVN", 2);
2325 cpl_propertylist_update_int (
plist,
"OI_REVN", 1);
2330 self->exts_tbs[self->nb_ext] = table;
2331 self->exts_imgl[self->nb_ext] = NULL;
2336 return CPL_ERROR_NONE;
2354 cpl_propertylist *
plist,
2355 const char * extname,
2356 cpl_imagelist * imglist)
2359 cpl_ensure_code (self, CPL_ERROR_NULL_INPUT);
2360 cpl_ensure_code (imglist, CPL_ERROR_NULL_INPUT);
2362 if (
plist == NULL)
plist = cpl_propertylist_new ();
2363 if (extname != NULL) cpl_propertylist_update_string (
plist,
"EXTNAME", extname);
2366 self->exts_hdrs[self->nb_ext] =
plist;
2367 cpl_propertylist_update_string (self->exts_hdrs[self->nb_ext],
"XTENSION",
"IMAGE");
2370 self->exts_imgl[self->nb_ext] = (imglist);
2371 self->exts_tbs[self->nb_ext] = NULL;
2376 return CPL_ERROR_NONE;
2395 cpl_propertylist *
plist,
2396 const char * extname,
2397 cpl_image * image) {
2399 cpl_ensure_code (self, CPL_ERROR_NULL_INPUT);
2400 cpl_ensure_code (image, CPL_ERROR_NULL_INPUT);
2402 if (
plist == NULL)
plist = cpl_propertylist_new ();
2403 if (extname != NULL) cpl_propertylist_update_string (
plist,
"EXTNAME", extname);
2406 self->exts_hdrs[self->nb_ext] =
plist;
2407 cpl_propertylist_update_string (self->exts_hdrs[self->nb_ext],
"XTENSION",
"IMAGE");
2410 cpl_imagelist * imglist = cpl_imagelist_new ();
2411 cpl_imagelist_set (imglist, image, 0);
2414 self->exts_imgl[self->nb_ext] = (imglist);
2415 self->exts_tbs[self->nb_ext] = NULL;
2420 return CPL_ERROR_NONE;
2438 cpl_ensure_code (data, CPL_ERROR_NULL_INPUT);
2440 cpl_table * new_oimet_table;
2457 if (cpl_propertylist_has (
plist,
"INSNAME") &&
2472 cpl_size length = cpl_table_get_nrow (old_oimet_table);
2473 new_oimet_table = cpl_table_new(length);
2477 const char *names[] = {
"TIME",
"PHASE_FC_DRS",
"PHASE_TELFC_CORR",
"OPD_TELFC_CORR_XY",
"OPD_FC_CORR",
"OPD_TELFC_MCORR"};
2478 for (
int j =0; j<nb_names;j++)
2480 cpl_msg_info(cpl_func,
"duplicating columns %s",names[j]);
2481 cpl_table_duplicate_column (new_oimet_table, names[j], old_oimet_table, names[j]);
2482 CPLCHECK_MSG (
"Failed at duplicating column to new OI_VIS_MET table");
2488 FREE (cpl_propertylist_delete, data->exts_hdrs[i]);
2489 FREE (cpl_table_delete, data->exts_tbs[i]);
2490 FREE (cpl_imagelist_delete, data->exts_imgl[i]);
2494 if (new_oimet_table != NULL)
2502 if (data->exts_hdrs[i] || data->exts_tbs[i] || data->exts_imgl[i]) {
2504 data->exts_hdrs[j] = data->exts_hdrs[i]; data->exts_hdrs[i] = NULL;
2505 data->exts_tbs[j] = data->exts_tbs[i]; data->exts_tbs[i] = NULL;
2506 data->exts_imgl[j] = data->exts_imgl[i]; data->exts_imgl[i] = NULL;
2515 return CPL_ERROR_NONE;
2534 cpl_ensure_code (data, CPL_ERROR_NULL_INPUT);
2540 cpl_propertylist_append_int (
header,
"ESO QC CHECK FLAGS", 0);
2544 const char *extname[] = {
"ARRAY_DESCRIPTION",
"ARRAY_GEOMETRY",
"OPTICAL_TRAIN",
2545 "IMAGING_DATA_ACQ",
"ACQ_ABS_REF_POSITION",
2546 "OPDC",
"FDDL",
"METROLOGY",
2547 "IMAGING_DATA_SC",
"IMAGING_DETECTOR_SC",
2548 "IMAGING_DATA_FT",
"IMAGING_DETECTOR_FT"};
2550 for (
int ext = 0; ext< nb_ext; ext++) {
2554 sprintf (qc_msg,
"%s is missing", extname[ext]);
2559 cpl_propertylist *
plist;
2563 if (cpl_propertylist_has (
plist,
"ESO DET FRAM NO")) {
2564 int frame_no = cpl_propertylist_get_int (
plist,
"ESO DET FRAM NO");
2565 int naxis_3 = cpl_propertylist_get_int (
plist,
"NAXIS3");
2566 if ( frame_no != naxis_3) {
2567 sprintf (qc_msg,
"%s is missing DITs", extname[ext]);
2573 CPLCHECK_MSG (
"Cannot check consistency of tables...");
2580 int ndit = cpl_propertylist_get_int (
header,
"ESO DET2 NDIT");
2585 cpl_msg_debug (cpl_func,
"start = %8.0f and end = %10.0f (%s [us] from PCR.ACQ.START)",
2586 start_sc, end_sc,
"SC");
2590 const char *ext_rmn[] = {
"OPDC",
"FDDL",
"METROLOGY",
"IMAGING_DATA_FT"};
2592 for (
int ext = 0; ext< nb_ext_rmn; ext++) {
2599 double min_table = cpl_table_get_column_min (table,
"TIME");
2600 double max_table = cpl_table_get_column_max (table,
"TIME");
2602 cpl_msg_debug (cpl_func,
"start = %8.0f and end = %10.0f (%s [us] from PCR.ACQ.START)",
2603 min_table, max_table, ext_rmn[ext]);
2606 if ( min_table > start_sc) {
2607 sprintf (qc_msg,
"%s starts *after* the science exposure", ext_rmn[ext]);
2610 if ( max_table < end_sc) {
2611 sprintf (qc_msg,
"%s finish *before* the science exposure", ext_rmn[ext]);
2616 cpl_size nrow = cpl_table_get_nrow (table);
2617 int * time = cpl_table_get_data_int (table,
"TIME");
2621 cpl_size nsamp = CPL_MIN (10000, nrow-1);
2622 cpl_array * delta = cpl_array_new (nsamp, CPL_TYPE_INT);
2623 for (cpl_size row = 0; row < nsamp ; row++) {
2624 cpl_array_set_int (delta, row, time[row+1] - time[row]);
2626 double median_delta = cpl_array_get_median (delta);
2627 FREE (cpl_array_delete, delta);
2631 int nwrong_warning = 0;
2632 if (!strcmp (ext_rmn[ext],
"OPDC")) nwrong_warning = 2;
2633 for (cpl_size row = 0; row < nrow-1 ; row++) {
2634 double current_delta = time[row+1] - time[row];
2635 if (current_delta > 1.5 * median_delta) nwrong ++;
2637 if (nwrong > nwrong_warning) {
2638 sprintf (qc_msg,
"%s has %i wrong steps", ext_rmn[ext], nwrong);
2644 CPLCHECK_MSG (
"Cannot check consistency of RMN tables...");
2647 return CPL_ERROR_NONE;
2666 cpl_ensure (data, CPL_ERROR_NULL_INPUT, NULL);
2667 cpl_ensure (npol == 1 || npol == 2, CPL_ERROR_ILLEGAL_INPUT, NULL);
2668 cpl_ensure (type_data ==
GRAVI_SC || type_data ==
GRAVI_FT, CPL_ERROR_ILLEGAL_INPUT, NULL);
2670 cpl_table ** oiwave_tables = cpl_calloc (npol,
sizeof(cpl_table *));
2671 for (
int pol = 0; pol < npol; pol++)
2674 return oiwave_tables;
#define GRAVI_PRIMARY_HDR_EXT
#define gravi_table_get_value(table, name, row, value)
typedefCPL_BEGIN_DECLS struct _gravi_data_ gravi_data
#define gravi_data_get_header(data)
#define gravi_data_get_oi_wave(data, type, pol, npol)
#define gravi_data_get_qc(data)
cpl_table_save(vis_met, NULL, NULL, "vismet.fits", CPL_IO_CREATE)
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_VIS2_EXT
#define GRAVI_OI_VIS_ACQ_EXT
#define GRAVI_OI_VIS_MET_EXT
#define GRAVI_OI_TARGET_EXT
#define GRAVI_OI_ARRAY_EXT
#define GRAVI_OI_FLUX_EXT
#define GRAVI_IMAGING_DATA_SC_EXT
#define GRAVI_IMAGING_DETECTOR_SC_EXT
#define GRAVI_OI_WAVELENGTH_EXT
#define CPLCHECK_INT(msg)
#define gravi_msg_function_exit(flag)
#define FREE(function, variable)
#define CPLCHECK_NUL(msg)
#define gravi_msg_function_start(flag)
#define CPLCHECK_MSG(msg)
#define FREELOOP(function, variable, n)
cpl_error_code gravi_image_subtract_collapse(cpl_image *img, const cpl_image *collapse, int direction)
double gravi_vector_get_mean_clip(cpl_vector *vector_in, double percent, double nsigma)
Return the mean of a vector after extrema and RMS clipping.
int gravi_table_are_equal(cpl_table *first, cpl_table *second)
Check if two tables have the same content.
int gravi_data_patch(gravi_data *file_to_patch, cpl_frameset *patch_frameset)
Load a RAW FITS file and create a gravi_data.
cpl_error_code gravi_data_erase(gravi_data *self, const char *extname)
Erase an extension by its EXTNAME.
cpl_propertylist * gravi_data_get_oi_plist(gravi_data *self, const char *extname, const char *insname)
Get the propertylist from EXTNAME and INSNAME.
gravi_data * gravi_data_duplicate(const gravi_data *self)
Create a copy of the gravi data.
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.
int gravi_data_get_dark_pos(cpl_table *detector_table, int reg)
retrun the position of the dark line on top of the region at x position
cpl_mask * gravi_data_create_bias_mask(cpl_table *detector_table, cpl_size nx, cpl_size ny)
return a mask with pixel to be possibly illuminated
cpl_imagelist * gravi_data_get_cube_x(gravi_data *self, int i)
Get the cube of an extension by position.
cpl_propertylist * gravi_data_get_extra_primary_header(gravi_data *self)
Get the propertylist for additional keywords to the primary header.
gravi_data * gravi_data_load_ext(const char *filename, const char *extensions_regexp)
Low-level function to load FITS file.
gravi_data * gravi_data_load(const char *filename)
Low-level function to load FITS file.
cpl_error_code gravi_data_clean_for_astro(gravi_data *data)
Clean the data to keep only OIFITS extensions related to SC.
cpl_propertylist * gravi_data_get_plist(gravi_data *self, const char *extname)
Get the propertylist from EXTNAME.
cpl_error_code gravi_data_check_savetypes(cpl_propertylist *hdr, cpl_table *oi_table)
Set the savetypes of the OIFITS table.
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.
static int _gravi_data_find(const gravi_data *self, const char *name)
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_error_code gravi_data_erase_type(gravi_data *self, const char *type)
Erase all extension related to an instrument (SC, FT, MET...)
cpl_error_code gravi_data_copy_ext_i(gravi_data *output, gravi_data *input, cpl_size num)
Copy extensions from one data to another.
gravi_data * gravi_data_load_frame(cpl_frame *frame, cpl_frameset *used_frameset)
Load a FITS file and create a gravi_data.
cpl_error_code gravi_data_detector_cleanup(gravi_data *data, const cpl_parameterlist *parlist)
Perform self-bias correction to the SC raw 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_error_code gravi_data_dump_mode(gravi_data *data)
Dump some information about data in messagin.
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.
int gravi_data_is_oi_ext(cpl_propertylist *hdr)
Check if EXTNAME starts with 'OI_' (OIFITS extension)
int gravi_data_has_type(gravi_data *self, const char *type)
Return the number of ext whose EXTNAME and INSNAME match 'type'.
cpl_error_code gravi_data_save_data(gravi_data *self, const char *filename, unsigned mode)
Save a gravi data in a FITS file.
cpl_table * gravi_data_get_table(gravi_data *self, const char *extname)
Return a pointer on a table extension by its EXTNAME.
cpl_table * gravi_data_get_oi_table(gravi_data *self, const char *extname, const char *insname)
Get an OI_FITS table from EXTNAME and INSNAME.
cpl_error_code gravi_remove_cosmicrays_sc(cpl_imagelist *imglist_sc)
Remove cosmic rays via filtering through images.
gravi_data * gravi_data_load_rawframe(cpl_frame *frame, cpl_frameset *used_frameset)
Load a RAW FITS file and create a gravi_data.
cpl_error_code gravi_data_move_ext(gravi_data *output, gravi_data *input, const char *name)
Move extensions from one data to another.
cpl_error_code gravi_data_erase_x(gravi_data *self, int pos)
Erase an extension by its position.
cpl_error_code gravi_data_append(gravi_data *first, const gravi_data *second, int force)
Append a gravi_data into another existing one.
cpl_error_code gravi_data_save_new(gravi_data *self, cpl_frameset *allframes, const char *filename, const char *suffix, const cpl_parameterlist *parlist, cpl_frameset *usedframes, cpl_frame *frame, const char *recipe, cpl_propertylist *applist, const char *proCatg)
Save a gravi data in a CPL-complian FITS file.
cpl_propertylist * gravi_data_get_plist_x(gravi_data *self, int i)
Get the propertylist of an extension by position.
int gravi_data_get_size(const gravi_data *self)
Get the number of extension in a gravi_data.
cpl_error_code gravi_data_copy_ext(gravi_data *output, gravi_data *input, const char *name)
Copy extensions from one data to another.
cpl_error_code gravi_data_dump(gravi_data *self)
Dump the overall structure of a gravi_data in stdout.
cpl_error_code gravi_data_copy_ext_insname(gravi_data *output, gravi_data *input, const char *name, const char *insname)
Copy extensions from one data to another.
gravi_data * gravi_data_load_rawframe_ext(cpl_frame *frame, cpl_frameset *used_frameset, const char *extensions_regexp)
Load a RAW FITS file and create a gravi_data from specified extensions.
cpl_error_code gravi_data_check_consistency(gravi_data *data)
Verify the integrity of RAW data.
cpl_table * gravi_data_get_table_x(gravi_data *self, int i)
Get the table of an extension by position.
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
int gravi_param_get_bool(const cpl_parameterlist *parlist, const char *name)
int gravi_param_get_bool_default(const cpl_parameterlist *parlist, const char *name, int def)
const char * gravi_param_get_string_default(const cpl_parameterlist *parlist, const char *name, const char *def)
const char * gravi_pfits_get_insname(const cpl_propertylist *plist)
cpl_propertylist * gravi_plist_get_oifits_keywords(cpl_propertylist *header)
Create OIFITS keywords to satisfy standar.
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.
int gravi_pfits_get_extension_type(const cpl_propertylist *plist)
const char * gravi_pfits_get_spec_res(const cpl_propertylist *plist)
double gravi_pfits_get_dit_sc(const cpl_propertylist *plist)
const char * gravi_pfits_get_resolution(const cpl_propertylist *plist)
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.
cpl_error_code gravi_pfits_add_pipe_build(cpl_propertylist *header)
Add the ESO PRO REC# PIPE LAST_BUILD in header.
const char * gravi_pfits_get_extname(const cpl_propertylist *plist)
cpl_error_code gravi_msg_warning(const char *component, const char *msg)
cpl_propertylist * extra_primary_hdr
cpl_propertylist ** exts_hdrs
cpl_propertylist * primary_hdr
cpl_imagelist ** exts_imgl