49#include "irplib_utils.h"
50#include "irplib_hist.h"
133 int (*
load_fset) (
const cpl_frameset *, cpl_type, cpl_imagelist *);
134 cpl_imagelist * (* load_fset_wrp) (
const cpl_frameset *, cpl_type, int);
151 const char *,
const cpl_parameterlist *,
159 const char *,
const char * );
163 const cpl_frameset *,
164 int* index_on,
int* index_off,
165 double* exptime_on,
double* exptime_off,
166 int *next_index_on,
int* next_index_off,
180 const cpl_boolean,
int);
188 const cpl_imagelist *,
189 const cpl_imagelist *,
197 double c_dit,
int c_ndit,
198 cpl_imagelist * autocorr_images,
199 cpl_imagelist * diff_flats,
200 const cpl_imagelist * ons,
201 const cpl_imagelist * offs,
202 double kappa,
int nclip,
207 const int pos,
unsigned mode,
int* rows_affected);
212 cpl_imagelist * diff_flats,
213 const cpl_imagelist * ons,
214 const cpl_imagelist * offs,
215 double kappa,
int nclip,
218 const int pos,
unsigned mode,
219 int* rows_linear_affected);
227 const cpl_propertylist *,
228 const cpl_propertylist *,
229 const cpl_propertylist *,
230 const cpl_propertylist *,
231 const cpl_propertylist *,
232 const cpl_propertylist *,
244 const int,
const int,
const cpl_frameset *,
249 cpl_propertylist *,
unsigned,
int);
253 cpl_propertylist *,
int);
263 const char* prop_name);
266 cpl_boolean,
const double,
int *);
270 cpl_image **,
int,
int);
276 const cpl_imagelist *,
277 unsigned mode, cpl_propertylist *);
280xsh_detmon_opt_lampcr(cpl_frameset *,
int);
294 const cpl_imagelist *,
295 const cpl_table *,
int, cpl_boolean);
315 const cpl_frameset *,
321 int* index_on,
double* exptime_on,
324 const cpl_frameset * set_off,
325 int * index_off,
double* exptime_off,
326 int* next_on,
int* next_off,
327 cpl_table * linear_table,
328 cpl_table * gain_table,
329 cpl_imagelist * linearity_inputs,
330 cpl_propertylist * qclist,
332 cpl_imagelist * autocorr_images,
333 cpl_imagelist * diff_flats,
334 cpl_imagelist * opt_offs,
336 int * rows_linear_affected,
337 int * rows_gain_affected);
341 cpl_frameset * cur_fset_off,
345 double * exptime_off,
348 const char * recipe_name,
349 const char * pipeline_name,
350 const char * pafregexp,
351 const cpl_propertylist * pro_lintbl,
352 const cpl_propertylist * pro_gaintbl,
353 const cpl_propertylist * pro_coeffscube,
354 const cpl_propertylist * pro_bpm,
355 const cpl_propertylist * pro_corr,
356 const cpl_propertylist * pro_diff,
357 const char * package,
361 int nsets, cpl_boolean
opt_nir,
362 cpl_frameset * frameset,
const cpl_parameterlist * parlist,
363 cpl_frameset * cur_fset);
388 const cpl_vector * vec_ndits,
390 cpl_vector** diff_dits,
391 cpl_vector** diff_ndits);
396 int last_linear_best,
397 cpl_propertylist *lint_qclist,
406static double irplib_fpn_lg(
const cpl_image* f1,
int* range,
double gain,
411 cpl_type,
int whichext);
416 cpl_propertylist* plist);
418 cpl_propertylist* plist,
428 cpl_frameset ** pair,
435 cpl_frameset ** pair);
455 return cpl_propertylist_get_int(plist,
"ESO DET NDIT");
484 const double ron, cpl_image ** ima_errs)
486 cpl_ensure_code(ima_data, CPL_ERROR_NULL_INPUT);
487 cpl_ensure_code(ima_errs, CPL_ERROR_NULL_INPUT);
488 cpl_ensure_code(gain > 0., CPL_ERROR_ILLEGAL_INPUT);
489 cpl_ensure_code(ron > 0., CPL_ERROR_ILLEGAL_INPUT);
491 *ima_errs = cpl_image_duplicate(ima_data);
493 cpl_image_threshold(*ima_errs, 0., INFINITY, ron, ron);
497 cpl_image_divide_scalar(*ima_errs, gain);
498 cpl_image_add_scalar(*ima_errs, ron * ron);
499 cpl_image_power(*ima_errs, 0.5);
501 return cpl_error_get_code();
510 const char * tag_off,
511 const char * recipe_name,
512 const char * pipeline_name,
513 const char * pafregexp,
514 const cpl_propertylist * pro_lintbl,
515 const cpl_propertylist * pro_gaintbl,
516 const cpl_propertylist * pro_coeffscube,
517 const cpl_propertylist * pro_bpm,
518 const cpl_propertylist * pro_corr,
519 const cpl_propertylist * pro_diff,
520 const char * package,
522 (
const cpl_frameset *, cpl_type, cpl_imagelist *),
524 const cpl_parameterlist * parlist,
531 const cpl_parameterlist * parlist,
532 const cpl_frameset *usedframes,
533 const cpl_imagelist *coeffs,
534 const char *recipe_name,
535 const cpl_propertylist *mypro_coeffscube,
536 const char * package,
537 const char * name_o);
542 if(pointer && *pointer) {
551 const char * tag_off,
552 const char * recipe_name,
553 const char * pipeline_name,
554 const char * pafregexp,
555 const cpl_propertylist * pro_lintbl,
556 const cpl_propertylist * pro_gaintbl,
557 const cpl_propertylist * pro_coeffscube,
558 const cpl_propertylist * pro_bpm,
559 const cpl_propertylist * pro_corr,
560 const cpl_propertylist * pro_diff,
561 const char * package,
563 (
const cpl_frameset *, cpl_type, cpl_imagelist *),
565 const cpl_parameterlist * parlist,
572 double* exptime_on = 0;
573 double* exptime_off = 0;
576 cpl_frameset * cur_fset = NULL;
577 cpl_frameset* cur_fset_on = 0;
578 cpl_frameset* cur_fset_off = 0;
583 cpl_frameset_duplicate(frameset) : cpl_frameset_extract(frameset, selection, i);
586 skip_if(cur_fset == NULL);
589 cur_fset_on = cpl_frameset_new();
590 cur_fset_off = cpl_frameset_new();
591 cpl_msg_info(cpl_func,
"Splitting into ON and OFF sub-framesets");
593 cur_fset_on, cur_fset_off,
595 if (cpl_frameset_get_size(cur_fset_on) == 0)
597 cpl_msg_error(cpl_func,
"No lamp frames in input");
601 if (cpl_frameset_get_size(cur_fset_off) == 0)
603 cpl_msg_error(cpl_func,
"No dark / bias frames in input");
606 cpl_msg_info(cpl_func,
"found on-frames[%" CPL_SIZE_FORMAT
"] off-frames[%" CPL_SIZE_FORMAT
"]",cpl_frameset_get_size(cur_fset_on), cpl_frameset_get_size(cur_fset_off));
614 exptime_on = cpl_malloc(
sizeof(
double)*cpl_frameset_get_size(cur_fset_on));
615 exptime_off = cpl_malloc(
sizeof(
double)*cpl_frameset_get_size(cur_fset_off));
617 index_on = cpl_malloc(
sizeof(
int)*cpl_frameset_get_size(cur_fset_on));
618 index_off = cpl_malloc(
sizeof(
int)*cpl_frameset_get_size(cur_fset_off));
619 irplib_frameset_sort(cur_fset_on, index_on, exptime_on);
620 irplib_frameset_sort(cur_fset_off, index_off, exptime_off);
644 skip_if(xsh_detmon_opt_lampcr(cur_fset, 0));
654 recipe_name, pipeline_name, pafregexp,
655 pro_lintbl, pro_gaintbl, pro_coeffscube, pro_bpm, pro_corr, pro_diff,
658 for(j = 1; j <= nexts; j++) {
666 skip_if(xsh_detmon_opt_lampcr(cur_fset, j));
675 j, i, recipe_name, pipeline_name,pafregexp, pro_lintbl, pro_gaintbl, pro_coeffscube, pro_bpm, pro_corr, pro_diff, package,
load_fset, nsets,
opt_nir, frameset, parlist, cur_fset));
680 cpl_frameset_delete(cur_fset);
681 cpl_frameset_delete(cur_fset_on);
682 cpl_frameset_delete(cur_fset_off);
685 cpl_free(exptime_on);
686 cpl_free(exptime_off);
687 return cpl_error_get_code();
766 const cpl_parameterlist * parlist,
768 const char * tag_off,
769 const char * recipe_name,
770 const char * pipeline_name,
771 const char * pafregexp,
772 const cpl_propertylist * pro_lintbl,
773 const cpl_propertylist * pro_gaintbl,
774 const cpl_propertylist * pro_coeffscube,
775 const cpl_propertylist * pro_bpm,
776 const cpl_propertylist * pro_corr,
777 const cpl_propertylist * pro_diff,
778 const char * package,
779 int (* compare) (
const cpl_frame *,
786 cpl_errorstate cleanstate = cpl_errorstate_get();
788 cpl_size * selection = NULL;
789 cpl_frame *
first = NULL;
790 cpl_image * reference = NULL;
797 cpl_frameset * cur_fset = NULL;
798 cpl_frameset * cur_fset_on = NULL;
799 cpl_frameset * cur_fset_off = NULL;
802 cpl_ensure_code(frameset != NULL, CPL_ERROR_NULL_INPUT);
803 cpl_ensure_code(parlist != NULL, CPL_ERROR_NULL_INPUT);
804 cpl_ensure_code(tag_on != NULL, CPL_ERROR_NULL_INPUT);
805 cpl_ensure_code(tag_off != NULL, CPL_ERROR_NULL_INPUT);
806 cpl_ensure_code(recipe_name != NULL, CPL_ERROR_NULL_INPUT);
807 cpl_ensure_code(pipeline_name != NULL, CPL_ERROR_NULL_INPUT);
808 cpl_ensure_code(pro_lintbl != NULL, CPL_ERROR_NULL_INPUT);
809 cpl_ensure_code(pro_gaintbl != NULL, CPL_ERROR_NULL_INPUT);
810 cpl_ensure_code(pro_coeffscube != NULL, CPL_ERROR_NULL_INPUT);
811 cpl_ensure_code(pro_bpm != NULL, CPL_ERROR_NULL_INPUT);
812 cpl_ensure_code(pro_corr != NULL, CPL_ERROR_NULL_INPUT);
813 cpl_ensure_code(pro_diff != NULL, CPL_ERROR_NULL_INPUT);
814 cpl_ensure_code(package != NULL, CPL_ERROR_NULL_INPUT);
816 cpl_msg_info(cpl_func,
"frameset size [%" CPL_SIZE_FORMAT
"]", cpl_frameset_get_size(frameset));
834 first = cpl_frameset_get_position(frameset, 0);
835 irplib_ensure (
first != NULL, CPL_ERROR_ILLEGAL_INPUT,
"Empty data set! Provide %s and %s input frames",tag_on,tag_off);
846 reference = cpl_image_load(cpl_frame_get_filename(
first),
847 CPL_TYPE_FLOAT, 0, i);
848 if (reference == NULL) {
849 cpl_msg_warning(cpl_func,
"Extension %d empty, skipping", i);
850 cpl_errorstate_set(cleanstate);
854 cpl_errorstate_set(cleanstate);
855 irplib_ensure (reference != NULL, CPL_ERROR_ILLEGAL_INPUT,
856 "No data found in any extension");
857 cpl_msg_info(cpl_func,
"Using extension %d as reference", i - 1);
860 cpl_frameset *
new = cpl_frameset_new();
861 cpl_imagelist * p = cpl_imagelist_new();
862 cpl_frameset_insert(
new, cpl_frame_duplicate(
first));
863 (*load_fset)(
new, CPL_TYPE_FLOAT, p);
864 reference = cpl_image_duplicate(cpl_imagelist_get(p, 0));
865 cpl_imagelist_delete(p);
866 cpl_frameset_delete(
new);
868 cpl_msg_info(cpl_func,
"name=%s",cpl_frame_get_filename(
first));
869 reference = cpl_image_load(cpl_frame_get_filename(
first),
872 cpl_errorstate_set(cleanstate);
873 irplib_ensure (reference != NULL, CPL_ERROR_ILLEGAL_INPUT,
874 "No data found in requested extension %d",
877 skip_if (reference == NULL);
888 if (compare == NULL) {
891 cpl_msg_info(cpl_func,
"Identifying different settings");
892 selection = cpl_frameset_labelise(frameset, compare, &nsets);
893 skip_if (selection == NULL);
897 for(
int i = 0; i < nsets; i++)
899 int fr_size = cpl_frameset_get_size(frameset);
901 cpl_msg_info(cpl_func,
"Reduce data set nb %d out of %" CPL_SIZE_FORMAT
"",
918 fr_size_new = cpl_frameset_get_size(frameset);
924 if (fr_size_new > fr_size)
926 selection = cpl_realloc(selection, fr_size_new *
sizeof(selection[0]));
927 memset(selection + fr_size, -1, (fr_size_new - fr_size) *
sizeof(selection[0]));
933 cpl_frameset_delete(cur_fset);
934 cpl_frameset_delete(cur_fset_on);
935 cpl_frameset_delete(cur_fset_off);
937 cpl_image_delete(reference);
939 return cpl_error_get_code();
977 cpl_frameset * cur_fset_off,
981 double * exptime_off,
984 const char * recipe_name,
985 const char * pipeline_name,
986 const char * pafregexp,
987 const cpl_propertylist * pro_lintbl,
988 const cpl_propertylist * pro_gaintbl,
989 const cpl_propertylist * pro_coeffscube,
990 const cpl_propertylist * pro_bpm,
991 const cpl_propertylist * pro_corr,
992 const cpl_propertylist * pro_diff,
993 const char * package,
997 int nsets, cpl_boolean
opt_nir,
998 cpl_frameset * frameset,
const cpl_parameterlist * parlist,
999 cpl_frameset * cur_fset)
1001 cpl_table * gain_table = cpl_table_new(
1002 cpl_frameset_get_size(cur_fset_on) / 2);
1003 cpl_table * linear_table = cpl_table_new(
1004 cpl_frameset_get_size(cur_fset_on) / 2);
1005 cpl_imagelist * coeffs = NULL;
1006 cpl_image * bpm = NULL;
1007 cpl_imagelist * autocorr_images = NULL;
1008 cpl_imagelist * diff_flats = NULL;
1009 cpl_propertylist * gaint_qclist = NULL;
1010 cpl_propertylist * lint_qclist = NULL;
1011 cpl_propertylist * linc_qclist = NULL;
1012 cpl_propertylist * bpm_qclist = NULL;
1014 int next_index_on = 0;
1015 int next_index_off = 0;
1018 cpl_msg_info(cpl_func,
"Reduce extension nb %d ", whichext);
1023 autocorr_images = cpl_imagelist_new();
1024 diff_flats = cpl_imagelist_new();
1027 gaint_qclist = cpl_propertylist_new();
1028 lint_qclist = cpl_propertylist_new();
1029 linc_qclist = cpl_propertylist_new();
1030 bpm_qclist = cpl_propertylist_new();
1033 cpl_msg_info(cpl_func,
"Starting data reduction");
1035 index_on, index_off, exptime_on, exptime_off,
1036 &next_index_on, &next_index_off,
1037 &coeffs, gain_table,
1038 linear_table, &bpm, autocorr_images,
1039 diff_flats, gaint_qclist, lint_qclist,
1041 opt_nir, whichext) == CPL_ERROR_CONTINUE) {
1042 cpl_msg_info(cpl_func,
"Empty extension %d", whichext);
1044 if(cpl_table_has_column(linear_table,
"ESO DET WIN1 UIT1") ) {
1045 cpl_table_name_column(linear_table,
"ESO DET WIN1 UIT1",
"ESO_DET_WIN1_UIT1" );
1047 if(cpl_table_has_column(linear_table,
"ESO DET WIN1 UIT1") ) {
1048 cpl_table_name_column(gain_table,
"ESO DET WIN1 UIT1",
"ESO_DET_WIN1_UIT1" );
1051 cpl_msg_info(cpl_func,
"Saving the products");
1055 pipeline_name, pafregexp,
1056 pro_lintbl, pro_gaintbl,
1057 pro_coeffscube, pro_bpm,
1058 pro_corr, pro_diff, package,
1059 coeffs, gain_table, linear_table,
1060 bpm, autocorr_images, diff_flats,
1061 gaint_qclist, lint_qclist, linc_qclist,
1062 bpm_qclist, 0, 0, cur_fset, whichext));
1066 pipeline_name, pafregexp,
1067 pro_lintbl, pro_gaintbl,
1068 pro_coeffscube, pro_bpm,
1069 pro_corr, pro_diff, package,
1070 coeffs, gain_table, linear_table,
1071 bpm, autocorr_images, diff_flats,
1072 gaint_qclist, lint_qclist, linc_qclist,
1073 bpm_qclist, 1, whichset+ 1, cur_fset,
1081 cpl_table_delete(gain_table);
1082 cpl_table_delete(linear_table);
1083 cpl_imagelist_delete(coeffs);
1084 cpl_propertylist_delete(gaint_qclist);
1085 cpl_propertylist_delete(lint_qclist);
1086 cpl_propertylist_delete(linc_qclist);
1087 if(bpm_qclist != NULL) cpl_propertylist_delete(bpm_qclist);
1088 cpl_image_delete(bpm);
1089 cpl_imagelist_delete(autocorr_images);
1090 cpl_imagelist_delete(diff_flats);
1092 return cpl_error_get_code();
1118 const cpl_image * image2,
1119 const int m,
const int n)
1121 cpl_image *image1_padded = NULL;
1122 cpl_image *image2_padded = NULL;
1126 cpl_image *corr_image_window = NULL;
1128 cpl_image* image_ri1 = NULL;
1129 cpl_image* image_ri2 = NULL;
1130 cpl_error_code err = CPL_ERROR_NONE;
1133 cpl_ensure(image1 != NULL, CPL_ERROR_NULL_INPUT, NULL);
1134 cpl_ensure(image2 != NULL, CPL_ERROR_NULL_INPUT, NULL);
1136 cpl_ensure(
m > 0, CPL_ERROR_NULL_INPUT, NULL);
1137 cpl_ensure(
n > 0, CPL_ERROR_NULL_INPUT, NULL);
1139 nx = cpl_image_get_size_x(image1);
1140 ny = cpl_image_get_size_y(image1);
1142 nx2 = cpl_image_get_size_x(image2);
1143 ny2 = cpl_image_get_size_y(image2);
1146 cpl_ensure(
nx == nx2 &&
ny == ny2, CPL_ERROR_ILLEGAL_INPUT, NULL);
1149 image1_padded = cpl_image_new(
nx + 2 *
m,
ny + 2 *
n, CPL_TYPE_FLOAT);
1150 cpl_image_copy(image1_padded, image1,
m + 1,
n + 1);
1152 image2_padded = cpl_image_new(
nx + 2 *
m,
ny + 2 *
n, CPL_TYPE_FLOAT);
1153 cpl_image_copy(image2_padded, image2,
m + 1,
n + 1);
1159 image_ri1 = cpl_image_new(
nx,
ny, CPL_TYPE_FLOAT_COMPLEX);
1160 image_ri2 = cpl_image_new(
nx,
ny , CPL_TYPE_FLOAT_COMPLEX);
1162 cpl_fft_image(image_ri1, image1_padded, CPL_FFT_FORWARD);
1163 cpl_fft_image(image_ri2, image2_padded, CPL_FFT_FORWARD);
1164 err = cpl_error_get_code();
1165 cpl_image_delete(image1_padded);
1166 image1_padded = NULL;
1167 cpl_image_delete(image2_padded);
1168 image2_padded = NULL;
1169 if (err == CPL_ERROR_NONE)
1172 cpl_image * corr_image = NULL;
1173 cpl_image * reorganised= NULL;
1174 cpl_image * image_ri_inv = cpl_image_new(
nx,
ny, CPL_TYPE_FLOAT);
1175 cpl_image * image_in_inv = cpl_image_new(
nx,
ny,
1176 CPL_TYPE_FLOAT_COMPLEX);
1179 for (i = 1; i <=
nx; i++)
1181 for (j = 1; j <=
ny; j++)
1184 double complex value1, value2, value;
1185 value1 = cpl_image_get_complex(image_ri1, i, j, &rej);
1186 value2 = cpl_image_get_complex(image_ri2, i, j, &rej);;
1187 value = conj(value1) * value2;
1188 cpl_image_set_complex(image_in_inv, i, j, value);
1191 cpl_image_delete(image_ri1);
1193 cpl_image_delete(image_ri2);
1196 err = cpl_error_get_code();
1197 if (err == CPL_ERROR_NONE)
1201 cpl_fft_image(image_ri_inv, image_in_inv,CPL_FFT_BACKWARD);
1202 cpl_image_delete(image_in_inv);
1205 corr_image = cpl_image_new(
nx,
ny, CPL_TYPE_FLOAT);
1206 for (i = 1; i <=
nx; i++)
1208 for (j = 1; j <=
ny; j++)
1212 value = cpl_image_get(image_ri_inv, i, j, &rej);
1213 cpl_image_set(corr_image, i, j, value);
1216 cpl_image_delete(image_ri_inv);
1217 err = cpl_error_get_code();
1218 if (err == CPL_ERROR_NONE)
1222 cpl_image_extract(corr_image,
nx / 2 + 1, 1,
nx,
ny);
1223 reorganised = cpl_image_new(
nx,
ny, CPL_TYPE_FLOAT);
1225 cpl_image_copy(reorganised, image, 1, 1);
1226 cpl_image_delete(image);
1227 image = cpl_image_extract(corr_image, 1, 1,
nx / 2,
ny);
1228 cpl_image_copy(reorganised, image,
nx / 2 + 1, 1);
1229 cpl_image_delete(image);
1231 cpl_image_delete(corr_image);
1233 corr_image = cpl_image_new(
nx,
ny, CPL_TYPE_FLOAT);
1234 image = cpl_image_extract(reorganised, 1,
ny / 2 + 1,
nx,
ny);
1235 cpl_image_copy(corr_image, image, 1, 1);
1236 cpl_image_delete(image);
1238 image = cpl_image_extract(reorganised, 1, 1,
nx,
ny / 2);
1239 cpl_image_copy(corr_image, image, 1,
ny / 2 + 1);
1240 cpl_image_delete(image);
1242 corr_image_window = cpl_image_extract(corr_image,
1245 nx / 2 + 1 +
m,
ny / 2 + 1 +
n);
1250 cpl_image_delete(reorganised);
1251 cpl_image_delete(corr_image);
1253 if(cpl_image_divide_scalar(corr_image_window,
1254 cpl_image_get_max(corr_image_window))) {
1255 cpl_image_delete(corr_image_window);
1259 cpl_image_delete (image_ri1);
1260 cpl_image_delete (image_ri2);
1261 cpl_image_delete (image1_padded);
1262 cpl_image_delete (image2_padded);
1263 return corr_image_window;
1289 cpl_image *im_re = NULL;
1290 cpl_image *im_im = NULL;
1292 cpl_image *ifft_re = NULL;
1293 cpl_image *ifft_im = NULL;
1295 cpl_image *autocorr_norm_double = NULL;
1296 cpl_image *autocorr_norm = NULL;
1297 cpl_image *reorganised = NULL;
1298 cpl_image *image = NULL;
1300 cpl_error_code error;
1303 cpl_ensure(input2 != NULL, CPL_ERROR_NULL_INPUT, NULL);
1305 cpl_ensure(
m > 0, CPL_ERROR_NULL_INPUT, NULL);
1306 cpl_ensure(
n > 0, CPL_ERROR_NULL_INPUT, NULL);
1308 nx = cpl_image_get_size_x(input2) + 2 *
m;
1309 ny = cpl_image_get_size_y(input2) + 2 *
n;
1312 while(
nx > p ||
ny > p) {
1316 input = cpl_image_cast(input2, CPL_TYPE_DOUBLE);
1318 im_re = cpl_image_new(p, p, CPL_TYPE_DOUBLE);
1319 error = cpl_image_copy(im_re, input, 1, 1);
1320 cpl_image_delete(input);
1322 cpl_ensure(!error, error, NULL);
1324 im_im = cpl_image_new(p, p, CPL_TYPE_DOUBLE);
1326 error = cpl_image_fft(im_re, im_im, CPL_FFT_DEFAULT);
1327 cpl_ensure(!error, error, NULL);
1329 ifft_re = cpl_image_new(p, p, CPL_TYPE_DOUBLE);
1330 error = cpl_image_power(im_re, 2);
1331 cpl_ensure(!error, error, NULL);
1333 error = cpl_image_add(ifft_re, im_re);
1334 cpl_ensure(!error, error, NULL);
1336 cpl_image_delete(im_re);
1338 error = cpl_image_power(im_im, 2);
1339 cpl_ensure(!error, error, NULL);
1341 error = cpl_image_add(ifft_re, im_im);
1342 cpl_ensure(!error, error, NULL);
1344 cpl_image_delete(im_im);
1346 ifft_im = cpl_image_new(p, p, CPL_TYPE_DOUBLE);
1348 error = cpl_image_fft(ifft_re, ifft_im, CPL_FFT_INVERSE);
1349 cpl_ensure(!error, error, NULL);
1351 autocorr = cpl_image_new(p, p, CPL_TYPE_DOUBLE);
1353 error = cpl_image_power(ifft_re, 2);
1354 cpl_ensure(!error, error, NULL);
1356 error = cpl_image_add(
autocorr, ifft_re);
1357 cpl_ensure(!error, error, NULL);
1359 cpl_image_delete(ifft_re);
1361 error = cpl_image_power(ifft_im, 2);
1362 cpl_ensure(!error, error, NULL);
1364 error = cpl_image_add(
autocorr, ifft_im);
1365 cpl_ensure(!error, error, NULL);
1367 cpl_image_delete(ifft_im);
1370 reorganised = cpl_image_new(p, p, CPL_TYPE_DOUBLE);
1372 image = cpl_image_extract(
autocorr, p / 2 + 1, 1, p, p);
1373 cpl_image_copy(reorganised, image, 1, 1);
1374 cpl_image_delete(image);
1376 image = cpl_image_extract(
autocorr, 1, 1, p / 2, p);
1377 cpl_image_copy(reorganised, image, p / 2 + 1, 1);
1378 cpl_image_delete(image);
1382 autocorr = cpl_image_new(p, p, CPL_TYPE_DOUBLE);
1384 image = cpl_image_extract(reorganised, 1, p / 2 + 1, p, p);
1385 cpl_image_copy(
autocorr, image, 1, 1);
1386 cpl_image_delete(image);
1388 image = cpl_image_extract(reorganised, 1, 1, p, p / 2);
1389 cpl_image_copy(
autocorr, image, 1, p / 2 + 1);
1390 cpl_image_delete(image);
1392 cpl_image_delete(reorganised);
1394 autocorr_norm_double =
1395 cpl_image_extract(
autocorr, p / 2 + 1 -
m, p / 2 + 1 -
n,
1396 p / 2 + 1 +
m, p / 2 + 1 +
n);
1400 if(cpl_image_divide_scalar(autocorr_norm_double,
1401 cpl_image_get_max(autocorr_norm_double))) {
1402 cpl_image_delete(autocorr_norm_double);
1403 cpl_ensure(0, cpl_error_get_code(), NULL);
1407 autocorr_norm = cpl_image_cast(autocorr_norm_double, CPL_TYPE_FLOAT);
1408 cpl_image_delete(autocorr_norm_double);
1410 return autocorr_norm;
1427 const char *recipe_name,
1428 const char *pipeline_name)
1430 const cpl_error_code error =
1477 cpl_ensure_code(!error, error);
1479 return cpl_error_get_code();
1496 const char *recipe_name,
1497 const char *pipeline_name)
1499 const cpl_error_code error =
1545 cpl_ensure_code(!error, error);
1547 return cpl_error_get_code();
1552 const char *recipe_name,
1553 const char *pipeline_name)
1555 char * group_name = cpl_sprintf(
"%s.%s", pipeline_name, recipe_name);
1556 char * par_name = cpl_sprintf(
"%s.%s", group_name,
"regions-file");
1557 cpl_parameter * p = cpl_parameter_new_value(par_name, CPL_TYPE_STRING,
1558 "File containing regions, "
1559 "four comma separated points "
1562 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"regions-file");
1563 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
1564 cpl_parameterlist_append(parlist, p);
1566 cpl_free(group_name);
1568 group_name = cpl_sprintf(
"%s.%s", pipeline_name, recipe_name);
1569 par_name = cpl_sprintf(
"%s.%s", group_name,
"regions");
1570 p = cpl_parameter_new_value(par_name, CPL_TYPE_STRING,
1571 "Colon separated list of regions, four "
1572 "points each, comma separated: "
1573 "llx,lly,urx,ury:llx,...",
1575 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"regions");
1576 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
1577 cpl_parameterlist_append(parlist, p);
1579 cpl_free(group_name);
1581 return cpl_error_get_code();
1586 const char *recipe_name,
1587 const char *pipeline_name)
1591 return cpl_error_get_code();
1596 const char *recipe_name,
1597 const char *pipeline_name)
1602 return cpl_error_get_code();
1663 const char *recipe_name,
const char *pipeline_name,
1704 const cpl_error_code error =
1707 "Method to be used when computing GAIN. Methods appliable: <PTC | MED>. By default PTC method will be applied.",
1708 "CPL_TYPE_STRING",
method,
1711 "Polynomial order for the fit (Linearity)",
1712 "CPL_TYPE_INT",
order,
1714 "Kappa value for the kappa-sigma clipping (Gain)",
1715 "CPL_TYPE_DOUBLE",
kappa,
1717 "Number of iterations to compute rms (Gain)",
1718 "CPL_TYPE_INT",
niter,
1720 "x coordinate of the lower-left "
1721 "point of the region of interest. If not modified, default value will be 1.",
1722 "CPL_TYPE_INT",
llx,
1724 "y coordinate of the lower-left "
1725 "point of the region of interest. If not modified, default value will be 1.",
1726 "CPL_TYPE_INT",
lly,
1728 "x coordinate of the upper-right "
1729 "point of the region of interest. If not modified, default value will be X dimension of the input image.",
1730 "CPL_TYPE_INT",
urx,
1732 "y coordinate of the upper-right "
1733 "point of the region of interest. If not modified, default value will be Y dimension of the input image.",
1734 "CPL_TYPE_INT",
ury,
1736 "User reference level",
1739 "De-/Activate intermediate products",
1743 "De-/Activate the autocorr option",
1747 "De-/Activate the collapse option",
1750 "De-/Activate the image rescale option",
1753 "De-/Activate the computation with pixel to pixel accuracy",
1756 "De-/Activate the binary bpm option",
1759 "Maximum x-shift for the autocorr",
1762 "Upper limit of Median flux to be filtered",
1765 "Maximum y-shift for the autocorr",
1768 "Tolerance for pair discrimination",
1772 "Generate PAF file",
1775 "Specific name for PAF file",
1780 "Activate the multi-exts option. Choose -1 to process all extensions. Choose an extension number"
1781 " to process the appropriate extension.",
1782 "CPL_TYPE_INT",
exts,
1785 "Method for computing Fixed Pattern Noise (SMOOTH or HISTOGRAM)",
1786 "CPL_TYPE_STRING",
"HISTOGRAM",
1789 "template size in pixels for smoothing during FPN computation (only for SMOOTH method)",
1793 "all frames with mean saturation above the limit would not be used in linearity calculation",
1794 "CPL_TYPE_DOUBLE", 65535.0,
1797 "all frames with mean flux above the threshold would not be used in gain calculation",
1798 "CPL_TYPE_DOUBLE", 65535.0
1802 "coeffs_cube_split",
1803 "if TRUE, the recipe writes as many "
1804 "COEFFS_CUBE_Pi (i=0..order) as the value of "
1805 "the order parameter in a separate file",
1806 "CPL_TYPE_BOOL",
"CPL_FALSE");
1809 const cpl_error_code erroropt =
1812 "x coord of the lower-left point of the first "
1813 "field used for contamination measurement. If not modified, default value will be 1.",
1814 "CPL_TYPE_INT",
llx1,
1816 "y coord of the lower-left point of the first "
1817 "field used for contamination measurement. If not modified, default value will be 1.",
1818 "CPL_TYPE_INT",
lly1,
1820 "x coord of the upper-right point of the first "
1821 "field used for contamination measurement. If not modified, default value will be X dimension of the input image.",
1822 "CPL_TYPE_INT",
urx1,
1824 "y coord of the upper-right point of the first "
1825 "field used for contamination measurement. If not modified, default value will be Y dimension of the input image.",
1826 "CPL_TYPE_INT",
ury1,
1828 "x coord of the lower-left point of the second "
1829 "field used for contamination measurement. If not modified, default value will be 1.",
1830 "CPL_TYPE_INT",
llx2,
1832 "y coord of the lower-left point of the second "
1833 "field used for contamination measurement. If not modified, default value will be 1.",
1834 "CPL_TYPE_INT",
lly2,
1836 "x coord of the upper-right point of the second "
1837 "field used for contamination measurement. If not modified, default value will be half of the X dimension of the input image.",
1838 "CPL_TYPE_INT",
urx2,
1840 "y coord of the upper-right point of the second "
1841 "field used for contamination measurement. If not modified, default value will be half of the Y dimension of the input image.",
1842 "CPL_TYPE_INT",
ury2,
1844 "x coord of the lower-left point of the third "
1845 "field used for contamination measurement. If not modified, default value will be 1.",
1846 "CPL_TYPE_INT",
llx3,
1848 "y coord of the lower-left point of the third "
1849 "field used for contamination measurement. If not modified, default value will be half of the Y dimension of the input image.",
1850 "CPL_TYPE_INT",
lly3,
1852 "x coord of the upper-right point of the third "
1853 "field used for contamination measurement. If not modified, default value will be half of X dimension of the image.",
1854 "CPL_TYPE_INT",
urx3,
1856 "y coord of the upper-right point of the third "
1857 "field used for contamination measurement. If not modified, default value will be Y dimension of the image.",
1858 "CPL_TYPE_INT",
ury3,
1860 "x coord of the lower-left point of the fourth "
1861 "field used for contamination measurement. If not modified, default value will be half of X dimension of the image.",
1862 "CPL_TYPE_INT",
llx4,
1864 "y coord of the lower-left point of the fourth "
1865 "field used for contamination measurement. If not modified, default value will be half of the Y dimension of the input image.",
1866 "CPL_TYPE_INT",
lly4,
1868 "x coord of the upper-right point of the fourth "
1869 "field used for contamination measurement. If not modified, default value will be X dimension of the image.",
1870 "CPL_TYPE_INT",
urx4,
1872 "y coord of the upper-right point of the fourth "
1873 "field used for contamination measurement. If not modified, default value will be Y dimension of the input image.",
1874 "CPL_TYPE_INT",
ury4,
1876 "x coord of the lower-left point of the fifth "
1877 "field used for contamination measurement. If not modified, default value will be half of the X dimension of the input image.",
1878 "CPL_TYPE_INT",
llx5,
1880 "y coord of the lower-left point of the fifth "
1881 "field used for contamination measurement. If not modified, default value will be 1.",
1882 "CPL_TYPE_INT",
lly5,
1884 "x coord of the upper-right point of the fifth "
1885 "field used for contamination measurement. If not modified, default value will be X dimension of the image.",
1886 "CPL_TYPE_INT",
urx5,
1889 "y coord of the upper-right point of the fifth "
1890 "field used for contamination measurement. If not modified, default value will be half of Y dimension of the input image.",
1891 "CPL_TYPE_INT",
ury5);
1894 cpl_ensure_code(!erroropt, erroropt);
1897 cpl_ensure_code(!error, error);
1899 return cpl_error_get_code();
1912static cpl_error_code
1914 const char * recipe_name,
1915 const cpl_parameterlist * parlist,
1920 cpl_parameter * par;
1923 par_name = cpl_sprintf(
"%s.%s.method", pipeline_name, recipe_name);
1924 assert(par_name != NULL);
1925 par = cpl_parameterlist_find((cpl_parameterlist *) parlist, par_name);
1971 cpl_sprintf(
"%s.%s.intermediate", pipeline_name, recipe_name);
1972 assert(par_name != NULL);
1973 par = cpl_parameterlist_find((cpl_parameterlist *) parlist, par_name);
1978 par_name = cpl_sprintf(
"%s.%s.autocorr", pipeline_name, recipe_name);
1979 assert(par_name != NULL);
1980 par = cpl_parameterlist_find((cpl_parameterlist *) parlist, par_name);
1985 par_name = cpl_sprintf(
"%s.%s.coeffs_cube_split", pipeline_name, recipe_name);
1986 assert(par_name != NULL);
1987 par = cpl_parameterlist_find((cpl_parameterlist *) parlist, par_name);
1992 par_name = cpl_sprintf(
"%s.%s.collapse", pipeline_name, recipe_name);
1993 assert(par_name != NULL);
1994 par = cpl_parameterlist_find((cpl_parameterlist *) parlist, par_name);
1999 par_name = cpl_sprintf(
"%s.%s.rescale", pipeline_name, recipe_name);
2000 assert(par_name != NULL);
2001 par = cpl_parameterlist_find((cpl_parameterlist *) parlist, par_name);
2006 par_name = cpl_sprintf(
"%s.%s.pix2pix", pipeline_name, recipe_name);
2007 assert(par_name != NULL);
2008 par = cpl_parameterlist_find((cpl_parameterlist *) parlist, par_name);
2013 par_name = cpl_sprintf(
"%s.%s.bpmbin", pipeline_name, recipe_name);
2014 assert(par_name != NULL);
2015 par = cpl_parameterlist_find((cpl_parameterlist *) parlist, par_name);
2022 recipe_name, parlist);
2033 par_name = cpl_sprintf(
"%s.%s.tolerance", pipeline_name, recipe_name);
2034 assert(par_name != NULL);
2035 par = cpl_parameterlist_find((cpl_parameterlist *) parlist, par_name);
2041 par_name = cpl_sprintf(
"%s.%s.pafgen", pipeline_name, recipe_name);
2042 assert(par_name != NULL);
2043 par = cpl_parameterlist_find((cpl_parameterlist *) parlist, par_name);
2048 par_name = cpl_sprintf(
"%s.%s.pafname", pipeline_name, recipe_name);
2049 assert(par_name != NULL);
2050 par = cpl_parameterlist_find((cpl_parameterlist *) parlist, par_name);
2164 cpl_sprintf(
"%s.%s.fpn_method", pipeline_name, recipe_name);
2165 assert(par_name != NULL);
2166 par = cpl_parameterlist_find((cpl_parameterlist *) parlist, par_name);
2169 const char * str_method = cpl_parameter_get_string(par);
2170 if (strcmp(str_method,
"SMOOTH") == 0)
2174 else if (strcmp(str_method,
"HISTOGRAM") == 0)
2189 cpl_sprintf(
"%s.%s.saturation_limit", pipeline_name, recipe_name);
2190 assert(par_name != NULL);
2191 par = cpl_parameterlist_find((cpl_parameterlist *) parlist, par_name);
2203 cpl_sprintf(
"%s.%s.gain_threshold", pipeline_name, recipe_name);
2204 assert(par_name != NULL);
2205 par = cpl_parameterlist_find((cpl_parameterlist *) parlist, par_name);
2213 if(cpl_error_get_code())
2215 cpl_msg_error(cpl_func,
"Failed to retrieve the input parameters");
2216 cpl_ensure_code(0, CPL_ERROR_DATA_NOT_FOUND);
2220 return cpl_error_get_code();
2230static cpl_error_code
2233 const int nx = cpl_image_get_size_x(reference);
2234 const int ny = cpl_image_get_size_y(reference);
2302 cpl_msg_warning(cpl_func,
"PLEASE NOTE: The --intermediate option saves the difference and correlation images produced during autocorrelation computation. Therefore, --autocorr option has been automatically activated. If you didn't want to run this, please abort and rerun.");
2313 return cpl_error_get_code();
2328static cpl_error_code
2330 cpl_frameset * cur_fset_on,
2331 cpl_frameset * cur_fset_off,
2333 const char *tag_off)
2338 cpl_frame * cur_frame_dup = NULL;
2341 const cpl_frame *
first;
2342 const cpl_frame * second;
2343 const char * first_tag;
2344 const char * second_tag;
2345 skip_if((
first = cpl_frameset_get_position_const(cur_fset, 0)) == NULL);
2346 skip_if((second = cpl_frameset_get_position_const(cur_fset, 1)) == NULL);
2348 skip_if((first_tag = cpl_frame_get_tag(
first)) == NULL);
2349 skip_if((second_tag = cpl_frame_get_tag(second)) == NULL);
2351 ((!strcmp(first_tag, tag_on ) && !strcmp(second_tag, tag_off)) ||
2352 (!strcmp(first_tag, tag_off) && !strcmp(second_tag, tag_on )))) {
2357 nframes = cpl_frameset_get_size(cur_fset);
2359 const cpl_frame * cur_frame =
2360 cpl_frameset_get_position_const(cur_fset, i);
2364 cur_frame_dup = cpl_frame_duplicate(cur_frame);
2365 tag = (
char *) cpl_frame_get_tag(cur_frame_dup);
2368 if(!strcmp(tag, tag_on)) {
2369 skip_if(cpl_frameset_insert(cur_fset_on, cur_frame_dup));
2370 }
else if(!strcmp(tag, tag_off)) {
2371 skip_if(cpl_frameset_insert(cur_fset_off, cur_frame_dup));
2373 cpl_frame_delete(cur_frame_dup);
2374 cur_frame_dup = NULL;
2377 cur_frame_dup = NULL;
2381 cpl_frame_delete(cur_frame_dup);
2383 return cpl_error_get_code();
2410static cpl_error_code
2412 const cpl_frameset * set_off,
2413 int* index_on,
int* index_off,
2414 double* exptime_on,
double* exptime_off,
2415 int *next_index_on,
int* next_index_off,
2416 cpl_imagelist ** coeffs_ptr,
2417 cpl_table * gain_table,
2418 cpl_table * linear_table,
2419 cpl_image ** bpm_ptr,
2420 cpl_imagelist * autocorr_images,
2421 cpl_imagelist * diff_flats,
2422 cpl_propertylist * gaint_qclist,
2423 cpl_propertylist * lint_qclist,
2424 cpl_propertylist * linc_qclist,
2425 cpl_propertylist * bpm_qclist,
2426 int (*
load_fset) (
const cpl_frameset *,
2432 cpl_errorstate prestate = cpl_errorstate_get();
2433 const double D_INVALID_VALUE = -999;
2435 cpl_imagelist * linearity_inputs = NULL;
2436 cpl_imagelist * opt_offs = NULL;
2438 cpl_propertylist * reflist = NULL;
2440 int rows_linear_affected = 1;
2441 int rows_gain_affected = 1;
2442 int last_linear_best = 0;
2445 cpl_ensure(set_on != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2446 cpl_ensure(set_off != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT);
2448 nsets = cpl_frameset_get_size(set_on) / 2;
2458 const cpl_frame *
first = cpl_frameset_get_position_const(set_off, 0);
2459 cpl_frame *dup_first = cpl_frame_duplicate(
first);
2461 const cpl_frame *second = cpl_frameset_get_position_const(set_off, 1);
2462 cpl_frame *dup_second = cpl_frame_duplicate(second);
2464 cpl_frameset *raw_offs = cpl_frameset_new();
2466 skip_if(cpl_frameset_insert(raw_offs, dup_first));
2467 skip_if(cpl_frameset_insert(raw_offs, dup_second));
2469 opt_offs = cpl_imagelist_load_frameset(raw_offs, CPL_TYPE_FLOAT,
2472 cpl_frameset_delete(raw_offs);
2473 if (opt_offs == NULL) {
2474 cpl_errorstate_set(prestate);
2475 return CPL_ERROR_CONTINUE;
2493 cpl_errorstate_set(prestate);
2500 skip_if(cpl_table_unselect_all(linear_table));
2501 skip_if(cpl_table_unselect_all(gain_table));
2505 for(i = 0; i < nsets ; i++)
2508 index_on, exptime_on,
2512 index_off, exptime_off,
2513 next_index_on, next_index_off,
2515 gain_table, linearity_inputs,
2517 autocorr_images, diff_flats,
2519 &rows_linear_affected,&rows_gain_affected));
2523 if (rows_linear_affected == 0)
2525 cpl_msg_warning(cpl_func,
"The rest frames would not be taken "
2526 "into linear calculation, check the messages above");
2527 cpl_table_select_row(linear_table, i);
2531 last_linear_best = i;
2534 if (rows_gain_affected == 0)
2536 cpl_msg_warning(cpl_func,
"The rest frames would not be taken "
2537 "into gain calculation, check the messages above");
2538 cpl_table_select_row(gain_table, i);
2542 int last_gain_best = i;
2555 skip_if(cpl_table_erase_selected(gain_table));
2556 skip_if(cpl_table_erase_selected(linear_table));
2559 reflist = cpl_propertylist_new();
2560 skip_if(cpl_propertylist_append_bool(reflist,
"ADU", FALSE));
2561 skip_if(cpl_table_sort(gain_table, reflist));
2568 gaint_qclist, lint_qclist, linc_qclist,
2569 bpm_qclist, coeffs_ptr, bpm_ptr,
2571 gain_table, whichext,
opt_nir));
2574 double gain = cpl_propertylist_get_double(gaint_qclist,
DETMON_QC_GAIN);
2577 cpl_error_code cplerr = cpl_error_get_code();
2578 if (cplerr != CPL_ERROR_NONE || (gain == 0.0))
2580 cpl_msg_warning(cpl_func,
"Cannot read gain from QC parameters - "
2581 "FPN will not be computed");
2601 cpl_imagelist_delete(linearity_inputs);
2602 cpl_imagelist_delete(opt_offs);
2603 cpl_propertylist_delete(reflist);
2605 return cpl_error_get_code();
2610 int ncols = cpl_table_get_ncol(ptable);
2611 cpl_array* pnames = cpl_table_get_column_names(ptable);
2612 int nrows = cpl_table_get_nrow(ptable);
2614 for (i=0; i < ncols; i++)
2617 for (j = 0; j< nrows; j++)
2619 const char* colname = cpl_array_get_data_string_const(pnames)[i];
2621 cpl_type type = cpl_table_get_column_type(ptable, colname);
2622 cpl_table_get(ptable, colname, j, &isnull);
2625 if (type == CPL_TYPE_DOUBLE)
2627 cpl_table_set(ptable,colname,j, code);
2629 else if (type == CPL_TYPE_FLOAT)
2631 cpl_table_set_float(ptable,colname,j, (
float)code);
2636 cpl_array_delete(pnames);
2637 return cpl_error_get_code();
2640static cpl_error_code
2643 int last_linear_best,
2644 cpl_propertylist *lint_qclist,
2655 const cpl_image* im1 = 0;
2657 cpl_imagelist* ons = 0;
2658 cpl_frameset * pair_on = 0;
2659 int nsets_extracted = cpl_frameset_get_size(set_on);
2660 cpl_size * selection = NULL;
2669 selection = cpl_malloc(
sizeof(cpl_size) * nsets_extracted);
2670 memset(&selection[0], 0,
sizeof(cpl_size) * nsets_extracted);
2672 selection[index_on[last_linear_best*2 + 0] ] = 1;
2673 selection[index_on[last_linear_best*2 + 1] ] = 1;
2674 pair_on = cpl_frameset_extract(set_on, selection, 1);
2677 skip_if(ons == NULL);
2678 skip_if((im1 = cpl_imagelist_get_const(ons, 0)) == NULL);
2681 skip_if(cpl_propertylist_append_double(lint_qclist,
DETMON_QC_FPN,
2683 skip_if(cpl_propertylist_append_double(lint_qclist,
"ESO QC GAIN ERR",
2687 cpl_frameset_delete(pair_on);
2688 cpl_imagelist_delete(ons);
2689 cpl_free(selection);
2690 return cpl_error_get_code();
2702static cpl_error_code
2704 const cpl_frameset * darks,
2718 cpl_vector * selection = NULL;
2719 cpl_propertylist * plist;
2720 double dit_lamp, dit_dark;
2722 cpl_imagelist * lamps_data = NULL;
2723 cpl_imagelist * darks_data = NULL;
2724 double * stab_levels = NULL;
2726 double * ditvals = NULL;
2730 cpl_ensure_code((nb_lamps = cpl_frameset_get_size(lamps)) >= 3,
2731 CPL_ERROR_ILLEGAL_INPUT);
2737 cpl_msg_info(__func__,
"Checking DIT consistency");
2738 selection = cpl_vector_new(nb_lamps);
2739 ditvals = cpl_malloc(nb_lamps *
sizeof(
double));
2741 for (i = 0; i < nb_lamps; i++) {
2742 const cpl_frame * c_lamp;
2743 const cpl_frame * c_dark;
2745 skip_if (cpl_error_get_code());
2748 c_lamp = cpl_frameset_get_position_const(lamps, i);
2749 plist = cpl_propertylist_load(cpl_frame_get_filename(c_lamp), 0);
2754 cpl_propertylist_delete(plist);
2755 skip_if (cpl_error_get_code());
2758 c_dark = cpl_frameset_get_position_const(darks, i);
2759 plist = cpl_propertylist_load(cpl_frame_get_filename(c_dark), 0);
2764 cpl_propertylist_delete(plist);
2765 skip_if (cpl_error_get_code());
2768 if (fabs(dit_dark-dit_lamp) > 1e-3) {
2769 cpl_msg_error(__func__,
"DIT not consistent between LAMP and DARK, skip lamp stability computation");
2774 ditvals[i] = dit_lamp;
2777 cpl_vector_set(selection, i, -1.0);
2785 if (fabs(dit_lamp - ditvals[0]) < 1e-5 && i - last_stab > 3) {
2786 cpl_vector_set(selection, i, -1.0);
2790 cpl_vector_set(selection, i, 1.0);
2797 cpl_msg_info(__func__,
"Not enough frames for stability check");
2801 cpl_msg_info(__func__,
"Compute the differences lamp - dark");
2820 nb_darks=cpl_imagelist_get_size(darks_data);
2821 if(nb_darks==nb_lamps) {
2822 skip_if(cpl_imagelist_subtract(lamps_data,darks_data));
2824 cpl_image* master_dark=cpl_imagelist_collapse_median_create(darks_data);
2825 cpl_imagelist_subtract_image(lamps_data,master_dark);
2826 cpl_image_delete(master_dark);
2829 cpl_msg_info(__func__,
"Check the lamp stability");
2830 stab_levels = cpl_malloc(dit_stab *
sizeof(
double));
2832 for (i=0; i<nb_lamps; i++) {
2833 if (cpl_vector_get(selection, i) < 0) {
2835 cpl_image_get_mean(cpl_imagelist_get(lamps_data, i));
2841 for (i=1; i<dit_stab; i++) {
2842 if ((fabs(stab_levels[i]-stab_levels[0]) / stab_levels[0]) >
2845 fabs(stab_levels[i]-stab_levels[0]) / stab_levels[0];
2851 cpl_msg_warning(__func__,
2852 "Lamp stability level %g difference too high - proceed anyway",
xsh_detmon_lg_config.lamp_stability);
2859 cpl_vector_delete(selection);
2860 cpl_imagelist_delete(lamps_data);
2861 cpl_imagelist_delete(darks_data);
2862 cpl_free(stab_levels);
2864 return cpl_error_get_code();
2891static cpl_error_code
2893 int* index_on,
double* exptime_on,
2896 const cpl_frameset * set_off,
2897 int * index_off,
double* exptime_off,
2898 int* next_on,
int* next_off,
2899 cpl_table * linear_table,
2900 cpl_table * gain_table,
2901 cpl_imagelist * linearity_inputs,
2902 cpl_propertylist * qclist,
2904 cpl_imagelist * autocorr_images,
2905 cpl_imagelist * diff_flats,
2906 cpl_imagelist * opt_offs,
2908 int* rows_linear_affected,
2909 int* rows_gain_affected)
2911 cpl_frameset * pair_on = NULL;
2912 cpl_frameset * pair_off = NULL;
2913 cpl_imagelist * ons = NULL;
2914 cpl_imagelist * offs = NULL;
2915 cpl_boolean follow = CPL_TRUE;
2920 double current_dit = 0;
2922 const char * filename;
2924 cpl_propertylist * plist = NULL;
2925 cpl_propertylist* pDETlist = NULL;
2939 current_dit = exptime_on[*next_on - 1];
2943 skip_if(ons == NULL);
2944 cpl_msg_debug(cpl_func,
" Loaded ON images: %" CPL_SIZE_FORMAT
2945 ", exptime[%f]",cpl_imagelist_get_size(ons), current_dit );
2946 if(cpl_imagelist_get_size(ons) != 2)
2948 cpl_msg_error(cpl_func,
"cannot take ON pair, number of images[%"
2949 CPL_SIZE_FORMAT
"]", cpl_imagelist_get_size(ons));
2955 cpl_image_get_median_window(cpl_imagelist_get(ons, 0),
2961 cpl_image_get_median_window(cpl_imagelist_get(ons, 1),
2970 cpl_table_select_row(gain_table, dit_nb);
2971 cpl_table_select_row(linear_table, dit_nb);
2973 cpl_msg_warning(cpl_func,
"Frames of EXPTIME nb %d "
2974 "will not be taken into account for computation "
2975 "as they are above --filter threshold", dit_nb);
3005 cpl_frameset_get_size(set_on) == cpl_frameset_get_size(set_off))
3014 cpl_msg_debug(cpl_func,
" Load the OFF images, ext[%d], exptime[%f]", whichext, exptime_off[*next_off - 1]);
3017 skip_if(offs == NULL);
3018 skip_if(cpl_error_get_code());
3021 offs = (cpl_imagelist *) opt_offs;
3035 cpl_frame_get_filename(cpl_frameset_get_position_const(pair_on, 0));
3036 skip_if ((plist = cpl_propertylist_load(filename, 0)) == NULL);
3040 pDETlist = cpl_propertylist_new();
3041 cpl_propertylist_copy_property_regexp(pDETlist, plist,
"DET[0-9]* WIN[0-9]* UIT[0-9]*",0);
3064 cpl_msg_info(cpl_func,
"Computing GAIN for EXPTIME value nb %d",
3070 cpl_table_erase_column(gain_table,
"MEAN_OFF1");
3071 cpl_table_erase_column(gain_table,
"MEAN_OFF2");
3072 cpl_table_erase_column(gain_table,
"SIG_OFF_DIF");
3073 cpl_table_erase_column(gain_table,
"GAIN");
3074 cpl_table_erase_column(gain_table,
"GAIN_CORR");
3075 cpl_table_new_column(gain_table,
"MEAN_OFF", CPL_TYPE_DOUBLE);
3082 diff_flats, ons, offs,
3093 dit_nb,
mode, rows_gain_affected));
3097 diff_flats,ons,offs,
3105 dit_nb,
mode, rows_linear_affected));
3108 if (*rows_gain_affected)
3113 cpl_msg_info(cpl_func,
"Linearity reduction for nb %d",
3116 if (*rows_linear_affected) {
3118 linearity_inputs, ons, offs,
3123 dit_nb, *dit_nskip,
mode));
3138 *rows_linear_affected != 0 ) {
3146 cpl_frameset_delete(pair_on);
3147 cpl_imagelist_delete(ons);
3150 cpl_imagelist_delete(offs);
3154 cpl_frameset_delete(pair_off);
3157 cpl_propertylist_delete(plist);
3158 cpl_propertylist_delete(pDETlist);
3159 return cpl_error_get_code();
3169static cpl_error_code
3173 cpl_error_code error;
3174 double mean_med_dit;
3177 cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT);
3179 mean_med_dit = cpl_table_get_column_mean(table,
"MED_DIT");
3181 dits = cpl_table_get_data_double(table,
"EXPTIME");
3183 dits = cpl_table_get_data_double(table,
"DIT");
3185 error = cpl_table_copy_data_double(table,
"ADL", dits);
3186 cpl_ensure_code(!error, error);
3187 error = cpl_table_multiply_scalar(table,
"ADL", mean_med_dit);
3188 cpl_ensure_code(!error, error);
3190 return cpl_error_get_code();
3202static cpl_error_code
3204 cpl_table * linear_table,
3205 cpl_imagelist ** linearity_inputs,
3212 *linearity_inputs = cpl_imagelist_new();
3213 skip_if(*linearity_inputs == NULL);
3218 return cpl_error_get_code();
3253static cpl_propertylist*
3256 cpl_propertylist* pro_keys=NULL;
3257 pro_keys=cpl_propertylist_load_regexp(NAME_O,0,
"^(ESO PRO)",0);
3263 const char* prop_name)
3266 dit = cpl_propertylist_get_double(plist, prop_name);
3267 if(cpl_error_get_code() != CPL_ERROR_NONE)
3269 cpl_msg_error(cpl_func,
"Cannot read property '%s', err[%s]",
3270 prop_name, cpl_error_get_where());
3275static cpl_error_code
3277 const cpl_imagelist* offs,
unsigned mode,
3278 double double_adu,
double avg_on1,
double avg_on2,
3279 double avg_off1,
double avg_off2,
double sigma,
3280 double sig_off_dif,
double gain,
int c_ndit,
3281 double gain_corr,
double autocorr, cpl_image* on_dif,
3282 cpl_table* gain_table)
3286 double avg_on_dif, sig_on_dif;
3288 cpl_image_get_size_y(on_dif),
kappa, nclip, 1e-5,
3289 &avg_on_dif, &sig_on_dif);
3291 cpl_table_set_double(gain_table,
"SIG_ON_DIF", pos,
3294 double_adu = (avg_on1 + avg_on2) - 2 * avg_off1;
3297 double_adu = (avg_on1 + avg_on2) - (avg_off1 + avg_off2);
3299 sigma = (sig_on_dif * sig_on_dif) - (sig_off_dif * sig_off_dif);
3303 gain = double_adu / (c_ndit *
sigma);
3307 skip_if(cpl_table_set_double(gain_table,
"GAIN", pos, gain));
3309 cpl_table_set_double(gain_table,
"GAIN_CORR", pos,
3313 skip_if(cpl_table_set_double(gain_table,
"AUTOCORR", pos,
autocorr));
3314 skip_if(cpl_table_set_double(gain_table,
"ADU", pos, double_adu / 2));
3317 cpl_table_set_double(gain_table,
"Y_FIT", pos,
3318 c_ndit * sig_on_dif * sig_on_dif));
3320 cpl_table_set_double(gain_table,
"Y_FIT_CORR", pos,
3321 c_ndit * sig_on_dif * sig_on_dif));
3322 skip_if(cpl_table_set_double(gain_table,
"X_FIT", pos, double_adu));
3324 cpl_table_set_double(gain_table,
"X_FIT_CORR", pos,
3329 return cpl_error_get_code();
3334 int m,
int n, cpl_imagelist* diff_flats,
3335 cpl_image* on_dif, cpl_imagelist* autocorr_images)
3339 cpl_image * diff = cpl_image_duplicate(on_dif);
3340 skip_if(cpl_imagelist_set(diff_flats, diff, pos));
3342 if (autocorr_images) {
3343 cpl_image * corr = NULL;
3346 skip_if(cpl_imagelist_set(autocorr_images, corr, pos));
3368 double avg_off1,
double std,
const int pos,
3369 cpl_table* gain_table,
double* avg_off2,
3370 double* sig_off_dif)
3383 skip_if(cpl_table_set_double(gain_table,
"MEAN_OFF", pos, avg_off1));
3388 cpl_image * off_dif = NULL;
3394 skip_if(cpl_table_set_double(gain_table,
"MEAN_OFF1", pos, avg_off1));
3399 skip_if(cpl_table_set_double(gain_table,
"MEAN_OFF2", pos, *avg_off2));
3401 cpl_imagelist_get_const(offs, 0),
3403 skip_if(off_dif == NULL);
3405 cpl_image_get_size_y(off_dif),
kappa, nclip, 1e-5,
3406 &avg_off_dif, sig_off_dif);
3407 cpl_image_delete(off_dif);
3409 cpl_table_set_double(gain_table,
"SIG_OFF_DIF", pos,
3415 avg_off1 = cpl_table_get_double(gain_table,
"MEAN_OFF1", 0, &status);
3416 skip_if(cpl_table_set_double(gain_table,
"MEAN_OFF1", pos, avg_off1));
3417 *avg_off2 = cpl_table_get_double(gain_table,
"MEAN_OFF2", 0, &status);
3418 skip_if(cpl_table_set_double(gain_table,
"MEAN_OFF2", pos, *avg_off2));
3419 *sig_off_dif = cpl_table_get_double(gain_table,
"SIG_OFF_DIF", 0,
3422 cpl_table_set_double(gain_table,
"SIG_OFF_DIF", pos,
3467static cpl_error_code
3469 double c_dit,
int c_ndit,
3470 cpl_imagelist * autocorr_images,
3471 cpl_imagelist * diff_flats,
3472 const cpl_imagelist * ons,
3473 const cpl_imagelist * offs,
3474 double kappa,
int nclip,
3479 const int pos,
unsigned mode,
int* rows_gain_affected)
3481 const cpl_image *image;
3482 cpl_image *on_dif = NULL;
3484 double avg_on1, avg_on2;
3485 double avg_off1=0, avg_off2;
3486 double double_adu=0,
autocorr=0, gain=0, gain_corr=0;
3489 cpl_table_set(gain_table,
"FLAG", pos, 1);
3492 cpl_table_set(gain_table,
"DIT", pos, c_dit);
3493 cpl_table_set(gain_table,
"NDIT", pos, c_ndit);
3496 cpl_table_set(gain_table,
"EXPTIME", pos, c_dit);
3499 cpl_msg_error(cpl_func,
"Mandatory mode (OPT or NIR) not provided");
3502 if(*rows_gain_affected == 0)
3504 cpl_msg_info(cpl_func,
"skip the frame #%d", pos + 1);
3505 cpl_table_set(gain_table,
"FLAG", pos, 0);
3513 if (autocorr_images)
3518 return cpl_error_get_code();
3520 skip_if((image = cpl_imagelist_get_const(ons, 0)) == NULL);
3522 nclip, 1e-5, &avg_on1, &std));
3523 skip_if((image = cpl_imagelist_get_const(ons, 1)) == NULL);
3525 nclip, 1e-5, &avg_on2, &std));
3537 cpl_msg_warning(cpl_func,
"Average level is above the limit set by the gain_theshold parameter, "
3538 "the frames would not be taken into calculation");
3540 cpl_msg_warning(cpl_func,
"Average levels [%f ; %f], limit [%f]",
3544 cpl_msg_info(cpl_func,
"skip the frame #%d", pos + 1);
3545 cpl_table_set(gain_table,
"FLAG", pos, 0);
3553 if (autocorr_images)
3558 *rows_gain_affected = 0;
3566 *rows_gain_affected = 1;
3567 skip_if(cpl_table_set_double(gain_table,
"MEAN_ON1", pos, avg_on1));
3568 skip_if(cpl_table_set_double(gain_table,
"MEAN_ON2", pos, avg_on2));
3572 cpl_imagelist_get_const(ons, 1),
3574 skip_if(on_dif == NULL);
3577 diff_flats, on_dif, autocorr_images);
3580 kappa, nclip, avg_off1, std, pos, gain_table, &avg_off2,
3584 avg_on1, avg_on2, avg_off1, avg_off2,
sigma,
3585 sig_off_dif, gain, c_ndit, gain_corr,
autocorr, on_dif,
3590 cpl_image_delete(on_dif);
3592 return cpl_error_get_code();
3620static cpl_error_code
3622 cpl_imagelist * diff_flats,
3623 const cpl_imagelist * ons,
3624 const cpl_imagelist * offs,
3625 double kappa,
int nclip,
3628 const int pos,
unsigned mode,
int* rows_linear_affected)
3630 const cpl_image *image;
3632 double avg_on1, avg_on2;
3635 if(*rows_linear_affected == 0)
3637 cpl_msg_info(cpl_func,
"For linearity skip the frame #%d", pos + 1);
3644 if (autocorr_images)
3649 return cpl_error_get_code();
3651 skip_if((image = cpl_imagelist_get_const(ons, 0)) == NULL);
3653 nclip, 1e-5, &avg_on1, &std));
3654 skip_if((image = cpl_imagelist_get_const(ons, 1)) == NULL);
3656 nclip, 1e-5, &avg_on2, &std));
3668 cpl_msg_warning(cpl_func,
"Average level is above the limit set by the saturation_limit parameter, "
3669 "the frames would not be taken into calculation");
3671 cpl_msg_warning(cpl_func,
"Average levels [%f ; %f], limit [%f]",
3675 cpl_msg_info(cpl_func,
"skip the frame #%d", pos + 1);
3676 *rows_linear_affected = 0;
3683 return cpl_error_get_code();
3706 const cpl_image *
first= cpl_imagelist_get_const(coeffs, 0);
3713 cpl_mask *mask = cpl_mask_new(cpl_image_get_size_x(
first),
3714 cpl_image_get_size_y(
first));
3716 cpl_image *bpm = NULL;
3719 int size = cpl_imagelist_get_size(coeffs);
3722 bpm = cpl_image_new(cpl_image_get_size_x(
first),
3723 cpl_image_get_size_y(
first),
3728 for(
int i = 0; i <
size; i++) {
3729 const cpl_image * cur_coeff = cpl_imagelist_get_const(coeffs, i);
3731 cpl_stats* stats = cpl_stats_new_from_image(cur_coeff,
3732 CPL_STATS_MEAN | CPL_STATS_STDEV);
3733 double cur_mean = cpl_stats_get_mean(stats);
3734 double cur_stdev = cpl_stats_get_stdev(stats);
3736 double lo_cut = cur_mean -
kappa * cur_stdev;
3737 double hi_cut = cur_mean +
kappa * cur_stdev;
3739 cpl_mask* cur_mask = cpl_mask_threshold_image_create(cur_coeff, lo_cut, hi_cut);
3740 cpl_mask_not(cur_mask);
3743 cpl_image* cur_image = cpl_image_new_from_mask(cur_mask);
3744 double p = pow(2, i);
3745 cpl_image_power(cur_image, p);
3746 cpl_image_add(bpm, cur_image);
3747 cpl_image_delete(cur_image);
3750 cpl_mask_or(mask, cur_mask);
3752 cpl_mask_delete(cur_mask);
3753 cpl_stats_delete(stats);
3757 bpm = cpl_image_new_from_mask(mask);
3760 *nbpixs += cpl_mask_count(mask);
3762 cpl_mask_delete(mask);
3890 cpl_image ** autocorr_image,
int m,
int n)
3892 cpl_image * mycorr_image = NULL;
3894 cpl_error_code err = CPL_ERROR_NONE;
3897 err=cpl_error_get_code();
3898 if (err == CPL_ERROR_UNSUPPORTED_MODE)
3900 cpl_msg_warning(cpl_func,
"FFTW is not supported by CPL, autocorrelation "
3901 "would be computed using internal implementation");
3904 cpl_image_delete(mycorr_image);
3907 if(mycorr_image == NULL) {
3911 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), -1);
3913 autocorr = cpl_image_get_flux(mycorr_image);
3915 if (autocorr_image) *autocorr_image = mycorr_image;
3916 else cpl_image_delete(mycorr_image);
3921static cpl_propertylist*
3925 cpl_propertylist* sub_set=NULL;
3928 sub_set=cpl_propertylist_new();
3929 qc_key=cpl_sprintf(
"QC LIN COEF%d",ip);
3930 cpl_propertylist_copy_property_regexp(sub_set,linc_qclist,qc_key,0);
3947static cpl_error_code
3949 cpl_propertylist* gaint_qclist,
3950 cpl_propertylist* lint_qclist,
3951 cpl_propertylist* linc_qclist,
3952 cpl_propertylist* bpm_qclist,
3956 cpl_propertylist * xplist = NULL;
3958 const char * filename =
3959 cpl_frame_get_filename(cpl_frameset_get_position(frameset, 0));
3961 xplist = cpl_propertylist_load_regexp(filename, whichext,
3962 "ESO DET|EXTNAME", 0);
3966 cpl_property* propExtname = NULL;
3967 propExtname = cpl_propertylist_get_property(xplist,
"EXTNAME");
3969 if (NULL != propExtname)
3971 propExtname = cpl_property_duplicate(propExtname);
3973 cpl_propertylist_delete(xplist);
3975 if (NULL != propExtname)
3977 xplist = cpl_propertylist_new();
3978 cpl_propertylist_append_property(xplist, propExtname);
3979 cpl_property_delete(propExtname);
3984 cpl_propertylist_append(gaint_qclist, xplist);
3985 cpl_propertylist_append(lint_qclist, xplist);
3986 cpl_propertylist_append(linc_qclist, xplist);
3987 cpl_propertylist_append(bpm_qclist, xplist);
3988 cpl_propertylist_delete(xplist);
3991 return cpl_error_get_code();
4008static cpl_error_code
4011 cpl_propertylist* xheader,
4012 unsigned CPL_IO_MODE)
4015 cpl_propertylist* pro_keys=NULL;
4018 cpl_propertylist_append(xheader,pro_keys);
4020 if(CPL_IO_MODE==CPL_IO_DEFAULT) {
4021 cpl_propertylist * pri_head=cpl_propertylist_load(name_o,0);
4022 cpl_table_save(table, pri_head,xheader,name_o,
4024 cpl_propertylist_delete(pri_head);
4027 cpl_table_save(table,NULL,xheader,name_o,
4030 cpl_propertylist_delete(pro_keys);
4032 return cpl_error_get_code();
4044static cpl_error_code
4047 cpl_propertylist* xheader)
4050 cpl_propertylist* pro_keys=NULL;
4052 cpl_propertylist_append(xheader,pro_keys);
4054 cpl_image_save(image,name_o, CPL_BPP_IEEE_FLOAT,
4055 xheader,CPL_IO_EXTEND);
4056 cpl_propertylist_delete(pro_keys);
4059 return cpl_error_get_code();
4071static cpl_error_code
4074 cpl_propertylist* xheader)
4077 cpl_propertylist* pro_keys=NULL;
4079 cpl_propertylist_append(xheader,pro_keys);
4081 cpl_imagelist_save(imagelist,name_o, CPL_BPP_IEEE_FLOAT,
4082 xheader,CPL_IO_EXTEND);
4084 cpl_propertylist_delete(pro_keys);
4087 return cpl_error_get_code();
4107static cpl_error_code
4109 cpl_frameset* frameset,
4110 const cpl_frameset * usedframes,
4112 const char* recipe_name,
4113 cpl_propertylist* mypro_coeffscube,
4114 cpl_propertylist* linc_plane_qclist,
4115 const char* package,
4120 cpl_propertylist* plist=NULL;
4121 cpl_dfs_save_image(frameset, NULL, parlist, usedframes,
4123 CPL_BPP_IEEE_FLOAT, recipe_name,
4124 mypro_coeffscube, NULL,
4126 plist=cpl_propertylist_load(NAME_O,0);
4127 cpl_image_save(plane,NAME_O, CPL_BPP_IEEE_FLOAT,
4128 plist,CPL_IO_DEFAULT);
4129 cpl_propertylist_delete(plist);
4132 cpl_dfs_save_image(frameset, NULL, parlist, usedframes,
4134 CPL_BPP_IEEE_FLOAT, recipe_name,
4135 mypro_coeffscube, NULL,
4142 cpl_dfs_save_image(frameset, NULL, parlist,
4143 usedframes,NULL, NULL,
4144 CPL_BPP_IEEE_FLOAT, recipe_name,
4145 mypro_coeffscube, NULL,
4156 return cpl_error_get_code();
4179static cpl_error_code
4181 cpl_frameset* frameset,
4182 const cpl_frameset * usedframes,
4184 const char* recipe_name,
4185 cpl_propertylist* mypro_coeffscube,
4186 cpl_propertylist* linc_qclist,
4187 const char* package,
4189 cpl_imagelist* coeffs)
4193 cpl_propertylist_append(mypro_coeffscube, linc_qclist);
4195 (frameset, parlist, usedframes, coeffs,
4196 recipe_name, mypro_coeffscube, package,
4199 cpl_dfs_save_image(frameset, NULL, parlist, usedframes,
4201 CPL_BPP_IEEE_FLOAT, recipe_name,
4202 mypro_coeffscube, NULL,
4209 cpl_dfs_save_image(frameset, NULL, parlist, usedframes,
4211 CPL_BPP_IEEE_FLOAT, recipe_name,
4212 mypro_coeffscube, NULL,
4217 cpl_propertylist_save(linc_qclist, NAME_O, CPL_IO_EXTEND);
4222 cpl_propertylist_save(linc_qclist, NAME_O, CPL_IO_EXTEND);
4226 return cpl_error_get_code();
4231 int flag_sets,
int which_set,
4233 const char* paf_suf,
4234 cpl_propertylist** plist)
4236 char * paf_name=NULL;
4240 *plist =cpl_propertylist_load(cpl_frame_get_filename(ref_frame),
4249 paf_name=cpl_sprintf(
"%s_%s_set%02d.paf",
4255 *plist = cpl_propertylist_load(cpl_frame_get_filename(ref_frame),
4261 paf_name=cpl_sprintf(
"%s_%s_ext%02d.paf",
4266 paf_name=cpl_sprintf(
"%s_%s_set%02d_ext%02d.paf",
4268 which_set, whichext);
4278 int flag_sets,
int which_set,
4280 const char* paf_suf,
4281 cpl_propertylist** plist)
4283 char* paf_name=NULL;
4287 *plist = cpl_propertylist_load(cpl_frame_get_filename(ref_frame),
4295 paf_name=cpl_sprintf(
"%s_%s_set%02d.paf",
4300 *plist = cpl_propertylist_load(cpl_frame_get_filename(ref_frame),
4304 paf_name=cpl_sprintf(
"%s_%s_ext%02d.paf",
4308 paf_name=cpl_sprintf(
"%s_%s_set%02d_ext%02d.paf",
4310 which_set, whichext);
4317static cpl_error_code
4319 int which_set,
int whichext,
4320 const char* pafregexp,
4321 const char* procatg,
4322 const char* pipeline_name,
4323 const char* recipe_name,
4324 const char* paf_suf,
4325 cpl_propertylist* qclist,
4330 char* paf_name=NULL;
4331 cpl_propertylist* plist=NULL;
4332 cpl_propertylist* paflist = NULL;
4333 cpl_propertylist* mainplist=NULL;
4335 mainplist =cpl_propertylist_load(cpl_frame_get_filename(ref_frame),0);
4347 paflist = cpl_propertylist_new();
4348 cpl_propertylist_append_string(paflist, CPL_DFS_PRO_CATG,procatg);
4351 cpl_propertylist_copy_property_regexp(paflist, plist,pafregexp, 0);
4352 cpl_propertylist_copy_property_regexp(paflist, mainplist,pafregexp, 0);
4353 cpl_propertylist_append(paflist,qclist);
4356 cpl_dfs_save_paf(pipeline_name, recipe_name,paflist,paf_name);
4359 cpl_propertylist_delete(mainplist);
4360 cpl_propertylist_delete(paflist);
4361 cpl_propertylist_delete(plist);
4364 return cpl_error_get_code();
4401static cpl_error_code
4403 cpl_frameset * frameset,
4404 const char *recipe_name,
4405 const char *pipeline_name,
4406 const char *pafregexp,
4407 const cpl_propertylist * pro_lintbl,
4408 const cpl_propertylist * pro_gaintbl,
4409 const cpl_propertylist * pro_coeffscube,
4410 const cpl_propertylist * pro_bpm,
4411 const cpl_propertylist * pro_corr,
4412 const cpl_propertylist * pro_diff,
4413 const char *package,
4414 cpl_imagelist * coeffs,
4415 cpl_table * gain_table,
4416 cpl_table * linear_table,
4418 cpl_imagelist * autocorr_images,
4419 cpl_imagelist * diff_flats,
4420 cpl_propertylist * gaint_qclist,
4421 cpl_propertylist * lint_qclist,
4422 cpl_propertylist * linc_qclist,
4423 cpl_propertylist * bpm_qclist,
4424 const int flag_sets,
4425 const int which_set,
4426 const cpl_frameset * usedframes,
4430 cpl_frame *ref_frame;
4431 cpl_propertylist *plist = NULL;
4432 cpl_propertylist *mainplist = NULL;
4438 cpl_propertylist * xplist = NULL;
4440 cpl_propertylist* linc_plane_qclist=NULL;
4441 cpl_image* plane=NULL;
4443 char* pcatg_plane=NULL;
4445 cpl_propertylist * mypro_lintbl =
4446 cpl_propertylist_duplicate(pro_lintbl);
4447 cpl_propertylist * mypro_gaintbl =
4448 cpl_propertylist_duplicate(pro_gaintbl);
4449 cpl_propertylist * mypro_coeffscube =
4450 cpl_propertylist_duplicate(pro_coeffscube);
4451 cpl_propertylist * mypro_bpm =
4452 cpl_propertylist_duplicate(pro_bpm);
4453 cpl_propertylist * mypro_corr =
4454 cpl_propertylist_duplicate(pro_corr);
4455 cpl_propertylist * mypro_diff =
4456 cpl_propertylist_duplicate(pro_diff);
4458 const char * procatg_lintbl =
4459 cpl_propertylist_get_string(mypro_lintbl, CPL_DFS_PRO_CATG);
4461 const char * procatg_gaintbl =
4462 cpl_propertylist_get_string(mypro_gaintbl, CPL_DFS_PRO_CATG);
4464 const char * procatg_coeffscube =
4465 cpl_propertylist_get_string(mypro_coeffscube, CPL_DFS_PRO_CATG);
4466 const char * procatg_bpm =
4467 cpl_propertylist_get_string(mypro_bpm, CPL_DFS_PRO_CATG);
4472 linc_qclist,bpm_qclist,whichext);
4477 ref_frame = cpl_frameset_get_position(frameset, 0);
4479 skip_if((mainplist =
4480 cpl_propertylist_load(cpl_frame_get_filename(ref_frame),
4486 cpl_msg_info(cpl_func,
"Write the LINEARITY TABLE");
4489 NAME_O=cpl_sprintf(
"%s_linearity_table.fits", recipe_name);
4491 NAME_O=cpl_sprintf(
"%s_linearity_table_set%02d.fits", recipe_name,
4497 cpl_propertylist_append(mypro_lintbl, lint_qclist);
4498 skip_if(cpl_dfs_save_table(frameset, NULL,parlist, usedframes, NULL,
4499 linear_table,NULL, recipe_name,
4500 mypro_lintbl, NULL, package, NAME_O));
4503 lint_qclist,CPL_IO_DEFAULT);
4508 skip_if(cpl_dfs_save_table(frameset,NULL, parlist, usedframes, NULL,
4509 linear_table,lint_qclist, recipe_name,
4510 mypro_lintbl,NULL, package, NAME_O));
4512 lint_qclist,CPL_IO_DEFAULT);
4520 lint_qclist,CPL_IO_EXTEND);
4527 cpl_msg_info(cpl_func,
"Write the GAIN TABLE");
4530 NAME_O=cpl_sprintf(
"%s_gain_table.fits", recipe_name);
4532 NAME_O=cpl_sprintf(
"%s_gain_table_set%02d.fits", recipe_name,
4540 cpl_propertylist_append(mypro_gaintbl, gaint_qclist);
4541 skip_if(cpl_dfs_save_table(frameset, NULL, parlist, usedframes, NULL,
4542 gain_table,NULL, recipe_name, mypro_gaintbl,
4543 NULL, package, NAME_O));
4545 gaint_qclist,CPL_IO_DEFAULT);
4553 skip_if(cpl_dfs_save_table(frameset, NULL, parlist, usedframes, NULL, gain_table,
4554 gaint_qclist, recipe_name, mypro_gaintbl,
4555 NULL, package, NAME_O));
4557 gaint_qclist,CPL_IO_DEFAULT);
4564 gaint_qclist,CPL_IO_EXTEND);
4574 cpl_msg_info(cpl_func,
"Write the COEFFS FITS");
4578 PREF_O=cpl_sprintf(
"%s_coeffs_cube", recipe_name);
4581 PREF_O=cpl_sprintf(
"%s_coeffs_cube_set%02d",
4582 recipe_name, which_set);
4585 NAME_O=cpl_sprintf(
"%s.fits", PREF_O);
4593 nb_images = cpl_imagelist_get_size(coeffs);
4594 for(ip=0;ip<nb_images;ip++) {
4595 NAME_O=cpl_sprintf(
"%s_P%d.fits", PREF_O,ip);
4596 pcatg_plane=cpl_sprintf(
"COEFFS_CUBE_P%d",ip);
4597 cpl_propertylist_delete(mypro_coeffscube);
4598 mypro_coeffscube=cpl_propertylist_duplicate(pro_coeffscube);
4599 cpl_propertylist_set_string(mypro_coeffscube,CPL_DFS_PRO_CATG,
4602 cpl_propertylist_append(mypro_coeffscube, linc_plane_qclist);
4603 plane=cpl_imagelist_get(coeffs,ip);
4605 recipe_name,mypro_coeffscube,
4606 linc_plane_qclist,package,NAME_O,plane);
4608 if(NULL!=linc_plane_qclist) {
4609 cpl_propertylist_delete(linc_plane_qclist);
4617 recipe_name,mypro_coeffscube,
4618 linc_qclist,package,NAME_O,coeffs);
4624 cpl_msg_info(cpl_func,
"Write the BAD PIXEL MAP");
4629 NAME_O=cpl_sprintf(
"%s_bpm.fits", recipe_name);
4632 NAME_O=cpl_sprintf(
"%s_bpm_set%02d.fits", recipe_name, which_set);
4638 cpl_propertylist_append(mypro_bpm, bpm_qclist);
4639 cpl_dfs_save_image(frameset, NULL, parlist, usedframes, NULL, bpms,
4640 CPL_BPP_IEEE_FLOAT, recipe_name,
4641 mypro_bpm, NULL, package,
4646 skip_if(cpl_dfs_save_image(frameset, NULL, parlist, usedframes,NULL, NULL,
4647 CPL_BPP_IEEE_FLOAT, recipe_name,
4648 mypro_bpm, NULL, package,
4656 skip_if(cpl_dfs_save_image(frameset, NULL, parlist, usedframes,NULL, NULL,
4657 CPL_BPP_IEEE_FLOAT, recipe_name,
4658 mypro_bpm, NULL, package,
4673 cpl_msg_info(cpl_func,
"Write the AUTOCORRS FITS");
4674 nb_images = cpl_imagelist_get_size(autocorr_images);
4675 cpl_ensure_code(nb_images > 0, CPL_ERROR_DATA_NOT_FOUND);
4676 for(i = 0; i < nb_images; i++)
4678 cpl_propertylist* pplist = cpl_propertylist_duplicate(mypro_corr);
4680 cpl_array* pnames = cpl_table_get_column_names(linear_table);
4682 if(i < cpl_table_get_nrow(linear_table))
4684 ddit = cpl_table_get_double(linear_table,
4685 cpl_array_get_data_string_const(pnames)[0], i, &inull);
4687 cpl_array_delete(pnames);
4693 NAME_O=cpl_sprintf(
"%s_autocorr_%d.fits", recipe_name, i);
4694 assert(NAME_O != NULL);
4697 NAME_O=cpl_sprintf(
"%s_autocorr_%02d_set%02d.fits",
4698 recipe_name, i, which_set);
4699 assert(NAME_O != NULL);
4704 cpl_propertylist* pextlist = cpl_propertylist_new();
4705 cpl_propertylist_append_double(pextlist,
"ESO DET DIT", ddit);
4706 skip_if(cpl_dfs_save_image(frameset, NULL, parlist, usedframes,
4707 NULL,NULL,CPL_BPP_IEEE_FLOAT,
4708 recipe_name, pplist, NULL,
4712 cpl_imagelist_get(autocorr_images, i),NAME_O,pextlist);
4714 cpl_propertylist_delete(pextlist);
4718 cpl_propertylist_append_double(pplist,
"ESO DET DIT", ddit);
4719 cpl_dfs_save_image(frameset, NULL, parlist, usedframes, NULL,
4720 cpl_imagelist_get(autocorr_images, i),
4722 recipe_name, pplist, NULL, package,
4728 cpl_propertylist* pextlist = cpl_propertylist_new();
4729 cpl_propertylist_append_double(pextlist,
"ESO DET DIT", ddit);
4732 skip_if(cpl_dfs_save_image(frameset, NULL, parlist,
4733 usedframes, NULL,NULL,
4734 CPL_BPP_IEEE_FLOAT, recipe_name,
4739 cpl_imagelist_get(autocorr_images, i),NAME_O,pextlist);
4745 cpl_imagelist_get(autocorr_images, i),NAME_O,pextlist);
4747 cpl_propertylist_delete(pextlist);
4749 cpl_propertylist_delete (pplist);
4760 cpl_msg_info(cpl_func,
"Write the DIFFS FITS");
4762 for(i = 0; i < nb_images; i++)
4764 cpl_propertylist* pplist = cpl_propertylist_duplicate(mypro_diff);
4766 cpl_array* pnames = cpl_table_get_column_names(linear_table);
4768 if(i < cpl_table_get_nrow(linear_table))
4770 ddit = cpl_table_get_double(linear_table,
4771 cpl_array_get_data_string_const(pnames)[0], i, &inull);
4773 cpl_array_delete(pnames);
4778 NAME_O=cpl_sprintf(
"%s_diff_flat_%d.fits", recipe_name, i);
4781 NAME_O=cpl_sprintf(
"%s_diff_flat_%d_set%02d.fits",
4782 recipe_name, i, which_set);
4787 cpl_propertylist* pextlist = cpl_propertylist_new();
4788 cpl_propertylist_append_double(pextlist,
"ESO DET DIT", ddit);
4789 cpl_propertylist_append_double(mypro_diff,
"ESO DET DIT", ddit);
4790 skip_if(cpl_dfs_save_image(frameset, NULL, parlist, usedframes,
4791 NULL,NULL,CPL_BPP_IEEE_FLOAT,
4793 mypro_diff, NULL,package, NAME_O));
4796 cpl_imagelist_get(diff_flats, i),NAME_O,pextlist);
4798 cpl_propertylist_delete(pextlist);
4802 cpl_propertylist_append_double(pplist,
"ESO DET DIT", ddit);
4804 (frameset, NULL, parlist, usedframes, NULL,
4805 cpl_imagelist_get(diff_flats, i), CPL_BPP_IEEE_FLOAT,
4806 recipe_name, pplist, NULL, package,
4811 cpl_propertylist* pextlist = cpl_propertylist_new();
4812 cpl_propertylist_append_double(pextlist,
"ESO DET DIT", ddit);
4815 cpl_propertylist_append_double(mypro_diff,
"ESO DET DIT",ddit);
4817 skip_if(cpl_dfs_save_image(frameset, NULL, parlist,
4818 usedframes, NULL,NULL,
4819 CPL_BPP_IEEE_FLOAT, recipe_name,
4820 mypro_diff, NULL,package, NAME_O));
4823 cpl_imagelist_get(diff_flats, i),NAME_O,pextlist);
4829 cpl_imagelist_get(diff_flats, i),NAME_O,pextlist);
4832 cpl_propertylist_delete(pextlist);
4834 cpl_propertylist_delete(pplist);
4843 cpl_msg_info(cpl_func,
"Write the PAF file(s)");
4848 pafregexp,procatg_gaintbl,
4849 pipeline_name,recipe_name,
4850 "qc01",gaint_qclist,0);
4853 pafregexp,procatg_lintbl,
4854 pipeline_name,recipe_name,
4855 "qc02",lint_qclist,0);
4863 pipeline_name,recipe_name,
4864 "qc03",linc_qclist,1);
4867 whichext,pafregexp,procatg_bpm,
4868 pipeline_name,recipe_name,
4869 "qc04",bpm_qclist,1);
4874 cpl_msg_info(cpl_func,
"exit");
4876 cpl_propertylist_delete(xplist);
4878 cpl_propertylist_delete(plist);
4884 cpl_free(pcatg_plane);
4885 cpl_propertylist_delete(mainplist);
4886 cpl_propertylist_delete(mypro_lintbl);
4887 cpl_propertylist_delete(mypro_gaintbl);
4888 cpl_propertylist_delete(mypro_coeffscube);
4889 cpl_propertylist_delete(mypro_bpm);
4890 cpl_propertylist_delete(mypro_corr);
4891 cpl_propertylist_delete(mypro_diff);
4893 return cpl_error_get_code();
4906static cpl_error_code
4908 const cpl_imagelist * offs,
4910 cpl_propertylist * qclist)
4918 struct rect rects[5] = {
4941 for (
size_t i = 0; i < 5; i++) {
4942 cpl_image * dif_avg;
4943 const cpl_image * off2;
4947 off2 = cpl_imagelist_get_const(offs, 0);
4949 off2 = cpl_imagelist_get_const(offs, 1);
4952 cpl_imagelist_get_const(offs, 0),
4953 cpl_imagelist_get_const(ons, 1),
4960 median = cpl_image_get_median(dif_avg);
4961 cpl_image_delete(dif_avg);
4966 if(cpl_propertylist_has(qclist,kname)){
4967 skip_if(cpl_propertylist_update_double(qclist,kname,median));
4969 skip_if(cpl_propertylist_append_double(qclist,kname,median));
4976 return cpl_error_get_code();
4990 const char *tag_on,
const char *tag_off)
5002 int nframes = cpl_frameset_get_size(set);
5005 for(
int i = 0; i < nframes; i++) {
5006 cpl_frame* cur_frame = cpl_frameset_get_position(set, i);
5007 const char* tag = cpl_frame_get_tag(cur_frame);
5010 if(!strcmp(tag, tag_on) || !strcmp(tag, tag_off))
5011 cpl_frame_set_group(cur_frame, CPL_FRAME_GROUP_RAW);
5031static cpl_error_code
5033 cpl_image **bpms_ptr)
5052 cpl_imagelist* dummy_coeffs = cpl_imagelist_new();
5054 int* db_p = cpl_image_get_data_int(dummy_bpm);
5055 int* rb_p = cpl_image_get_data_int(*bpms_ptr);;
5067 cpl_imagelist_set(dummy_coeffs, dummy_coeff, i);
5068 dcs_p[i] = cpl_image_get_data_float(dummy_coeff);
5069 rcs_p[i] = cpl_image_get_data_float(cpl_imagelist_get(*coeffs_ptr, i));
5078 *(db_p + i * dlength + j) = *(rb_p + shift_idx);
5081 *(dcs_p[k] + i * dlength + j) =
5087 cpl_imagelist_delete(*coeffs_ptr);
5088 cpl_image_delete(*bpms_ptr);
5089 *coeffs_ptr = dummy_coeffs;
5090 *bpms_ptr = dummy_bpm;
5094 return cpl_error_get_code();
5131#ifdef DETMON_USE_DETECTOR_SHOTNOISE_MODEL
5155xsh_detmon_detector_shotnoise_model(
const cpl_image* ima_data,
const double gain,
5156 const double ron, cpl_image ** ima_errs)
5158 cpl_ensure_code(ima_data, CPL_ERROR_NULL_INPUT);
5159 cpl_ensure_code(ima_errs, CPL_ERROR_NULL_INPUT);
5160 cpl_ensure_code(gain > 0., CPL_ERROR_ILLEGAL_INPUT);
5161 cpl_ensure_code(ron > 0., CPL_ERROR_ILLEGAL_INPUT);
5163 *ima_errs = cpl_image_duplicate(ima_data);
5165 cpl_image_threshold(*ima_errs, 0., INFINITY, ron, ron);
5169 cpl_image_divide_scalar(*ima_errs, gain);
5170 cpl_image_add_scalar(*ima_errs, ron * ron);
5171 cpl_image_power(*ima_errs, 0.5);
5173 return cpl_error_get_code();
5179 const cpl_table* linear_table,
5180 const cpl_imagelist* linearity_inputs,
int nbpixs,
5181 cpl_vector*
x, cpl_propertylist* gaint_qclist,
5182 cpl_image** bpms_ptr)
5189 x = cpl_vector_wrap(nsets,
5190 (
double *) cpl_table_get_data_double_const(linear_table,
5194 x = cpl_vector_wrap(nsets,
5195 (
double *) cpl_table_get_data_double_const(linear_table,
5199 int sz = cpl_imagelist_get_size(linearity_inputs);
5210 cpl_image *ima, *err;
5213 cpl_imagelist*
errors = cpl_imagelist_new();
5235 cpl_imagelist* linearity_scaled = cpl_imagelist_new();
5237 gain = cpl_propertylist_get_double(gaint_qclist,
DETMON_QC_GAIN);
5241 gain = (gain < 0) ? 1 : gain;
5247 for (
int i = 0; i < sz; i++) {
5248 ima = cpl_imagelist_get_const(linearity_inputs, i);
5270 cpl_image_get_mad(ima, &dmad);
5271 err = cpl_image_duplicate(ima);
5272 cpl_image_multiply_scalar(err, 0);
5273 cpl_image_add_scalar(err, dmad * CPL_MATH_STD_MAD);
5283 cpl_imagelist_set(
errors, err, i);
5291 cpl_imagelist_set(linearity_scaled,
5292 cpl_image_duplicate(ima), i));
5295 hdrl_imagelist* hil = hdrl_imagelist_create(linearity_scaled,
errors);
5300 cpl_imagelist_delete(
errors);
5302 double pval = 0.001;
5303 p = hdrl_bpm_fit_parameter_create_pval(1, pval);
5312 hdrl_bpm_fit_compute(p, hil,
x, bpms_ptr);
5337 nbpixs = cpl_image_get_flux(*bpms_ptr);
5339 hdrl_imagelist_delete(hil);
5340 cpl_imagelist_delete(linearity_scaled);
5341 cpl_vector_unwrap((cpl_vector*)
x);
5342 hdrl_parameter_delete(p);
5358 skip_if(*bpms_ptr == NULL);
5379static cpl_error_code
5381 cpl_propertylist * gaint_qclist,
5382 cpl_propertylist * lint_qclist,
5383 cpl_propertylist * linc_qclist,
5384 cpl_propertylist * bpm_qclist,
5385 cpl_imagelist ** coeffs_ptr,
5386 cpl_image ** bpms_ptr,
5387 const cpl_imagelist * linearity_inputs,
5388 const cpl_table * gain_table,
5389 int which_ext, cpl_boolean
opt_nir)
5393 const int linear_nsets = cpl_table_get_nrow(linear_table);
5394 const int gain_nsets = cpl_table_get_nrow(gain_table);
5396 cpl_polynomial *poly_linfit = NULL;
5397 cpl_image *fiterror = NULL;
5398 char * name_o1 = NULL;
5399 char * name_o2 = NULL;
5400 double * pcoeffs = NULL;
5404 cpl_vector *
x =NULL;
5405 const cpl_vector *
y =NULL;
5408 const cpl_image *
first = NULL;
5416 cpl_ensure_code(gaint_qclist != NULL, CPL_ERROR_NULL_INPUT);
5417 cpl_ensure_code(lint_qclist != NULL, CPL_ERROR_NULL_INPUT);
5418 cpl_ensure_code(linc_qclist != NULL, CPL_ERROR_NULL_INPUT);
5419 cpl_ensure_code(bpm_qclist != NULL, CPL_ERROR_NULL_INPUT);
5432 cpl_msg_info(cpl_func,
5433 "Polynomial fitting for the GAIN (constant term method)");
5435 cpl_msg_info(cpl_func,
5436 "Polynomial fitting for the GAIN (constant term method)"
5437 " for extension nb %d", which_ext);
5455 autocorr = cpl_table_get_column_median(gain_table,
"AUTOCORR");
5462 cpl_msg_info(cpl_func,
"Polynomial fitting pix-to-pix");
5464 cpl_msg_info(cpl_func,
"Polynomial fitting pix-to-pix"
5465 " for extension nb %d", which_ext);
5477 y = cpl_vector_wrap(linear_nsets,
5478 (
double *)cpl_table_get_data_double_const(linear_table,
5482 x = cpl_vector_wrap(linear_nsets,
5483 (
double *)cpl_table_get_data_double_const(linear_table,
5486 x = cpl_vector_wrap(linear_nsets,
5487 (
double *)cpl_table_get_data_double_const(linear_table,
5491 if(
x == NULL ||
y == NULL) {
5492 cpl_vector_unwrap((cpl_vector *)
x);
5493 cpl_vector_unwrap((cpl_vector *)
y);
5503 cpl_msg_info(cpl_func,
"Polynomial fitting for the LINEARITY");
5504 poly_linfit = irplib_polynomial_fit_1d_create(
x,
y,
order,&mse);
5506 if(
order == cpl_vector_get_size(
x) - 1) {
5507 cpl_msg_warning(cpl_func,
"The fitting is not over-determined.");
5511 if(poly_linfit == NULL) {
5512 cpl_vector_unwrap((cpl_vector *)
x);
5513 cpl_vector_unwrap((cpl_vector *)
y);
5519 min_val=cpl_vector_get_min(
y);
5520 max_val=cpl_vector_get_max(
y);
5522 cpl_vector_unwrap((cpl_vector *)
x);
5523 cpl_vector_unwrap((cpl_vector *)
y);
5525 for(deg = 0; deg <=
order; deg++) {
5526 const double coeff =
5527 cpl_polynomial_get_coeff(poly_linfit, °);
5529 cpl_sprintf(
"ESO QC LIN COEF%" CPL_SIZE_FORMAT
"", deg);
5530 assert(name_o != NULL);
5531 skip_if(cpl_propertylist_append_double(lint_qclist, name_o, coeff));
5532 skip_if(cpl_propertylist_set_comment(lint_qclist,name_o,
5536 pcoeffs[deg] = coeff;
5538 skip_if(cpl_propertylist_append_double(lint_qclist,
DETMON_QC_ERRFIT, mse));
5546 y = cpl_vector_wrap(linear_nsets,
5547 (
double *)cpl_table_get_data_double_const(linear_table,
5552 x = cpl_vector_wrap(linear_nsets,
5553 (
double *)cpl_table_get_data_double_const(linear_table,
5556 x = cpl_vector_wrap(linear_nsets,
5557 (
double *)cpl_table_get_data_double_const(linear_table,
5562 first = cpl_imagelist_get_const(linearity_inputs, 0);
5563 sizex = cpl_image_get_size_x(
first);
5564 sizey = cpl_image_get_size_y(
first);
5565 vsize = cpl_vector_get_size(
x);
5566 fiterror = cpl_image_new(sizex, sizey, CPL_TYPE_FLOAT);
5568 cpl_fit_imagelist_polynomial(
x, linearity_inputs, 0,
order, FALSE,
5569 CPL_TYPE_FLOAT, fiterror);
5570 min_val=cpl_vector_get_min(
y);
5571 max_val=cpl_vector_get_max(
y);
5572 cpl_vector_unwrap((cpl_vector*)
x);
5573 cpl_vector_unwrap((cpl_vector*)
y);
5575 irplib_ensure(*coeffs_ptr != NULL, CPL_ERROR_UNSPECIFIED,
5576 "Failed polynomial fit");
5579 for(deg = 0; deg <=
order; deg++)
5581 cpl_image *image = cpl_imagelist_get(*coeffs_ptr, deg);
5582 const double coeff = cpl_image_get_median(image);
5583 pcoeffs[deg] = coeff;
5584 name_o1 = cpl_sprintf(
"ESO QC LIN COEF%d", (
int)deg);
5585 name_o2 = cpl_sprintf(
"ESO QC LIN COEF%d ERR", (
int)deg);
5586 assert(name_o1 != NULL);
5587 assert(name_o2 != NULL);
5588 skip_if(cpl_propertylist_append_double(linc_qclist, name_o1, coeff));
5589 skip_if(cpl_propertylist_set_comment(linc_qclist,name_o1,
5593 skip_if(cpl_propertylist_append_double(linc_qclist, name_o2,
5594 cpl_image_get_stdev(image)));
5595 skip_if(cpl_propertylist_set_comment(linc_qclist,name_o2,
5602 if(
order == vsize - 1)
5604 cpl_msg_warning(cpl_func,
"The fitting is not over-determined.");
5612 cpl_image_get_median(fiterror)));
5631 cpl_msg_info(cpl_func,
"Bad pixel detection");
5634 cpl_msg_info(cpl_func,
"Bad pixel detection"
5635 " for extension nb %d", which_ext);
5642 linearity_inputs, nbpixs,
x,gaint_qclist, bpms_ptr);
5668 cpl_image_delete(fiterror);
5669 cpl_polynomial_delete(poly_linfit);
5673 return cpl_error_get_code();
5685static cpl_error_code
5687 cpl_propertylist * qclist,
5693 double residual, slope;
5696 cpl_polynomial * poly = cpl_polynomial_new(1);
5712 for (i = 2; i <=
order; i++)
5715 for(j = 0; j < i; j++)
5717 pcoeffs[i] /= pcoeffs[1];
5723 for (deg = 0; deg <=
order; deg++) {
5725 skip_if(cpl_polynomial_set_coeff(poly, °, pcoeffs[deg]));
5734 residual = cpl_polynomial_eval_1d(poly, 0.0, &slope);
5736 if (slope <= 0.0 && residual >= 0.0) {
5737 cpl_msg_warning(cpl_func,
"Reference level (--ref_level) outside"
5738 " linearity range of the detector. Cannot compute"
5739 " linearity efficiency (QC.LINEFF).");
5744 cpl_error_code err = cpl_polynomial_solve_1d(poly, 0.0, &root, 1);
5749 if (err == CPL_ERROR_NONE)
5757 cpl_msg_warning(cpl_func,
5758 "Cannot compute linearity efficiency (QC.LINEFF)"
5759 "for the current combination "
5760 " of (--ref-level equal %d) and (--order equal %d) parameters. Try "
5764 cpl_msg_warning(cpl_func,
"DETMON_QC_LIN_EFF=%f",lineff );
5777 cpl_polynomial_delete(poly);
5779 return cpl_error_get_code();
5790static cpl_error_code
5792 cpl_propertylist * qclist,
unsigned mode,
int rows_in_gain)
5795 cpl_polynomial *poly_fit = NULL;
5796 cpl_polynomial *poly_fit2 = NULL;
5798 const int nsets = rows_in_gain;
5800 cpl_vector *
x = NULL;
5801 cpl_vector *
y = NULL;
5803 cpl_errorstate prestate;
5805 cpl_ensure_code(gain_table != NULL, CPL_ERROR_NULL_INPUT);
5806 cpl_ensure_code(qclist != NULL, CPL_ERROR_NULL_INPUT);
5808 x = cpl_vector_wrap(nsets, (
double *)cpl_table_get_data_double_const(gain_table,
"X_FIT"));
5810 y = cpl_vector_wrap(nsets, (
double *)cpl_table_get_data_double_const(gain_table,
"Y_FIT"));
5812 skip_if(
x == NULL ||
y == NULL);
5817 cpl_vector_unwrap(
x);
5821 cpl_vector_unwrap(
y);
5823 return CPL_ERROR_NONE;
5826 poly_fit = irplib_polynomial_fit_1d_create_chiq(
x,
y, 1, &mse);
5827 skip_if(poly_fit == NULL);
5831 prestate = cpl_errorstate_get();
5832 coef = cpl_polynomial_get_coeff(poly_fit, &i);
5833 skip_if (!cpl_errorstate_is_equal(prestate) || coef==0);
5834 skip_if(cpl_propertylist_append_double(qclist,
DETMON_QC_CONAD, coef));
5858 const cpl_vector *x2 =
5859 cpl_vector_wrap(nsets, (
double *)cpl_table_get_data_double_const(gain_table,
"X_FIT_CORR"));
5860 const cpl_vector *y2 =
5861 cpl_vector_wrap(nsets, (
double *)cpl_table_get_data_double_const(gain_table,
"Y_FIT"));
5863 if(x2 == NULL || y2 == NULL) {
5864 cpl_vector_unwrap((cpl_vector *)x2);
5865 cpl_vector_unwrap((cpl_vector *)y2);
5876 poly_fit2 = irplib_polynomial_fit_1d_create(x2, y2, 1, &mse);
5877 if(poly_fit2 == NULL) {
5878 cpl_vector_unwrap((cpl_vector *)x2);
5879 cpl_vector_unwrap((cpl_vector *)y2);
5881 cpl_msg_error(cpl_func,
"Error during polynomial fit, err[%s]", cpl_error_get_where());
5885 skip_if(cpl_error_get_code() != CPL_ERROR_NONE);
5886 cpl_vector_unwrap((cpl_vector *)x2);
5887 cpl_vector_unwrap((cpl_vector *)y2);
5888 skip_if(cpl_error_get_code() != CPL_ERROR_NONE);
5891 prestate = cpl_errorstate_get();
5892 coef = cpl_polynomial_get_coeff(poly_fit2, &i);
5893 skip_if(cpl_error_get_code() != CPL_ERROR_NONE);
5894 skip_if (!cpl_errorstate_is_equal(prestate) || coef == 0);
5910 cpl_vector_unwrap(
x);
5911 cpl_vector_unwrap(
y);
5912 cpl_polynomial_delete(poly_fit);
5913 cpl_polynomial_delete(poly_fit2);
5915 return cpl_error_get_code();
5926 const double TOLERANCE = 1e-37;
5927 double xmin = cpl_vector_get_min(
x);
5928 double xmax = cpl_vector_get_max(
x);
5929 double ymin = cpl_vector_get_min(
y);
5930 double ymax = cpl_vector_get_max(
y);
5931 double ystdev = cpl_vector_get_stdev(
y);
5932 double xstdev = cpl_vector_get_stdev(
x);
5934 if (fabs(xmax-xmin) < TOLERANCE &&
5935 fabs(ymax - ymin) < TOLERANCE &&
5936 xstdev < TOLERANCE &&
5939 cpl_msg_warning(cpl_func,
"An empty frame has been detected, linearity, coeffs, gain, FPN values will not be computed.");
5954static cpl_error_code
5956 cpl_propertylist * qclist,
int rows_in_gain)
5960 cpl_vector *
x = NULL;
5961 cpl_vector *
y = NULL;
5962 int check_result = 0;
5964 if (rows_in_gain) {};
5966 x = cpl_vector_wrap(rows_in_gain, (
double *)cpl_table_get_data_double_const(gain_table,
"X_FIT"));
5967 y = cpl_vector_wrap(rows_in_gain, (
double *)cpl_table_get_data_double_const(gain_table,
"Y_FIT"));
5971 cpl_vector_unwrap(
x);
5975 cpl_vector_unwrap(
y);
5977 if (0 == check_result)
5979 return CPL_ERROR_NONE;
5982 gain=cpl_table_get_column_median(gain_table,
"GAIN");
5984 skip_if(cpl_propertylist_append_double(qclist,
DETMON_QC_GAIN,gain));
5990 cpl_table_get_column_stdev
5991 (gain_table,
"GAIN")));
5995 skip_if(cpl_propertylist_append_double(qclist,
DETMON_QC_CONAD,1./gain));
6000 gain=cpl_table_get_column_median(gain_table,
"GAIN_CORR");
6015 return cpl_error_get_code();
6029static cpl_error_code
6033 cpl_image_get_median_window(cpl_imagelist_get(to_rescale, 0),
6039 cpl_image_get_median_window(cpl_imagelist_get(to_rescale, 1),
6047 if(fabs(med1 / med2 - 1) > 0.001) {
6049 skip_if(cpl_image_divide_scalar(cpl_imagelist_get(to_rescale, 0),
6052 skip_if(cpl_image_divide_scalar(cpl_imagelist_get(to_rescale, 1),
6058 return cpl_error_get_code();
6061static cpl_error_code
6066 cpl_frameset ** pair,
6070 double dit_next = -100;
6071 cpl_size* selection;
6072 int nsets_extracted = 0;
6073 cpl_ensure_code(set != NULL, CPL_ERROR_NULL_INPUT);
6074 cpl_ensure_code(dit_array != NULL, CPL_ERROR_NULL_INPUT);
6075 cpl_ensure_code(iindex != NULL, CPL_ERROR_NULL_INPUT);
6076 cpl_ensure_code(pair != NULL, CPL_ERROR_NULL_INPUT);
6078 nsets_extracted = cpl_frameset_get_size(set);
6079 selection = cpl_malloc(
sizeof(cpl_size) * nsets_extracted);
6080 memset(&selection[0], 0,
sizeof(cpl_size) * nsets_extracted);
6083 dit = dit_array[*next_element ];
6085 if (*next_element < nsets_extracted - 1)
6087 dit_next = dit_array[*next_element + 1 ];
6091 selection[iindex[*next_element] ] = 1;
6095 selection[iindex[*next_element + 1] ] = 1;
6100 cpl_msg_warning(cpl_func,
"DIT for the second frame in the pair is above tolerance level - could not be taken, dit1[%f] dit2[%f] next_element: %d . Check input data set and tolerance value", dit, dit_next, *next_element);
6104 cpl_frameset_delete(*pair);
6105 *pair = cpl_frameset_extract(set, selection, 1);
6108 cpl_free(selection);
6109 return cpl_error_get_code();
6112static cpl_error_code
6117 cpl_frameset ** pair)
6119 cpl_size* selection;
6120 int nsets_extracted = 0;
6121 cpl_ensure_code(set != NULL, CPL_ERROR_NULL_INPUT);
6122 cpl_ensure_code(dit_array != NULL, CPL_ERROR_NULL_INPUT);
6123 cpl_ensure_code(iindex != NULL, CPL_ERROR_NULL_INPUT);
6124 cpl_ensure_code(pair != NULL, CPL_ERROR_NULL_INPUT);
6126 nsets_extracted = cpl_frameset_get_size(set);
6127 selection = cpl_malloc(
sizeof(cpl_size) * nsets_extracted);
6128 memset(&selection[0], 0,
sizeof(cpl_size) * nsets_extracted);
6131 selection[iindex[*next_element] ] = 1;
6134 cpl_frameset_delete(*pair);
6135 *pair = cpl_frameset_extract(set, selection, 1);
6137 cpl_free(selection);
6138 return cpl_error_get_code();
6237 const cpl_imagelist * imlist_off,
6238 const cpl_vector * exptimes,
6239 const cpl_vector * ndit,
6249 cpl_propertylist * qclist,
6251 cpl_imagelist ** diff_imlist,
6252 cpl_imagelist ** autocorr_imlist)
6254 cpl_table * gain_table = NULL;
6255 cpl_imagelist * difflist = NULL;
6256 cpl_imagelist * autocorrlist = NULL;
6257 cpl_imagelist * c_onlist = NULL;
6258 cpl_imagelist * c_offlist = NULL;
6259 cpl_vector * diffdits = NULL;
6260 cpl_vector * diffndits = NULL;
6261 int rows_in_gain = 0;
6262 int ndiffdits, ndits;
6267 cpl_ensure(imlist_on != NULL, CPL_ERROR_NULL_INPUT, NULL);
6268 cpl_ensure(imlist_off != NULL, CPL_ERROR_NULL_INPUT, NULL);
6269 cpl_ensure(exptimes != NULL, CPL_ERROR_NULL_INPUT, NULL);
6270 cpl_ensure(qclist != NULL, CPL_ERROR_NULL_INPUT, NULL);
6273 gain_table = cpl_table_new(cpl_vector_get_size(exptimes) / 2);
6280 ndiffdits = cpl_vector_get_size(diffdits);
6282 ndits = cpl_vector_get_size(exptimes);
6286 difflist = cpl_imagelist_new();
6287 autocorrlist = cpl_imagelist_new();
6292 c_offlist = cpl_imagelist_duplicate(imlist_off);
6295 c_offlist = (cpl_imagelist *) imlist_off;
6300 for (i = 0; i < ndiffdits; i++) {
6307 c_dit=cpl_vector_get(diffdits, i);
6310 c_ndit=(int)cpl_vector_get(diffndits, i);
6313 c_onlist = cpl_imagelist_new();
6317 c_offlist = cpl_imagelist_new();
6322 for(j = 0; j < ndits; j++) {
6323 if (fabs(c_dit - cpl_vector_get(exptimes, j)) <=
tolerance) {
6334 const cpl_image * im =
6335 cpl_imagelist_get_const(imlist_on, j);
6336 im_on = cpl_image_duplicate(im);
6338 im_on = (cpl_image *)cpl_imagelist_get_const(imlist_on, j);
6340 skip_if(cpl_imagelist_set(c_onlist, im_on, c_nons));
6350 const cpl_image * im =
6351 cpl_imagelist_get_const(imlist_off, j);
6352 im_off = cpl_image_duplicate(im);
6355 (cpl_image *) cpl_imagelist_get_const(imlist_off, j);
6357 skip_if(cpl_imagelist_set(c_offlist, im_off, c_noffs));
6365 skip_if (c_nons != c_noffs);
6368 skip_if (c_nons == 0 || c_nons % 2 != 0);
6380 int rows_affected = 1;
6385 c_offlist,
kappa, nclip,
6387 xshift, yshift,1E10, 1E10, i,
6388 mode, &rows_affected));
6394 cpl_image_delete(cpl_imagelist_unset(c_onlist, 0));
6395 cpl_image_delete(cpl_imagelist_unset(c_onlist, 0));
6397 cpl_image_delete(cpl_imagelist_unset(c_offlist, 0));
6398 cpl_image_delete(cpl_imagelist_unset(c_offlist, 0));
6401 cpl_imagelist_unset(c_onlist, 0);
6403 cpl_imagelist_unset(c_onlist, 0);
6406 cpl_imagelist_unset(c_offlist, 0);
6408 cpl_imagelist_unset(c_offlist, 0);
6416 cpl_imagelist_delete(c_onlist);
6418 cpl_imagelist_delete(c_offlist);
6434 double autocorr = cpl_table_get_column_median(gain_table,
"AUTOCORR");
6441 if (diff_imlist != NULL) *diff_imlist = difflist;
6442 if (autocorr_imlist != NULL) *autocorr_imlist = autocorrlist;
6446 cpl_vector_delete(diffdits);
6447 cpl_vector_delete(diffndits);
6452static cpl_error_code
6457 skip_if(cpl_table_new_column(gain_table,
"DIT", CPL_TYPE_DOUBLE));
6458 skip_if(cpl_table_new_column(gain_table,
"NDIT", CPL_TYPE_INT));
6460 skip_if(cpl_table_new_column(gain_table,
"EXPTIME", CPL_TYPE_DOUBLE));
6462 skip_if(cpl_table_new_column(gain_table,
"MEAN_ON1", CPL_TYPE_DOUBLE));
6463 skip_if(cpl_table_new_column(gain_table,
"MEAN_ON2", CPL_TYPE_DOUBLE));
6464 skip_if(cpl_table_new_column(gain_table,
"MEAN_OFF1", CPL_TYPE_DOUBLE));
6465 skip_if(cpl_table_new_column(gain_table,
"MEAN_OFF2", CPL_TYPE_DOUBLE));
6466 skip_if(cpl_table_new_column(gain_table,
"SIG_ON_DIF", CPL_TYPE_DOUBLE));
6467 skip_if(cpl_table_new_column(gain_table,
"SIG_OFF_DIF", CPL_TYPE_DOUBLE));
6468 skip_if(cpl_table_new_column(gain_table,
"GAIN", CPL_TYPE_DOUBLE));
6469 skip_if(cpl_table_new_column(gain_table,
"AUTOCORR", CPL_TYPE_DOUBLE));
6470 skip_if(cpl_table_new_column(gain_table,
"GAIN_CORR", CPL_TYPE_DOUBLE));
6471 skip_if(cpl_table_new_column(gain_table,
"ADU", CPL_TYPE_DOUBLE));
6472 skip_if(cpl_table_new_column(gain_table,
"X_FIT", CPL_TYPE_DOUBLE));
6473 skip_if(cpl_table_new_column(gain_table,
"X_FIT_CORR", CPL_TYPE_DOUBLE));
6474 skip_if(cpl_table_new_column(gain_table,
"Y_FIT", CPL_TYPE_DOUBLE));
6475 skip_if(cpl_table_new_column(gain_table,
"Y_FIT_CORR", CPL_TYPE_DOUBLE));
6476 skip_if(cpl_table_new_column(gain_table,
"FLAG", CPL_TYPE_INT));
6480 return cpl_error_get_code();
6483static cpl_error_code
6488 skip_if(cpl_table_new_column(lin_table,
"DIT", CPL_TYPE_DOUBLE));
6490 skip_if(cpl_table_new_column(lin_table,
"EXPTIME", CPL_TYPE_DOUBLE));
6492 skip_if(cpl_table_new_column(lin_table,
"MED", CPL_TYPE_DOUBLE));
6493 skip_if(cpl_table_new_column(lin_table,
"MEAN", CPL_TYPE_DOUBLE));
6494 skip_if(cpl_table_new_column(lin_table,
"MED_DIT", CPL_TYPE_DOUBLE));
6495 skip_if(cpl_table_new_column(lin_table,
"MEAN_DIT", CPL_TYPE_DOUBLE));
6496 skip_if(cpl_table_new_column(lin_table,
"ADL", CPL_TYPE_DOUBLE));
6499 return cpl_error_get_code();
6506 cpl_vector * dits = cpl_vector_new(cpl_vector_get_size(exptimes) / 2);
6512 cpl_vector_set(dits, 0, cpl_vector_get(exptimes, 0));
6516 for(i = 1; i < cpl_vector_get_size(exptimes); i++) {
6518 for (j = 0; j < ndits; j++) {
6519 if (fabs(cpl_vector_get(exptimes, i) -
6523 if(ndiffs == ndits) {
6524 cpl_vector_set(dits, ndits, cpl_vector_get(exptimes, i));
6529 cpl_vector_set_size(dits, ndits);
6537static cpl_error_code
6539 const cpl_vector * vec_ndits,
6541 cpl_vector** diff_dits,
6542 cpl_vector** diff_ndits)
6550 * diff_dits = cpl_vector_new(cpl_vector_get_size(exptimes) / 2);
6551 * diff_ndits = cpl_vector_new(cpl_vector_get_size(*diff_dits));
6554 cpl_vector_set(*diff_dits, 0, cpl_vector_get(exptimes, 0));
6555 cpl_vector_set(*diff_ndits, 0, cpl_vector_get(vec_ndits, 0));
6558 size=cpl_vector_get_size(exptimes);
6560 for(i = 1; i <
size; i++) {
6562 for (j = 0; j < ndits; j++) {
6563 if (fabs(cpl_vector_get(exptimes, i) -
6564 cpl_vector_get(*diff_dits,j)) >
tolerance)
6567 if(ndiffs == ndits) {
6568 cpl_vector_set(*diff_dits, ndits, cpl_vector_get(exptimes, i));
6569 cpl_vector_set(*diff_ndits, ndits, cpl_vector_get(vec_ndits, i));
6574 cpl_vector_set_size(*diff_dits, ndits);
6575 cpl_vector_set_size(*diff_ndits, ndits);
6578 return cpl_error_get_code();
6669 const cpl_imagelist * imlist_off,
6670 const cpl_vector * exptimes,
6680 cpl_propertylist * qclist,
6682 cpl_imagelist ** coeffs_cube,
6685 cpl_table * lin_table = NULL;
6686 cpl_imagelist * c_onlist = NULL;
6687 cpl_imagelist * c_offlist = NULL;
6688 cpl_vector * diffdits = NULL;
6689 cpl_imagelist * lin_inputs = NULL;
6690 cpl_polynomial * poly_linfit = NULL;
6691 cpl_image * fiterror = NULL;
6692 cpl_vector * vcoeffs = NULL;
6693 double * pcoeffs = NULL;
6694 int ndiffdits, ndits;
6697 const cpl_vector *
x = NULL;
6698 const cpl_vector *
y = NULL;
6700 const cpl_image *
first = NULL;
6708 cpl_ensure(imlist_on != NULL, CPL_ERROR_NULL_INPUT, NULL);
6709 cpl_ensure(imlist_off != NULL, CPL_ERROR_NULL_INPUT, NULL);
6710 cpl_ensure(exptimes != NULL, CPL_ERROR_NULL_INPUT, NULL);
6711 cpl_ensure(qclist != NULL, CPL_ERROR_NULL_INPUT, NULL);
6712 cpl_ensure(
order > 0 , CPL_ERROR_ILLEGAL_INPUT, NULL);
6714 vcoeffs = cpl_vector_new(
order + 1);
6715 pcoeffs = cpl_vector_get_data(vcoeffs);
6719 cpl_ensure(coeffs_cube != NULL, CPL_ERROR_NULL_INPUT, NULL);
6720 cpl_ensure(bpm != NULL, CPL_ERROR_NULL_INPUT, NULL);
6721 lin_inputs = cpl_imagelist_new();
6725 lin_table = cpl_table_new(cpl_vector_get_size(exptimes) / 2);
6731 ndiffdits = cpl_vector_get_size(diffdits);
6733 ndits = cpl_vector_get_size(exptimes);
6768 cpl_image *
collapse = cpl_imagelist_collapse_create(imlist_off);
6771 c_offlist = cpl_imagelist_new();
6772 skip_if(cpl_imagelist_set(c_offlist,
collapse, 0));
6776 for (i = 0; i < ndiffdits; i++) {
6780 double c_dit = cpl_vector_get(diffdits, i);
6782 c_onlist = cpl_imagelist_new();
6786 c_offlist = cpl_imagelist_new();
6790 for(j = 0; j < ndits; j++) {
6791 if (fabs(c_dit - cpl_vector_get(exptimes, j)) <=
tolerance) {
6802 const cpl_image * im =
6803 cpl_imagelist_get_const(imlist_on, j);
6804 im_on = cpl_image_duplicate(im);
6806 im_on = (cpl_image *)cpl_imagelist_get_const(imlist_on, j);
6808 skip_if(cpl_imagelist_set(c_onlist, im_on, c_nons));
6818 const cpl_image * im =
6819 cpl_imagelist_get_const(imlist_off, j);
6820 im_off = cpl_image_duplicate(im);
6823 (cpl_image *) cpl_imagelist_get_const(imlist_off, j);
6825 skip_if(cpl_imagelist_set(c_offlist, im_off, c_noffs));
6833 skip_if (c_nons != c_noffs);
6836 skip_if (c_nons == 0 || c_nons % 2 != 0);
6851 c_onlist, c_offlist,
6856 cpl_image_delete(cpl_imagelist_unset(c_onlist, 0));
6857 cpl_image_delete(cpl_imagelist_unset(c_onlist, 0));
6859 cpl_image_delete(cpl_imagelist_unset(c_offlist, 0));
6860 cpl_image_delete(cpl_imagelist_unset(c_offlist, 0));
6863 cpl_imagelist_unset(c_onlist, 0);
6865 cpl_imagelist_unset(c_onlist, 0);
6868 cpl_imagelist_unset(c_offlist, 0);
6870 cpl_imagelist_unset(c_offlist, 0);
6878 cpl_imagelist_delete(c_onlist);
6880 cpl_imagelist_delete(c_offlist);
6889 y = cpl_vector_wrap(cpl_table_get_nrow(lin_table),
6890 (
double *)cpl_table_get_data_double_const(lin_table,
6893 x=cpl_vector_wrap(cpl_table_get_nrow(lin_table),
6894 (
double *)cpl_table_get_data_double_const(lin_table,
"DIT"));
6896 x=cpl_vector_wrap(cpl_table_get_nrow(lin_table),
6897 (
double *)cpl_table_get_data_double_const(lin_table,
"EXPTIME"));
6899 if(
x == NULL ||
y == NULL) {
6900 cpl_vector_unwrap((cpl_vector *)
x);
6901 cpl_vector_unwrap((cpl_vector *)
y);
6911 cpl_msg_info(cpl_func,
"Polynomial fitting for the LINEARITY");
6912 poly_linfit = irplib_polynomial_fit_1d_create_chiq(
x,
y,
order, &mse);
6914 if(
order == cpl_vector_get_size(
x) - 1) {
6915 cpl_msg_warning(cpl_func,
"The fitting is not over-determined.");
6919 if(poly_linfit == NULL) {
6920 cpl_vector_unwrap((cpl_vector *)
x);
6921 cpl_vector_unwrap((cpl_vector *)
y);
6926 cpl_vector_unwrap((cpl_vector *)
x);
6927 cpl_vector_unwrap((cpl_vector *)
y);
6929 for(deg = 0; deg <=
order; deg++) {
6930 const double coeff =
6931 cpl_polynomial_get_coeff(poly_linfit, °);
6933 cpl_sprintf(
"ESO QC LIN COEF%" CPL_SIZE_FORMAT
"", deg);
6934 assert(name_o != NULL);
6935 skip_if(cpl_propertylist_append_double(qclist, name_o, coeff));
6936 skip_if(cpl_propertylist_set_comment(qclist,name_o,
6939 pcoeffs[deg] = coeff;
6948 x=cpl_vector_wrap(cpl_table_get_nrow(lin_table),
6949 (
double *)cpl_table_get_data_double_const(lin_table,
6952 x=cpl_vector_wrap(cpl_table_get_nrow(lin_table),
6953 (
double *)cpl_table_get_data_double_const(lin_table,
6958 first = cpl_imagelist_get_const(lin_inputs, 0);
6959 sizex = cpl_image_get_size_x(
first);
6960 sizey = cpl_image_get_size_y(
first);
6962 vsize = cpl_vector_get_size(
x);
6964 fiterror = cpl_image_new(sizex, sizey, CPL_TYPE_FLOAT);
6967 cpl_fit_imagelist_polynomial(
x, lin_inputs, 0,
6968 order, FALSE, CPL_TYPE_FLOAT,
6971 cpl_vector_unwrap((cpl_vector*)
x);
6972 irplib_ensure(*coeffs_cube != NULL, CPL_ERROR_UNSPECIFIED,
6973 "Failed polynomial fit");
6975 for(i = 0; i <=
order; i++) {
6976 cpl_image *image = cpl_imagelist_get(*coeffs_cube, i);
6977 const double coeff = cpl_image_get_median(image);
6978 char * name_o1 = cpl_sprintf(
"ESO QC LIN COEF%d", i);
6979 char * name_o2 = cpl_sprintf(
"ESO QC LIN COEF%d ERR", i);
6981 assert(name_o1 != NULL);
6982 assert(name_o2 != NULL);
6983 skip_if(cpl_propertylist_append_double(qclist, name_o1, coeff));
6984 skip_if(cpl_propertylist_set_comment(qclist,name_o1,
6988 skip_if(cpl_propertylist_append_double(qclist, name_o2,
6989 cpl_image_get_stdev(image)));
6990 skip_if(cpl_propertylist_set_comment(qclist,name_o2,
6996 if(
order == vsize - 1) {
6997 cpl_msg_warning(cpl_func,
"The fitting is not over-determined.");
7006 cpl_image_get_median(fiterror)));
7018 skip_if(*bpm == NULL);
7027 cpl_vector_delete(diffdits);
7028 cpl_polynomial_delete(poly_linfit);
7029 cpl_imagelist_delete(lin_inputs);
7030 cpl_vector_delete(vcoeffs);
7031 cpl_image_delete(fiterror);
7062static cpl_error_code
7064 cpl_imagelist * linearity_inputs,
7065 const cpl_imagelist * ons,
7066 const cpl_imagelist * offs,
7075 cpl_image * extracted=NULL;
7077 cpl_ensure_code(lin_table != NULL, CPL_ERROR_NULL_INPUT);
7078 cpl_ensure_code(ons != NULL, CPL_ERROR_NULL_INPUT);
7079 cpl_ensure_code(offs != NULL, CPL_ERROR_NULL_INPUT);
7082 cpl_msg_debug(cpl_func,
"checking linearity inputs");
7083 cpl_ensure_code(linearity_inputs != NULL, CPL_ERROR_NULL_INPUT);
7088 cpl_table_set(lin_table,
"DIT", pos, c_dit);
7090 cpl_table_set(lin_table,
"EXPTIME", pos, c_dit);
7092 cpl_msg_error(cpl_func,
"Mandatory mode not given");
7096 const cpl_image * off2;
7098 off2 = cpl_imagelist_get_const(offs, 0);
7100 off2 = cpl_imagelist_get_const(offs, 1);
7103 cpl_imagelist_get_const(offs, 0),
7104 cpl_imagelist_get_const(ons, 1),
7107 cpl_ensure_code(extracted != NULL, cpl_error_get_code());
7111 double median = cpl_image_get_median(extracted);
7112 double mean= cpl_image_get_mean(extracted);
7113 cpl_table_set(lin_table,
"MED", pos, median);
7114 cpl_table_set(lin_table,
"MEAN", pos, mean);
7116 cpl_table_set(lin_table,
"MED_DIT", pos, median / c_dit);
7117 cpl_table_set(lin_table,
"MEAN_DIT", pos, mean / c_dit);
7122 cpl_error_code error = cpl_imagelist_set(linearity_inputs, extracted,
7124 cpl_ensure_code(!error, error);
7126 cpl_image_delete(extracted);
7129 return cpl_error_get_code();
7133 int pattern_x,
int pattern_y)
7135 cpl_image * p_tmp_image = 0;
7136 cpl_image * psmooth_image = 0;
7138 cpl_mask * mask = cpl_mask_new(pattern_x, pattern_y);
7140 p_tmp_image = cpl_image_duplicate(pimage);
7141 cpl_image_filter_mask(p_tmp_image,pimage, mask,CPL_FILTER_MEDIAN ,CPL_BORDER_FILTER);
7142 cpl_image_divide_scalar(p_tmp_image, cpl_image_get_median(pimage));
7143 psmooth_image = cpl_image_divide_create(pimage,p_tmp_image);
7145 cpl_mask_delete(mask);
7146 cpl_image_delete(psmooth_image);
7147 cpl_image_delete(p_tmp_image);
7153 double total_noise = -1;
7154 unsigned long max_bin_size = 1E5;
7155 const double hstart = cpl_image_get_min(pimage);
7156 const double hrange = cpl_image_get_max(pimage) - hstart;
7157 const unsigned long nbins = max_bin_size;
7158 cpl_error_code err = CPL_ERROR_NONE;
7160 irplib_hist * phist = 0;
7161 phist = irplib_hist_new();
7164 irplib_hist_init(phist, nbins, hstart, hrange);
7165 err = irplib_hist_fill(phist, pimage);
7166 if (err == CPL_ERROR_NONE)
7174 unsigned long n_bins = irplib_hist_get_nbins(phist);
7175 double start = irplib_hist_get_start(phist);
7176 double bin_size = irplib_hist_get_bin_size(phist);
7177 cpl_vector* pdata_vector = cpl_vector_new(n_bins);
7178 cpl_vector* ppos_vector = cpl_vector_new(n_bins);
7179 cpl_table* ptable = cpl_table_new(n_bins);
7180 cpl_table_new_column(ptable,
"bin", CPL_TYPE_DOUBLE);
7181 cpl_table_new_column(ptable,
"value", CPL_TYPE_DOUBLE);
7182 for(i = 0; i < n_bins; i++)
7184 unsigned int value = irplib_hist_get_value(phist, i);
7185 double dvalue = (double)(value);
7186 cpl_vector_set(pdata_vector, i, dvalue);
7187 cpl_vector_set(ppos_vector, i, start + i * bin_size);
7189 cpl_table_set(ptable,
"bin", i, start + i * bin_size);
7190 cpl_table_set(ptable,
"value", i, dvalue);
7192 err = cpl_vector_fit_gaussian(ppos_vector, NULL, pdata_vector, NULL, CPL_FIT_ALL, &x0, &total_noise, &area, &offset, NULL, NULL, NULL );
7193 if (err == CPL_ERROR_NONE)
7195 cpl_msg_info(cpl_func,
"FPN Calculation: histogram x0[%f] total_noise[%f] area[%f] offset[%f]", x0, total_noise, area, offset);
7199 cpl_msg_warning(cpl_func,
"FPN could not be computed due failed Gaussian Fit, err msg [%s]", cpl_error_get_message());
7202 cpl_table_delete(ptable);
7203 cpl_vector_delete(ppos_vector);
7204 cpl_vector_delete(pdata_vector);
7208 cpl_msg_warning(cpl_func,
"FPN could not be computed due failed histogram computation, err msg [%s]", cpl_error_get_message());
7211 irplib_hist_delete(phist);
7218 double int_gain = (gain * gain - 1) / 12;
7223 return sqrt(ron * ron + FA / gain + int_gain);
7229 cpl_image* im_diff = 0;
7230 const cpl_image* im_f1 = f1;
7231 cpl_image* im_inrange1 = 0;
7240 cpl_msg_warning(cpl_func,
"gain[%f]<0", gain);
7241 cpl_msg_warning(cpl_func,
"We set dummy values for FPN");
7248 im_inrange1 = cpl_image_extract(f1, range[0], range[1], range[2], range[3]);
7249 im_f1 = im_inrange1;
7251 FA = cpl_image_get_median(im_f1);
7258 cpl_msg_info(cpl_func,
"SMOOTH method is used for FPN, pattern size[%d x %d] pixels",smooth_size,smooth_size );
7262 cpl_msg_info(cpl_func,
"HISTOGRAM method is used for FPN");
7268 cpl_msg_warning(cpl_func,
"fpn_method is not defined");
7277 cpl_msg_warning(cpl_func,
"Median flux on sum of flats<0");
7278 cpl_msg_warning(cpl_func,
"We set dummy values for FPN");
7283 if ((s_tot * s_tot - FA / gain) > 0)
7285 s_fpn = sqrt(s_tot * s_tot - FA / gain);
7286 sr_fpn = s_fpn / FA;
7291 cpl_msg_warning(cpl_func,
"s_tot * s_tot < FA / gain");
7292 cpl_msg_warning(cpl_func,
"We set dummy values for FPN");
7301 cpl_image_delete(im_diff);
7304 cpl_image_delete(im_inrange1);
7311 cpl_type type ,
int whichext)
7325 cpl_type type ,
int whichext)
7328 cpl_imagelist* offs = cpl_imagelist_new();
7335 cpl_propertylist* plist)
7337 if (ptable && plist)
7339 int size = cpl_propertylist_get_size(plist);
7341 for (i = 0; i <
size; i++)
7343 cpl_property* pprop = cpl_propertylist_get(plist,i);
7346 const char* pname = cpl_property_get_name(pprop);
7349 cpl_table_new_column(ptable, pname, cpl_property_get_type(pprop));
7350 if (cpl_error_get_code() != CPL_ERROR_NONE)
7352 cpl_msg_warning(cpl_func,
"cannot create new column[%s], err[%s]", pname, cpl_error_get_message());
7359 return cpl_error_get_code();
7363 cpl_propertylist* plist,
int row)
7365 cpl_error_code err = CPL_ERROR_NONE;
7366 if (ptable && plist)
7368 int size = cpl_propertylist_get_size(plist);
7370 for (i = 0; i <
size; i++)
7372 cpl_property* pprop = cpl_propertylist_get(plist,i);
7375 const char* pname = cpl_property_get_name(pprop);
7376 double value = cpl_property_get_double(pprop);
7379 cpl_table_set_double(ptable, pname, row, value);
7380 if (cpl_error_get_code() != CPL_ERROR_NONE)
7382 cpl_msg_warning(cpl_func,
"cannot write value to the table, column[%s] value[%f], err[%s]", pname, value, cpl_error_get_message());
7412 }
while(i < sz - 1);
7417 cpl_error_set_message(cpl_func,CPL_ERROR_INCOMPATIBLE_INPUT,
7418 "Not enough frames for the polynomial"
7419 " fitting. nsets = %d <= %d order",
7422 return cpl_error_get_code();
7425static cpl_error_code
7427 cpl_frameset * frameset,
7428 const cpl_parameterlist * parlist,
7429 const cpl_frameset *usedframes,
7430 const cpl_imagelist *coeffs,
7431 const char *recipe_name,
7432 const cpl_propertylist *mypro_coeffscube,
7433 const char * package,
7434 const char * name_o)
7436 return(cpl_dfs_save_imagelist
7437 (frameset, NULL, parlist, usedframes, NULL,coeffs, CPL_BPP_IEEE_FLOAT,
7438 recipe_name, mypro_coeffscube, NULL, package,
7444 const cpl_image*
first = cpl_imagelist_get(imlist, 0);
7447 int x = cpl_image_get_size_x(
first);
7448 int y = cpl_image_get_size_y(
first);
7449 cpl_type type = cpl_image_get_type(
first);
7450 cpl_image * blank = cpl_image_new(
x,
y, type);
7451 cpl_imagelist_set(imlist, blank, pos);
7467 }
else if (ntag_new) {
7471 cpl_msg_error(cpl_func,
"Provide %s and %s (or %s and %s) input frames",
7477 return cpl_error_get_code();
irplib_error errors[MAX_ERRORS]
double xsh_detmon_retrieve_par_double(const char *parn, const char *pipeline_name, const char *recipe_name, const cpl_parameterlist *parlist)
cpl_error_code xsh_detmon_fill_parlist(cpl_parameterlist *parlist, const char *recipe_name, const char *pipeline_name, int npars,...)
int xsh_detmon_retrieve_par_int(const char *parn, const char *pipeline_name, const char *recipe_name, const cpl_parameterlist *parlist)
double irplib_pfits_get_exptime(const cpl_propertylist *plist)
static cpl_error_code TYPE_ADD() xsh_ksigma_clip(const CPL_TYPE *pi, cpl_binary *pm, int llx, int lly, int urx, int ury, int nx, double var_sum, int npixs, double kappa, int nclip, double tolerance, double *mean, double *stdev)
static cpl_error_code xsh_detmon_lg_save_image_with_pro_keys(cpl_image *image, const char *name_o, cpl_propertylist *xheader)
Save cube product.
double xsh_detmon_gain_prepare_table(const cpl_imagelist *offs, unsigned mode, int llx, int lly, int urx, int ury, double kappa, int nclip, double avg_off1, double std, const int pos, cpl_table *gain_table, double *avg_off2, double *sig_off_dif)
static cpl_error_code xsh_detmon_lg_find_dits_ndits(const cpl_vector *exptimes, const cpl_vector *vec_ndits, double tolerance, cpl_vector **diff_dits, cpl_vector **diff_ndits)
cpl_error_code xsh_detmon_lg_fill_parlist(cpl_parameterlist *parlist, const char *recipe_name, const char *pipeline_name, const char *method, int order, double kappa, int niter, int llx, int lly, int urx, int ury, int ref_level, const char *intermediate, const char *autocorr, const char *collapse, const char *rescale, const char *pix2pix, const char *bpmbin, int filter, int m, int n, double tolerance, const char *pafgen, const char *pafname, int llx1, int lly1, int urx1, int ury1, int llx2, int lly2, int urx2, int ury2, int llx3, int lly3, int urx3, int ury3, int llx4, int lly4, int urx4, int ury4, int llx5, int lly5, int urx5, int ury5, int exts, cpl_boolean opt_nir)
Generic parlist filling for Lin/Gain recipe.
static double irplib_calculate_total_noise(const cpl_image *pimage)
static cpl_error_code xsh_detmon_add_adl_column(cpl_table *, cpl_boolean)
Compute ADL column of Linearity Table.
static cpl_error_code xsh_detmon_lg_qc_med(const cpl_table *, cpl_propertylist *, int)
MED method final computation. The median and stdev of the column "GAIN", and the median of the column...
static cpl_image * xsh_detmon_bpixs(const cpl_imagelist *, cpl_boolean, const double, int *)
Produce bad pixel map according to coefficients' cube.
double xsh_detmon_gain_prepare_autocorr(unsigned mode, const int pos, double autocorr, int m, int n, cpl_imagelist *diff_flats, cpl_image *on_dif, cpl_imagelist *autocorr_images)
static double irplib_pfits_get_prop_double(const cpl_propertylist *plist, const char *prop_name)
static cpl_error_code xsh_detmon_pair_extract_next(const cpl_frameset *set, int *index, int *next_element, double *dit_array, cpl_frameset **pair, double tolerance)
static cpl_error_code xsh_detmon_lg_core(cpl_frameset *cur_fset_on, cpl_frameset *cur_fset_off, int *index_on, int *index_off, double *exptime_on, double *exptime_off, int whichext, int whichset, const char *recipe_name, const char *pipeline_name, const char *pafregexp, const cpl_propertylist *pro_lintbl, const cpl_propertylist *pro_gaintbl, const cpl_propertylist *pro_coeffscube, const cpl_propertylist *pro_bpm, const cpl_propertylist *pro_corr, const cpl_propertylist *pro_diff, const char *package, int(*load_fset)(const cpl_frameset *, cpl_type, cpl_imagelist *), int nsets, cpl_boolean opt_nir, cpl_frameset *frameset, const cpl_parameterlist *parlist, cpl_frameset *cur_fset)
Core: Reduction and saving (encapsulated to avoid repetition)
static cpl_error_code xsh_detmon_lg_reduce_init(cpl_table *, cpl_table *, cpl_imagelist **, const cpl_boolean)
Create columns of product tables and init linearity_inputs.
static cpl_error_code xsh_detmon_lg_lineff(double *, cpl_propertylist *, int, int)
Linearity effective correction (LIN.EFF) computation.
int(* load_fset)(const cpl_frameset *, cpl_type, cpl_imagelist *)
static cpl_error_code xsh_detmon_lg_save_plane(const cpl_parameterlist *parlist, cpl_frameset *frameset, const cpl_frameset *usedframes, int whichext, const char *recipe_name, cpl_propertylist *mypro_coeffscube, cpl_propertylist *linc_plane_qclist, const char *package, const char *NAME_O, cpl_image *plane)
Save cube product.
static void xsh_detmon_lg_add_empty_image(cpl_imagelist *imlist, int pos)
cpl_image * xsh_detmon_autocorrelate(const cpl_image *input2, const int m, const int n)
int xsh_detmon_compute_badpixmap(cpl_boolean opt_nir, const int nsets, const cpl_table *linear_table, const cpl_imagelist *linearity_inputs, int nbpixs, cpl_vector *x, cpl_propertylist *gaint_qclist, cpl_image **bpms_ptr)
cpl_error_code xsh_detmon_lg_fill_parlist_nir_default_mr(cpl_parameterlist *parlist, const char *recipe_name, const char *pipeline_name)
static char * xsh_detmon_lg_set_paf_name_and_header(cpl_frame *ref_frame, int flag_sets, int which_set, int whichext, const char *paf_suf, cpl_propertylist **plist)
int xsh_detmon_lg_dfs_set_groups(cpl_frameset *, const char *, const char *)
DFS related function.
static double xsh_detmon_autocorr_factor(const cpl_image *, cpl_image **, int, int)
Produce bad pixel map by comparing to coefficients' cube fits to actual intensity values.
static cpl_error_code xsh_detmon_fpn_compute(const cpl_frameset *set_on, int *index_on, int last_linear_best, cpl_propertylist *lint_qclist, int llx, int lly, int urx, int ury, double gain, int whichext, FPN_METHOD fpn_method, int smooth_size)
static cpl_error_code xsh_detmon_lg_check_defaults(const cpl_image *)
Check and set default values with depend on the inputs.
static cpl_error_code xsh_detmon_lg_reduce_dit(const cpl_frameset *set_on, int *index_on, double *exptime_on, const int dit_nb, int *dit_nskip, const cpl_frameset *set_off, int *index_off, double *exptime_off, int *next_on, int *next_off, cpl_table *linear_table, cpl_table *gain_table, cpl_imagelist *linearity_inputs, cpl_propertylist *qclist, cpl_boolean opt_nir, cpl_imagelist *autocorr_images, cpl_imagelist *diff_flats, cpl_imagelist *opt_offs, int whichext, int *rows_linear_affected, int *rows_gain_affected)
Reduction step to be applied together to frames of same DIT.
static cpl_error_code xsh_detmon_lg_rescale(cpl_imagelist *)
Rescale of images (one to another level)
static cpl_error_code xsh_detmon_opt_contamination(const cpl_imagelist *, const cpl_imagelist *, unsigned mode, cpl_propertylist *)
Contamination computation (OPT only)
static cpl_error_code xsh_detmon_lin_table_create(cpl_table *, const cpl_boolean)
cpl_error_code xsh_detmon_lg_set_tag(cpl_frameset *set, const char **tag_on, const char **tag_off)
static cpl_error_code xsh_detmon_lg_save_imagelist_with_pro_keys(cpl_imagelist *imagelist, const char *name_o, cpl_propertylist *xheader)
Save cube product.
static cpl_error_code xsh_detmon_lg_reduce(const cpl_frameset *, const cpl_frameset *, int *index_on, int *index_off, double *exptime_on, double *exptime_off, int *next_index_on, int *next_index_off, cpl_imagelist **, cpl_table *, cpl_table *, cpl_image **, cpl_imagelist *, cpl_imagelist *, cpl_propertylist *, cpl_propertylist *, cpl_propertylist *, cpl_propertylist *, int(*load_fset)(const cpl_frameset *, cpl_type, cpl_imagelist *), const cpl_boolean, int)
Apply linearity and gain reduction algorithms.
static double irplib_compute_err(double gain, double ron, double photon_noise)
static cpl_error_code xsh_detmon_lg_save_cube(const cpl_parameterlist *parlist, cpl_frameset *frameset, const cpl_frameset *usedframes, int whichext, const char *recipe_name, cpl_propertylist *mypro_coeffscube, cpl_propertylist *linc_qclist, const char *package, const char *NAME_O, cpl_imagelist *coeffs)
Save cube product.
static cpl_error_code xsh_detmon_lg_reduce_set(int i, cpl_frameset *frameset, int nsets, const char *tag_on, const char *tag_off, const char *recipe_name, const char *pipeline_name, const char *pafregexp, const cpl_propertylist *pro_lintbl, const cpl_propertylist *pro_gaintbl, const cpl_propertylist *pro_coeffscube, const cpl_propertylist *pro_bpm, const cpl_propertylist *pro_corr, const cpl_propertylist *pro_diff, const char *package, int(*load_fset)(const cpl_frameset *, cpl_type, cpl_imagelist *), const cpl_boolean opt_nir, const cpl_parameterlist *parlist, cpl_size *selection)
static cpl_error_code xsh_detmon_lg_reduce_all(const cpl_table *, cpl_propertylist *, cpl_propertylist *, cpl_propertylist *, cpl_propertylist *, cpl_imagelist **, cpl_image **, const cpl_imagelist *, const cpl_table *, int, cpl_boolean)
Final reduction step (after DIT-per-DIT reduction): fit linearity data and determine corresponding QC...
static int irplib_pfits_get_ndit(const cpl_propertylist *plist)
find out the character string associated to the DIT keyword in a propertylist
static cpl_error_code xsh_detmon_lg_qc_ptc(const cpl_table *, cpl_propertylist *, unsigned, int)
PTC (Photon Transfer Curve) method final computation.
static int xsh_detmon_lg_check_before_gain(const cpl_vector *x, const cpl_vector *y)
cpl_table * xsh_detmon_lin(const cpl_imagelist *imlist_on, const cpl_imagelist *imlist_off, const cpl_vector *exptimes, double tolerance, int llx, int lly, int urx, int ury, int order, int ref_level, double kappa, cpl_boolean bpmbin, cpl_propertylist *qclist, unsigned mode, cpl_imagelist **coeffs_cube, cpl_image **bpm)
Linearity computation.
static cpl_error_code xsh_detmon_gain_table_create(cpl_table *, const cpl_boolean)
static cpl_error_code xsh_detmon_lg_extract_extention_header(cpl_frameset *frameset, cpl_propertylist *gaint_qclist, cpl_propertylist *lint_qclist, cpl_propertylist *linc_qclist, cpl_propertylist *bpm_qclist, int whichext)
Extract extension headers if multi-extension.
static cpl_error_code xsh_detmon_lin_table_fill_row(cpl_table *, double, cpl_imagelist *, const cpl_imagelist *, const cpl_imagelist *, int, int, int, int, const int, const int, unsigned)
Fill i-th row in Linearity Table: DIT or EXPTIME, MEAN, MED, MEAN_DIT, MED_DIT.
static cpl_error_code irplib_table_create_column(cpl_table *ptable, cpl_propertylist *plist)
static cpl_error_code xsh_detmon_check_saturation_on_pair(cpl_imagelist *autocorr_images, cpl_imagelist *diff_flats, const cpl_imagelist *ons, const cpl_imagelist *offs, double kappa, int nclip, int llx, int lly, int urx, int ury, double saturation_limit, const int pos, unsigned mode, int *rows_linear_affected)
Operate on input ON and OFF images related to gain Computes all quantities needed to determine the ga...
cpl_error_code xsh_detmon_lg_fill_parlist_opt_default(cpl_parameterlist *parlist, const char *recipe_name, const char *pipeline_name)
Parlist filling with OPT required parameters and its default values.
static cpl_error_code xsh_detmon_table_fill_invalid(cpl_table *ptable, double code)
static char * xsh_detmon_lg_set_paf_name_and_header_ext(cpl_frame *ref_frame, int flag_sets, int which_set, int whichext, const char *paf_suf, cpl_propertylist **plist)
static cpl_error_code xsh_detmon_lg_lamp_stab(const cpl_frameset *, const cpl_frameset *, cpl_boolean, int)
Compute lamp stability.
cpl_table * xsh_detmon_gain(const cpl_imagelist *imlist_on, const cpl_imagelist *imlist_off, const cpl_vector *exptimes, const cpl_vector *ndit, double tolerance, int llx, int lly, int urx, int ury, double kappa, int nclip, int xshift, int yshift, cpl_propertylist *qclist, unsigned mode, cpl_imagelist **diff_imlist, cpl_imagelist **autocorr_imlist)
Gain computation.
static cpl_error_code xsh_detmon_gain_compute_qc(double kappa, int nclip, const int pos, const cpl_imagelist *offs, unsigned mode, double double_adu, double avg_on1, double avg_on2, double avg_off1, double avg_off2, double sigma, double sig_off_dif, double gain, int c_ndit, double gain_corr, double autocorr, cpl_image *on_dif, cpl_table *gain_table)
static cpl_error_code xsh_detmon_lg_retrieve_parlist(const char *, const char *, const cpl_parameterlist *, cpl_boolean)
Parlist extraction and copy to global struct variable.
static cpl_error_code irplib_fill_table_DETWINUIT(cpl_table *ptable, cpl_propertylist *plist, int row)
static cpl_error_code xsh_detmon_lg_save_paf_product(cpl_frame *ref_frame, int flag_sets, int which_set, int whichext, const char *pafregexp, const char *procatg, const char *pipeline_name, const char *recipe_name, const char *paf_suf, cpl_propertylist *qclist, const int ext)
static struct @2 xsh_detmon_lg_config
static cpl_propertylist * xsh_detmon_lg_extract_qclist_4plane(cpl_propertylist *linc_qclist, const int ip)
cpl_error_code xsh_detmon_lg_fill_parlist_nir_default(cpl_parameterlist *parlist, const char *recipe_name, const char *pipeline_name)
Parlist filling with NIR required parameters and its default values.
static cpl_imagelist * irplib_load_fset_wrp_ext(const cpl_frameset *, cpl_type, int)
static cpl_propertylist * xsh_detmon_load_pro_keys(const char *NAME_O)
Load pro keys.
static void irplib_free(char **pointer)
static cpl_error_code xsh_detmon_lg_fits_coeffs_and_bpm2chip(cpl_imagelist **coeffs_ptr, cpl_image **bpms_ptr)
Fits COEFFS_CUBE and BPM outputs to whole-chip size images (DFS05711)
enum _FPN_METHOD FPN_METHOD
static cpl_error_code xsh_detmon_gain_table_fill_row(cpl_table *gain_table, double c_dit, int c_ndit, cpl_imagelist *autocorr_images, cpl_imagelist *diff_flats, const cpl_imagelist *ons, const cpl_imagelist *offs, double kappa, int nclip, int llx, int lly, int urx, int ury, int m, int n, double saturation_limit, double gain_threshold, const int pos, unsigned mode, int *rows_affected)
Operate on input ON and OFF images related to gain Computes all quantities needed to determine the ga...
cpl_error_code hdrldemo_detector_shotnoise_model(const cpl_image *ima_data, const double gain, const double ron, cpl_image **ima_errs)
compute photon count error in [ADU]
static double irplib_pfits_get_dit(const cpl_propertylist *)
Find out the character string associated to the DIT keyword (NIR)
static cpl_error_code xsh_detmon_lg_save_table_with_pro_keys(cpl_table *table, const char *name_o, cpl_propertylist *xheader, unsigned CPL_IO_MODE)
Save cube product.
static cpl_vector * xsh_detmon_lg_find_dits(const cpl_vector *, double)
static cpl_error_code xsh_detmon_lg_save(const cpl_parameterlist *, cpl_frameset *, const char *, const char *, const char *, const cpl_propertylist *, const cpl_propertylist *, const cpl_propertylist *, const cpl_propertylist *, const cpl_propertylist *, const cpl_propertylist *, const char *, cpl_imagelist *, cpl_table *, cpl_table *, cpl_image *, cpl_imagelist *, cpl_imagelist *, cpl_propertylist *, cpl_propertylist *, cpl_propertylist *, cpl_propertylist *, const int, const int, const cpl_frameset *, int)
Save all products.
static double irplib_fpn_lg(const cpl_image *f1, int *range, double gain, FPN_METHOD fpn_method, int, double *mse)
cpl_error_code xsh_detmon_lg_fill_parlist_opt_default_mr(cpl_parameterlist *parlist, const char *recipe_name, const char *pipeline_name)
cpl_error_code xsh_detmon_lg_fill_parlist_default_mr(cpl_parameterlist *parlist, const char *recipe_name, const char *pipeline_name)
cpl_error_code xsh_detmon_check_order(const double *exptime, int sz, double tolerance, int order)
static double irplib_pfits_get_dit_opt(const cpl_propertylist *)
Find out the character string associated to the DIT keyword (OPT)
cpl_error_code xsh_detmon_lg(cpl_frameset *frameset, const cpl_parameterlist *parlist, const char *tag_on, const char *tag_off, const char *recipe_name, const char *pipeline_name, const char *pafregexp, const cpl_propertylist *pro_lintbl, const cpl_propertylist *pro_gaintbl, const cpl_propertylist *pro_coeffscube, const cpl_propertylist *pro_bpm, const cpl_propertylist *pro_corr, const cpl_propertylist *pro_diff, const char *package, int(*compare)(const cpl_frame *, const cpl_frame *), int(*load_fset)(const cpl_frameset *, cpl_type, cpl_imagelist *), const cpl_boolean opt_nir)
static double irplib_calculate_total_noise_smooth(const cpl_image *pimage, int pattern_x, int pattern_y)
static cpl_error_code xsh_detmon_lg_split_onoff(const cpl_frameset *, cpl_frameset *, cpl_frameset *, const char *, const char *)
Split the input frameset into two sub-framesets (ON and OFF)
static cpl_error_code xsh_detmon_lg_dfs_save_imagelist(cpl_frameset *frameset, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_imagelist *coeffs, const char *recipe_name, const cpl_propertylist *mypro_coeffscube, const char *package, const char *name_o)
cpl_image * xsh_detmon_image_correlate(const cpl_image *image1, const cpl_image *image2, const int m, const int n)
static cpl_imagelist * irplib_load_fset_wrp(const cpl_frameset *, cpl_type, int whichext)
static cpl_error_code xsh_detmon_single_extract_next(const cpl_frameset *set, int *index, int *next_element, double *dit_array, cpl_frameset **pair)
#define DETMON_QC_COUNTS_MAX
#define DETMON_QC_COUNTS_MIN
#define DETMON_QC_COUNTS_MIN_C
#define IRPLIB_GAIN_WITH_RESCALE
#define IRPLIB_GAIN_NO_COLLAPSE
#define DETMON_QC_AUTOCORR
#define DETMON_QC_GAIN_MSE
#define DETMON_QC_LAMP_FLUX
#define DETMON_QC_GAIN_MSE_C
#define DETMON_QC_ERRFIT_C
#define DETMON_QC_CONAD_CORR_C
#define IRPLIB_LIN_NO_COLLAPSE
#define DETMON_QC_GAIN_CORR
#define DETMON_QC_AUTOCORR_C
#define DETMON_QC_LIN_EFF
#define DETMON_QC_LIN_EFF_FLUX_C
#define DETMON_QC_ERRFIT_MSE_C
#define DETMON_QC_CONAD_CORR
#define DETMON_QC_CONAD_C
#define IRPLIB_GAIN_COLLAPSE
#define DETMON_QC_LIN_EFF_FLUX
#define IRPLIB_LIN_PIX2PIX
#define DETMON_LG_OFF_RAW_OLD
#define DETMON_QC_LAMP_STAB_C
#define DETMON_QC_LAMP_FLUX_C
#define DETMON_QC_METHOD_C
#define DETMON_QC_GAIN_CORR_C
#define DETMON_QC_LIN_COEF_ERR_C
#define DETMON_QC_LAMP_STAB
#define IRPLIB_LIN_WITH_RESCALE
#define DETMON_LG_OFF_RAW_NEW
#define DETMON_QC_LIN_COEF_C
#define DETMON_QC_CONTAM_C
#define IRPLIB_LIN_COLLAPSE
#define IRPLIB_GAIN_WITH_AUTOCORR
#define DETMON_QC_LIN_EFF_C
#define DETMON_LG_ON_RAW_NEW
#define DETMON_LG_ON_RAW_OLD
#define DETMON_QC_NUM_BPM_C
#define DETMON_QC_NUM_BPM
#define DETMON_QC_COUNTS_MAX_C
cpl_image * xsh_detmon_subtracted_avg(const cpl_image *on1, const cpl_image *off1, const cpl_image *on2, const cpl_image *off2, cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury)
return absolute average of subtracted images
cpl_image * xsh_detmon_subtract_create_window(const cpl_image *a, const cpl_image *b, cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury)
subtract window two images creating new image of window size
cpl_imagelist * xsh_detmon_load_frameset_window(const cpl_frameset *fset, cpl_type type, cpl_size pnum, cpl_size xtnum, cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury, cpl_size nx, cpl_size ny)
load data in frameset into an imagelist