ERIS Pipeline Reference Manual 1.8.10
eris_ifu_detlin_static.c
1/* $Id$
2 *
3 * This file is part of the ERIS Pipeline
4 * Copyright (C) 2002,2003 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "eris_ifu_detlin_static.h"
22#include "eris_ifu_error.h"
23#include "eris_ifu_utils.h"
24#include "eris_ifu_debug.h"
25#include "eris_ifu_dfs.h"
26#include "eris_utils.h"
27#include "eris_ifu_functions.h"
28#include "eris_pfits.h"
29#include "eris_utils.h"
30
31#include <hdrl.h>
32#include <string.h>
33#define FILE_NAME_SZ 256
34
35cpl_error_code eris_ifu_detlin_load_frames(const cpl_frameset *frameset,
36 int exposureCorrectionMode,
37 hdrl_imagelist **hdrl_imglist_on,
38 hdrl_imagelist **hdrl_imglist_off,
39 cpl_vector **vec_dit_on,
40 cpl_vector **vec_dit_off)
41{
42 cpl_error_code ret = CPL_ERROR_NONE;
43 const cpl_frame *fr = NULL;
44 const char *fn = NULL;
45 cpl_size nr_dit_on = 0,
46 nr_dit_off = 0;
47 double_t dit = 0.;
48 hdrl_image *tmp_img = NULL;
49 cpl_propertylist *pl = NULL;
50
51 cpl_ensure_code(frameset, CPL_ERROR_NULL_INPUT);
52 cpl_ensure_code(hdrl_imglist_on, CPL_ERROR_NULL_INPUT);
53 cpl_ensure_code(hdrl_imglist_off, CPL_ERROR_NULL_INPUT);
54 cpl_ensure_code(vec_dit_on, CPL_ERROR_NULL_INPUT);
55 cpl_ensure_code(vec_dit_off, CPL_ERROR_NULL_INPUT);
56
57 TRY
58 {
59 *hdrl_imglist_on = hdrl_imagelist_new();
60 *hdrl_imglist_off = hdrl_imagelist_new();
61 *vec_dit_on = cpl_vector_new(cpl_frameset_get_size(frameset));
62 *vec_dit_off = cpl_vector_new(cpl_frameset_get_size(frameset));
63
64 /*
65 * Loop through all LINEARITY_LAMP frames and save on- and off-frames
66 * accordingly in their cpl_imagelists
67 */
68 fr = cpl_frameset_find_const(frameset, ERIS_IFU_RAW_LIN);
69 while (fr != NULL) {
70 fn = cpl_frame_get_filename(fr);
71 eris_ifu_file_exists(fn);
72 tmp_img = eris_ifu_load_exposure_file(fn,
73 exposureCorrectionMode, NULL);
74
75 pl = cpl_propertylist_load(fn, 0);
76 dit = eris_ifu_get_dit(pl);
78
79 if (eris_ifu_frame_is_on(fr) == 1) {
80 hdrl_imagelist_set(*hdrl_imglist_on, tmp_img, nr_dit_on);
81 cpl_vector_set(*vec_dit_on, nr_dit_on++, dit);
82 } else {
83 hdrl_imagelist_set(*hdrl_imglist_off, tmp_img, nr_dit_off);
84 cpl_vector_set(*vec_dit_off, nr_dit_off++, dit);
85 }
86
87 /* next frame */
88 fr = cpl_frameset_find_const(frameset, NULL);
90 }
91 cpl_vector_set_size(*vec_dit_on, nr_dit_on);
92 cpl_vector_set_size(*vec_dit_off, nr_dit_off);
93
94 /*
95 * check if there are twice as dits of on- than and dits of off-frames
96 */
97 if (nr_dit_on != 2*nr_dit_off) {
98 cpl_msg_warning(cpl_func, "Found %lld on-frames and %lld off-frames, "
99 "but twice as many on-frmaes than off-frames are expected",
100 nr_dit_on, nr_dit_off);
101 }
102 }
103 CATCH
104 {
105 CATCH_MSGS();
106 ret = cpl_error_get_code();
107 eris_ifu_free_hdrl_imagelist(hdrl_imglist_on);
108 eris_ifu_free_hdrl_imagelist(hdrl_imglist_off);
109 eris_ifu_free_vector(vec_dit_on);
110 eris_ifu_free_vector(vec_dit_off);
111 }
112
114 eris_check_error_code("eris_ifu_detlin_load_frames");
115 return ret;
116}
117
118//cpl_table* eris_ifu_detlin_compute_linearity_old(
119// const hdrl_imagelist* hdrl_imglist_on,
120// const hdrl_imagelist* hdrl_imglist_off,
121// const cpl_vector *vec_dit)
122//{
123// int nr_img_on = hdrl_imagelist_get_size(hdrl_imglist_on),
124// nr_img_off = hdrl_imagelist_get_size(hdrl_imglist_off),
125// nr_vec_dit = cpl_vector_get_size(vec_dit),
126// *status = 0;
127// double dit = 0.,
128// med_dit = 0.,
129// avg_dit = 0.;
130// hdrl_value med,
131// avg,
132// tmp_on,
133// tmp_off;
134// cpl_table *lin_tbl = NULL;
135// cpl_vector *vec_med_dit = NULL;
136// const hdrl_image *img_on = NULL,
137// *img_off = NULL;
138
139// cpl_ensure(hdrl_imglist_on, CPL_ERROR_NULL_INPUT, NULL);
140// cpl_ensure(hdrl_imglist_off, CPL_ERROR_NULL_INPUT, NULL);
141// cpl_ensure(vec_dit, CPL_ERROR_NULL_INPUT, NULL);
142// cpl_ensure(nr_img_on == nr_img_off, CPL_ERROR_ILLEGAL_INPUT, NULL);
143// cpl_ensure(nr_img_on == nr_vec_dit, CPL_ERROR_ILLEGAL_INPUT, NULL);
144
145// TRY
146// {
147// BRK_IF_NULL(
148// lin_tbl = cpl_table_new(nr_img_on));
149
150// cpl_table_new_column(lin_tbl, "med", CPL_TYPE_DOUBLE);
151// cpl_table_new_column(lin_tbl, "avg", CPL_TYPE_DOUBLE);
152// cpl_table_new_column(lin_tbl, "med_dit", CPL_TYPE_DOUBLE);
153// cpl_table_new_column(lin_tbl, "avg_dit", CPL_TYPE_DOUBLE);
154// cpl_table_new_column(lin_tbl, "dit", CPL_TYPE_DOUBLE);
155// cpl_table_new_column(lin_tbl, "med_err", CPL_TYPE_DOUBLE);
156// cpl_table_new_column(lin_tbl, "avg_err", CPL_TYPE_DOUBLE);
157// CHECK_ERROR_STATE();
158
159// BRK_IF_NULL(
160// vec_med_dit = cpl_vector_new(nr_img_on));
161
162// for(int i = 0; i < nr_img_on; i++) {
163// img_on = hdrl_imagelist_get_const(hdrl_imglist_on, i);
164// img_off = hdrl_imagelist_get_const(hdrl_imglist_off, i);
165
166// tmp_on = hdrl_image_get_median(img_on);
167// tmp_off = hdrl_image_get_median(img_off);
168// med.data = tmp_on.data - tmp_off.data;
169// med.error = sqrt(pow(tmp_on.error, 2) - pow(tmp_off.error, 2));
170
171// tmp_on = hdrl_image_get_mean(img_on);
172// tmp_off = hdrl_image_get_mean(img_off);
173// avg.data = tmp_on.data - tmp_off.data;
174// avg.error = sqrt(pow(tmp_on.error, 2) - pow(tmp_off.error, 2));
175
176// dit = cpl_vector_get(vec_dit, i);
177// CHECK_ERROR_STATE();
178
179// // errors of med_dit and avg_dit are the same as for med and avg
180// med_dit = med.data / dit;
181// avg_dit = avg.data / dit;
182
183// BRK_IF_ERROR(
184// cpl_table_set_double(lin_tbl, "dit", i, dit));
185// BRK_IF_ERROR(
186// cpl_table_set_double(lin_tbl, "avg", i, avg.data));
187// BRK_IF_ERROR(
188// cpl_table_set_double(lin_tbl, "avg_dit", i, avg_dit));
189// BRK_IF_ERROR(
190// cpl_table_set_double(lin_tbl, "med", i, med.data));
191// BRK_IF_ERROR(
192// cpl_table_set_double(lin_tbl, "med_dit", i, med_dit));
193// BRK_IF_ERROR(
194// cpl_table_set_double(lin_tbl, "med_err", i, med.error));
195// BRK_IF_ERROR(
196// cpl_table_set_double(lin_tbl, "avg_err", i, avg.error));
197// BRK_IF_ERROR(
198// cpl_vector_set(vec_med_dit, i, med_dit));
199// }
200
201// BRK_IF_ERROR(
202// cpl_table_new_column(lin_tbl, "adl", CPL_TYPE_DOUBLE));
203
204// med_dit = cpl_vector_get_mean(vec_med_dit);
205// CHECK_ERROR_STATE();
206
207// for(int i = 0; i < nr_img_on; i++) {
208// dit = cpl_table_get_double(lin_tbl, "dit", i, status);
209// CHECK_ERROR_STATE();
210
211// // errors of adl are the same as for med
212// BRK_IF_ERROR(
213// cpl_table_set_double(lin_tbl, "adl", i, dit*med_dit));
214// }
215// }
216// CATCH
217// {
218// CATCH_MSGS();
219// eris_ifu_free_table(&lin_tbl);
220// }
221
222// eris_ifu_free_vector(&vec_med_dit);
223
224// return lin_tbl;
225//}
226static cpl_error_code
227eris_detlin_qc_lin_log(hdrl_imagelist* fit_coef, cpl_image* chi2,
228 cpl_image* dof, cpl_mask* mask, cpl_propertylist* linc_qclist)
229{
230
231 cpl_mask* bpm;
232 cpl_size planes = hdrl_imagelist_get_size(fit_coef);
233 cpl_image* image = NULL;
234 cpl_image* error = NULL;
235 char* name_o1;
236 char* name_o2;
237
238 for(cpl_size deg = 0; deg < planes; deg++)
239 {
240
241 image = hdrl_image_get_image(hdrl_imagelist_get(fit_coef, deg));
242 error = hdrl_image_get_error(hdrl_imagelist_get(fit_coef, deg));
243 cpl_image_power(error, 2.);
244 cpl_image_multiply(error, chi2);
245 cpl_image_divide(error, dof);
246 cpl_image_power(error, 0.5);
247
248 bpm = cpl_image_set_bpm(image, mask);
249 const double coeff = cpl_image_get_median(image);
250 cpl_image_set_bpm(image, bpm);
251
252 name_o1 = cpl_sprintf("ESO QC LIN COEF%d", (int)deg);
253
254 cpl_propertylist_append_double(linc_qclist, name_o1, coeff);
255 cpl_propertylist_set_comment(linc_qclist, name_o1, ERIS_QC_LIN_COEF_C);
256
257 cpl_free(name_o1);
258 name_o1= NULL;
259
260 name_o2 = cpl_sprintf("ESO QC LIN COEF%d ERR", (int)deg);
261
262 bpm = cpl_image_set_bpm(error, mask);
263 const double coeff_err = cpl_image_get_median(error);
264 cpl_image_set_bpm(error, bpm);
265
266 cpl_propertylist_append_double(linc_qclist, name_o2, coeff_err);
267 cpl_propertylist_set_comment(linc_qclist, name_o2, ERIS_QC_LIN_COEF_ERR_C);
268
269 cpl_free(name_o2);
270 name_o2= NULL;
271
272 }
273 eris_check_error_code("eris_detlin_qc_lin_log");
274 return cpl_error_get_code();
275}
276cpl_image* eris_ifu_detlin_compute_linearity(
277 const cpl_parameterlist *parlist,
278 const hdrl_imagelist *imglist,
279 const cpl_vector *vec_dit,
280 cpl_propertylist* qclog)
281{
282 hdrl_parameter *hp = NULL;
283 cpl_image *bpm_fit = NULL;
284
285 cpl_ensure(parlist, CPL_ERROR_NULL_INPUT, NULL);
286 cpl_ensure(imglist, CPL_ERROR_NULL_INPUT, NULL);
287 cpl_ensure(vec_dit, CPL_ERROR_NULL_INPUT, NULL);
288
289 cpl_size nr_img = hdrl_imagelist_get_size(imglist),
290 nr_vec = cpl_vector_get_size(vec_dit);
291 cpl_ensure(nr_img == nr_vec, CPL_ERROR_ILLEGAL_INPUT, NULL);
292
293 TRY
294 {
295 // get bpm_fit-parameter
296 hp = hdrl_bpm_fit_parameter_parse_parlist(parlist, REC_NAME_DETLIN);
297
298 // calculate bpm_fit
299 hdrl_bpm_fit_compute(hp, imglist, vec_dit, &bpm_fit);
300
301 cpl_size sx = cpl_image_get_size_x(bpm_fit);
302 cpl_size sy = cpl_image_get_size_y(bpm_fit);
303 cpl_mask* mask = cpl_mask_new(sx, sy);
304 int* pbpm = cpl_image_get_data(bpm_fit);
305 cpl_binary* pmsk = cpl_mask_get_data(mask);
306 for (cpl_size j = 0; j < sy; j++) {
307 for (cpl_size i = 0; i < sx; i++) {
308 if(pbpm[i+j*sx] != 0 ) {
309 pmsk[i+j*sx] = BAD_PIX;
310 }
311 }
312 }
313 /* flag pixels defined in bpm_fit into hdrl imagelist imglist */
314 cpl_image* image;
315 cpl_image* error;
316 hdrl_image* hima;
317
318 for(cpl_size i = 0; i < hdrl_imagelist_get_size(imglist); i++) {
319 hima = hdrl_imagelist_get(imglist,i);
320 image = hdrl_image_get_image(hima);
321 cpl_image_reject_from_mask(image, mask);
322 error = hdrl_image_get_error(hima);
323 cpl_image_reject_from_mask(error, mask);
324 //cpl_image_set_bpm(error, mask);
325 }
326
327 cpl_image * out_chi2 = NULL, * out_dof = NULL;
328 hdrl_imagelist * out_coef = NULL;
329 int order = hdrl_bpm_fit_parameter_get_degree(hp);
330 hdrl_fit_polynomial_imagelist(imglist, vec_dit, order, &out_coef,
331 &out_chi2, &out_dof);
332
333 /* log fit coeff as QC params */
334 eris_detlin_qc_lin_log(out_coef, out_chi2, out_dof, mask, qclog);
335 hdrl_imagelist_delete(out_coef);
336 cpl_image_delete(out_chi2);
337 cpl_image_delete(out_dof);
338 cpl_mask_delete(mask);
339 eris_ifu_get_badpix_qc_from_ima(bpm_fit, qclog, "LINEARITY");
340 }
341 CATCH
342 {
343 CATCH_MSGS();
344 eris_ifu_free_image(&bpm_fit);
345 }
347 eris_check_error_code("eris_ifu_detlin_compute_linearity");
348 return bpm_fit;
349}
350
351cpl_mask* eris_ifu_detlin_filter_mask(const cpl_mask *bpm,
352 const cpl_parameterlist *parlist)
353{
354 cpl_mask *filtered = NULL;
355 const cpl_parameter *p = NULL;
356 int pfx = 0,
357 pfy = 0;
358 const char *pfm = NULL;
359 cpl_filter_mode filter_mode = CPL_FILTER_CLOSING;
360
361 cpl_ensure(bpm, CPL_ERROR_NULL_INPUT, NULL);
362 cpl_ensure(parlist, CPL_ERROR_NULL_INPUT, NULL);
363
364 TRY
365 {
366 p = cpl_parameterlist_find_const(parlist,
367 REC_NAME_DETLIN".post-filter-x");
368 pfx = cpl_parameter_get_int(p);
370
371 p = cpl_parameterlist_find_const(parlist,
372 REC_NAME_DETLIN".post-filter-y");
373 pfy = cpl_parameter_get_int(p);
375
376 p = cpl_parameterlist_find_const(parlist,
377 REC_NAME_DETLIN".post-filter-mode");
378 pfm = cpl_parameter_get_string(p);
379
380 if (!strcmp(pfm, "closing")) {
381 filter_mode = CPL_FILTER_CLOSING ;
382 }
383 else if (!strcmp(pfm, "dilation")) {
384 filter_mode = CPL_FILTER_DILATION ;
385 }
386 else {
388 CPL_ERROR_ILLEGAL_INPUT,
389 "Filter mode can only be \"closing\" or \"dilation\" (not %s)",
390 pfm);
391 }
392
393 /* Post Filtering */
394 if ((pfx > 0) && (pfy > 0)) {
396 filtered = hdrl_bpm_filter(bpm, pfx, pfy, filter_mode));
397 }
398 }
399 CATCH
400 {
401 CATCH_MSGS();
402 eris_ifu_free_mask(&filtered);
403 }
404 eris_check_error_code("eris_ifu_detlin_filter_mask");
405 return filtered;
406}
407
423static int
424eris_get_clean_mean_window(cpl_image* img,
425 int llx, int lly, int urx, int ury,
426 const int kappa, const int nclip,
427 double* local_clean_mean,
428 double* clean_stdev)
429{
430
431 double mean = 0;
432 double stdev = 0;
433
434 cpl_image * tmp = NULL;
435 cpl_stats * stats = NULL;
436 int i = 0;
437
438 tmp = cpl_image_extract(img, llx, lly, urx, ury);
439 cpl_image_accept_all(tmp);
440 for(i = 0; i < nclip; i++) {
441
442 cpl_stats_delete(stats);
443 stats = cpl_stats_new_from_image(tmp, CPL_STATS_MEAN | CPL_STATS_STDEV);
444 mean = cpl_stats_get_mean(stats);
445 stdev = cpl_stats_get_stdev(stats);
446
447 double threshold = kappa * stdev;
448 double lo_cut = mean - threshold;
449 double hi_cut = mean + threshold;
450 cpl_image_accept_all(tmp);
451 cpl_mask* mask = cpl_mask_threshold_image_create(tmp, lo_cut, hi_cut);
452
453 cpl_mask_not(mask);
454 cpl_image_reject_from_mask(tmp, mask);
455 cpl_mask_delete(mask);
456
457 }
458 *local_clean_mean = mean;
459 *clean_stdev = stdev;
460 cpl_image_delete(tmp);
461 cpl_stats_delete(stats);
462 eris_check_error_code("eris_get_clean_mean_window");
463 return 0;
464
465}
466
472cpl_table* eris_compute_gain(cpl_frameset* frameset)
473{
474
475 cpl_ensure(frameset,CPL_ERROR_NULL_INPUT, NULL);
476
477 cpl_frame* frm = NULL;
478
479 cpl_image* img_on1 = NULL;
480 cpl_image* img_on2 = NULL;
481 cpl_image* img_on_dif = NULL;
482 cpl_image* img_on_sub = NULL;
483
484
485 cpl_image* img_of1 = NULL;
486 cpl_image* img_of2 = NULL;
487 cpl_image* img_of_dif = NULL;
488 cpl_image* img_of_sub = NULL;
489
490 cpl_table* res_tbl = NULL;
491 cpl_vector* dit_on = NULL;
492 cpl_vector* dit_of = NULL;
493 cpl_vector* exptime_on = NULL;
494 cpl_vector* exptime_of = NULL;
495 cpl_propertylist* plist = NULL;
496
497 int non = 0;
498 int nof = 0;
499 int nfr = 0;
500 double avg_on1 = 0;
501 double avg_on2 = 0;
502 double avg_of1 = 0;
503 double avg_of2 = 0;
504 double std = 0;
505
506 double sig_on_dif = 0;
507 double sig_of_dif = 0;
508 char* name = NULL;
509 int i = 0;
510 int m = 0;
511
512 int llx = 270;
513 int lly = 1000;
514 int urx = 320;
515 int ury = 1050;
516 //int zone[4];
517 double gain = 0;
518 double dit_ref = 0;
519 double dit_tmp = 0;
520 double exptime_ref = 0;
521 double exptime_tmp = 0;
522 int kappa = 5;
523 int nclip = 25;
524 double centre = 0;
525
526 cpl_size nff = cpl_frameset_get_size(frameset);
527 cpl_frameset* son = cpl_frameset_new();
528 cpl_frameset* sof = cpl_frameset_new();
529 cpl_frame* frm_dup;
530 /* separates on and off frames */
531
532 for(i = 0; i < nff; i++) {
533 frm = cpl_frameset_get_position(frameset, i);
534 frm_dup = cpl_frame_duplicate(frm);
535 if(eris_ifu_frame_is_on(frm)) {
536 cpl_frameset_insert(son, frm_dup);
537 } else {
538 cpl_frameset_insert(sof, frm_dup);
539 }
540 }
541
542 non = cpl_frameset_get_size(son);
543 nof = cpl_frameset_get_size(sof);
544 nfr = (non <= nof) ? non : nof;
545
546 dit_on = cpl_vector_new(nfr);
547 dit_of = cpl_vector_new(nfr);
548 exptime_on = cpl_vector_new(nfr);
549 exptime_of = cpl_vector_new(nfr);
550
551 for(i = 0; i < nfr; i++) {
552
553 frm = cpl_frameset_get_position(son, i);
554 name = (char*) cpl_frame_get_filename(frm);
555 plist = cpl_propertylist_load(name, 0);
556 dit_ref = eris_pfits_get_dit(plist);
557 exptime_ref = cpl_propertylist_get_double(plist, "EXPTIME");
558 cpl_propertylist_delete(plist);
559 cpl_vector_set(dit_on, i, dit_ref);
560 cpl_vector_set(exptime_on, i, exptime_ref);
561
562 frm = cpl_frameset_get_position(sof, i);
563 name = (char*) cpl_frame_get_filename(frm);
564 plist = cpl_propertylist_load(name, 0);
565 dit_ref = eris_pfits_get_dit(plist);
566 exptime_ref = cpl_propertylist_get_double(plist, "EXPTIME");
567 cpl_propertylist_delete(plist);
568 cpl_vector_set(dit_of, i, dit_ref);
569 cpl_vector_set(exptime_of, i, exptime_ref);
570
571 }
572
573 res_tbl = cpl_table_new(nfr);
574 cpl_table_new_column(res_tbl, "adu", CPL_TYPE_DOUBLE);
575 cpl_table_new_column(res_tbl, "gain", CPL_TYPE_DOUBLE);
576
577 for(i = 0; i < nfr; i++) {
578 frm = cpl_frameset_get_position(son, i);
579 name = (char*) cpl_frame_get_filename(frm);
580 img_on1 = cpl_image_load(name, CPL_TYPE_DOUBLE, 0, 0);
581
582 frm = cpl_frameset_get_position(sof, i);
583 name = (char*) cpl_frame_get_filename(frm);
584 img_of1 = cpl_image_load(name, CPL_TYPE_DOUBLE, 0, 0);
585
586
587 dit_ref = cpl_vector_get(dit_on, i);
588 exptime_ref = cpl_vector_get(exptime_on, i);
589
590 for(m = 0; m < nfr; m++) {
591 if(m != i) {
592 frm = cpl_frameset_get_position(son, m);
593 name = (char*) cpl_frame_get_filename(frm);
594 dit_tmp = cpl_vector_get(dit_on, m);
595 exptime_tmp = cpl_vector_get(exptime_on, m);
596 if(dit_tmp == dit_ref && exptime_tmp == exptime_ref) {
597 /* eris_msg("m=%d i=%d\n", m, i); */
598 img_on2 = cpl_image_load(name, CPL_TYPE_DOUBLE, 0, 0);
599 frm = cpl_frameset_get_position(sof, m);
600 name = (char*) cpl_frame_get_filename(frm);
601 img_of2 = cpl_image_load(name, CPL_TYPE_DOUBLE, 0, 0);
602
603 img_on_dif = cpl_image_subtract_create(img_on1, img_on2);
604 img_of_dif = cpl_image_subtract_create(img_of1, img_of2);
605
606 img_on_sub = cpl_image_extract(img_on_dif, llx, lly, urx, ury);
607 img_of_sub = cpl_image_extract(img_of_dif, llx, lly, urx, ury);
608
609 eris_get_clean_mean_window(img_on1, llx, lly, urx, ury, kappa,
610 nclip, &avg_on1, &std);
611 eris_get_clean_mean_window(img_on2, llx, lly, urx, ury, kappa,
612 nclip, &avg_on2, &std);
613 eris_get_clean_mean_window(img_of1, llx, lly, urx, ury, kappa,
614 nclip, &avg_of1, &std);
615 eris_get_clean_mean_window(img_of2, llx, lly, urx, ury, kappa,
616 nclip, &avg_of2, &std);
617 /*
618 cpl_image_save(img_on_sub, "ima_on_sub.fits",
619 CPL_BPP_IEEE_FLOAT, NULL, CPL_IO_DEFAULT);
620 cpl_image_save(img_of_sub, "ima_of_sub.fits",
621 CPL_BPP_IEEE_FLOAT, NULL, CPL_IO_DEFAULT);
622 */
623 /*
624 //worse accuracy
625 eris_stat_rectangle(img_on_dif, kappa, nclip, &centre, &sig_on_dif);
626 eris_stat_rectangle(img_of_dif, kappa, nclip, &centre, &sig_of_dif);
627 */
628
629
630 //better accuracy
631 eris_get_clean_mean_window(img_on_dif, llx, lly, urx, ury, kappa,
632 nclip, &centre, &sig_on_dif);
633 eris_get_clean_mean_window(img_of_dif, llx, lly, urx, ury, kappa,
634 nclip, &centre, &sig_of_dif);
646 cpl_image_delete(img_on2);
647 cpl_image_delete(img_of2);
648 cpl_image_delete(img_on_dif);
649 cpl_image_delete(img_of_dif);
650 cpl_image_delete(img_on_sub);
651 cpl_image_delete(img_of_sub);
652
653 gain = ( (avg_on1 + avg_on2) - (avg_of1 + avg_of2) ) /
654 ( (sig_on_dif * sig_on_dif) - (sig_of_dif * sig_of_dif) );
655
656 cpl_table_set_double(res_tbl, "gain", m, gain);
657 cpl_table_set_double(res_tbl, "adu", m,
658 ( (avg_on1 + avg_on2) / 2 - (avg_of1 + avg_of2) / 2) );
659 /* eris_msg("gain=%f ADU=%f\n",gain,
660 (avg_on1 + avg_on2) / 2 - (avg_of1 + avg_of2) / 2);
661 eris_msg("g=%f avg_on1=%f avg_on2=%f", gain, avg_on1, avg_on2);
662 eris_msg("avg_of1=%f avg_of2=%f sig_on_dif=%f sig_of_dif=%f",
663 avg_of1, avg_of2, sig_on_dif, sig_of_dif);
664 */
665
666 }
667 }
668 }
669 cpl_image_delete(img_on1);
670 cpl_image_delete(img_of1);
671 }
672
673
674 /*
675 eris_get_clean_mean_window(img_on_dif, llx, lly, urx, ury, kappa,
676 nclip, &avg, &sig_on_dif);
677 eris_get_clean_mean_window(img_of_dif, llx, lly, urx, ury, kappa,
678 nclip, &avg, &sig_of_dif);
679 */
680
681 cpl_vector_delete(dit_on);
682 cpl_vector_delete(dit_of);
683 cpl_vector_delete(exptime_on);
684 cpl_vector_delete(exptime_of);
685 cpl_frameset_delete(son);
686 cpl_frameset_delete(sof);
687 eris_check_error_code("eris_compute_gain");
688 return res_tbl;
689
690}
float eris_ifu_get_dit(cpl_propertylist *header)
Determine if a frame is a Sky frame or not.
bool eris_ifu_frame_is_on(const cpl_frame *fr)
Determine if a frame is obtained with lamps ON or OFF.
#define CHECK_ERROR_STATE(void)
Check the CPL error state, and exit the try-block if not CPL_ERROR_NONE.
#define BRK_WITH_ERROR_MSG(code,...)
Set a new CPL error, and exit the try-block.
#define TRY
Beginning of a TRY-block.
#define CATCH
End of a TRY-block, beginning of a CATCH-block.
#define BRK_IF_NULL(function)
If function is or returns a NULL pointer, then the try-block is exited.
#define CATCH_MSGS()
Displays an error message stack.
hdrl_image * eris_ifu_load_exposure_file(const char *filename, int exposureCorrectionMode, cpl_image *dqi)
Read a raw detector exposure, perform some correction, add noise data.
void eris_ifu_free_propertylist(cpl_propertylist **item)
free memory and set pointer to null
void eris_ifu_free_vector(cpl_vector **item)
free memory and set pointer to null
cpl_error_code eris_ifu_get_badpix_qc_from_ima(const cpl_image *image, cpl_propertylist *qc_list, const char *prefix)
compute QC keyword with number of bad pixels and fraction to total
void eris_ifu_free_hdrl_imagelist(hdrl_imagelist **item)
free memory and set pointer to null
void eris_ifu_free_image(cpl_image **item)
free memory and set pointer to null
void eris_ifu_free_mask(cpl_mask **item)
free memory and set pointer to null
void eris_ifu_free_hdrl_parameter(hdrl_parameter **item)
free memory and set pointer to null
double eris_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
Definition: eris_pfits.c:98
cpl_error_code eris_check_error_code(const char *func_id)
handle CPL errors
Definition: eris_utils.c:56
hdrl_parameter * hdrl_bpm_fit_parameter_parse_parlist(const cpl_parameterlist *parlist, const char *prefix)
Parse a parameterlist to create input parameters for the BPM_FIT.
Definition: hdrl_bpm_fit.c:442
int hdrl_bpm_fit_parameter_get_degree(const hdrl_parameter *p)
get degree of polynomial fit of parameter
Definition: hdrl_bpm_fit.c:263
cpl_error_code hdrl_bpm_fit_compute(const hdrl_parameter *par, const hdrl_imagelist *data, const cpl_vector *sample_pos, cpl_image **out_mask)
compute bad pixel map based on fitting a stack of images
Definition: hdrl_bpm_fit.c:587
cpl_mask * hdrl_bpm_filter(const cpl_mask *input_mask, cpl_size kernel_nx, cpl_size kernel_ny, cpl_filter_mode filter)
Allows the growing and shrinking of bad pixel masks. It can be used to e.g. set pixels to bad if the ...
cpl_error_code hdrl_fit_polynomial_imagelist(const hdrl_imagelist *list, const cpl_vector *samplepos, const int degree, hdrl_imagelist **coef, cpl_image **chi2, cpl_image **dof)
weighted least squares polynomial fit of each pixel of a imagelist
Definition: hdrl_fit.c:367
cpl_image * hdrl_image_get_error(hdrl_image *himg)
get error as cpl image
Definition: hdrl_image.c:131
cpl_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
Definition: hdrl_image.c:105
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.
cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *himlist)
Get the number of images in the imagelist.
hdrl_imagelist * hdrl_imagelist_new(void)
Create an empty imagelist.
hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.