34#include <cr2res_dfs.h>
35#include <cr2res_calib.h>
37#include "cr2res_pfits.h"
38#include "cr2res_utils.h"
45#define pow2(x) (x) * (x)
46#define detlin(x, a, b, c) (x) * ((a) + (x) * ((b) + (x) * (c)))
47#define deterr(x, a, b, c, sx, sa, sb, sc) sqrt(detlin(pow2(x), pow2(sa), pow2(sb), pow2(sc)) + pow2(sx) * pow2((a) + 2 * (b) * (x) + 3 * (c) * pow2(x)))
51static hdrl_image * cr2res_create_hdrl(
int nx,
int ny,
double value,
double error);
53static void test_cr2res_calib_image(
void);
54static void test_cr2res_calib_cosmic(
void);
55static void test_cr2res_calib_flat(
void);
56static void test_cr2res_calib_dark(
void);
57static void test_cr2res_calib_bpm(
void);
58static void test_cr2res_calib_detlin(
void);
61static void create_empty_fits()
65 char *my_path = cpl_sprintf(
"%s/TEST_empty.fits", localdir);
66 cpl_propertylist * list = cpl_propertylist_new();
67 cpl_propertylist_append_string(list, CR2RES_HEADER_DRS_TYPE,
"DEBUG");
68 cpl_propertylist_save(list, my_path, CPL_IO_CREATE);
69 cpl_propertylist_delete(list);
78static void save_hdrl(
char * filename, hdrl_image * hdrl,
int mode,
double dit)
82 cpl_frame * empty = cpl_frame_new();
84 char *my_path = cpl_sprintf(
"%s/TEST_empty.fits", localdir);
85 cpl_frame_set_filename(empty, my_path);
86 cpl_frame_set_tag(empty,
"DEBUG");
87 cpl_frame_set_group(empty, CPL_FRAME_GROUP_CALIB);
89 cpl_parameterlist * parlist = cpl_parameterlist_new();
90 cpl_propertylist * ext1 = cpl_propertylist_new();
91 cpl_propertylist_append_double(ext1, CR2RES_HEADER_DIT, dit);
92 cpl_propertylist * ext[] = {ext1, NULL, NULL};
95 cpl_frameset * all = cpl_frameset_new();
96 cpl_frameset * in = cpl_frameset_new();
97 cpl_frameset_insert(all, empty);
98 empty = cpl_frame_duplicate(empty);
99 cpl_frameset_insert(in, empty);
101 hdrl_image * list[] = {hdrl, NULL, NULL};
103 if (mode == MODE_FLAT)
105 if (mode == MODE_DARK)
107 if (mode == MODE_BPM)
110 cr2res_io_save_BPM(filename, all, in, parlist, list2, ext1, ext, CR2RES_CAL_FLAT_BPM_PROCATG,
"debug");
112 if (mode == MODE_DETLIN){
118 hdrl_imagelist * list4[] = {list3, NULL, NULL};
127 cpl_frameset_delete(all);
128 cpl_frameset_delete(in);
130 cpl_parameterlist_delete(parlist);
131 cpl_propertylist_delete(ext1);
139static cpl_frame * create_master_flat(
char * filename,
int nx,
int ny,
double value,
double error, cpl_mask ** bpm)
141 cpl_frame * out = cpl_frame_new();
142 cpl_frame_set_filename(out, filename);
143 cpl_frame_set_tag(out,
"FLAT");
144 cpl_frame_set_group(out, CPL_FRAME_GROUP_CALIB);
146 hdrl_image * hdrl = cr2res_create_hdrl(nx, ny, value, error);
153 save_hdrl(filename, hdrl, MODE_FLAT, 0);
164static cpl_frame * create_master_dark(
char * filename,
int nx,
int ny,
double value,
double error,
double dit, cpl_mask ** bpm)
167 cpl_frame * out = cpl_frame_new();
168 cpl_frame_set_filename(out, filename);
169 cpl_frame_set_tag(out,
"DARK");
170 cpl_frame_set_group(out, CPL_FRAME_GROUP_CALIB);
172 hdrl_image * hdrl = cr2res_create_hdrl(nx, ny, value, error);
179 save_hdrl(filename, hdrl, MODE_DARK, dit);
190static cpl_frame * create_bpm(
char * filename,
int nx,
int ny,
double value)
192 cpl_frame * out = cpl_frame_new();
193 cpl_frame_set_filename(out, filename);
194 cpl_frame_set_tag(out,
"BPM");
195 cpl_frame_set_group(out, CPL_FRAME_GROUP_CALIB);
197 hdrl_image * hdrl = cr2res_create_hdrl(nx, ny, value, 0);
198 save_hdrl(filename, hdrl, MODE_BPM, 0);
209static cpl_frame * create_detlin(
char * filename, hdrl_image * a, hdrl_image * b, hdrl_image * c)
211 char *my_path = cpl_sprintf(
"%s/TEST_empty.fits", localdir);
215 cpl_frame * empty = cpl_frame_new();
216 cpl_frame_set_filename(empty, my_path);
217 cpl_frame_set_tag(empty,
"DEBUG");
218 cpl_frame_set_group(empty, CPL_FRAME_GROUP_CALIB);
220 cpl_parameterlist * parlist = cpl_parameterlist_new();
221 cpl_propertylist * ext1 = cpl_propertylist_new();
222 cpl_propertylist * ext[] = {ext1, NULL, NULL};
224 cpl_frameset * all = cpl_frameset_new();
225 cpl_frameset * in = cpl_frameset_new();
226 cpl_frameset_insert(all, empty);
227 empty = cpl_frame_duplicate(empty);
228 cpl_frameset_insert(in, empty);
235 hdrl_imagelist * list4[] = {list3, NULL, NULL};
245 cpl_frameset_delete(all);
246 cpl_frameset_delete(in);
247 cpl_parameterlist_delete(parlist);
248 cpl_propertylist_delete(ext1);
250 cpl_frame * out = cpl_frame_new();
251 cpl_frame_set_filename(out, filename);
252 cpl_frame_set_tag(out,
"DETLIN");
253 cpl_frame_set_group(out, CPL_FRAME_GROUP_CALIB);
265static hdrl_image * cr2res_create_hdrl(
int nx,
int ny,
double value,
double error)
275static double calc_read_noise(
double dit,
int ndit,
int chip)
277 double min_dit = 1.427;
278 double lim_dit = 50.0;
287 return min_rn/CR2RES_GAIN_CHIP1;
288 }
else if(dit >= lim_dit) {
289 return lim_rn/CR2RES_GAIN_CHIP1;
291 double rn = min_rn + (lim_rn-min_rn)*(dit-min_dit)/(lim_dit-min_dit);
292 return rn/CR2RES_GAIN_CHIP1;
297static double expected_noise(
double err,
double value,
double dit,
int ndit,
300 double n = ndsamples ;
301 double alpha = ndsamples < 2 ? 1.0 :
302 6.0 * (n * n + 1.0) / (5.0 * n * (n + 1.0)) ;
303 double rn = calc_read_noise(dit, 1, 1) ;
304 return sqrt(err * err + alpha * (value > 0.0 ? value : 0.0) /
305 (CR2RES_GAIN_CHIP1 * ndit) + rn * rn / ndit) ;
309static void add_expected_noise(hdrl_image * im,
double dit)
316 for (j = 1; j <= cpl_image_get_size_y(err); j++) {
317 for (i = 1; i <= cpl_image_get_size_x(err); i++) {
318 cpl_image_set(err, i, j, expected_noise(
319 cpl_image_get(err, i, j, &badpix),
320 cpl_image_get(val, i, j, &badpix), dit, 1, 2)) ;
325static void test_cr2res_calib_image()
331 double img_value = 100;
332 double img_error = 1;
334 hdrl_image * in = cr2res_create_hdrl(nx, ny, img_value, img_error);
337 char *my_path1 = cpl_sprintf(
"%s/TEST_master_flat.fits", localdir);
338 char *my_path2 = cpl_sprintf(
"%s/TEST_master_dark.fits", localdir);
339 char *my_path3 = cpl_sprintf(
"%s/TEST_bpm.fits", localdir);
340 cpl_frame * flat = create_master_flat(my_path1, nx, ny, 1, 0, NULL);
341 cpl_frame * dark = create_master_dark(my_path2, nx, ny, 10, 1, 10, NULL);
342 cpl_frame * bpm = create_bpm(my_path3, nx, ny, 0);
343 cpl_frame * detlin = NULL;
350 out =
cr2res_calib_image(NULL, chip, 0, 0, 1, 0, NULL, NULL, NULL, NULL,dit,1,2);
353 out =
cr2res_calib_image(in, 0, 0, 0, 1, 0, NULL, NULL, NULL, NULL, dit, 1, 2);
357 NULL, NULL, NULL, NULL, dit, 1, 2);
361 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, NULL, NULL, NULL, NULL, dit, 1, 2);
362 cpl_test_nonnull(out);
367 add_expected_noise(cmp, dit);
374 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, NULL, NULL, NULL, NULL, dit, 4, 33);
375 cpl_test_nonnull(out);
376 cmp = cr2res_create_hdrl(nx, ny, img_value,
377 expected_noise(img_error, img_value, dit, 4, 33));
383 hdrl_image * neg = cr2res_create_hdrl(nx, ny, -img_value, img_error);
384 out =
cr2res_calib_image(neg, chip, 0, 0, 1, 0, NULL, NULL, NULL, NULL, dit, 1, 2);
385 cpl_test_nonnull(out);
386 cmp = cr2res_create_hdrl(nx, ny, -img_value,
387 expected_noise(img_error, -img_value, dit, 1, 2));
395 cpl_frame_delete(flat);
396 cpl_frame_delete(dark);
397 cpl_frame_delete(bpm);
398 cpl_frame_delete(detlin);
409static void test_cr2res_calib_cosmic()
415 double img_value = 100;
416 double img_error = 1;
420 hdrl_image * in, * out;
426 in = cr2res_create_hdrl(nx, ny, img_value, img_error);
429 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, NULL, NULL, NULL, NULL, dit, 1, 2);
431 add_expected_noise(in, dit);
449static void test_cr2res_calib_flat()
455 double img_value = 100;
456 double img_error = 1;
457 double tmp_error = 0;
458 double out_value, out_error;
459 double flat_value, flat_error;
461 hdrl_image * in, * out, * cmp;
468 in = cr2res_create_hdrl(nx, ny, img_value, img_error);
473 char *my_path1 = cpl_sprintf(
"%s/TEST_master_flat.fits", localdir);
474 flat = create_master_flat(my_path1, nx, ny, flat_value, flat_error, NULL);
475 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, flat, NULL, NULL, NULL, dit, 1, 2);
477 out_value = img_value / flat_value;
478 out_error = sqrt( pow(img_error / flat_value, 2) + pow(img_value * flat_error/ (flat_value * flat_value), 2));
479 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
480 add_expected_noise(cmp, dit);
487 cpl_frame_delete(flat);
492 flat = create_master_flat(my_path1, nx, ny, flat_value, flat_error, NULL);
493 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, flat, NULL, NULL, NULL, dit, 1, 2);
495 out_value = img_value / flat_value;
496 tmp_error = expected_noise(img_error, img_value, dit, 1, 2);
498 out_error = sqrt( pow(tmp_error / flat_value, 2) + pow(img_value * flat_error/ (flat_value * flat_value), 2));
499 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
506 cpl_frame_delete(flat);
511 flat = create_master_flat(my_path1, nx, ny, flat_value, flat_error, NULL);
512 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, flat, NULL, NULL, NULL, dit, 1, 2);
517 cpl_frame_delete(flat);
520 flat = cpl_frame_new();
521 cpl_frame_set_filename(flat,
"TEST_tobeornottobe.fits");
522 cpl_frame_set_tag(flat,
"FLAT");
523 cpl_frame_set_group(flat, CPL_FRAME_GROUP_CALIB);
525 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, flat, NULL, NULL, NULL, dit, 1, 2);
526 cpl_test_error(CPL_ERROR_FILE_IO);
528 cpl_frame_delete(flat);
531 flat = create_master_dark(my_path1, nx, ny, 1, 0, 10, NULL);
532 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, flat, NULL, NULL, NULL, dit, 1, 2);
534 cpl_frame_delete(flat);
537 flat = cpl_frame_new();
538 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, flat, NULL, NULL, NULL, dit, 1, 2);
539 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
541 cpl_frame_delete(flat);
544 flat = cpl_frame_new();
545 char *my_path2 = cpl_sprintf(
"%s/TEST_empty.fits", localdir);
546 cpl_frame_set_filename(flat, my_path2);
547 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, flat, NULL, NULL, NULL, dit, 1, 2);
549 cpl_frame_delete(flat);
569static void test_cr2res_calib_dark()
575 double img_value = 100;
576 double img_error = 1;
577 double tmp_error = 0;
578 double out_value, out_error;
579 double dark_value, dark_error, dark_dit;
581 hdrl_image * in, * out, * cmp;
587 in = cr2res_create_hdrl(nx, ny, img_value, img_error);
588 char *my_path = cpl_sprintf(
"%s/TEST_master_dark.fits", localdir);
589 char *my_path2 = cpl_sprintf(
"%s/TEST_empty.fits", localdir);
596 dark = create_master_dark(my_path, nx, ny, dark_value, dark_error, dark_dit, NULL);
597 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1, 2);
599 out_value = img_value - dit/dark_dit * dark_value;
600 tmp_error = expected_noise(img_error, img_value, dit, 1, 2);
601 out_error = sqrt(pow(tmp_error, 2) + pow(dit/dark_dit * dark_error, 2));
602 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
609 cpl_frame_delete(dark);
614 dark_dit = dit * 2.3;
615 dark = create_master_dark(my_path, nx, ny, dark_value, dark_error, dark_dit, NULL);
616 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1, 2);
618 out_value = img_value - dit/dark_dit * dark_value;
619 tmp_error = expected_noise(img_error, img_value, dit, 1, 2);
620 out_error = sqrt(pow(tmp_error, 2) + pow(dit/dark_dit * dark_error, 2));
621 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
628 cpl_frame_delete(dark);
634 dark = create_master_dark(my_path, nx, ny, dark_value, dark_error, dark_dit, NULL);
635 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1, 2);
637 out_value = img_value - dit/dark_dit * dark_value;
638 tmp_error = expected_noise(img_error, img_value, dit, 1, 2);
639 out_error = sqrt(pow(tmp_error, 2) + pow(dit/dark_dit * dark_error, 2));
640 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
647 cpl_frame_delete(dark);
653 dark = create_master_dark(my_path, nx, ny, dark_value, dark_error, dark_dit, NULL);
654 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1, 2);
656 out_value = img_value - dit/dark_dit * dark_value;
657 tmp_error = expected_noise(img_error, img_value, dit, 1, 2);
658 out_error = sqrt(pow(tmp_error, 2) + pow(dit/dark_dit * dark_error, 2));
659 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
666 cpl_frame_delete(dark);
671 dark_dit = dit * 2.3;
672 dark = create_master_dark(my_path, nx, ny, dark_value, dark_error, dark_dit, NULL);
673 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1, 2);
675 out_value = img_value - dit/dark_dit * dark_value;
676 tmp_error = expected_noise(img_error, img_value, dit, 1, 2);
677 out_error = sqrt(pow(tmp_error, 2) + pow(dit/dark_dit * dark_error, 2));
678 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
685 cpl_frame_delete(dark);
690 dark_dit = dit * 2.3;
691 dark = create_master_dark(my_path, nx, ny, dark_value, dark_error, dark_dit, NULL);
692 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1, 2);
694 out_value = img_value - dit/dark_dit * dark_value;
695 tmp_error = expected_noise(img_error, img_value, dit, 1, 2);
696 out_error = sqrt(pow(tmp_error, 2) + pow(dit/dark_dit * dark_error, 2));
697 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
704 cpl_frame_delete(dark);
709 dark_dit = -dit * 2.3;
710 dark = create_master_dark(my_path, nx, ny, dark_value, dark_error, dark_dit, NULL);
711 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1, 2);
713 out_value = img_value - dit/dark_dit * dark_value;
714 tmp_error = expected_noise(img_error, img_value, dit, 1, 2);
715 out_error = sqrt(pow(tmp_error, 2) + pow(dit/dark_dit * dark_error, 2));
716 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
723 cpl_frame_delete(dark);
728 dark_dit = -dit * 2.3;
729 dark = create_master_dark(my_path, nx, ny, dark_value, dark_error, dark_dit, NULL);
730 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1, 2);
732 out_value = img_value - dit/dark_dit * dark_value;
733 tmp_error = expected_noise(img_error, img_value, dit, 1, 2);
734 out_error = sqrt(pow(tmp_error, 2) + pow(dit/dark_dit * dark_error, 2));
735 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
742 cpl_frame_delete(dark);
745 dark = cpl_frame_new();
746 cpl_frame_set_filename(dark,
"TEST_tobeornottobe.fits");
747 cpl_frame_set_tag(dark,
"DARK");
748 cpl_frame_set_group(dark, CPL_FRAME_GROUP_CALIB);
750 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1, 2);
751 cpl_test_error(CPL_ERROR_FILE_IO);
753 cpl_frame_delete(dark);
756 dark = create_master_flat(my_path, nx, ny, 1, 0, NULL);
757 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1, 2);
759 cpl_frame_delete(dark);
762 dark = cpl_frame_new();
763 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1, 2);
764 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
766 cpl_frame_delete(dark);
771 dark = cpl_frame_new();
772 cpl_frame_set_filename(dark, my_path2);
773 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1, 2);
775 cpl_frame_delete(dark);
796static void test_cr2res_calib_bpm()
802 double img_value = 100;
803 double img_error = 1;
809 hdrl_image * in, * out, * cmp;
814 in = cr2res_create_hdrl(nx, ny, img_value, img_error);
815 value.data = 10; value.error = img_error;
818 char *my_path = cpl_sprintf(
"%s/TEST_master_bpm.fits", localdir);
819 char *my_path2 = cpl_sprintf(
"%s/TEST_empty.fits", localdir);
823 bpm = create_bpm(my_path, nx, ny, 0);
824 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, bpm, NULL, dit, 1, 2);
826 add_expected_noise(cmp, dit);
830 cpl_frame_delete(bpm);
835 bpm = create_bpm(my_path, nx, ny, 1);
836 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, bpm, NULL, dit, 1, 2);
837 cpl_test_nonnull(out);
839 cpl_frame_delete(bpm);
843 bpm = cpl_frame_new();
844 cpl_frame_set_filename(bpm, my_path);
845 cpl_frame_set_tag(bpm,
"BPM");
846 cpl_frame_set_group(bpm, CPL_FRAME_GROUP_CALIB);
848 hdrl = cr2res_create_hdrl(nx, ny, 0, 0);
851 save_hdrl(my_path, hdrl, MODE_BPM, 0);
854 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, bpm, NULL, dit, 1, 2);
856 add_expected_noise(cmp, dit);
862 for (
size_t i = 1; i <= (size_t) nx; i++)
864 for (
size_t j = 1; j <= (size_t) ny; j++)
875 cpl_frame_delete(bpm);
880 bpm = cpl_frame_new();
881 cpl_frame_set_filename(bpm, my_path);
882 cpl_frame_set_tag(bpm,
"BPM");
883 cpl_frame_set_group(bpm, CPL_FRAME_GROUP_CALIB);
885 hdrl = cr2res_create_hdrl(nx, ny, 1, 0);
888 save_hdrl(my_path, hdrl, MODE_BPM, 0);
891 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, bpm, NULL, dit, 1, 2);
893 add_expected_noise(cmp, dit);
899 for (
size_t i = 1; i <= (size_t) nx; i++)
901 for (
size_t j = 1; j <= (size_t) ny; j++)
913 cpl_frame_delete(bpm);
918 bpm = cpl_frame_new();
919 cpl_frame_set_filename(bpm,
"TEST_tobeornottobe.fits");
920 cpl_frame_set_tag(bpm,
"BPM");
921 cpl_frame_set_group(bpm, CPL_FRAME_GROUP_CALIB);
923 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, bpm, NULL, dit, 1, 2);
924 cpl_test_error(CPL_ERROR_FILE_IO);
926 cpl_frame_delete(bpm);
929 bpm = create_master_flat(my_path, nx, ny, 1, 0, NULL);
930 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, bpm, NULL, dit, 1, 2);
932 cpl_frame_delete(bpm);
935 bpm = cpl_frame_new();
936 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, bpm, NULL, dit, 1, 2);
937 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
939 cpl_frame_delete(bpm);
943 bpm = cpl_frame_new();
944 cpl_frame_set_filename(bpm, my_path2);
945 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, bpm, NULL, dit, 1, 2);
947 cpl_frame_delete(bpm);
955static void test_cr2res_calib_detlin()
961 double img_value = 20000;
962 double img_error = 0;
963 double out_value, out_error;
968 hdrl_image * in, * out, * cmp;
969 hdrl_image * ima, * imb, * imc;
970 double a, b, c, sa, sb, sc;
976 in = cr2res_create_hdrl(nx, ny, img_value, img_error);
977 i = img_value; si = img_error;
979 char *my_path = cpl_sprintf(
"%s/TEST_master_detlin.fits", localdir);
980 char *my_path2 = cpl_sprintf(
"%s/TEST_empty.fits", localdir);
990 ima = cr2res_create_hdrl(nx, ny, a, sa);
991 imb = cr2res_create_hdrl(nx, ny, b, sb);
992 imc = cr2res_create_hdrl(nx, ny, c, sc);
994 detlin = create_detlin(my_path, ima, imb, imc);
995 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1, 2);
997 add_expected_noise(cmp, dit);
1002 cpl_frame_delete(detlin);
1011 ima = cr2res_create_hdrl(nx, ny, a, sa);
1012 imb = cr2res_create_hdrl(nx, ny, b, sb);
1013 imc = cr2res_create_hdrl(nx, ny, c, sc);
1014 detlin = create_detlin(my_path, ima, imb, imc);
1015 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1, 2);
1016 out_value = detlin(img_value, a, b, c);
1017 out_error = deterr(img_value, a, b, c, img_error, sa, sb, sc);
1018 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
1019 add_expected_noise(cmp, dit);
1027 cpl_frame_delete(detlin);
1036 ima = cr2res_create_hdrl(nx, ny, a, sa);
1037 imb = cr2res_create_hdrl(nx, ny, b, sb);
1038 imc = cr2res_create_hdrl(nx, ny, c, sc);
1039 detlin = create_detlin(my_path, ima, imb, imc);
1040 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1, 2);
1041 cmp = cr2res_create_hdrl(nx, ny, 0, 0);
1042 add_expected_noise(cmp, dit);
1050 cpl_frame_delete(detlin);
1058 ima = cr2res_create_hdrl(nx, ny, a, sa);
1059 imb = cr2res_create_hdrl(nx, ny, b, sb);
1060 imc = cr2res_create_hdrl(nx, ny, c, sc);
1061 detlin = create_detlin(my_path, ima, imb, imc);
1062 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1, 2);
1063 out_value = img_value * a;
1064 out_error = img_error * a;
1065 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
1066 add_expected_noise(cmp, dit);
1074 cpl_frame_delete(detlin);
1081 a = 2; b = 0; c = 0;
1083 ima = cr2res_create_hdrl(nx, ny, a, sa);
1084 imb = cr2res_create_hdrl(nx, ny, b, sb);
1085 imc = cr2res_create_hdrl(nx, ny, c, sc);
1086 detlin = create_detlin(my_path, ima, imb, imc);
1087 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1, 2);
1088 out_value = detlin(i, a, b, c);
1089 out_error = deterr(i, a, b, c, si, sa, sb, sc);
1090 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
1091 add_expected_noise(cmp, dit);
1099 cpl_frame_delete(detlin);
1108 ima = cr2res_create_hdrl(nx, ny, a, sa);
1109 imb = cr2res_create_hdrl(nx, ny, b, sb);
1110 imc = cr2res_create_hdrl(nx, ny, c, sc);
1111 detlin = create_detlin(my_path, ima, imb, imc);
1112 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1, 2);
1113 out_value = detlin(i, a, b, c);
1114 out_error = deterr(i, a, b, c, si, sa, sb, sc);
1115 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
1116 add_expected_noise(cmp, dit);
1124 cpl_frame_delete(detlin);
1132 sa = sc = 0; sb = 1;
1133 ima = cr2res_create_hdrl(nx, ny, a, sa);
1134 imb = cr2res_create_hdrl(nx, ny, b, sb);
1135 imc = cr2res_create_hdrl(nx, ny, c, sc);
1136 detlin = create_detlin(my_path, ima, imb, imc);
1137 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1, 2);
1138 out_value = pow2(img_value);
1139 out_error = deterr(i, a, b, c, si, sa, sb, sc);
1140 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
1141 add_expected_noise(cmp, dit);
1147 cpl_frame_delete(detlin);
1153 a = 1; c = 0; b = 1;
1154 sa = 1 ; sc = 0; sb = 1;
1155 ima = cr2res_create_hdrl(nx, ny, a, sa);
1156 imb = cr2res_create_hdrl(nx, ny, b, sb);
1157 imc = cr2res_create_hdrl(nx, ny, c, sc);
1158 detlin = create_detlin(my_path, ima, imb, imc);
1159 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1, 2);
1160 out_value = detlin(i, a, b, c);
1161 out_error = deterr(i, a, b, c, si, sa, sb, sc);
1162 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
1163 add_expected_noise(cmp, dit);
1171 cpl_frame_delete(detlin);
1178 a = 1; c = 1; b = 0;
1179 sa = 1 ; sc = 1; sb = 0;
1180 i = img_value; si = img_error;
1181 ima = cr2res_create_hdrl(nx, ny, a, sa);
1182 imb = cr2res_create_hdrl(nx, ny, b, sb);
1183 imc = cr2res_create_hdrl(nx, ny, c, sc);
1184 detlin = create_detlin(my_path, ima, imb, imc);
1185 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1, 2);
1186 out_value = detlin(i, a, b, c);
1187 out_error = deterr(i, a, b, c, si, sa, sb, sc);
1188 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
1189 add_expected_noise(cmp, dit);
1195 cpl_frame_delete(detlin);
1202 a = 1; c = 1; b = 1;
1203 sa = 1 ; sc = 1; sb = 1;
1204 i = img_value; si = img_error;
1205 ima = cr2res_create_hdrl(nx, ny, a, sa);
1206 imb = cr2res_create_hdrl(nx, ny, b, sb);
1207 imc = cr2res_create_hdrl(nx, ny, c, sc);
1208 detlin = create_detlin(my_path, ima, imb, imc);
1209 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1, 2);
1210 out_value = detlin(i, a, b, c);
1211 out_error = deterr(i, a, b, c, si, sa, sb, sc);
1212 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
1213 add_expected_noise(cmp, dit);
1219 cpl_frame_delete(detlin);
1225 detlin = cpl_frame_new();
1226 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1, 2);
1227 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
1229 cpl_frame_delete(detlin);
1233 detlin = cpl_frame_new();
1234 cpl_frame_set_filename(detlin, my_path2);
1235 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1, 2);
1237 cpl_frame_delete(detlin);
1254 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_DEBUG);
1256 create_empty_fits();
1258 test_cr2res_calib_image();
1259 test_cr2res_calib_cosmic();
1260 test_cr2res_calib_flat();
1261 test_cr2res_calib_dark();
1262 test_cr2res_calib_bpm();
1263 test_cr2res_calib_detlin();
1265 return cpl_test_end(0);
hdrl_image * cr2res_calib_image(const hdrl_image *in, int chip, int clean_bad, int subtract_nolight_rows, int subtract_interorder_column, int cosmics_corr, const cpl_frame *flat, const cpl_frame *dark, const cpl_frame *bpm, const cpl_frame *detlin, double dit, int ndit, int ndsamples)
The images calibration routine for a given chip.
int cr2res_io_save_MASTER_FLAT(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_image **master_flats, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a MASTER_FLAT.
int cr2res_io_save_MASTER_DARK(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_image **master_darks, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a MASTER_DARK.
int cr2res_io_save_DETLIN_COEFFS(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, hdrl_imagelist **coeffs, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a DETLIN COEFFS.
int cr2res_io_save_BPM(const char *filename, cpl_frameset *allframes, cpl_frameset *inframes, const cpl_parameterlist *parlist, cpl_image **bpms, const cpl_propertylist *qc_list, cpl_propertylist **ext_plist, const char *procatg, const char *recipe)
Save a BPM.
int hdrl_image_is_rejected(hdrl_image *self, cpl_size xpos, cpl_size ypos)
return if pixel is marked bad
cpl_error_code hdrl_image_set_pixel(hdrl_image *self, cpl_size xpos, cpl_size ypos, hdrl_value value)
set pixel values of hdrl_image
hdrl_image * hdrl_image_duplicate(const hdrl_image *himg)
copy hdrl_image
cpl_mask * hdrl_image_get_mask(hdrl_image *himg)
get cpl bad pixel mask from image
cpl_error_code hdrl_image_add_scalar(hdrl_image *self, hdrl_value value)
Elementwise addition of a scalar to an image.
cpl_image * hdrl_image_get_error(hdrl_image *himg)
get error as cpl image
cpl_size hdrl_image_count_rejected(const hdrl_image *self)
return number of rejected pixels
cpl_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
cpl_error_code hdrl_image_reject(hdrl_image *self, cpl_size xpos, cpl_size ypos)
mark pixel as bad
const cpl_image * hdrl_image_get_image_const(const hdrl_image *himg)
get data as cpl image
hdrl_image * hdrl_image_new(cpl_size nx, cpl_size ny)
create new zero filled hdrl image
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
hdrl_image * hdrl_imagelist_unset(hdrl_imagelist *himlist, cpl_size pos)
Remove an image from an imagelist.
cpl_error_code hdrl_imagelist_set(hdrl_imagelist *himlist, hdrl_image *himg, cpl_size pos)
Insert an image into an imagelist.
void hdrl_imagelist_delete(hdrl_imagelist *himlist)
Free all memory used by a hdrl_imagelist object including the images.
hdrl_imagelist * hdrl_imagelist_new(void)
Create an empty imagelist.