X-shooter Pipeline Reference Manual 3.8.15
test-combine_flux_with_scaling.c
Go to the documentation of this file.
1/* *
2 * This file is part of the ESO X-shooter Pipeline *
3 * Copyright (C) 2006 European Southern Observatory *
4 * *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
18 * */
19
20/*
21 * $Author: amodigli $
22 * $Date: 2011-12-02 14:13:14 $
23 * $Revision: 1.3 $
24 * $Name: not supported by cvs2svn $
25 */
26#ifdef HAVE_CONFIG_H
27# include <config.h>
28#endif
29
30/*--------------------------------------------------------------------------*/
36/*--------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------
40 Includes
41 ---------------------------------------------------------------------------*/
42#include <string.h>
43#include <stdio.h>
44#include <math.h>
45#include <cpl.h>
46#include <xsh_msg.h>
47#include <xsh_dfs.h>
48#include <xsh_utils.h>
49#include <xsh_data_rec.h>
50#include <xsh_pfits.h>
51#include <xsh_parameters.h>
52
53static cpl_image*
55
56 cpl_image* res;
57
58
59 cpl_image* tmp;
60
61 cpl_binary* pbpm;
62 int sx=0;
63 int sy=0;
64 int sz=0;
65 double* flux;
66 sz=cpl_imagelist_get_size(iml);
67 tmp=cpl_imagelist_get(iml,0);
68 sx=cpl_image_get_size_x(tmp);
69 sy=cpl_image_get_size_y(tmp);
70 cpl_mask* bpm;
71 cpl_mask* bpmr;
72 cpl_binary* pbpmr;
73 double* pima;
74 int good;
75 int bad;
76 int sx_j;
77 int pix;
78 cpl_vector* flux_vec;
79 double* pres;
80 cpl_binary bp_code;
81 res=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
82
83 pres=cpl_image_get_data_double(res);
84
85 flux= (double*) cpl_calloc(sz , sizeof(double));
86 //XSH_MALLOC( flux, double, sz);
87 bpmr=cpl_image_get_bpm(res);
88 pbpmr=cpl_mask_get_data(bpmr);
89 for(int j=0;j<sy;j++) {
90
91 sx_j=sx*j;
92 for(int i=0;i<sx;i++) {
93
94 good=0;
95 bad=0;
96 pix=sx_j+i;
97 bp_code=CPL_BINARY_0;
98 for (int k = 0; k < sz; k++) {
99 tmp=cpl_imagelist_get(iml,k);
100 pima=cpl_image_get_data_double(tmp);
101 bpm=cpl_image_get_bpm(tmp);
102 pbpm=cpl_mask_get_data(bpm);
103 if( pbpm[pix] == CPL_BINARY_0 ) {
104 flux[good]=pima[pix];
105 good++;
106 } else {
107 flux[good+bad]=pima[pix];
108 bad++;
109 bp_code=CPL_BINARY_1;
110 //xsh_msg("found bp");
111 }
112 }
113
114 if (good == 0) {
115 flux_vec = cpl_vector_wrap( bad, flux);
116
117 } else {
118 flux_vec = cpl_vector_wrap( good, flux);
119
120 }
121 pres[pix] = cpl_vector_get_mean( flux_vec);
122 pbpmr[pix] = bp_code;
123 xsh_unwrap_vector(&flux_vec);
124 }
125 }
126
127 cpl_free ( flux);
128 return res;
129
130}
131
132cpl_error_code
133test_mem(void) {
134 cpl_image* ima;
135 cpl_imagelist* iml;
136 cpl_imagelist* iml1;
137 cpl_imagelist* iml2;
138 int sx=100;
139 int sy=100;
140 iml=cpl_imagelist_new();
141 int sz=5;
142 int niter=1;
143 for(int i=0;i < sz;i++) {
144 ima=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
145 cpl_imagelist_set(iml,ima,i);
146 }
147
148
149
150 for(int i=0;i < niter;i++) {
151 iml1=cpl_imagelist_duplicate(iml);
152 iml2=cpl_imagelist_duplicate(iml);
153
154 cpl_imagelist_delete(iml1);
155 cpl_imagelist_delete(iml2);
156 }
157
158
159 cpl_imagelist_delete(iml);
160
161 return cpl_error_get_code();
162}
163static cpl_image*
164xsh_compute_scale(cpl_imagelist* iml_data, cpl_mask* bpm,
165 const int mode, const int win_hsz)
166{
167 cpl_image* res;
168 int sx_j;
169 int pix;
170 int win_hsx;
171 int win_hsy;
172 if(mode==0) {
173 win_hsx=0;
174 win_hsy=win_hsz;
175 } else {
176 win_hsx=win_hsz;
177 win_hsy=0;
178 }
179 int win_sx=2*win_hsx+1;
180 int win_sy=2*win_hsy+1;
181 int sz=cpl_imagelist_get_size(iml_data);
182 double sum_all;
183 double sum_good;
184 double sum_good_pix;
185 double sum_tot_pix;
186 double* pdata;
187 //double sum_bad;
188 double scale;
189
190 cpl_image* ima_tmp;
191
192 //cpl_imagelist* iml_tmp;
193 cpl_imagelist* iml_good;
194 cpl_imagelist* iml_all;
195 cpl_binary* pbpm;
196 cpl_binary* pbpm_tmp;
197
198 cpl_mask* not=cpl_mask_duplicate(bpm);
199 cpl_mask_not(not);
200 cpl_binary* pnot=cpl_mask_get_data(not);
201 cpl_mask* bpm_tmp;
202 ima_tmp=cpl_imagelist_get(iml_data,0);
203 cpl_imagelist* iml_copy=cpl_imagelist_duplicate(iml_data);
204
205 int sx=cpl_image_get_size_x(ima_tmp);
206 int sy=cpl_image_get_size_y(ima_tmp);
207 double* pres;
208 res=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
209 cpl_image_add_scalar(res,1.);
210 pres=cpl_image_get_data(res);
211 pbpm=cpl_mask_get_data(bpm);
212 int point;
213 int num_good_pix;
214 int num_tot_pix;
215 //int good;
216 int frame_bad;
217 int x,y;
218 xsh_msg("total frames: %d",sz);
219
220 for(int j=0;j<sy;j++) {
221 //xsh_msg("j=%d",j);
222
223 sx_j=sx*j;
224 for(int i=0;i<sx;i++) {
225 //xsh_msg("i=%d",i);
226
227 pix=sx_j+i;
228 frame_bad=0;
229 //xsh_msg("pix=%d",pix);
230 if ( pbpm[pix] == CPL_BINARY_0 ) {
231 /* if the pixel was not flagged the scaling factor is 1 */
232 pres[pix] = 1;
233
234 } else if ( pbpm[pix] == CPL_BINARY_1 ) {
235 sum_good_pix=0;
236 num_good_pix=0;
237 sum_tot_pix=0;
238 num_tot_pix=0;
239 //xsh_msg("found bad pix at pos[%d,%d]",i,j);
240 /* if the pixel is flagged we compute the scaling factor */
241 int y_min=j-win_hsy, y_max=j+win_hsy;
242 //xsh_msg("init y_min=%d y_max=%d",y_min,y_max);
243 /* Not to hit image edges use asymmetric interval at image edges */
244 if (y_min < 0) {
245 //xsh_msg("y case1");
246 y_min = 0;
247 y_max = win_sy;
248 } else if ( y_max > sy) {
249 //xsh_msg("y case2 j=%d j+y_max=%d,sy=%d",j,j+y_max,sy);
250 y_max=sy;
251 y_min=y_max-win_sy;
252 }
253 //xsh_msg("corrected y_min=%d y_max=%d",y_min,y_max);
254 int x_min=i-win_hsx, x_max=i+win_hsx;
255 //xsh_msg("init x_min=%d x_max=%d",x_min,x_max);
256 if (x_min < 0) {
257 //xsh_msg("x case1")/;
258 x_min = 0;
259 x_max = win_sx;
260 } else if ( x_max > sx) {
261 //xsh_msg("x case2 i=%d i+x_max=%d,sx=%d",i,i+x_max,sx);
262 x_max=sx;
263 x_min=x_max-win_sx;
264 }
265 //xsh_msg("corrected x_min=%d x_max=%d",x_min,x_max);
266 sum_all=0;
267 sum_good=0;
268 //sum_bad=0;
269 //good=0;
270
271 /* copy data to accessory imagelist (because we will unset only
272 * on the wrapped imagelist the frame at which we found a bad
273 * pixel in the original list */
274 iml_all = cpl_imagelist_new();
275 iml_good = cpl_imagelist_new();
276 //iml_all=cpl_imagelist_duplicate(iml_data);
277 //iml_good=cpl_imagelist_duplicate(iml_data);
278
279 for(int k=0;k<sz;k++) {
280 ima_tmp=cpl_imagelist_get(iml_copy,k);
281
282 cpl_imagelist_set(iml_good,cpl_image_duplicate(ima_tmp),k);
283 cpl_imagelist_set(iml_all,cpl_image_duplicate(ima_tmp),k);
284
285 }
286
287 /* we search now on which frame image of the original list was
288 * present the flagged pixel and we un-set that frame in the
289 * wrapped list
290 */
291
292 for(int k=0;k<sz-frame_bad;k++) {
293
294 ima_tmp=cpl_imagelist_get(iml_good,k);
295 pdata=cpl_image_get_data_double(ima_tmp);
296 bpm_tmp=cpl_image_get_bpm(ima_tmp);
297 pbpm_tmp=cpl_mask_get_data(bpm_tmp);
298
299 if(pbpm_tmp[pix] == CPL_BINARY_1) {
300 //xsh_msg("found bad pix unset frame %d",k);
301 ima_tmp=cpl_imagelist_unset(iml_good,k);
302 bpm_tmp=cpl_image_unset_bpm(ima_tmp);
303 cpl_mask_delete(bpm_tmp);
304 cpl_image_delete(ima_tmp);
305
306 //sum_bad = pdata[pix];
307 frame_bad++;
308 }
309 }
310
311 //xsh_msg("Found bad pix=%d",frame_bad);
312
313 /* to sum only over good pixels we flag the bad ones */
314 for(int k=0;k<sz-frame_bad;k++) {
315 ima_tmp=cpl_imagelist_get(iml_good,k);
316 bpm_tmp=cpl_image_set_bpm(ima_tmp,cpl_mask_duplicate(bpm));
317 cpl_mask_delete(bpm_tmp);
318 }
319
320 /* to sum only over good pixels we flag the bad ones */
321 for(int k=0;k<sz;k++) {
322 ima_tmp=cpl_imagelist_get(iml_all,k);
323 bpm_tmp=cpl_image_set_bpm(ima_tmp,cpl_mask_duplicate(bpm));
324 cpl_mask_delete(bpm_tmp);
325
326 }
327
328 /* now search for the good pixels in the remaining images of
329 * the wrapped imagelist around the bad pixel to compute the sum
330 * of good and the sum of all pixels
331 */
332 xsh_msg("Compute sums");
333
334 for(y=y_min; y <= y_max; y++) {
335 //xsh_msg("y=%d",y);
336 for(x=x_min; x <= x_max; x++) {
337 //xsh_msg("x=%d",x);
338 point=y*sx+x;
339
340 //xsh_msg("compute sum on all %d frames",sz);
341 for(int k=0;k<sz;k++) {
342 ima_tmp=cpl_imagelist_get(iml_all,k);
343 pdata=cpl_image_get_data_double(ima_tmp);
344 bpm_tmp=cpl_image_get_bpm(ima_tmp);
345 pbpm_tmp=cpl_mask_get_data(bpm_tmp);
346 if(pbpm_tmp[point] == CPL_BINARY_0) {
347 sum_all += pdata[point];
348 }
349 //xsh_msg("scan point %d at %d,%d",point,i,j);
350
351 }
352
353 //xsh_msg("compute sum on %d left frames",sz-frame_bad);
354 for(int k=0;k<sz-frame_bad;k++) {
355 ima_tmp=cpl_imagelist_get(iml_good,k);
356 pdata=cpl_image_get_data_double(ima_tmp);
357 bpm_tmp=cpl_image_get_bpm(ima_tmp);
358 pbpm_tmp=cpl_mask_get_data(bpm_tmp);
359 //xsh_msg("scan point %d at %d,%d",point,i,j);
360 if( pbpm[point] == CPL_BINARY_0 ) {
361 sum_good += pdata[point];
362 }
363 }
364
365 // determine the sum of good pixel at pos of bad pix
366 for(int k=0;k<sz-frame_bad;k++) {
367 ima_tmp=cpl_imagelist_get(iml_good,k);
368 pdata=cpl_image_get_data_double(ima_tmp);
369
370 if( pnot[pix] == CPL_BINARY_0 && pix != point) {
371 sum_good_pix += pdata[pix];
372 num_good_pix++;
373 }
374
375 if( pnot[pix] == CPL_BINARY_0 && pix == point) {
376 sum_tot_pix += pdata[pix];
377 num_tot_pix++;
378 }
379 }
380
381 }
382 } //end loop to compute sum
383
384 scale = sum_all / sum_good;
385 //pres[pix] = scale*num_tot_pix/sz;
386 //pres[pix] = scale*sum_tot_pix/sz;
387 pres[pix]=scale*num_tot_pix/sz; //good for uniform images case
388 //pres[pix]=1;
389 xsh_msg("sum all %g good %g good_pix %g num_good %d sum_tot_pix %g num_tot_pix %d scale %g res: %g",
390 sum_all,sum_good,sum_good_pix, num_good_pix, sum_tot_pix, num_tot_pix, scale, pres[pix]);
391
393
394 int n=cpl_imagelist_get_size(iml_good);
395 xsh_msg("ok1 sz=%d n=%d",sz,n);
396 for(int k=0;k<n;k++) {
397 ima_tmp=cpl_imagelist_get(iml_good,k);
398 cpl_image_delete(ima_tmp);
399 }
400 for(int k=0;k<sz;k++) {
401 ima_tmp=cpl_imagelist_get(iml_all,k);
402 cpl_image_delete(ima_tmp);
403 }
404
406 //cpl_imagelist_delete(iml_good);
407 //cpl_imagelist_delete(iml_all);
408 //cpl_imagelist_empty(iml_good);
409 //cpl_imagelist_empty(iml_all);
410 cpl_imagelist_unwrap(iml_good);
411 cpl_imagelist_unwrap(iml_all);
412 }
413 }
414 }
415 cpl_imagelist_delete(iml_copy);
416 cpl_mask_delete(not);
417 return res;
418}
419
420
421
422static cpl_image*
423xsh_compute_scale_tab(cpl_imagelist* iml_data, cpl_mask* bpm, cpl_table* tab_bpm,
424 const int mode, const int win_hsz)
425{
426 cpl_image* res;
427 int sx_j;
428 int pix;
429 int win_hsx;
430 int win_hsy;
431 if(mode==0) {
432 win_hsx=0;
433 win_hsy=win_hsz;
434 } else {
435 win_hsx=win_hsz;
436 win_hsy=0;
437 }
438 int win_sx=2*win_hsx+1;
439 int win_sy=2*win_hsy+1;
440 int sz=cpl_imagelist_get_size(iml_data);
441 double sum_all;
442 double sum_good;
443 double sum_good_pix;
444 double sum_tot_pix;
445 double* pdata;
446 //double sum_bad;
447 double scale;
448
449 cpl_image* ima_tmp;
450
451 //cpl_imagelist* iml_tmp;
452 cpl_imagelist* iml_good;
453 cpl_imagelist* iml_all;
454 cpl_binary* pbpm;
455 cpl_binary* pbpm_tmp;
456
457 cpl_mask* not=cpl_mask_duplicate(bpm);
458 cpl_mask_not(not);
459 cpl_binary* pnot=cpl_mask_get_data(not);
460 cpl_mask* bpm_tmp;
461 ima_tmp=cpl_imagelist_get(iml_data,0);
462 cpl_imagelist* iml_copy=cpl_imagelist_duplicate(iml_data);
463
464 int sx=cpl_image_get_size_x(ima_tmp);
465 int sy=cpl_image_get_size_y(ima_tmp);
466 double* pres;
467 res=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
468 cpl_image_add_scalar(res,1.);
469 pres=cpl_image_get_data(res);
470
471 int* px=cpl_table_get_data_int(tab_bpm,"x");
472 int* py=cpl_table_get_data_int(tab_bpm,"y");
473 int size=cpl_table_get_nrow(tab_bpm);
474 pbpm=cpl_mask_get_data(bpm);
475 int point;
476 int num_good_pix;
477 int num_tot_pix;
478 //int good;
479 int frame_bad;
480 int x,y;
481 xsh_msg("total frames: %d",sz);
482 int i,j,m;
483 for(m=0;m<size;m++) {
484
485 i=px[m];
486 j=py[m];
487 //xsh_msg("j=%d",j);
488 //xsh_msg("i=%d",i);
489 sx_j=sx*j;
490 pix=sx_j+i;
491
492 frame_bad=0;
493 //xsh_msg("pix=%d",pix);
494
495 sum_good_pix=0;
496 num_good_pix=0;
497 sum_tot_pix=0;
498 num_tot_pix=0;
499 //xsh_msg("found bad pix at pos[%d,%d]",i,j);
500 /* if the pixel is flagged we compute the scaling factor */
501 int y_min=j-win_hsy, y_max=j+win_hsy;
502 //xsh_msg("init y_min=%d y_max=%d",y_min,y_max);
503 /* Not to hit image edges use asymmetric interval at image edges */
504 if (y_min < 0) {
505 //xsh_msg("y case1");
506 y_min = 0;
507 y_max = win_sy;
508 } else if ( y_max > sy) {
509 //xsh_msg("y case2 j=%d j+y_max=%d,sy=%d",j,j+y_max,sy);
510 y_max=sy;
511 y_min=y_max-win_sy;
512 }
513 //xsh_msg("corrected y_min=%d y_max=%d",y_min,y_max);
514 int x_min=i-win_hsx, x_max=i+win_hsx;
515 //xsh_msg("init x_min=%d x_max=%d",x_min,x_max);
516 if (x_min < 0) {
517 //xsh_msg("x case1")/;
518 x_min = 0;
519 x_max = win_sx;
520 } else if ( x_max > sx) {
521 //xsh_msg("x case2 i=%d i+x_max=%d,sx=%d",i,i+x_max,sx);
522 x_max=sx;
523 x_min=x_max-win_sx;
524 }
525 //xsh_msg("corrected x_min=%d x_max=%d",x_min,x_max);
526 sum_all=0;
527 sum_good=0;
528 //sum_bad=0;
529 //good=0;
530
531 /* copy data to accessory imagelist (because we will unset only
532 * on the wrapped imagelist the frame at which we found a bad
533 * pixel in the original list */
534 iml_all = cpl_imagelist_new();
535 iml_good = cpl_imagelist_new();
536 //iml_all=cpl_imagelist_duplicate(iml_data);
537 //iml_good=cpl_imagelist_duplicate(iml_data);
538
539 for(int k=0;k<sz;k++) {
540 ima_tmp=cpl_imagelist_get(iml_copy,k);
541
542 cpl_imagelist_set(iml_good,cpl_image_duplicate(ima_tmp),k);
543 cpl_imagelist_set(iml_all,cpl_image_duplicate(ima_tmp),k);
544
545 }
546
547 /* we search now on which frame image of the original list was
548 * present the flagged pixel and we un-set that frame in the
549 * wrapped list
550 */
551
552 for(int k=0;k<sz-frame_bad;k++) {
553
554 ima_tmp=cpl_imagelist_get(iml_good,k);
555 pdata=cpl_image_get_data_double(ima_tmp);
556 bpm_tmp=cpl_image_get_bpm(ima_tmp);
557 pbpm_tmp=cpl_mask_get_data(bpm_tmp);
558
559 if(pbpm_tmp[pix] == CPL_BINARY_1) {
560 //xsh_msg("found bad pix unset frame %d",k);
561 ima_tmp=cpl_imagelist_unset(iml_good,k);
562 bpm_tmp=cpl_image_unset_bpm(ima_tmp);
563 cpl_mask_delete(bpm_tmp);
564 cpl_image_delete(ima_tmp);
565
566 //sum_bad = pdata[pix];
567 frame_bad++;
568 }
569 }
570
571 //xsh_msg("Found bad pix=%d",frame_bad);
572
573 /* to sum only over good pixels we flag the bad ones */
574 for(int k=0;k<sz-frame_bad;k++) {
575 ima_tmp=cpl_imagelist_get(iml_good,k);
576 bpm_tmp=cpl_image_set_bpm(ima_tmp,cpl_mask_duplicate(bpm));
577 cpl_mask_delete(bpm_tmp);
578 }
579
580 /* to sum only over good pixels we flag the bad ones */
581 for(int k=0;k<sz;k++) {
582 ima_tmp=cpl_imagelist_get(iml_all,k);
583 bpm_tmp=cpl_image_set_bpm(ima_tmp,cpl_mask_duplicate(bpm));
584 cpl_mask_delete(bpm_tmp);
585
586 }
587
588 /* now search for the good pixels in the remaining images of
589 * the wrapped imagelist around the bad pixel to compute the sum
590 * of good and the sum of all pixels
591 */
592 xsh_msg("Compute sums");
593
594 for(y=y_min; y <= y_max; y++) {
595 //xsh_msg("y=%d",y);
596 for(x=x_min; x <= x_max; x++) {
597 //xsh_msg("x=%d",x);
598 point=y*sx+x;
599
600 //xsh_msg("compute sum on all %d frames",sz);
601 for(int k=0;k<sz;k++) {
602 ima_tmp=cpl_imagelist_get(iml_all,k);
603 pdata=cpl_image_get_data_double(ima_tmp);
604 bpm_tmp=cpl_image_get_bpm(ima_tmp);
605 pbpm_tmp=cpl_mask_get_data(bpm_tmp);
606 if(pbpm_tmp[point] == CPL_BINARY_0) {
607 sum_all += pdata[point];
608 }
609 //xsh_msg("scan point %d at %d,%d",point,i,j);
610
611 }
612
613 //xsh_msg("compute sum on %d left frames",sz-frame_bad);
614 for(int k=0;k<sz-frame_bad;k++) {
615 ima_tmp=cpl_imagelist_get(iml_good,k);
616 pdata=cpl_image_get_data_double(ima_tmp);
617 bpm_tmp=cpl_image_get_bpm(ima_tmp);
618 pbpm_tmp=cpl_mask_get_data(bpm_tmp);
619 //xsh_msg("scan point %d at %d,%d",point,i,j);
620 if( pbpm[point] == CPL_BINARY_0 ) {
621 sum_good += pdata[point];
622 }
623 }
624
625 // determine the sum of good pixel at pos of bad pix
626 for(int k=0;k<sz-frame_bad;k++) {
627 ima_tmp=cpl_imagelist_get(iml_good,k);
628 pdata=cpl_image_get_data_double(ima_tmp);
629
630 if( pnot[pix] == CPL_BINARY_0 && pix != point) {
631 sum_good_pix += pdata[pix];
632 num_good_pix++;
633 }
634
635 if( pnot[pix] == CPL_BINARY_0 && pix == point) {
636 sum_tot_pix += pdata[pix];
637 num_tot_pix++;
638 }
639 }
640
641 }
642 } //end loop to compute sum
643
644 scale = sum_all / sum_good;
645 //scale = sum_tot_pix / num_tot_pix * num_good_pix / sum_good_pix;
646 //pres[pix] = scale*num_tot_pix/num_good_pix;
647 //pres[pix] = scale;
648 pres[pix]=scale*num_tot_pix/sz; //good for uniform images case
649 //pres[pix]=1;
650 xsh_msg("sum all %g good %g good_pix %g num_good %d sum_tot_pix %g num_tot_pix %d scale %g res: %g",
651 sum_all,sum_good,sum_good_pix, num_good_pix, sum_tot_pix, num_tot_pix, scale, pres[pix]);
652
654
655 int n=cpl_imagelist_get_size(iml_good);
656 xsh_msg("ok1 sz=%d n=%d",sz,n);
657 for(int k=0;k<n;k++) {
658 ima_tmp=cpl_imagelist_get(iml_good,k);
659 cpl_image_delete(ima_tmp);
660 }
661 for(int k=0;k<sz;k++) {
662 ima_tmp=cpl_imagelist_get(iml_all,k);
663 cpl_image_delete(ima_tmp);
664 }
665
667 //cpl_imagelist_delete(iml_good);
668 //cpl_imagelist_delete(iml_all);
669 //cpl_imagelist_empty(iml_good);
670 //cpl_imagelist_empty(iml_all);
671 cpl_imagelist_unwrap(iml_good);
672 cpl_imagelist_unwrap(iml_all);
673
674 }
675
676 cpl_imagelist_delete(iml_copy);
677 cpl_mask_delete(not);
678 return res;
679}
680
681
682
683static cpl_error_code
684xsh_compute_scale_tab2(cpl_imagelist* iml_data, cpl_table* tab_bpm,
685 cpl_imagelist* scale_frames,cpl_image** ima_corr)
686{
687 xsh_msg("start of function");
688 cpl_image* scale_ima;
689 int sx_j;
690 int pix;
691
692 int sz=cpl_imagelist_get_size(iml_data);
693 double norm_good_pix;
694 double* pdata;
695 cpl_image* ima_tmp;
696 cpl_binary* pbpm;
697
698 cpl_mask* bpm_tmp;
699
700 ima_tmp=cpl_imagelist_get(iml_data,0);
701 int sx=cpl_image_get_size_x(ima_tmp);
702 int sy=cpl_image_get_size_y(ima_tmp);
703
704
705 int* px=cpl_table_get_data_int(tab_bpm,"x");
706 int* py=cpl_table_get_data_int(tab_bpm,"y");
707 int size=cpl_table_get_nrow(tab_bpm);
708 int num_good_pix;
709
710 int i,j,m;
711 char name[80];
712 double* pscale;
713 double* pcor=cpl_image_get_data_double(*ima_corr);
714 for(m=0;m<size;m++) {
715
716 i=px[m];
717 j=py[m];
718 xsh_msg("j=%d",j);
719 xsh_msg("i=%d",i);
720 sx_j=sx*j;
721 pix=sx_j+i;
722
723 //xsh_msg("pix=%d",pix);
724
725 norm_good_pix=0;
726 num_good_pix=0;
727
728 /* to sum only over good pixels we flag the bad ones */
729 for(int k=0;k<sz;k++) {
730 ima_tmp=cpl_imagelist_get(iml_data,k);
731 bpm_tmp=cpl_image_get_bpm(ima_tmp);
732 pbpm=cpl_mask_get_data(bpm_tmp);
733 sprintf(name,"bad_%d.fits",k);
734 cpl_mask_save(bpm_tmp,name,NULL,CPL_IO_DEFAULT);
735
736 if( pbpm[pix] == CPL_BINARY_0 ) {
737 pdata=cpl_image_get_data_double(ima_tmp);
738 //xsh_msg("k=%d j=%d pdata=%g",k,j,pdata[pix]);
739 scale_ima=cpl_imagelist_get(scale_frames,k);
740 pscale=cpl_image_get_data_double(scale_ima);
741 //xsh_msg("k=%d j=%d pscale=%g",k,j,pscale[j]);
742 norm_good_pix += pdata[pix]/pscale[j];
743 num_good_pix++;
744 //xsh_msg("k=%d j=%d ratio=%g",k,j,pdata[pix]/pscale[j]);
745
746 }
747
748
749 }
750 norm_good_pix /= num_good_pix;
751 xsh_msg("m=%d norm=%g num=%d",m,norm_good_pix,num_good_pix);
752 pcor[pix] = norm_good_pix;
753
754 }
755 xsh_msg("end of function");
756 return cpl_error_get_code();
757}
758
759
760
761cpl_error_code
762xsh_flag_bp_at_location(cpl_binary* pbpm, int pix, cpl_binary bp_code,
763 const int mode, const int sx)
764{
765 /*
766 pima[pix-2]=0;
767 pima[pix-1]=0;
768 pima[pix]=0;
769 pima[pix+1]=0;
770 pima[pix+2]=0;
771 */
772 if(mode == 0) {
773 pbpm[pix-2]=bp_code;
774 pbpm[pix-1]=bp_code;
775 pbpm[pix]=bp_code;
776 pbpm[pix+1]=bp_code;
777 pbpm[pix+2]=bp_code;
778 } else {
779 pbpm[pix-2*sx]=bp_code;
780 pbpm[pix-1*sx]=bp_code;
781 pbpm[pix]=bp_code;
782 pbpm[pix+1*sx]=bp_code;
783 pbpm[pix+2*sx]=bp_code;
784 }
785
786 return cpl_error_get_code();
787
788}
789/*---------------------------------------------------------------------------
790 Defines
791 ---------------------------------------------------------------------------*/
792static cpl_image*
793xsh_define_gauss_profile(const int sx, const int sy,
794 const double A, const double sigma, const double bkg,
795 cpl_vector* trace,const int min, const int max,
796 const int mode)
797{
798
799 /* add Gauss profile positioned where the trace is
800 * I=A*exp( -0.5*( (X-Xo)/sigma )^2 ) +bkg
801 */
802
803 cpl_image* gauss = cpl_image_new(sx, sy, CPL_TYPE_DOUBLE);
804 double* pgauss = NULL;
805 pgauss = cpl_image_get_data_double(gauss);
806
807 double arg = 0;
808 int i, j;
809 double x=0,y=0;
810 double* pvec = cpl_vector_get_data(trace);
811 if (mode == 0) {
812 /* uniform along X (horizontal direction) Gauss along Y (vertical) */
813 for (j = min; j <= max; j++) {
814 y=j;
815 for (i = 0; i < sx; i++) {
816 arg = (y - pvec[i]) / sigma;
817 arg *= arg;
818 //xsh_msg("arg=%g",arg);
819 pgauss[j * sx + i] += A * exp(-0.5 * arg) + bkg;
820 //xsh_msg("val=%g",pgauss[j * sx + i]);
821 }
822 }
823 } else {
824 for (j = 0; j < sy; j++) {
825 for (i = min; i <= max; i++) {
826 x=i;
827
828 arg = (x - pvec[j]) / sigma;
829 arg *= arg;
830 //xsh_msg("arg=%g",arg);
831 pgauss[j * sx + i] += A * exp(-0.5 * arg) + bkg;
832 //xsh_msg("val=%g",pgauss[j * sx + i]);
833 }
834 }
835 }
836 return gauss;
837}
838
839static cpl_error_code
840test_xsh_set_min_max(const int sx, const int sy, const int mode,
841 int* min, int* max) {
842 if (mode == 0) {
843 *min=2*sy/5;
844 *max=3*sy/5;
845 } else {
846 *min=2*sx/5;
847 *max=3*sx/5;
848 }
849 return cpl_error_get_code();
850}
851
852static cpl_vector*
853test_xsh_set_trace(const int sx, const int sy, const int mode) {
854 cpl_vector* trace=cpl_vector_new(sx);
855 if (mode == 0) {
856 for(int i=0;i<sx;i++) {
857 cpl_vector_set(trace,i,sy/2);
858 }
859 } else {
860 for(int j=0;j<sy;j++) {
861 cpl_vector_set(trace,j,sx/2);
862 }
863 }
864 return trace;
865}
866
867static cpl_error_code
868test_xsh_fill_bpm(const int sx, const int sy, const int mode, const int i,
869 cpl_image** ima, cpl_mask** bpm_tot) {
870 cpl_mask* bpm=NULL;
871
872 cpl_binary* pbpm=CPL_BINARY_0;
873
874 int pix;
875
876 if(i==0) {
877 pix=sy*sx/4+sx/4;
878 bpm=cpl_mask_new(sx,sy);
879 pbpm=cpl_mask_get_data(bpm);
880 xsh_flag_bp_at_location(pbpm, pix,CPL_BINARY_1,mode,sx);
881 cpl_image_set_bpm(*ima,cpl_mask_duplicate(bpm));
882 *bpm_tot=cpl_mask_duplicate(bpm);
883 cpl_mask_delete(bpm);
884 }
885
886
887 if(i==1) {
888 //bpm=cpl_image_get_bpm(ima);
889 bpm=cpl_mask_new(sx,sy);
890 pbpm=cpl_mask_get_data(bpm);
891 xsh_msg("flag image %d",i);
892 pix=sy*sx/2+sx/2;
893
894 xsh_flag_bp_at_location(pbpm, pix,CPL_BINARY_1,mode,sx);
895 //pix=(sy+2)*sx/2+sx/2;
896 //xsh_flag_bp_at_location(pbpm, pix,CPL_BINARY_1);
897 cpl_image_set_bpm(*ima,cpl_mask_duplicate(bpm));
898 cpl_mask_or(*bpm_tot,bpm);
899 cpl_mask_delete(bpm);
900
901 }
902
903 if(i==2) {
904 bpm=cpl_mask_new(sx,sy);
905 pbpm=cpl_mask_get_data(bpm);
906 pix=3*sy*sx/4+sx/4;
907 xsh_flag_bp_at_location(pbpm, pix,CPL_BINARY_1,mode,sx);
908 cpl_image_set_bpm(*ima,cpl_mask_duplicate(bpm));
909 cpl_mask_or(*bpm_tot,bpm);
910 cpl_mask_delete(bpm);
911 }
912
913
914 if(i==3) {
915 bpm=cpl_mask_new(sx,sy);
916 pbpm=cpl_mask_get_data(bpm);
917 pix=3*sy*sx/4+3*sx/4;
918 xsh_flag_bp_at_location(pbpm, pix,CPL_BINARY_1,mode,sx);
919 //pix=3*sy*sx/4+sx/4;
920 //xsh_flag_bp_at_location(pbpm, pix,CPL_BINARY_1,mode,sx);
921 cpl_image_set_bpm(*ima,cpl_mask_duplicate(bpm));
922 cpl_mask_or(*bpm_tot,bpm);
923 cpl_mask_delete(bpm);
924 }
925
926 if(i==4) {
927 bpm=cpl_mask_new(sx,sy);
928 pbpm=cpl_mask_get_data(bpm);
929 pix=sy*sx/4+3*sx/4;
930 xsh_flag_bp_at_location(pbpm, pix,CPL_BINARY_1,mode,sx);
931 cpl_image_set_bpm(*ima,cpl_mask_duplicate(bpm));
932 cpl_mask_or(*bpm_tot,bpm);
933 cpl_mask_delete(bpm);
934 }
935
936 return cpl_error_get_code();
937}
938
939static cpl_table*
940test_xsh_bpm2tab(const cpl_mask* bpm)
941{
942
943 const int size=cpl_mask_count(bpm);
944 cpl_table* xy_pos=cpl_table_new(size);
945 cpl_table_new_column(xy_pos,"x",CPL_TYPE_INT);
946 cpl_table_new_column(xy_pos,"y",CPL_TYPE_INT);
947 int* px=cpl_table_get_data_int(xy_pos,"x");
948 int* py=cpl_table_get_data_int(xy_pos,"y");
949 int sx=cpl_mask_get_size_x(bpm);
950 int sy=cpl_mask_get_size_y(bpm);
951 cpl_binary* pbpm=cpl_mask_get_data(bpm);
952 int j_nx;
953 int pix;
954 int k=0;
955 //xsh_msg("copy bad pixels in table");
956 for(int j=0;j<sy;j++){
957 j_nx=j*sx;
958 for(int i=0;i<sx;i++){
959 pix=j_nx+i;
960 if ( pbpm[pix] == CPL_BINARY_1 ) {
961 //xsh_msg("found bad pixel at [%d,%d]",i,j);
962 px[k]=i;
963 py[k]=j;
964 k++;
965 }
966 }
967 }
968
969 return xy_pos;
970}
971
972static cpl_imagelist*
973xsh_find_image_scale_factors(const cpl_imagelist* iml_in, cpl_image* ima_in)
974{
975 cpl_imagelist* scale_factors;
976 cpl_imagelist* iml_copy=cpl_imagelist_duplicate(iml_in);
977 cpl_image* scale;
978 const cpl_image* ima;
979 cpl_mask* bpm;
980 cpl_mask* bpm_copy;
981 int sx;
982 int sy;
983 double avg;
984 double med;
985 double rms;
986 double* pima;
987 double* pscale;
988 int nbad;
989 double val;
990 cpl_binary* pbpm;
991 int pix;
992 int size = cpl_imagelist_get_size(iml_copy);
993 scale_factors=cpl_imagelist_new();
994 bpm_copy=cpl_image_unset_bpm(ima_in);
995 char fname[80];
996 for(int k = 0; k < size; k++) {
997 ima=cpl_imagelist_get_const(iml_copy,k);
998 sx=cpl_image_get_size_x(ima);
999 sy=cpl_image_get_size_y(ima);
1000 sprintf(fname,"orig_%d.fits",k);
1001 cpl_image_save(ima,fname,CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1002 cpl_image_divide(ima,ima_in);
1003 sprintf(fname,"scaled_%d.fits",k);
1004 cpl_image_save(ima,fname,CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1005 pima=cpl_image_get_data_double(ima);
1006 val=pima[0];
1007 bpm=cpl_image_get_bpm(ima);
1008 pbpm=cpl_mask_get_data(bpm);
1009 for(int j=0; j < sy; j++) {
1010 for(int i=0; i < sx; i++) {
1011 pix=i+j*sx;
1012 if( (pbpm[pix] == CPL_BINARY_1) ||
1013 isnan(pima[pix]) || isinf(pima[pix]) )
1014 {
1015 pbpm[pix] = CPL_BINARY_1;
1016 }
1017
1018 }
1019 }
1020 scale=cpl_image_new(1,sy,CPL_TYPE_DOUBLE);
1021 pscale=cpl_image_get_data_double(scale);
1022 for(int j=0;j<sy;j++){
1023 nbad=cpl_mask_count_window(bpm,j+1,1,j+1,sx);
1024 if( nbad < sx) {
1025 avg=cpl_image_get_mean_window(ima,1,j+1,sx,j+1);
1026 med=cpl_image_get_median_window(ima,1,j+1,sx,j+1);
1027 rms=cpl_image_get_stdev_window(ima,1,j+1,sx,j+1);
1028 /*
1029 xsh_msg("frame %d slice %d mean=%g median=%g rm==%g",
1030 k, j, avg,med,rms);
1031
1032 xsh_msg("val=%g scaled=%g",val,val/avg);
1033 */
1034 }
1035 pscale[j]=med;
1036 }
1037 cpl_imagelist_set(scale_factors,scale,k);
1038
1039 }
1040 cpl_image_set_bpm(ima_in,bpm_copy);
1041 cpl_imagelist_delete(iml_copy);
1042 return scale_factors;
1043}
1044
1045static cpl_error_code
1046test_combine_ima_gauss(const int mode,const int win_hsz) {
1047
1048
1049 cpl_image* ima=NULL;
1050 cpl_image* res=NULL;
1051 cpl_image* corr;
1052 cpl_imagelist* flag=NULL;
1053 cpl_imagelist* all=NULL;
1054 int sx=100;
1055 int sy=100;
1056 double value=1;
1057 double step=0;
1058 const int nframes=5;
1059 cpl_mask* bpm;
1060 cpl_mask* bpm_tot=NULL;
1061 //double* pima=NULL;
1062 cpl_image* scale;
1063 cpl_image* flagged;
1064 cpl_image* norm;
1065 //int pix;
1066 //cpl_binary* pbpm=CPL_BINARY_0;
1067 flag=cpl_imagelist_new();
1068 all=cpl_imagelist_new();
1069 double A;
1070 double sigma=3;
1071 double bkg=10;
1072 int min=2*sy/5;
1073 int max=3*sy/5;
1074
1075 cpl_vector* trace=test_xsh_set_trace(sx,sy,mode);
1076 test_xsh_set_min_max(sx,sy,mode,&min,&max);
1077 char name[80];
1078 //cpl_vector_dump(trace,stdout);
1079 for(int i=0;i<nframes;i++) {
1080 //ima=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
1081 xsh_msg("frame value %g",value+i*step);
1082 A=i*10;
1083 ima=xsh_define_gauss_profile(sx,sy,A,sigma, bkg, trace,min,max,mode);
1084
1085 cpl_image_add_scalar(ima,value+i*step);
1086 cpl_imagelist_set(all,cpl_image_duplicate(ima),i);
1087
1088
1089 //pima=cpl_image_get_data_double(ima);
1090
1091 /* on one image we set some pixels as bad to simulate the change of
1092 * intensity in the image resulting from image combination
1093 */
1094
1095 test_xsh_fill_bpm(sx, sy, mode, i, &ima, &bpm_tot);
1096 bpm=cpl_image_get_bpm(ima);
1097 sprintf(name,"bpm_%d.fits",i);
1098 cpl_mask_save(bpm,name,NULL,CPL_IO_DEFAULT);
1099 //cpl_image_set_bpm(ima,bpm);
1100 cpl_imagelist_set(flag,cpl_image_duplicate(ima),i);
1101 cpl_image_delete(ima);
1102 }
1103
1104 cpl_table* tab_bp=test_xsh_bpm2tab(bpm_tot);
1105 cpl_table_save(tab_bp,NULL,NULL,"tab_bp.fits",CPL_IO_DEFAULT);
1106 cpl_vector_delete(trace);
1107 cpl_imagelist_save(flag,"flag.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1108
1109 flagged = xsh_imagelist_collapse_create(flag);
1110
1111 for(int i=0;i < nframes;i++) {
1112 ima=cpl_imagelist_get(flag,i);
1113 bpm=cpl_image_get_bpm(ima);
1114 //sprintf(name,"bpm_%d.fits",i);
1115 //cpl_mask_save(bpm,name,NULL,CPL_IO_DEFAULT);
1116 }
1117 sprintf(name,"bpm_tot.fits");
1118 cpl_mask_save(bpm_tot,name,NULL,CPL_IO_DEFAULT);
1119 //flagged = cpl_imagelist_collapse_create(flag);
1120 //scale = xsh_compute_scale(flag,bpm_tot,mode,win_hsz);
1121 scale = xsh_compute_scale_tab(flag,bpm_tot,tab_bp,mode,win_hsz);
1122 for(int i=0;i < nframes;i++) {
1123 ima=cpl_imagelist_get(flag,i);
1124 bpm=cpl_image_get_bpm(ima);
1125 //sprintf(name,"bpm3_%d.fits",i);
1126 //cpl_mask_save(bpm,name,NULL,CPL_IO_DEFAULT);
1127 }
1128
1129
1130 cpl_image_save(scale,"scale.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1131 bpm=cpl_image_get_bpm(flagged);
1132 cpl_mask_save(bpm,"bpm.fits",NULL, CPL_IO_DEFAULT);
1133
1134 norm = cpl_imagelist_collapse_create(all);
1135 res=cpl_image_duplicate(flagged);
1136 if( scale != NULL ) {
1137 cpl_image_multiply(res,scale);
1138 }
1139 cpl_image_save(res,"res.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1140 corr=cpl_image_duplicate(flagged);
1141 cpl_image_multiply(corr,res);
1142 cpl_image_save(flagged,"flagged.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1143 cpl_image_save(norm,"norm.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1144
1145 cpl_mask_delete(bpm_tot);
1146 cpl_image_delete(res);
1147 cpl_image_delete(flagged);
1148 cpl_image_delete(scale);
1149 cpl_image_delete(norm);
1150 cpl_image_delete(corr);
1151 cpl_imagelist_delete(flag);
1152 cpl_imagelist_delete(all);
1153 cpl_table_delete(tab_bp);
1154 return cpl_error_get_code();
1155
1156}
1157
1158static cpl_error_code
1160
1161 cpl_image* ima=NULL;
1162 cpl_imagelist* flag=NULL;
1163 cpl_imagelist* all=NULL;
1164 int sx=100;
1165 int sy=100;
1166 double value=1;
1167 double step=0;
1168 const int nframes=5;
1169 cpl_mask* bpm;
1170 cpl_mask* bpm_tot=NULL;
1171 //double* pima=NULL;
1172
1173 cpl_image* flagged;
1174 cpl_image* norm;
1175 //int pix;
1176 //cpl_binary* pbpm=CPL_BINARY_0;
1177 flag=cpl_imagelist_new();
1178 all=cpl_imagelist_new();
1179 double A;
1180 double sigma=3;
1181 double bkg=0;
1182 int min=2*sy/5;
1183 int max=3*sy/5;
1184 xsh_msg("ok0");
1186 cpl_vector* trace=test_xsh_set_trace(sx,sy,mode);
1187 test_xsh_set_min_max(sx,sy,mode,&min,&max);
1188 char name[80];
1189 //cpl_vector_dump(trace,stdout);
1190 xsh_msg("ok1");
1192 for(int i=0;i<nframes;i++) {
1193 //ima=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
1194 xsh_msg("frame value %g",value+i*step);
1195 A=i*10;
1196 ima=xsh_define_gauss_profile(sx,sy,A,sigma, bkg, trace,min,max,mode);
1197
1198 cpl_image_add_scalar(ima,value+i*step);
1199 cpl_imagelist_set(all,cpl_image_duplicate(ima),i);
1200
1201
1202 //pima=cpl_image_get_data_double(ima);
1203
1204 /* on one image we set some pixels as bad to simulate the change of
1205 * intensity in the image resulting from image combination
1206 */
1207
1208 test_xsh_fill_bpm(sx, sy, mode, i, &ima, &bpm_tot);
1209 bpm=cpl_image_get_bpm(ima);
1210 sprintf(name,"bpm_%d.fits",i);
1211 cpl_mask_save(bpm,name,NULL,CPL_IO_DEFAULT);
1212 //cpl_image_set_bpm(ima,bpm);
1213 cpl_imagelist_set(flag,cpl_image_duplicate(ima),i);
1214 cpl_image_delete(ima);
1215 }
1216 xsh_msg("ok0");
1218 cpl_imagelist_save(flag,"flag.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1219
1220 sprintf(name,"bpm_tot.fits");
1221 cpl_mask_save(bpm_tot,name,NULL,CPL_IO_DEFAULT);
1222 xsh_msg("ok1");
1224 cpl_table* tab_bp=test_xsh_bpm2tab(bpm_tot);
1225 cpl_table_save(tab_bp,NULL,NULL,"tab_bp.fits",CPL_IO_DEFAULT);
1226 cpl_vector_delete(trace);
1227 xsh_msg("ok2");
1229 flagged = xsh_imagelist_collapse_create(flag);
1230 cpl_image_save(flagged,"flagged1.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1231 xsh_msg("ok3");
1233 for(int i=0;i<nframes;i++) {
1234
1235 ima=cpl_imagelist_get(flag,i);
1236 bpm=cpl_image_get_bpm(ima);
1237 sprintf(name,"chk_%d.fits",i);
1238 cpl_mask_save(bpm,name,NULL,CPL_IO_DEFAULT);
1239
1240 }
1241 xsh_msg("ok4");
1243 cpl_imagelist* sf=xsh_find_image_scale_factors(flag,flagged);
1244 cpl_imagelist_save(sf,"sf.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1245 //exit(0);
1246 xsh_compute_scale_tab2(flag,tab_bp,sf,&flagged);
1247 cpl_image_save(flagged,"flagged2.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1248 xsh_msg("ok3");
1250 bpm=cpl_image_get_bpm(flagged);
1251 cpl_mask_save(bpm,"bpm.fits",NULL, CPL_IO_DEFAULT);
1252
1253 norm = cpl_imagelist_collapse_create(all);
1254 cpl_image_save(flagged,"result.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1255
1256 cpl_image_save(flagged,"flagged.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1257 cpl_image_save(norm,"norm.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1258 xsh_msg("ok4");
1260 cpl_mask_delete(bpm_tot);
1261 cpl_image_delete(flagged);
1262 cpl_image_delete(norm);
1263 cpl_imagelist_delete(flag);
1264 cpl_imagelist_delete(all);
1265 cpl_table_delete(tab_bp);
1266 return cpl_error_get_code();
1267
1268}
1269
1270
1271static cpl_error_code
1273
1274 cpl_image* ima=NULL;
1275 cpl_imagelist* flag=NULL;
1276 cpl_imagelist* all=NULL;
1277 int sx=100;
1278 int sy=100;
1279 double value=1.e-6;
1280 double step=0;
1281 const int nframes=15;
1282 cpl_mask* bpm;
1283 cpl_mask* bpm_tot=NULL;
1284 //double* pima=NULL;
1285
1286 cpl_image* flagged;
1287 cpl_image* norm;
1288 //int pix;
1289 //cpl_binary* pbpm=CPL_BINARY_0;
1290 flag=cpl_imagelist_new();
1291 all=cpl_imagelist_new();
1292 double A=10.;
1293 double sigma=15;
1294 double bkg=0;
1295 int min=0*sy/5;
1296 int max=5*sy/5;
1297 xsh_msg("ok0");
1299 cpl_vector* trace=test_xsh_set_trace(sx,sy,mode);
1300 test_xsh_set_min_max(sx,sy,mode,&min,&max);
1301 char name[80];
1302 //cpl_vector_dump(trace,stdout);
1303 xsh_msg("ok1");
1305 double factor=1.;
1306 for(int i=0;i<nframes;i++) {
1307 //ima=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
1308
1309 factor=0.8+i/10.;
1310 xsh_msg("frame value %g factor=%g",value+i*step,factor);
1311 ima=xsh_define_gauss_profile(sx,sy,A,sigma, bkg, trace,min,max,mode);
1312 cpl_image_multiply_scalar(ima,factor);
1313 cpl_image_add_scalar(ima,value+i*step);
1314 cpl_imagelist_set(all,cpl_image_duplicate(ima),i);
1315
1316
1317 //pima=cpl_image_get_data_double(ima);
1318
1319 /* on one image we set some pixels as bad to simulate the change of
1320 * intensity in the image resulting from image combination
1321 */
1322
1323 test_xsh_fill_bpm(sx, sy, mode, i, &ima, &bpm_tot);
1324 bpm=cpl_image_get_bpm(ima);
1325 sprintf(name,"bpm_%d.fits",i);
1326 cpl_mask_save(bpm,name,NULL,CPL_IO_DEFAULT);
1327 //cpl_image_set_bpm(ima,bpm);
1328 cpl_imagelist_set(flag,cpl_image_duplicate(ima),i);
1329 cpl_image_delete(ima);
1330 }
1331 xsh_msg("ok0");
1333 cpl_imagelist_save(flag,"flag.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1334
1335 sprintf(name,"bpm_tot.fits");
1336 cpl_mask_save(bpm_tot,name,NULL,CPL_IO_DEFAULT);
1337 xsh_msg("ok1");
1339 cpl_table* tab_bp=test_xsh_bpm2tab(bpm_tot);
1340 cpl_table_save(tab_bp,NULL,NULL,"tab_bp.fits",CPL_IO_DEFAULT);
1341 cpl_vector_delete(trace);
1342 xsh_msg("ok2");
1344 flagged = xsh_imagelist_collapse_create(flag);
1345 cpl_image_save(flagged,"flagged1.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1346 xsh_msg("ok3");
1348 for(int i=0;i<nframes;i++) {
1349
1350 ima=cpl_imagelist_get(flag,i);
1351 bpm=cpl_image_get_bpm(ima);
1352 sprintf(name,"chk_%d.fits",i);
1353 cpl_mask_save(bpm,name,NULL,CPL_IO_DEFAULT);
1354
1355 }
1356 xsh_msg("ok4");
1358 cpl_imagelist* sf=xsh_find_image_scale_factors(flag,flagged);
1359 cpl_imagelist_save(sf,"sf.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1360 //exit(0);
1361 xsh_compute_scale_tab2(flag,tab_bp,sf,&flagged);
1362 cpl_image_save(flagged,"flagged2.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1363 xsh_msg("ok3");
1365 bpm=cpl_image_get_bpm(flagged);
1366 cpl_mask_save(bpm,"bpm.fits",NULL, CPL_IO_DEFAULT);
1367
1368 norm = cpl_imagelist_collapse_create(all);
1369 cpl_image_save(flagged,"result.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1370
1371 cpl_image_save(flagged,"flagged.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1372 cpl_image_save(norm,"norm.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1373 xsh_msg("ok4");
1375 cpl_mask_delete(bpm_tot);
1376 cpl_image_delete(flagged);
1377 cpl_image_delete(norm);
1378 cpl_imagelist_delete(flag);
1379 cpl_imagelist_delete(all);
1380 cpl_table_delete(tab_bp);
1381 return cpl_error_get_code();
1382
1383}
1384
1385 static cpl_error_code
1387
1388 cpl_image* ima=NULL;
1389 cpl_imagelist* flag=NULL;
1390 cpl_imagelist* all=NULL;
1391 int sx=100;
1392 int sy=100;
1393 double value=100;
1394 double step=2;
1395 const int nframes=5;
1396 cpl_mask* bpm;
1397 cpl_mask* bpm_tot=NULL;
1398 //double* pima=NULL;
1399
1400 cpl_image* flagged;
1401 cpl_image* norm;
1402 //int pix;
1403 char name[80];
1404 //cpl_binary* pbpm=CPL_BINARY_0;
1405 flag=cpl_imagelist_new();
1406 all=cpl_imagelist_new();
1407 for(int i=0;i<nframes;i++) {
1408 ima=cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
1409 xsh_msg("frame value %g",value+i*step);
1410 cpl_image_add_scalar(ima,value+i*step);
1411 cpl_imagelist_set(all,cpl_image_duplicate(ima),i);
1412
1413 //pima=cpl_image_get_data_double(ima);
1414
1415 /* on one image we set some pixels as bad to simulate the change of
1416 * intensity in the image resulting from image combination
1417 */
1418
1419 test_xsh_fill_bpm(sx, sy, mode, i, &ima, &bpm_tot);
1420 //cpl_image_set_bpm(ima,bpm);
1421 bpm=cpl_image_get_bpm(ima);
1422 sprintf(name,"bpm_%d.fits",i);
1423 cpl_mask_save(bpm,name,NULL,CPL_IO_DEFAULT);
1424 cpl_imagelist_set(flag,cpl_image_duplicate(ima),i);
1425 cpl_image_delete(ima);
1426 }
1427 cpl_imagelist_save(flag,"flag.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1428
1429 sprintf(name,"bpm_tot.fits");
1430 cpl_mask_save(bpm_tot,name,NULL,CPL_IO_DEFAULT);
1431
1432 cpl_table* tab_bp=test_xsh_bpm2tab(bpm_tot);
1433 cpl_table_save(tab_bp,NULL,NULL,"tab_bp.fits",CPL_IO_DEFAULT);
1434
1435 flagged = xsh_imagelist_collapse_create(flag);
1436 //cpl_image_save(flagged,"flagged1.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1437
1438 cpl_imagelist* sf=xsh_find_image_scale_factors(flag,flagged);
1439
1440 xsh_compute_scale_tab2(flag,tab_bp,sf,&flagged);
1441
1442 cpl_image_save(flagged,"result.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1443
1444 bpm=cpl_image_get_bpm(flagged);
1445 cpl_mask_save(bpm,"bpm_flagged.fits",NULL, CPL_IO_DEFAULT);
1446
1447 norm = cpl_imagelist_collapse_create(all);
1448 cpl_image_save(norm,"norm.fits",CPL_TYPE_FLOAT,NULL,CPL_IO_DEFAULT);
1449
1450 cpl_mask_delete(bpm_tot);
1451 cpl_image_delete(flagged);
1452 cpl_image_delete(norm);
1453 cpl_imagelist_delete(flag);
1454 cpl_imagelist_delete(all);
1455 cpl_imagelist_delete(sf);
1456 cpl_table_delete(tab_bp);
1457
1458 return cpl_error_get_code();
1459
1460 }
1461
1462 static xsh_rec_list*
1463 test_xsh_create_list_from_image(const char* fname, const char* lname) {
1464
1465 cpl_frame* frame=cpl_frame_new();
1466 cpl_frame_set_filename(frame, fname);
1468 xsh_rec_list * rec_list=xsh_rec_list_load_eso(frame, instr);
1469 cpl_frame* tmp=xsh_rec_list_save2(rec_list, lname, "TEST");
1470
1471 xsh_instrument_free(&instr);
1472 xsh_free_frame(&tmp);
1473 xsh_free_frame(&frame);
1474 return rec_list;
1475 }
1476
1477
1478 static cpl_error_code
1479 test_create_ima_uniform(const int sx, const int sy, const double bkg,
1480 const double RON, const double gain, const char* fname)
1481 {
1482
1483 cpl_image* ima=NULL;
1484 cpl_image* err=NULL;
1485 cpl_image* qua=NULL;
1486 const int mode=0;
1487 int i=0;
1488
1489 cpl_mask* bpm_tot=NULL;
1490 cpl_propertylist* plist=NULL;
1491
1492 ima=cpl_image_new(sx,sy,CPL_TYPE_FLOAT);
1493 cpl_image_add_scalar(ima,bkg);
1494
1495 test_xsh_fill_bpm(sx, sy, mode, i, &ima, &bpm_tot);
1496
1497 plist=cpl_propertylist_new();
1498 int crpix1=0;
1499 double crval1=0.;
1500 double cdelt1=1;
1501 int crpix2=0;
1502 double crval2=0.;
1503 double cdelt2=1;
1504
1505 xsh_pfits_set_wcs1(plist,crpix1,crval1,cdelt1);
1506 xsh_pfits_set_wcs2(plist,crpix2,crval2,cdelt2);
1507
1508 cpl_propertylist_append_string(plist,"EXTNAME","FLUX");
1509 cpl_propertylist_append_double(plist,XSH_RECTIFY_BIN_SPACE,cdelt1);
1510
1511 //cpl_propertylist_append_string(plist,XSH_RECTIFY_BIN_SPACE,cdelt1);
1512 cpl_image_save(ima,fname,CPL_TYPE_FLOAT,plist,CPL_IO_DEFAULT);
1513 err=cpl_image_duplicate(ima);
1514 cpl_image_divide_scalar(err,gain);
1515
1516 double RON2=RON*RON;
1517 cpl_image_add_scalar(err,RON2);
1518 qua=cpl_image_new(sx,sy,CPL_TYPE_INT);
1519 cpl_image_power(err,0.5);
1520 cpl_image_save(err, fname, CPL_TYPE_FLOAT,plist,CPL_IO_EXTEND);
1521 cpl_image_save(qua, fname,CPL_TYPE_INT,plist,CPL_IO_EXTEND);
1522
1523 cpl_mask_delete(bpm_tot);
1524 cpl_image_delete(ima);
1525 cpl_image_delete(err);
1526 cpl_image_delete(qua);
1527 xsh_free_propertylist(&plist);
1528
1529 xsh_msg("ok6");
1530
1531 return cpl_error_get_code();
1532 }
1533
1534
1535
1536
1537
1538 static cpl_error_code
1539 test_create_ima_gauss(const int sx, const int sy, const double bkg,
1540 const double RON, const double gain, const double A,
1541 const double sigma, const char* fname)
1542 {
1543
1544 cpl_image* ima=NULL;
1545 cpl_image* err=NULL;
1546 cpl_image* qua=NULL;
1547 const int mode=0;
1548 int min=2*sy/5;
1549 int max=3*sy/5;
1550 int i=0;
1551
1552 cpl_mask* bpm_tot=NULL;
1553 cpl_vector* trace=test_xsh_set_trace(sx,sy,mode);
1554 test_xsh_set_min_max(sx,sy,mode,&min,&max);
1555 cpl_propertylist* plist=NULL;
1556
1557 ima=xsh_define_gauss_profile(sx,sy,A,sigma, bkg, trace,min,max,mode);
1558 cpl_image_add_scalar(ima,bkg);
1559 test_xsh_fill_bpm(sx, sy, mode, i, &ima, &bpm_tot);
1560 plist=cpl_propertylist_new();
1561 int crpix1=0;
1562 double crval1=0.;
1563 double cdelt1=1;
1564
1565 int crpix2=0;
1566 double crval2=0.;
1567 double cdelt2=1;
1568
1569 xsh_pfits_set_wcs1(plist,crpix1,crval1,cdelt1);
1570 xsh_pfits_set_wcs2(plist,crpix2,crval2,cdelt2);
1571 cpl_propertylist_append_string(plist,"EXTNAME","FLUX");
1572 cpl_propertylist_append_double(plist,XSH_RECTIFY_BIN_SPACE,cdelt1);
1573 //cpl_propertylist_append_string(plist,XSH_RECTIFY_BIN_SPACE,cdelt1);
1574 cpl_image_save(ima,fname,CPL_TYPE_FLOAT,plist,CPL_IO_DEFAULT);
1575 err=cpl_image_duplicate(ima);
1576 cpl_image_divide_scalar(err,gain);
1577 double RON2=RON*RON;
1578 cpl_image_add_scalar(err,RON2);
1579 qua=cpl_image_new(sx,sy,CPL_TYPE_INT);
1580 cpl_image_power(err,0.5);
1581 cpl_image_save(err, fname, CPL_TYPE_FLOAT,plist,CPL_IO_EXTEND);
1582 cpl_image_save(qua, fname,CPL_TYPE_INT,plist,CPL_IO_EXTEND);
1583
1584 cpl_mask_delete(bpm_tot);
1585 cpl_vector_delete(trace);
1586 cpl_image_delete(ima);
1587 cpl_image_delete(err);
1588 cpl_image_delete(qua);
1589 xsh_free_propertylist(&plist);
1590
1591 xsh_msg("ok6");
1593 return cpl_error_get_code();
1594 }
1595
1596
1597 static cpl_error_code
1599 {
1600
1601 const int sx=1000;
1602 const int sy=100;
1603 const double bkg=10;
1604 const double RON=3;
1605 const double gain=1;
1606 double A1=10;
1607 double sigma1=2;
1608 double A2=100;
1609 double sigma2=3;
1611 xsh_msg("ok0");
1612
1613 test_create_ima_gauss(sx, sy, bkg, RON, gain, A1, sigma1, "data1.fits");
1614 xsh_rec_list* l1=test_xsh_create_list_from_image("data1.fits","list1.fits");
1615
1616 test_create_ima_gauss(sx, sy, bkg, RON, gain, A2, sigma2, "data2.fits");
1617 xsh_rec_list* l2=test_xsh_create_list_from_image("data2.fits","list2.fits");
1618
1619 test_create_ima_uniform(sx, sy, bkg, RON, gain, "result.fits");
1620 xsh_rec_list* lr=test_xsh_create_list_from_image("result.fits","result.fits");
1621
1622 const int decode_bp=0;
1624 int no=0;
1625 int nb_frames=2;
1626 int *slit_index = NULL;
1627 float* nod_slit = NULL;
1628 float slit_min=999, slit_max=-999;
1629 float nod_slit_min, nod_slit_max;
1630
1631 int nslit = xsh_rec_list_get_nslit( l1, 0);
1632
1633 nod_slit = xsh_rec_list_get_slit( l1, 0);
1634
1635
1636
1637
1638 xsh_rec_list **rec_input_list = NULL ;
1639 XSH_CALLOC( rec_input_list, xsh_rec_list *, nb_frames);
1640 rec_input_list[0] = l1;
1641 rec_input_list[1] = l2;
1642 nod_slit_min = nod_slit[0];
1643 nod_slit_max = nod_slit[nslit-1];
1644 xsh_msg("nslit=%d nod_slit_min=%g nod_slit_max=%g",
1645 nslit,nod_slit_min, nod_slit_max);
1646
1647 /* Search for limits in slit */
1648 for ( int i = 0 ; i < nb_frames ; i++ ) {
1649 float nod_slit_min, nod_slit_max;
1650 xsh_rec_list * list = NULL;
1651 nslit=0;
1652 float* nod_slit = NULL;
1653
1654 list = rec_input_list[i];
1655 check( nslit = xsh_rec_list_get_nslit( list, 0));
1656 check( nod_slit = xsh_rec_list_get_slit( list, 0));
1657 nod_slit_min = nod_slit[0];
1658 nod_slit_max = nod_slit[nslit-1];
1659
1660 if ( nod_slit_min < slit_min){
1661 slit_min = nod_slit_min;
1662 }
1663 if (nod_slit_max > slit_max){
1664 slit_max = nod_slit_max;
1665 }
1666 }
1667
1668 cpl_propertylist* header = xsh_rec_list_get_header( l1);
1670 xsh_msg("slit_min=%g slit_max=%g slit_step=%g",slit_min, slit_max,slit_step);
1671
1672 XSH_CALLOC( slit_index, int, nb_frames);
1673 xsh_compute_slit_index( slit_min, slit_step, rec_input_list, slit_index, nb_frames);
1674
1675 xsh_msg("ok3 nb_frames=%d",nb_frames);
1676 /*
1677 xsh_rec_list *result_list = NULL ;
1678 int nb_orders=1;
1679 xsh_instrument* instrument=xsh_instrument_new();
1680 xsh_instrument_set_arm(instrument,XSH_ARM_NIR);
1681 xsh_print_rec_status(1);
1682 result_list = xsh_rec_list_create_with_size( nb_orders, instrument);
1683 */
1685 xsh_msg("sk2");
1686 xsh_rec_list_add(lr,rec_input_list, slit_index,nb_frames, no, method, decode_bp);
1687 xsh_rec_list_save2(lr,"lr.fits", "TEST");
1689 xsh_msg("sk3");
1690 exit(0);
1692 xsh_msg("ok4 nb_frames=%d",nb_frames);
1693
1694 cleanup:
1695 xsh_rec_list_free(&l1);
1696 xsh_rec_list_free(&l2);
1697 xsh_rec_list_free(&lr);
1698 if ( rec_input_list != NULL){
1699 for ( int i = 0 ; i < nb_frames ; i++ ) {
1700 xsh_rec_list_free( &rec_input_list[i]);
1701 }
1702 }
1703 XSH_FREE( slit_index);
1704 XSH_FREE( rec_input_list);
1705 return cpl_error_get_code();
1706 }
1707 static cpl_error_code
1708 test_combine_rec_list(const int mode,const int win_hsz) {
1709 // create two images with known profile
1711 // load that images as rec lists
1712 // combine rec lists
1713 // save results to check
1714
1715 return cpl_error_get_code();
1716 }
1717/*--------------------------------------------------------------------------*/
1723/*--------------------------------------------------------------------------*/
1724int main(int argc, char **argv)
1725{
1726
1727 cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_INFO);
1728 const int mode=1;
1729 const int win_hsz=2;
1730 //test_combine_ima_gauss(mode,win_hsz);
1732 //test_combine_ima_uniform(mode,win_hsz);
1733 //test_combine_ima_uniform2(mode);
1734
1735 //test_combine_rec_list(mode,win_hsz);
1736 //test_mem();
1737 cpl_test_error(CPL_ERROR_NONE);
1738 return cpl_test_end(0);
1739}
1740
1741
int main()
Unit test of xsh_bspline_interpol.
static const double step
static char mode[32]
static double sigma
static float slit_step
void xsh_rec_list_add(xsh_rec_list *dest, xsh_rec_list **from, int *slit_index, int nb_frames, int no, int method, const int decode_bp)
void xsh_compute_slit_index(float slit_min, float slit_step, xsh_rec_list **from, int *slit_index_tab, int size)
int xsh_rec_list_get_nslit(xsh_rec_list *list, int idx)
Definition: xsh_data_rec.c:827
cpl_frame * xsh_rec_list_save2(xsh_rec_list *list, const char *filename, const char *tag)
save an rec list to a frame
cpl_propertylist * xsh_rec_list_get_header(xsh_rec_list *list)
get header of the table
Definition: xsh_data_rec.c:809
xsh_rec_list * xsh_rec_list_load_eso(cpl_frame *frame, xsh_instrument *instrument)
Definition: xsh_data_rec.c:407
float * xsh_rec_list_get_slit(xsh_rec_list *list, int idx)
Definition: xsh_data_rec.c:884
void xsh_rec_list_free(xsh_rec_list **list)
free memory associated to a rec_list
Definition: xsh_data_rec.c:760
#define check(COMMAND)
Definition: xsh_error.h:71
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
xsh_instrument * xsh_instrument_new(void)
create new instrument structure
int size
int * y
int * x
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
cpl_error_code xsh_pfits_set_wcs2(cpl_propertylist *header, const double crpix2, const double crval2, const double cdelt2)
Definition: xsh_pfits.c:4322
double xsh_pfits_get_rectify_bin_space(cpl_propertylist *plist)
find out the rectify space (slit) binning
Definition: xsh_pfits.c:3302
cpl_error_code xsh_pfits_set_wcs1(cpl_propertylist *header, const double crpix1, const double crval1, const double cdelt1)
Definition: xsh_pfits.c:4307
static cpl_error_code test_combine_ima_gauss3(const int mode)
static cpl_error_code test_combine_ima_gauss(const int mode, const int win_hsz)
static cpl_error_code test_combine_rec_list(const int mode, const int win_hsz)
static xsh_rec_list * test_xsh_create_list_from_image(const char *fname, const char *lname)
static cpl_image * xsh_define_gauss_profile(const int sx, const int sy, const double A, const double sigma, const double bkg, cpl_vector *trace, const int min, const int max, const int mode)
static cpl_error_code test_combine_lists(void)
static cpl_error_code test_create_ima_gauss(const int sx, const int sy, const double bkg, const double RON, const double gain, const double A, const double sigma, const char *fname)
static cpl_image * xsh_compute_scale(cpl_imagelist *iml_data, cpl_mask *bpm, const int mode, const int win_hsz)
cpl_error_code test_mem(void)
static cpl_image * xsh_compute_scale_tab(cpl_imagelist *iml_data, cpl_mask *bpm, cpl_table *tab_bpm, const int mode, const int win_hsz)
static cpl_error_code test_xsh_fill_bpm(const int sx, const int sy, const int mode, const int i, cpl_image **ima, cpl_mask **bpm_tot)
static cpl_table * test_xsh_bpm2tab(const cpl_mask *bpm)
static cpl_error_code test_xsh_set_min_max(const int sx, const int sy, const int mode, int *min, int *max)
static cpl_error_code test_create_ima_uniform(const int sx, const int sy, const double bkg, const double RON, const double gain, const char *fname)
cpl_error_code xsh_flag_bp_at_location(cpl_binary *pbpm, int pix, cpl_binary bp_code, const int mode, const int sx)
static cpl_error_code test_combine_ima_uniform2(const int mode)
static cpl_error_code xsh_compute_scale_tab2(cpl_imagelist *iml_data, cpl_table *tab_bpm, cpl_imagelist *scale_frames, cpl_image **ima_corr)
static cpl_vector * test_xsh_set_trace(const int sx, const int sy, const int mode)
static cpl_image * xsh_imagelist_collapse_create(cpl_imagelist *iml)
static cpl_imagelist * xsh_find_image_scale_factors(const cpl_imagelist *iml_in, cpl_image *ima_in)
static cpl_error_code test_combine_ima_gauss2(const int mode)
void xsh_unwrap_vector(cpl_vector **v)
Unwrap a vector and set the pointer to NULL.
Definition: xsh_utils.c:2345
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
int niter
Definition: xsh_detmon_lg.c:82
int m
Definition: xsh_detmon_lg.c:91
int n
Definition: xsh_detmon_lg.c:92
const char * method
Definition: xsh_detmon_lg.c:78
int xsh_print_rec_status(const int val)
Check if an error has happened and returns error kind and location.
Definition: xsh_dfs.c:877
#define max(a, b)
@ COMBINE_MEAN_METHOD
#define XSH_RECTIFY_BIN_SPACE
Definition: xsh_pfits.h:203
#define XSH_FREE(POINTER)
Definition: xsh_utils.h:92
#define XSH_CALLOC(POINTER, TYPE, SIZE)
Definition: xsh_utils.h:56