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 void test_cr2res_calib_image()
281 double img_value = 100;
282 double img_error = 1;
284 hdrl_image * in = cr2res_create_hdrl(nx, ny, img_value, img_error);
287 char *my_path1 = cpl_sprintf(
"%s/TEST_master_flat.fits", localdir);
288 char *my_path2 = cpl_sprintf(
"%s/TEST_master_dark.fits", localdir);
289 char *my_path3 = cpl_sprintf(
"%s/TEST_bpm.fits", localdir);
290 cpl_frame * flat = create_master_flat(my_path1, nx, ny, 1, 0, NULL);
291 cpl_frame * dark = create_master_dark(my_path2, nx, ny, 10, 1, 10, NULL);
292 cpl_frame * bpm = create_bpm(my_path3, nx, ny, 0);
293 cpl_frame * detlin = NULL;
300 out =
cr2res_calib_image(NULL, chip, 0, 0, 1, 0, NULL, NULL, NULL, NULL,dit,1);
303 out =
cr2res_calib_image(in, 0, 0, 0, 1, 0, NULL, NULL, NULL, NULL, dit, 1);
307 NULL, NULL, NULL, NULL, dit, 1);
311 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, NULL, NULL, NULL, NULL, dit, 1);
312 cpl_test_nonnull(out);
322 cpl_frame_delete(flat);
323 cpl_frame_delete(dark);
324 cpl_frame_delete(bpm);
325 cpl_frame_delete(detlin);
336static void test_cr2res_calib_cosmic()
342 double img_value = 100;
343 double img_error = 1;
347 hdrl_image * in, * out;
353 in = cr2res_create_hdrl(nx, ny, img_value, img_error);
356 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, NULL, NULL, NULL, NULL, dit, 1);
376static void test_cr2res_calib_flat()
382 double img_value = 100;
383 double img_error = 1;
384 double tmp_error = 0;
385 double out_value, out_error;
386 double flat_value, flat_error;
388 hdrl_image * in, * out, * cmp;
395 in = cr2res_create_hdrl(nx, ny, img_value, img_error);
400 char *my_path1 = cpl_sprintf(
"%s/TEST_master_flat.fits", localdir);
401 flat = create_master_flat(my_path1, nx, ny, flat_value, flat_error, NULL);
402 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, flat, NULL, NULL, NULL, dit, 1);
404 out_value = img_value / flat_value;
405 out_error = sqrt( pow(img_error / flat_value, 2) + pow(img_value * flat_error/ (flat_value * flat_value), 2));
406 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
415 cpl_frame_delete(flat);
420 flat = create_master_flat(my_path1, nx, ny, flat_value, flat_error, NULL);
421 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, flat, NULL, NULL, NULL, dit, 1);
423 out_value = img_value / flat_value;
424 tmp_error = img_error + sqrt(img_value) / sqrt(CR2RES_GAIN_CHIP1);
425 out_error = sqrt( pow(tmp_error / flat_value, 2) + pow(img_value * flat_error/ (flat_value * flat_value), 2));
426 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
433 cpl_frame_delete(flat);
438 flat = create_master_flat(my_path1, nx, ny, flat_value, flat_error, NULL);
439 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, flat, NULL, NULL, NULL, dit, 1);
444 cpl_frame_delete(flat);
447 flat = cpl_frame_new();
448 cpl_frame_set_filename(flat,
"TEST_tobeornottobe.fits");
449 cpl_frame_set_tag(flat,
"FLAT");
450 cpl_frame_set_group(flat, CPL_FRAME_GROUP_CALIB);
452 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, flat, NULL, NULL, NULL, dit, 1);
453 cpl_test_error(CPL_ERROR_FILE_IO);
455 cpl_frame_delete(flat);
458 flat = create_master_dark(my_path1, nx, ny, 1, 0, 10, NULL);
459 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, flat, NULL, NULL, NULL, dit, 1);
461 cpl_frame_delete(flat);
464 flat = cpl_frame_new();
465 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, flat, NULL, NULL, NULL, dit, 1);
466 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
468 cpl_frame_delete(flat);
471 flat = cpl_frame_new();
472 char *my_path2 = cpl_sprintf(
"%s/TEST_empty.fits", localdir);
473 cpl_frame_set_filename(flat, my_path2);
474 out =
cr2res_calib_image(in, chip, 0, 0, 1, 0, flat, NULL, NULL, NULL, dit, 1);
476 cpl_frame_delete(flat);
496static void test_cr2res_calib_dark()
502 double img_value = 100;
503 double img_error = 1;
504 double tmp_error = 0;
505 double out_value, out_error;
506 double dark_value, dark_error, dark_dit;
508 hdrl_image * in, * out, * cmp;
514 in = cr2res_create_hdrl(nx, ny, img_value, img_error);
515 char *my_path = cpl_sprintf(
"%s/TEST_master_dark.fits", localdir);
516 char *my_path2 = cpl_sprintf(
"%s/TEST_empty.fits", localdir);
523 dark = create_master_dark(my_path, nx, ny, dark_value, dark_error, dark_dit, NULL);
524 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1);
526 out_value = img_value - dit/dark_dit * dark_value;
527 tmp_error = img_error + sqrt(img_value) / sqrt(CR2RES_GAIN_CHIP1);
528 out_error = sqrt(pow(tmp_error, 2) + pow(dit/dark_dit * dark_error, 2));
529 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
536 cpl_frame_delete(dark);
541 dark_dit = dit * 2.3;
542 dark = create_master_dark(my_path, nx, ny, dark_value, dark_error, dark_dit, NULL);
543 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1);
545 out_value = img_value - dit/dark_dit * dark_value;
546 tmp_error = img_error + sqrt(img_value) / sqrt(CR2RES_GAIN_CHIP1);
547 out_error = sqrt(pow(tmp_error, 2) + pow(dit/dark_dit * dark_error, 2));
548 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
555 cpl_frame_delete(dark);
561 dark = create_master_dark(my_path, nx, ny, dark_value, dark_error, dark_dit, NULL);
562 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1);
564 out_value = img_value - dit/dark_dit * dark_value;
565 tmp_error = img_error + sqrt(img_value) / sqrt(CR2RES_GAIN_CHIP1);
566 out_error = sqrt(pow(tmp_error, 2) + pow(dit/dark_dit * dark_error, 2));
567 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
574 cpl_frame_delete(dark);
580 dark = create_master_dark(my_path, nx, ny, dark_value, dark_error, dark_dit, NULL);
581 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1);
583 out_value = img_value - dit/dark_dit * dark_value;
584 tmp_error = img_error + sqrt(img_value) / sqrt(CR2RES_GAIN_CHIP1);
585 out_error = sqrt(pow(tmp_error, 2) + pow(dit/dark_dit * dark_error, 2));
586 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
593 cpl_frame_delete(dark);
598 dark_dit = dit * 2.3;
599 dark = create_master_dark(my_path, nx, ny, dark_value, dark_error, dark_dit, NULL);
600 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1);
602 out_value = img_value - dit/dark_dit * dark_value;
603 tmp_error = img_error + sqrt(img_value) / sqrt(CR2RES_GAIN_CHIP1);
604 out_error = sqrt(pow(tmp_error, 2) + pow(dit/dark_dit * dark_error, 2));
605 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
612 cpl_frame_delete(dark);
617 dark_dit = dit * 2.3;
618 dark = create_master_dark(my_path, nx, ny, dark_value, dark_error, dark_dit, NULL);
619 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1);
621 out_value = img_value - dit/dark_dit * dark_value;
622 tmp_error = img_error + sqrt(img_value) / sqrt(CR2RES_GAIN_CHIP1);
623 out_error = sqrt(pow(tmp_error, 2) + pow(dit/dark_dit * dark_error, 2));
624 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
631 cpl_frame_delete(dark);
636 dark_dit = -dit * 2.3;
637 dark = create_master_dark(my_path, nx, ny, dark_value, dark_error, dark_dit, NULL);
638 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1);
640 out_value = img_value - dit/dark_dit * dark_value;
641 tmp_error = img_error + sqrt(img_value) / sqrt(CR2RES_GAIN_CHIP1);
642 out_error = sqrt(pow(tmp_error, 2) + pow(dit/dark_dit * dark_error, 2));
643 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
650 cpl_frame_delete(dark);
655 dark_dit = -dit * 2.3;
656 dark = create_master_dark(my_path, nx, ny, dark_value, dark_error, dark_dit, NULL);
657 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1);
659 out_value = img_value - dit/dark_dit * dark_value;
660 tmp_error = img_error + sqrt(img_value) / sqrt(CR2RES_GAIN_CHIP1);
661 out_error = sqrt(pow(tmp_error, 2) + pow(dit/dark_dit * dark_error, 2));
662 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
669 cpl_frame_delete(dark);
672 dark = cpl_frame_new();
673 cpl_frame_set_filename(dark,
"TEST_tobeornottobe.fits");
674 cpl_frame_set_tag(dark,
"DARK");
675 cpl_frame_set_group(dark, CPL_FRAME_GROUP_CALIB);
677 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1);
678 cpl_test_error(CPL_ERROR_FILE_IO);
680 cpl_frame_delete(dark);
683 dark = create_master_flat(my_path, nx, ny, 1, 0, NULL);
684 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1);
686 cpl_frame_delete(dark);
689 dark = cpl_frame_new();
690 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1);
691 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
693 cpl_frame_delete(dark);
698 dark = cpl_frame_new();
699 cpl_frame_set_filename(dark, my_path2);
700 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, dark, NULL, NULL, dit, 1);
702 cpl_frame_delete(dark);
723static void test_cr2res_calib_bpm()
729 double img_value = 100;
730 double img_error = 1;
737 hdrl_image * in, * out, * cmp;
742 in = cr2res_create_hdrl(nx, ny, img_value, img_error);
743 value.data = 10; value.error = img_error;
746 char *my_path = cpl_sprintf(
"%s/TEST_master_bpm.fits", localdir);
747 char *my_path2 = cpl_sprintf(
"%s/TEST_empty.fits", localdir);
751 bpm = create_bpm(my_path, nx, ny, 0);
752 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, bpm, NULL, dit, 1);
755 cpl_image_divide_scalar(tmp, sqrt(CR2RES_GAIN_CHIP1));
757 cpl_image_delete(tmp);
761 cpl_frame_delete(bpm);
766 bpm = create_bpm(my_path, nx, ny, 1);
767 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, bpm, NULL, dit, 1);
768 cpl_test_nonnull(out);
770 cpl_frame_delete(bpm);
774 bpm = cpl_frame_new();
775 cpl_frame_set_filename(bpm, my_path);
776 cpl_frame_set_tag(bpm,
"BPM");
777 cpl_frame_set_group(bpm, CPL_FRAME_GROUP_CALIB);
779 hdrl = cr2res_create_hdrl(nx, ny, 0, 0);
782 save_hdrl(my_path, hdrl, MODE_BPM, 0);
785 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, bpm, NULL, dit, 1);
788 cpl_image_divide_scalar(tmp, sqrt(CR2RES_GAIN_CHIP1));
790 cpl_image_delete(tmp);
796 for (
size_t i = 1; i <= (size_t) nx; i++)
798 for (
size_t j = 1; j <= (size_t) ny; j++)
809 cpl_frame_delete(bpm);
814 bpm = cpl_frame_new();
815 cpl_frame_set_filename(bpm, my_path);
816 cpl_frame_set_tag(bpm,
"BPM");
817 cpl_frame_set_group(bpm, CPL_FRAME_GROUP_CALIB);
819 hdrl = cr2res_create_hdrl(nx, ny, 1, 0);
822 save_hdrl(my_path, hdrl, MODE_BPM, 0);
825 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, bpm, NULL, dit, 1);
828 cpl_image_divide_scalar(tmp, sqrt(CR2RES_GAIN_CHIP1));
830 cpl_image_delete(tmp);
836 for (
size_t i = 1; i <= (size_t) nx; i++)
838 for (
size_t j = 1; j <= (size_t) ny; j++)
850 cpl_frame_delete(bpm);
855 bpm = cpl_frame_new();
856 cpl_frame_set_filename(bpm,
"TEST_tobeornottobe.fits");
857 cpl_frame_set_tag(bpm,
"BPM");
858 cpl_frame_set_group(bpm, CPL_FRAME_GROUP_CALIB);
860 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, bpm, NULL, dit, 1);
861 cpl_test_error(CPL_ERROR_FILE_IO);
863 cpl_frame_delete(bpm);
866 bpm = create_master_flat(my_path, nx, ny, 1, 0, NULL);
867 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, bpm, NULL, dit, 1);
869 cpl_frame_delete(bpm);
872 bpm = cpl_frame_new();
873 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, bpm, NULL, dit, 1);
874 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
876 cpl_frame_delete(bpm);
880 bpm = cpl_frame_new();
881 cpl_frame_set_filename(bpm, my_path2);
882 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, bpm, NULL, dit, 1);
884 cpl_frame_delete(bpm);
892static void test_cr2res_calib_detlin()
898 double img_value = 20000;
899 double img_error = 200;
900 double out_value, out_error;
905 hdrl_image * in, * out, * cmp;
906 hdrl_image * ima, * imb, * imc;
907 double a, b, c, sa, sb, sc;
913 in = cr2res_create_hdrl(nx, ny, img_value, img_error);
914 i = img_value; si = img_error;
916 char *my_path = cpl_sprintf(
"%s/TEST_master_detlin.fits", localdir);
917 char *my_path2 = cpl_sprintf(
"%s/TEST_empty.fits", localdir);
927 ima = cr2res_create_hdrl(nx, ny, a, sa);
928 imb = cr2res_create_hdrl(nx, ny, b, sb);
929 imc = cr2res_create_hdrl(nx, ny, c, sc);
931 detlin = create_detlin(my_path, ima, imb, imc);
932 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1);
935 sqrt(img_value) / sqrt(CR2RES_GAIN_CHIP1));
940 cpl_frame_delete(detlin);
949 ima = cr2res_create_hdrl(nx, ny, a, sa);
950 imb = cr2res_create_hdrl(nx, ny, b, sb);
951 imc = cr2res_create_hdrl(nx, ny, c, sc);
952 detlin = create_detlin(my_path, ima, imb, imc);
953 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1);
954 out_value = detlin(img_value, a, b, c);
955 out_error = deterr(img_value, a, b, c, img_error, sa, sb, sc);
956 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
958 sqrt(out_value)/sqrt(CR2RES_GAIN_CHIP1));
966 cpl_frame_delete(detlin);
975 ima = cr2res_create_hdrl(nx, ny, a, sa);
976 imb = cr2res_create_hdrl(nx, ny, b, sb);
977 imc = cr2res_create_hdrl(nx, ny, c, sc);
978 detlin = create_detlin(my_path, ima, imb, imc);
979 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1);
980 cmp = cr2res_create_hdrl(nx, ny, 0, 0);
988 cpl_frame_delete(detlin);
996 ima = cr2res_create_hdrl(nx, ny, a, sa);
997 imb = cr2res_create_hdrl(nx, ny, b, sb);
998 imc = cr2res_create_hdrl(nx, ny, c, sc);
999 detlin = create_detlin(my_path, ima, imb, imc);
1000 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1);
1001 out_value = img_value * a;
1002 out_error = img_error * a;
1003 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
1005 sqrt(out_value)/sqrt(CR2RES_GAIN_CHIP1));
1013 cpl_frame_delete(detlin);
1020 a = 2; b = 0; c = 0;
1022 ima = cr2res_create_hdrl(nx, ny, a, sa);
1023 imb = cr2res_create_hdrl(nx, ny, b, sb);
1024 imc = cr2res_create_hdrl(nx, ny, c, sc);
1025 detlin = create_detlin(my_path, ima, imb, imc);
1026 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1);
1027 out_value = detlin(i, a, b, c);
1028 out_error = deterr(i, a, b, c, si, sa, sb, sc);
1029 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
1031 sqrt(out_value)/sqrt(CR2RES_GAIN_CHIP1));
1039 cpl_frame_delete(detlin);
1048 ima = cr2res_create_hdrl(nx, ny, a, sa);
1049 imb = cr2res_create_hdrl(nx, ny, b, sb);
1050 imc = cr2res_create_hdrl(nx, ny, c, sc);
1051 detlin = create_detlin(my_path, ima, imb, imc);
1052 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1);
1053 out_value = detlin(i, a, b, c);
1054 out_error = deterr(i, a, b, c, si, sa, sb, sc);
1055 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
1057 sqrt(out_value)/sqrt(CR2RES_GAIN_CHIP1));
1065 cpl_frame_delete(detlin);
1073 sa = sc = 0; sb = 1;
1074 ima = cr2res_create_hdrl(nx, ny, a, sa);
1075 imb = cr2res_create_hdrl(nx, ny, b, sb);
1076 imc = cr2res_create_hdrl(nx, ny, c, sc);
1077 detlin = create_detlin(my_path, ima, imb, imc);
1078 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1);
1079 out_value = pow2(img_value);
1080 out_error = deterr(i, a, b, c, si, sa, sb, sc);
1081 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
1083 sqrt(out_value)/sqrt(CR2RES_GAIN_CHIP1));
1089 cpl_frame_delete(detlin);
1095 a = 1; c = 0; b = 1;
1096 sa = 1 ; sc = 0; sb = 1;
1097 ima = cr2res_create_hdrl(nx, ny, a, sa);
1098 imb = cr2res_create_hdrl(nx, ny, b, sb);
1099 imc = cr2res_create_hdrl(nx, ny, c, sc);
1100 detlin = create_detlin(my_path, ima, imb, imc);
1101 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1);
1102 out_value = detlin(i, a, b, c);
1103 out_error = deterr(i, a, b, c, si, sa, sb, sc);
1104 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
1106 sqrt(out_value / CR2RES_GAIN_CHIP1));
1114 cpl_frame_delete(detlin);
1121 a = 1; c = 1; b = 0;
1122 sa = 1 ; sc = 1; sb = 0;
1123 i = img_value; si = img_error;
1124 ima = cr2res_create_hdrl(nx, ny, a, sa);
1125 imb = cr2res_create_hdrl(nx, ny, b, sb);
1126 imc = cr2res_create_hdrl(nx, ny, c, sc);
1127 detlin = create_detlin(my_path, ima, imb, imc);
1128 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1);
1129 out_value = detlin(i, a, b, c);
1130 out_error = deterr(i, a, b, c, si, sa, sb, sc);
1131 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
1133 sqrt(out_value)/sqrt(CR2RES_GAIN_CHIP1));
1139 cpl_frame_delete(detlin);
1146 a = 1; c = 1; b = 1;
1147 sa = 1 ; sc = 1; sb = 1;
1148 i = img_value; si = img_error;
1149 ima = cr2res_create_hdrl(nx, ny, a, sa);
1150 imb = cr2res_create_hdrl(nx, ny, b, sb);
1151 imc = cr2res_create_hdrl(nx, ny, c, sc);
1152 detlin = create_detlin(my_path, ima, imb, imc);
1153 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1);
1154 out_value = detlin(i, a, b, c);
1155 out_error = deterr(i, a, b, c, si, sa, sb, sc);
1156 cmp = cr2res_create_hdrl(nx, ny, out_value, out_error);
1158 sqrt(out_value)/sqrt(CR2RES_GAIN_CHIP1));
1164 cpl_frame_delete(detlin);
1170 detlin = cpl_frame_new();
1171 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1);
1172 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
1174 cpl_frame_delete(detlin);
1178 detlin = cpl_frame_new();
1179 cpl_frame_set_filename(detlin, my_path2);
1180 out =
cr2res_calib_image(in, chip, 0, 0, 0, 0, NULL, NULL, NULL, detlin, dit, 1);
1182 cpl_frame_delete(detlin);
1199 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_DEBUG);
1201 create_empty_fits();
1203 test_cr2res_calib_image();
1204 test_cr2res_calib_cosmic();
1205 test_cr2res_calib_flat();
1206 test_cr2res_calib_dark();
1207 test_cr2res_calib_bpm();
1208 test_cr2res_calib_detlin();
1210 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)
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
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.