GIRAFFE Pipeline Reference Manual

gislight.c
1 /* $Id$
2  *
3  * This file is part of the GIRAFFE Pipeline
4  * Copyright (C) 2002-2006 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 /*
22  * $Author$
23  * $Date$
24  * $Revision$
25  * $Name$
26  */
27 
28 #ifndef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31 
32 
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <math.h>
36 
37 #include <cxmemory.h>
38 #include <cxmessages.h>
39 #include <cxstrutils.h>
40 #include <cxstring.h>
41 
42 #include <cpl_propertylist.h>
43 #include <cpl_matrix.h>
44 #include <cpl_image.h>
45 #include <cpl_msg.h>
46 
47 #include "gialias.h"
48 #include "gimacros.h"
49 #include "gimath.h"
50 #include "gichebyshev.h"
51 #include "gimatrix.h"
52 #include "gislight.h"
53 
54 
63 struct GiSLightSetup {
64  cxint xstep;
65  cxint ystep;
66  cxdouble ewidth;
67  cxint iswidth;
68  cxbool istrim;
69  cpl_matrix* slices;
70 };
71 
72 typedef struct GiSLightSetup GiSLightSetup;
73 
74 
75 inline static GiSLightSetup*
76 _giraffe_slightsetup_new(cxint nslices)
77 {
78 
79  GiSLightSetup* self = cx_calloc(1, sizeof *self);
80 
81  if (self != NULL) {
82  self->slices = cpl_matrix_new(nslices, 3);
83  }
84 
85  return self;
86 
87 }
88 
89 
90 inline static void
91 _giraffe_slightsetup_delete(GiSLightSetup* self)
92 {
93 
94  if (self != NULL) {
95 
96  if (self->slices != NULL) {
97  cpl_matrix_delete(self->slices);
98  self->slices = NULL;
99  }
100 
101  cx_free(self);
102 
103  }
104 
105  return;
106 
107 }
108 
109 
110 inline static cxint
111 _giraffe_compute_isregion(cpl_matrix* xis, cpl_matrix* yis, cpl_matrix* zis,
112  const cpl_image* image, const cpl_image* locy,
113  const cpl_image* locw, const GiSLightSetup* setup)
114 {
115 
116  cxint nx = cpl_image_get_size_y(image);
117  cxint ny = cpl_image_get_size_x(image);
118  cxint oxend = 0;
119  cxint ns = 0;
120  cxint nsmax = 0;
121  cxint iscount = 0;
122  cxint ismax = ny * nx;
123 
124 
125  cx_assert(xis != NULL);
126  cx_assert(yis != NULL);
127  cx_assert(zis != NULL);
128 
129  cx_assert(setup->slices != NULL);
130 
131 
132  if (nx != cpl_image_get_size_y(locy) ||
133  nx != cpl_image_get_size_y(locw)) {
134  return -1;
135  }
136 
137  if (setup->istrim == FALSE) {
138 
139  cxint nregions = cpl_image_get_size_x(locy) - 1;
140  cxint kmax = ny;
141  cxint xs;
142  cxint x;
143 
144  for (xs = 0; xs < cpl_matrix_get_nrow(setup->slices); xs++) {
145 
146  cxint xstart = CX_MAX(cpl_matrix_get(setup->slices, xs, 0), oxend);
147  cxint xend = CX_MIN(cpl_matrix_get(setup->slices, xs, 1), nx - 1);
148  cxint xstep = CX_MAX(cpl_matrix_get(setup->slices, xs, 2), 1);
149 
150 
151  for (x = oxend; x < xstart; x += setup->xstep) {
152 
153  cxint zx = x * ny;
154  cxint lx = x * cpl_image_get_size_x(locy);
155  cxint ylower = 0;
156  cxint yupper = 0;
157 
158  const cxdouble* _locy = cpl_image_get_data_const(locy);
159  const cxdouble* _locw = cpl_image_get_data_const(locw);
160  const cxdouble* _image = cpl_image_get_data_const(image);
161 
162 
163  if (_locw[lx] <= 0. || _locw[lx + nregions] <= 0.) {
164  continue;
165  }
166 
167  ylower = (cxint)floor(_locy[lx] -
168  (_locw[lx] + setup->ewidth));
169  yupper = (cxint)ceil(_locy[lx + nregions] +
170  (_locw[lx + nregions] + setup->ewidth));
171 
172  ylower = CX_MAX(CX_MIN(ny, ylower), 0);
173  yupper = CX_MAX(CX_MIN(ny, yupper), 0);
174 
175 
176  /*
177  * First inter spectrum region
178  */
179 
180  if (ylower > setup->iswidth) {
181 
182  register cxint k;
183 
184  for (k = 0; k <= ylower; k += setup->ystep) {
185  cpl_matrix_set(xis, iscount, 0, x);
186  cpl_matrix_set(yis, iscount, 0, k);
187  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
188  ++iscount;
189  }
190 
191  }
192 
193 
194  /*
195  * Last inter spectrum region
196  */
197 
198  if (ny - yupper > setup->iswidth) {
199 
200  register cxint k;
201 
202  for (k = yupper; k < kmax; k += setup->ystep) {
203  cpl_matrix_set(xis, iscount, 0, x);
204  cpl_matrix_set(yis, iscount, 0, k);
205  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
206  ++iscount;
207  }
208 
209  }
210 
211  }
212 
213  for (x = xstart; x <= xend; x +=xstep) {
214 
215  cxint zx = x * ny;
216  cxint lx = x * cpl_image_get_size_x(locy);
217  cxint ylower = 0;
218  cxint yupper = 0;
219 
220  const cxdouble* _locy = cpl_image_get_data_const(locy);
221  const cxdouble* _locw = cpl_image_get_data_const(locw);
222  const cxdouble* _image = cpl_image_get_data_const(image);
223 
224 
225  if (_locw[lx] <= 0. || _locw[lx + nregions] <= 0.) {
226  continue;
227  }
228 
229  ylower = (cxint)floor(_locy[lx] -
230  (_locw[lx] + setup->ewidth));
231  yupper = (cxint)ceil(_locy[lx + nregions] +
232  (_locw[lx + nregions] + setup->ewidth));
233 
234  ylower = CX_MAX(CX_MIN(ny, ylower), 0);
235  yupper = CX_MAX(CX_MIN(ny, yupper), 0);
236 
237 
238  /*
239  * First inter spectrum region
240  */
241 
242  if (ylower > setup->iswidth) {
243 
244  register cxint k;
245 
246  for (k = 0; k <= ylower; k += setup->ystep) {
247  cpl_matrix_set(xis, iscount, 0, x);
248  cpl_matrix_set(yis, iscount, 0, k);
249  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
250  ++iscount;
251  }
252 
253  }
254 
255 
256  /*
257  * Last inter spectrum region
258  */
259 
260  if (ny - yupper > setup->iswidth) {
261 
262  register cxint k;
263 
264  for (k = yupper; k < kmax; k += setup->ystep) {
265  cpl_matrix_set(xis, iscount, 0, x);
266  cpl_matrix_set(yis, iscount, 0, k);
267  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
268  ++iscount;
269  }
270 
271  }
272 
273  }
274 
275  oxend = xend + 1;
276 
277  }
278 
279  for (x = oxend; x < nx; x += setup->xstep) {
280 
281  cxint zx = x * ny;
282  cxint lx = x * cpl_image_get_size_x(locy);
283  cxint ylower = 0;
284  cxint yupper = 0;
285 
286  const cxdouble* _locy = cpl_image_get_data_const(locy);
287  const cxdouble* _locw = cpl_image_get_data_const(locw);
288  const cxdouble* _image = cpl_image_get_data_const(image);
289 
290 
291  if (_locw[lx] <= 0. || _locw[lx + nregions] <= 0.) {
292  continue;
293  }
294 
295  ylower = (cxint)floor(_locy[lx] -
296  (_locw[lx] + setup->ewidth));
297  yupper = (cxint)ceil(_locy[lx + nregions] +
298  (_locw[lx + nregions] + setup->ewidth));
299 
300  ylower = CX_MAX(CX_MIN(ny, ylower), 0);
301  yupper = CX_MAX(CX_MIN(ny, yupper), 0);
302 
303 
304  /*
305  * First inter spectrum region
306  */
307 
308  if (ylower > setup->iswidth) {
309 
310  register cxint k;
311 
312  for (k = 0; k <= ylower; k += setup->ystep) {
313  cpl_matrix_set(xis, iscount, 0, x);
314  cpl_matrix_set(yis, iscount, 0, k);
315  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
316  ++iscount;
317  }
318 
319  }
320 
321 
322  /*
323  * Last inter spectrum region
324  */
325 
326  if (ny - yupper > setup->iswidth) {
327 
328  register cxint k;
329 
330  for (k = yupper; k < kmax; k += setup->ystep) {
331  cpl_matrix_set(xis, iscount, 0, x);
332  cpl_matrix_set(yis, iscount, 0, k);
333  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
334  ++iscount;
335  }
336 
337  }
338 
339  }
340 
341  }
342 
343  nsmax = cpl_image_get_size_x(locy) - 1;
344  for (ns = 0; ns < nsmax; ns++) {
345 
346  cxint nregions = ns + 1;
347  cxint xs = 0;
348  cxint x;
349 
350  oxend = 0;
351 
352  for (xs = 0; xs < cpl_matrix_get_nrow(setup->slices); xs++) {
353 
354  cxint xstart = CX_MAX(cpl_matrix_get(setup->slices, xs, 0), oxend);
355  cxint xend = CX_MIN(cpl_matrix_get(setup->slices, xs, 1), nx - 1);
356 
357 
358  for (x = oxend; x < xstart; x += setup->xstep) {
359 
360  cxint k;
361  cxint zx = x * ny;
362  cxint lx = x * cpl_image_get_size_x(locy);
363  cxint ylower = 0;
364  cxint yupper = 0;
365 
366  const cxdouble* _locy = cpl_image_get_data_const(locy);
367  const cxdouble* _locw = cpl_image_get_data_const(locw);
368  const cxdouble* _image = cpl_image_get_data_const(image);
369 
370 
371  if (_locw[lx + ns] <= 0.) {
372  continue;
373  }
374 
375  while (_locw[lx + nregions] <= 0. &&
376  _locy[lx + nregions] <= 0.) {
377  ++nregions;
378  }
379 
380  /* Lower border of upper spectrum */
381 
382  ylower = (cxint)floor(_locy[lx + nregions] -
383  (_locw[lx + nregions] + setup->ewidth));
384 
385  /* Upper border of lower spectrum */
386 
387  yupper = (cxint)ceil(_locy[lx + ns] +
388  (_locw[lx + ns] + setup->ewidth));
389 
390  ylower = CX_MAX(CX_MIN(ny, ylower), 0);
391  yupper = CX_MAX(CX_MIN(ny, yupper), 0);
392 
393  if (ylower - yupper <= setup->iswidth) {
394  continue;
395  }
396 
397  for (k = yupper; k <= ylower && iscount < ismax;
398  k += setup->ystep) {
399  cpl_matrix_set(xis, iscount, 0, x);
400  cpl_matrix_set(yis, iscount, 0, k);
401  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
402  ++iscount;
403  }
404 
405  }
406 
407  for (x = xstart; x <= xend; x += setup->xstep) {
408 
409  cxint k;
410  cxint zx = x * ny;
411  cxint lx = x * cpl_image_get_size_x(locy);
412  cxint ylower = 0;
413  cxint yupper = 0;
414 
415  const cxdouble* _locy = cpl_image_get_data_const(locy);
416  const cxdouble* _locw = cpl_image_get_data_const(locw);
417  const cxdouble* _image = cpl_image_get_data_const(image);
418 
419 
420  if (_locw[lx + ns] <= 0.) {
421  continue;
422  }
423 
424  while (_locw[lx + nregions] <= 0. &&
425  _locy[lx + nregions] <= 0.) {
426  ++nregions;
427  }
428 
429  /* Lower border of upper spectrum */
430 
431  ylower = (cxint)floor(_locy[lx + nregions] -
432  (_locw[lx + nregions] + setup->ewidth));
433 
434  /* Upper border of lower spectrum */
435 
436  yupper = (cxint)ceil(_locy[lx + ns] +
437  (_locw[lx + ns] + setup->ewidth));
438 
439  ylower = CX_MAX(CX_MIN(ny, ylower), 0);
440  yupper = CX_MAX(CX_MIN(ny, yupper), 0);
441 
442  if (ylower - yupper <= setup->iswidth) {
443  continue;
444  }
445 
446  for (k = yupper; k <= ylower && iscount < ismax;
447  k += setup->ystep) {
448  cpl_matrix_set(xis, iscount, 0, x);
449  cpl_matrix_set(yis, iscount, 0, k);
450  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
451  ++iscount;
452  }
453 
454  }
455 
456  oxend = xend + 1;
457 
458  }
459 
460  for (x = oxend; x < nx; x += setup->xstep) {
461 
462  cxint k;
463  cxint zx = x * ny;
464  cxint lx = x * cpl_image_get_size_x(locy);
465  cxint ylower = 0;
466  cxint yupper = 0;
467 
468  const cxdouble* _locy = cpl_image_get_data_const(locy);
469  const cxdouble* _locw = cpl_image_get_data_const(locw);
470  const cxdouble* _image = cpl_image_get_data_const(image);
471 
472 
473  if (_locw[lx + ns] <= 0.) {
474  continue;
475  }
476 
477  while (_locw[lx + nregions] <= 0. &&
478  _locy[lx + nregions] <= 0.) {
479  ++nregions;
480  }
481 
482  /* Lower border of upper spectrum */
483 
484  ylower = (cxint)floor(_locy[lx + nregions] -
485  (_locw[lx + nregions] + setup->ewidth));
486 
487  /* Upper border of lower spectrum */
488 
489  yupper = (cxint)ceil(_locy[lx + ns] +
490  (_locw[lx + ns] + setup->ewidth));
491 
492  ylower = CX_MAX(CX_MIN(ny, ylower), 0);
493  yupper = CX_MAX(CX_MIN(ny, yupper), 0);
494 
495  if (ylower - yupper <= setup->iswidth) {
496  continue;
497  }
498 
499  for (k = yupper; k <= ylower && iscount < ismax;
500  k += setup->ystep) {
501  cpl_matrix_set(xis, iscount, 0, x);
502  cpl_matrix_set(yis, iscount, 0, k);
503  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
504  ++iscount;
505  }
506 
507  }
508 
509  }
510 
511  return iscount;
512 
513 }
514 
515 
516 inline static cxint
517 _giraffe_compute_isregion_bpm(cpl_matrix* xis, cpl_matrix* yis,
518  cpl_matrix* zis, const cpl_image* image,
519  const cpl_image* locy, const cpl_image* locw,
520  const cpl_image* bpixel,
521  const GiSLightSetup* setup)
522 {
523 
524  cxint nx = cpl_image_get_size_y(image);
525  cxint ny = cpl_image_get_size_x(image);
526  cxint oxend = 0;
527  cxint ns = 0;
528  cxint nsmax = 0;
529  cxint iscount = 0;
530  cxint ismax = ny * nx;
531 
532 
533  cx_assert(xis != NULL);
534  cx_assert(yis != NULL);
535  cx_assert(zis != NULL);
536 
537  cx_assert(setup->slices != NULL);
538 
539 
540  if (nx != cpl_image_get_size_y(locy) ||
541  nx != cpl_image_get_size_y(locw)) {
542  return -1;
543  }
544 
545  if (nx != cpl_image_get_size_y(bpixel) ||
546  nx != cpl_image_get_size_y(bpixel)) {
547  return -2;
548  }
549 
550  if (setup->istrim == FALSE) {
551 
552  cxint nregions = cpl_image_get_size_x(locy) - 1;
553  cxint kmax = ny;
554  cxint xs;
555  cxint x;
556 
557 
558  for (xs = 0; xs < cpl_matrix_get_nrow(setup->slices); xs++) {
559 
560  cxint xstart = CX_MAX(cpl_matrix_get(setup->slices, xs, 0), oxend);
561  cxint xend = CX_MIN(cpl_matrix_get(setup->slices, xs, 1), nx - 1);
562  cxint xstep = CX_MAX(cpl_matrix_get(setup->slices, xs, 2), 1);
563 
564 
565  for (x = oxend; x < xstart; x += setup->xstep) {
566 
567  cxint zx = x * ny;
568  cxint lx = x * cpl_image_get_size_x(locy);
569  cxint ylower = 0;
570  cxint yupper = 0;
571 
572  const cxdouble* _locy = cpl_image_get_data_const(locy);
573  const cxdouble* _locw = cpl_image_get_data_const(locw);
574  const cxdouble* _image = cpl_image_get_data_const(image);
575 
576 
577  if (_locw[lx] <= 0. || _locw[lx + nregions] <= 0.) {
578  continue;
579  }
580 
581  ylower = (cxint)floor(_locy[lx] -
582  (_locw[lx] + setup->ewidth));
583  yupper = (cxint)ceil(_locy[lx + nregions] +
584  (_locw[lx + nregions] + setup->ewidth));
585 
586  ylower = CX_MAX(CX_MIN(ny, ylower), 0);
587  yupper = CX_MAX(CX_MIN(ny, yupper), 0);
588 
589 
590  /*
591  * First inter spectrum region
592  */
593 
594  if (ylower > setup->iswidth) {
595 
596  register cxint k;
597 
598  const cxint* _bpixel = cpl_image_get_data_const(bpixel);
599 
600 
601  for (k = 0; k <= ylower; k += setup->ystep) {
602 
603  if (_bpixel[zx + k] & GIR_M_PIX_SET) {
604  continue;
605  }
606 
607  cpl_matrix_set(xis, iscount, 0, x);
608  cpl_matrix_set(yis, iscount, 0, k);
609  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
610  ++iscount;
611  }
612 
613  }
614 
615 
616  /*
617  * Last inter spectrum region
618  */
619 
620  if (ny - yupper > setup->iswidth) {
621 
622  register cxint k;
623 
624  const cxint* _bpixel = cpl_image_get_data_const(bpixel);
625 
626 
627  for (k = yupper; k < kmax; k += setup->ystep) {
628 
629  if (_bpixel[zx + k] & GIR_M_PIX_SET) {
630  continue;
631  }
632 
633  cpl_matrix_set(xis, iscount, 0, x);
634  cpl_matrix_set(yis, iscount, 0, k);
635  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
636  ++iscount;
637  }
638 
639  }
640 
641  }
642 
643  for (x = xstart; x <= xend; x +=xstep) {
644 
645  cxint zx = x * ny;
646  cxint lx = x * cpl_image_get_size_x(locy);
647  cxint ylower = 0;
648  cxint yupper = 0;
649 
650  const cxdouble* _locy = cpl_image_get_data_const(locy);
651  const cxdouble* _locw = cpl_image_get_data_const(locw);
652  const cxdouble* _image = cpl_image_get_data_const(image);
653 
654 
655  if (_locw[lx] <= 0. || _locw[lx + nregions] <= 0.) {
656  continue;
657  }
658 
659  ylower = (cxint)floor(_locy[lx] -
660  (_locw[lx] + setup->ewidth));
661  yupper = (cxint)ceil(_locy[lx + nregions] +
662  (_locw[lx + nregions] + setup->ewidth));
663 
664  ylower = CX_MAX(CX_MIN(ny, ylower), 0);
665  yupper = CX_MAX(CX_MIN(ny, yupper), 0);
666 
667 
668  /*
669  * First inter spectrum region
670  */
671 
672  if (ylower > setup->iswidth) {
673 
674  register cxint k;
675 
676  const cxint* _bpixel = cpl_image_get_data_const(bpixel);
677 
678 
679  for (k = 0; k <= ylower; k += setup->ystep) {
680 
681  if (_bpixel[zx + k] & GIR_M_PIX_SET) {
682  continue;
683  }
684 
685  cpl_matrix_set(xis, iscount, 0, x);
686  cpl_matrix_set(yis, iscount, 0, k);
687  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
688  ++iscount;
689  }
690 
691  }
692 
693 
694  /*
695  * Last inter spectrum region
696  */
697 
698  if (ny - yupper > setup->iswidth) {
699 
700  register cxint k;
701 
702  const cxint* _bpixel = cpl_image_get_data_const(bpixel);
703 
704 
705  for (k = yupper; k < kmax; k += setup->ystep) {
706 
707  if (_bpixel[zx + k] & GIR_M_PIX_SET) {
708  continue;
709  }
710 
711  cpl_matrix_set(xis, iscount, 0, x);
712  cpl_matrix_set(yis, iscount, 0, k);
713  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
714  ++iscount;
715  }
716 
717  }
718 
719  }
720 
721  oxend = xend + 1;
722 
723  }
724 
725  for (x = oxend; x < nx; x += setup->xstep) {
726 
727  cxint zx = x * ny;
728  cxint lx = x * cpl_image_get_size_x(locy);
729  cxint ylower = 0;
730  cxint yupper = 0;
731 
732  const cxdouble* _locy = cpl_image_get_data_const(locy);
733  const cxdouble* _locw = cpl_image_get_data_const(locw);
734  const cxdouble* _image = cpl_image_get_data_const(image);
735 
736 
737  if (_locw[lx] <= 0. || _locw[lx + nregions] <= 0.) {
738  continue;
739  }
740 
741  ylower = (cxint)floor(_locy[lx] -
742  (_locw[lx] + setup->ewidth));
743  yupper = (cxint)ceil(_locy[lx + nregions] +
744  (_locw[lx + nregions] + setup->ewidth));
745 
746  ylower = CX_MAX(CX_MIN(ny, ylower), 0);
747  yupper = CX_MAX(CX_MIN(ny, yupper), 0);
748 
749 
750  /*
751  * First inter spectrum region
752  */
753 
754  if (ylower > setup->iswidth) {
755 
756  register cxint k;
757 
758  const cxint* _bpixel = cpl_image_get_data_const(bpixel);
759 
760 
761  for (k = 0; k <= ylower; k += setup->ystep) {
762 
763  if (_bpixel[zx + k] & GIR_M_PIX_SET) {
764  continue;
765  }
766 
767  cpl_matrix_set(xis, iscount, 0, x);
768  cpl_matrix_set(yis, iscount, 0, k);
769  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
770  ++iscount;
771  }
772 
773  }
774 
775 
776  /*
777  * Last inter spectrum region
778  */
779 
780  if (ny - yupper > setup->iswidth) {
781 
782  register cxint k;
783 
784  const cxint* _bpixel = cpl_image_get_data_const(bpixel);
785 
786 
787  for (k = yupper; k < kmax; k += setup->ystep) {
788 
789  if (_bpixel[zx + k] & GIR_M_PIX_SET) {
790  continue;
791  }
792 
793  cpl_matrix_set(xis, iscount, 0, x);
794  cpl_matrix_set(yis, iscount, 0, k);
795  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
796  ++iscount;
797  }
798 
799  }
800 
801  }
802 
803  }
804 
805  nsmax = cpl_image_get_size_x(locy) - 1;
806  for (ns = 0; ns < nsmax; ns++) {
807 
808  cxint nregions = ns + 1;
809  cxint xs = 0;
810  cxint x;
811 
812  oxend = 0;
813 
814  for (xs = 0; xs < cpl_matrix_get_nrow(setup->slices); xs++) {
815 
816  cxint xstart = CX_MAX(cpl_matrix_get(setup->slices, xs, 0), oxend);
817  cxint xend = CX_MIN(cpl_matrix_get(setup->slices, xs, 1), nx - 1);
818 
819 
820  for (x = oxend; x < xstart; x += setup->xstep) {
821 
822  cxint zx = x * ny;
823  cxint lx = x * cpl_image_get_size_x(locy);
824  cxint ylower = 0;
825  cxint yupper = 0;
826 
827  const cxdouble* _locy = cpl_image_get_data_const(locy);
828  const cxdouble* _locw = cpl_image_get_data_const(locw);
829  const cxdouble* _image = cpl_image_get_data_const(image);
830 
831 
832  if (_locw[lx + ns] <= 0.) {
833  continue;
834  }
835 
836  while (_locw[lx + nregions] <= 0. &&
837  _locy[lx + nregions] <= 0.) {
838  ++nregions;
839  }
840 
841  /* Lower border of upper spectrum */
842 
843  ylower = (cxint)floor(_locy[lx + nregions] -
844  (_locw[lx + nregions] + setup->ewidth));
845 
846  /* Upper border of lower spectrum */
847 
848  yupper = (cxint)ceil(_locy[lx + ns] +
849  (_locw[lx + ns] + setup->ewidth));
850 
851  ylower = CX_MAX(CX_MIN(ny, ylower), 0);
852  yupper = CX_MAX(CX_MIN(ny, yupper), 0);
853 
854  if (ylower - yupper > setup->iswidth) {
855 
856  register cxint k;
857 
858  const cxint* _bpixel = cpl_image_get_data_const(bpixel);
859 
860 
861  for (k = yupper; k <= ylower && iscount < ismax;
862  k += setup->ystep) {
863 
864  if (_bpixel[zx + k] & GIR_M_PIX_SET) {
865  continue;
866  }
867 
868  cpl_matrix_set(xis, iscount, 0, x);
869  cpl_matrix_set(yis, iscount, 0, k);
870  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
871  ++iscount;
872  }
873 
874  }
875 
876  }
877 
878  for (x = xstart; x <= xend; x += setup->xstep) {
879 
880  cxint zx = x * ny;
881  cxint lx = x * cpl_image_get_size_x(locy);
882  cxint ylower = 0;
883  cxint yupper = 0;
884 
885  const cxdouble* _locy = cpl_image_get_data_const(locy);
886  const cxdouble* _locw = cpl_image_get_data_const(locw);
887  const cxdouble* _image = cpl_image_get_data_const(image);
888 
889 
890  if (_locw[lx + ns] <= 0.) {
891  continue;
892  }
893 
894  while (_locw[lx + nregions] <= 0. &&
895  _locy[lx + nregions] <= 0.) {
896  ++nregions;
897  }
898 
899  /* Lower border of upper spectrum */
900 
901  ylower = (cxint)floor(_locy[lx + nregions] -
902  (_locw[lx + nregions] + setup->ewidth));
903 
904  /* Upper border of lower spectrum */
905 
906  yupper = (cxint)ceil(_locy[lx + ns] +
907  (_locw[lx + ns] + setup->ewidth));
908 
909  ylower = CX_MAX(CX_MIN(ny, ylower), 0);
910  yupper = CX_MAX(CX_MIN(ny, yupper), 0);
911 
912  if (ylower - yupper > setup->iswidth) {
913 
914  register cxint k;
915 
916  const cxint* _bpixel = cpl_image_get_data_const(bpixel);
917 
918  for (k = yupper; k <= ylower && iscount < ismax;
919  k += setup->ystep) {
920 
921  if (_bpixel[zx + k] & GIR_M_PIX_SET) {
922  continue;
923  }
924 
925  cpl_matrix_set(xis, iscount, 0, x);
926  cpl_matrix_set(yis, iscount, 0, k);
927  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
928  ++iscount;
929 
930  }
931 
932  }
933 
934  }
935 
936  oxend = xend + 1;
937 
938  }
939 
940  for (x = oxend; x < nx; x += setup->xstep) {
941 
942  cxint zx = x * ny;
943  cxint lx = x * cpl_image_get_size_x(locy);
944  cxint ylower = 0;
945  cxint yupper = 0;
946 
947  const cxdouble* _locy = cpl_image_get_data_const(locy);
948  const cxdouble* _locw = cpl_image_get_data_const(locw);
949  const cxdouble* _image = cpl_image_get_data_const(image);
950 
951 
952  if (_locw[lx + ns] <= 0.) {
953  continue;
954  }
955 
956  while (_locw[lx + nregions] <= 0. &&
957  _locy[lx + nregions] <= 0.) {
958  ++nregions;
959  }
960 
961  /* Lower border of upper spectrum */
962 
963  ylower = (cxint)floor(_locy[lx + nregions] -
964  (_locw[lx + nregions] + setup->ewidth));
965 
966  /* Upper border of lower spectrum */
967 
968  yupper = (cxint)ceil(_locy[lx + ns] +
969  (_locw[lx + ns] + setup->ewidth));
970 
971  ylower = CX_MAX(CX_MIN(ny, ylower), 0);
972  yupper = CX_MAX(CX_MIN(ny, yupper), 0);
973 
974  if (ylower - yupper > setup->iswidth) {
975 
976  register cxint k;
977 
978  const cxint* _bpixel = cpl_image_get_data_const(bpixel);
979 
980 
981  for (k = yupper; k <= ylower && iscount < ismax;
982  k += setup->ystep) {
983 
984  if (_bpixel[zx + k] & GIR_M_PIX_SET) {
985  continue;
986  }
987 
988  cpl_matrix_set(xis, iscount, 0, x);
989  cpl_matrix_set(yis, iscount, 0, k);
990  cpl_matrix_set(zis, 0, iscount, _image[zx + k]);
991  ++iscount;
992  }
993 
994  }
995 
996  }
997 
998  }
999 
1000  return iscount;
1001 
1002 }
1003 
1004 static cpl_image*
1005 _giraffe_slight_fit_polynom(const cpl_image* image, const cpl_image* locy,
1006  const cpl_image* locw, const cpl_image* bpixel,
1007  cxint xorder, cxint yorder, cxint *iscount,
1008  const GiSLightSetup* setup)
1009 {
1010 
1011  cxint i;
1012  cxint j;
1013  cxint nx = cpl_image_get_size_y(image);
1014  cxint ny = cpl_image_get_size_x(image);
1015 
1016  cpl_image* slfit = NULL;
1017 
1018  cpl_matrix* xis = cpl_matrix_new(nx * ny, 1);
1019  cpl_matrix* yis = cpl_matrix_new(nx * ny, 1);
1020  cpl_matrix* zis = cpl_matrix_new(1, nx * ny);
1021 
1022 
1023  *iscount = 0;
1024 
1025  if (bpixel != NULL) {
1026  *iscount = _giraffe_compute_isregion_bpm(xis, yis, zis, image, locy,
1027  locw, bpixel, setup);
1028  }
1029  else {
1030  *iscount = _giraffe_compute_isregion(xis, yis, zis, image, locy,
1031  locw, setup);
1032  }
1033 
1034  if (*iscount <= 0 || *iscount >= nx * ny) {
1035 
1036  cpl_matrix_delete(xis);
1037  xis = NULL;
1038 
1039  cpl_matrix_delete(yis);
1040  yis = NULL;
1041 
1042  cpl_matrix_delete(zis);
1043  zis = NULL;
1044 
1045  return NULL;
1046 
1047  }
1048  else {
1049 
1050  cxint status = 0;
1051 
1052  cpl_matrix* base = NULL;
1053  cpl_matrix* coeff = NULL;
1054  cpl_matrix* chebyshev = NULL;
1055 
1056  GiChebyshev2D* fit = NULL;
1057 
1058  cpl_matrix_set_size(xis, *iscount, 1);
1059  cpl_matrix_set_size(yis, *iscount, 1);
1060  cpl_matrix_set_size(zis, 1, *iscount);
1061 
1062 #if 0
1063 
1064  // FIXME: For tests only!
1065 
1066  cpl_image* tmp = cpl_image_new(ny, nx, CPL_TYPE_DOUBLE);
1067  cxdouble* _tmp = cpl_image_get_data(tmp);
1068 
1069  for (i = 0; i < *iscount; i++) {
1070  cxint k = cpl_matrix_get(xis, i, 0) * cpl_image_get_size_x(tmp) +
1071  cpl_matrix_get(yis, i, 0);
1072  _tmp[k] = cpl_matrix_get(zis, 0, i);
1073  }
1074 
1075  cpl_image_save(tmp, "idiot.fits", CPL_BPP_IEEE_FLOAT, NULL,
1076  CPL_IO_DEFAULT);
1077  cpl_image_delete(tmp);
1078  tmp = NULL;
1079 
1080 #endif
1081 
1082  base = giraffe_chebyshev_base2d(0., 0., nx, ny, xorder + 1,
1083  yorder + 1, xis, yis);
1084 
1085  coeff = giraffe_matrix_leastsq(base, zis);
1086 
1087  if (coeff == NULL) {
1088  cpl_matrix_delete(base);
1089  base = NULL;
1090 
1091  cpl_matrix_delete(xis);
1092  xis = NULL;
1093 
1094  cpl_matrix_delete(yis);
1095  yis = NULL;
1096 
1097  cpl_matrix_delete(zis);
1098  zis = NULL;
1099 
1100  return NULL;
1101  }
1102 
1103  cpl_matrix_delete(base);
1104  base = NULL;
1105 
1106  cpl_matrix_delete(xis);
1107  xis = NULL;
1108 
1109  cpl_matrix_delete(yis);
1110  yis = NULL;
1111 
1112  cpl_matrix_delete(zis);
1113  zis = NULL;
1114 
1115 
1116  /*
1117  * Compute scattered light model
1118  */
1119 
1120  chebyshev = cpl_matrix_wrap(xorder + 1, yorder + 1,
1121  cpl_matrix_get_data(coeff));
1122 
1123  fit = giraffe_chebyshev2d_new(xorder, yorder);
1124  status = giraffe_chebyshev2d_set(fit, 0., nx, 0., ny, chebyshev);
1125 
1126  if (status != 0) {
1127 
1128  giraffe_chebyshev2d_delete(fit);
1129  fit = NULL;
1130 
1131  cpl_matrix_unwrap(chebyshev);
1132  chebyshev = NULL;
1133 
1134  cpl_matrix_delete(coeff);
1135  coeff = NULL;
1136 
1137  return NULL;
1138 
1139  }
1140 
1141  cpl_matrix_unwrap(chebyshev);
1142  chebyshev = NULL;
1143 
1144  cpl_matrix_delete(coeff);
1145  coeff = NULL;
1146 
1147  slfit = cpl_image_new(ny, nx, CPL_TYPE_DOUBLE);
1148 
1149  if (slfit == NULL) {
1150  giraffe_chebyshev2d_delete(fit);
1151  fit = NULL;
1152 
1153  return NULL;
1154  }
1155 
1156 
1157  for (i = 0; i < nx; i++) {
1158 
1159  cxdouble* _slfit = cpl_image_get_data(slfit);
1160 
1161  for (j = 0; j < ny; j++) {
1162  cxint k = i * ny + j;
1163  cxdouble value = giraffe_chebyshev2d_eval(fit, i, j);
1164 
1165  _slfit[k] = value > 0. ? value : 0.;
1166  }
1167 
1168  }
1169 
1170  giraffe_chebyshev2d_delete(fit);
1171  fit = NULL;
1172 
1173  }
1174 
1175  return slfit;
1176 }
1177 
1178 
1204 cxint
1205 giraffe_adjust_scattered_light(GiImage* result, const GiImage* image,
1206  const GiLocalization* localization,
1207  const GiImage* bpixel, GiImage* phff,
1208  const GiSLightConfig* config)
1209 {
1210 
1211  const cxchar *const fctid = "giraffe_adjust_scattered_light";
1212 
1213 
1214  if (image == NULL) {
1215  return -1;
1216  }
1217 
1218  if (localization == NULL) {
1219  return -1;
1220  }
1221 
1222  if (localization->locy == NULL || localization->locw == NULL) {
1223  return -1;
1224  }
1225 
1226  if (config == NULL) {
1227  return -2;
1228  }
1229 
1230 
1231  /* FIXME: Remove support for unused code path, namely support for models
1232  * other than 'polynom' and photometric flat fields. This was
1233  * foreseen in the original code, but never implemented.
1234  */
1235 
1236  if (phff != NULL) {
1237  cpl_msg_warning(fctid, "Photometric flat field correction is not "
1238  "implemented! Ignoring photometric flat field.");
1239  }
1240 
1241 
1242  if (strncmp(config->model, "polynom", 7) != 0) {
1243  cpl_msg_error(fctid, "Scattered light model `%s' is not supported!",
1244  config->model);
1245  return -3;
1246  }
1247  else {
1248 
1249  cxint iscount = 0;
1250 
1251  cx_string* s = NULL;
1252 
1253  const cpl_image* _image = giraffe_image_get(image);
1254  const cpl_image* _locy = giraffe_image_get(localization->locy);
1255  const cpl_image* _locw = giraffe_image_get(localization->locw);
1256  const cpl_image* _bpixel = NULL;
1257 
1258  cpl_propertylist* properties = NULL;
1259 
1260  cpl_image* slfit = NULL;
1261 
1262  GiSLightSetup* setup = _giraffe_slightsetup_new(1);
1263 
1264 
1265  setup->xstep = config->xstep;
1266  setup->ystep = config->ystep;
1267  setup->ewidth = config->ewidth;
1268  setup->iswidth = config->iswidth;
1269  setup->istrim = config->istrim;
1270 
1271  cpl_matrix_set(setup->slices, 0, 0, 0);
1272  cpl_matrix_set(setup->slices, 0, 1, cpl_image_get_size_y(_image));
1273  cpl_matrix_set(setup->slices, 0, 2, config->xstep);
1274 
1275 
1276  if (bpixel != NULL) {
1277  _bpixel = giraffe_image_get(bpixel);
1278  }
1279 
1280  slfit = _giraffe_slight_fit_polynom(_image, _locy, _locw, _bpixel,
1281  config->xorder[0],
1282  config->yorder[0],
1283  &iscount, setup);
1284  if (slfit == NULL) {
1285  cpl_msg_error(fctid, "Fitting scattered light model failed!");
1286 
1287  _giraffe_slightsetup_delete(setup);
1288  setup = NULL;
1289 
1290  return 1;
1291  }
1292 
1293  _giraffe_slightsetup_delete(setup);
1294  setup = NULL;
1295 
1296  giraffe_image_set(result, slfit);
1297 
1298  cpl_image_delete(slfit);
1299  slfit = NULL;
1300 
1303  properties = giraffe_image_get_properties(result);
1304 
1305  cpl_propertylist_update_string(properties, GIALIAS_SLMNAME,
1306  config->model);
1307  cpl_propertylist_set_comment(properties, GIALIAS_SLMNAME,
1308  "Scattered light model type.");
1309 
1310 
1311  s = cx_string_new();
1312 
1313  if (strncmp(config->model, "polynom", 7) == 0) {
1314 
1315  cx_string_sprintf(s, "%d:%d", config->xorder[0],
1316  config->yorder[0]);
1317 
1318  cpl_propertylist_update_string(properties, GIALIAS_SLMORDER,
1319  cx_string_get(s));
1320  cpl_propertylist_set_comment(properties, GIALIAS_SLMORDER,
1321  "Scattered light polynom order "
1322  "X:Y.");
1323 
1324  }
1325  else if (strncmp(config->model, "polyfrac", 8) == 0) {
1326 
1327  cx_string_sprintf(s, "%d:%d/%d:%d", config->xorder[0],
1328  config->yorder[0], config->xorder[1],
1329  config->yorder[1]);
1330 
1331  cpl_propertylist_update_string(properties, GIALIAS_SLMORDER,
1332  cx_string_get(s));
1333  cpl_propertylist_set_comment(properties, GIALIAS_SLMORDER,
1334  "Scattered light polynom fraction "
1335  "order Xn:Yn/Xd:Xd.");
1336 
1337  }
1338 
1339 
1340  cx_string_sprintf(s, "%d:%d", config->xstep, config->ystep);
1341 
1342  cpl_propertylist_update_string(properties, GIALIAS_SLMSTEPS,
1343  cx_string_get(s));
1344  cpl_propertylist_set_comment(properties, GIALIAS_SLMSTEPS,
1345  "Scattered light X, Y sampling step.");
1346 
1347  cx_string_delete(s);
1348  s = NULL;
1349 
1350 
1351  cpl_propertylist_update_double(properties, GIALIAS_SLMEWIDTH,
1352  config->ewidth);
1353  cpl_propertylist_set_comment(properties, GIALIAS_SLMEWIDTH,
1354  "Extra pixels added to spectrum "
1355  "width.");
1356 
1357  cpl_propertylist_update_int(properties, GIALIAS_SLMIWIDTH,
1358  config->iswidth);
1359  cpl_propertylist_set_comment(properties, GIALIAS_SLMIWIDTH,
1360  "Minimum required inter-spectrum "
1361  "region width.");
1362 
1363  cpl_propertylist_update_bool(properties, GIALIAS_SLMTRIM,
1364  config->istrim);
1365  cpl_propertylist_set_comment(properties, GIALIAS_SLMTRIM,
1366  "Removal of first and last "
1367  "inter-spectrum region.");
1368 
1369  }
1370 
1371  return 0;
1372 }
1373 
1374 
1386 GiSLightConfig*
1387 giraffe_slight_config_create(cpl_parameterlist* list)
1388 {
1389 
1390  const cxchar* s;
1391 
1392  cpl_parameter* p = NULL;
1393 
1394  GiSLightConfig* config = NULL;
1395 
1396 
1397  if (list == NULL) {
1398  return NULL;
1399  }
1400 
1401  config = cx_calloc(1, sizeof *config);
1402 
1403  p = cpl_parameterlist_find(list, "giraffe.slight.model.name");
1404  config->model = cx_strdup(cpl_parameter_get_string(p));
1405 
1406  if (strncmp(config->model, "polynom", 7) != 0 &&
1407  strncmp(config->model, "polyfrac", 8) != 0) {
1409  return NULL;
1410  }
1411 
1412  p = cpl_parameterlist_find(list, "giraffe.slight.model.order");
1413  s = cpl_parameter_get_default_string(p);
1414 
1415  if (sscanf(s, "%d,%d", &config->xorder[0], &config->yorder[0]) != 2) {
1417  return NULL;
1418  }
1419 
1420  config->xorder[1] = 0;
1421  config->yorder[1] = 0;
1422 
1423  s = cpl_parameter_get_string(p);
1424 
1425  if (s == NULL) {
1427  return NULL;
1428  }
1429  else {
1430 
1431  cxchar** values = cx_strsplit(s, ",", 5);
1432 
1433  if (values == NULL) {
1435  return NULL;
1436  }
1437  else {
1438 
1439  cxchar* last;
1440 
1441  config->xorder[0] = strtol(values[0], &last, 10);
1442 
1443  if (*last != '\0') {
1444  cx_strfreev(values);
1446 
1447  return NULL;
1448  }
1449 
1450  if (values[1] != NULL) {
1451 
1452  config->yorder[0] = strtol(values[1], &last, 10);
1453 
1454  if (*last != '\0') {
1455  cx_strfreev(values);
1457 
1458  return NULL;
1459  }
1460 
1461  }
1462 
1463  if (strncmp(config->model, "polyfrac", 8) == 0) {
1464 
1465  if (values[2] != NULL) {
1466 
1467  config->xorder[1] = strtol(values[2], &last, 10);
1468 
1469  if (*last != '\0') {
1470  cx_strfreev(values);
1472 
1473  return NULL;
1474  }
1475 
1476  }
1477 
1478  if (values[3] != NULL) {
1479 
1480  config->yorder[1] = strtol(values[3], &last, 10);
1481 
1482  if (*last != '\0') {
1483  cx_strfreev(values);
1485 
1486  return NULL;
1487  }
1488 
1489  }
1490 
1491  }
1492 
1493  cx_strfreev(values);
1494  values = NULL;
1495 
1496  }
1497 
1498  }
1499 
1500 
1501  p = cpl_parameterlist_find(list, "giraffe.slight.xstep");
1502  config->xstep = cpl_parameter_get_int(p);
1503 
1504  p = cpl_parameterlist_find(list, "giraffe.slight.ystep");
1505  config->ystep = cpl_parameter_get_int(p);
1506 
1507  p = cpl_parameterlist_find(list, "giraffe.slight.xslice");
1508  s = cpl_parameter_get_default_string(p);
1509 
1510 
1511  /* FIXME: Whether slices should be supported is still TBD. Currently
1512  * there the parameter is accepted, but its support is not
1513  * implemented!
1514  */
1515 
1516  if (strncmp(s, "none", 4) != 0) {
1518  return NULL;
1519  }
1520 
1521  s = cpl_parameter_get_string(p);
1522 
1523  if (s == NULL) {
1525  return NULL;
1526  }
1527  else {
1528 
1529  cxchar** slices = cx_strsplit(s, ",", -1);
1530 
1531  if (slices == NULL) {
1533  return NULL;
1534  }
1535  else {
1536  cx_strfreev(slices);
1537  slices = NULL;
1538  }
1539 
1540  }
1541 
1542 
1543  p = cpl_parameterlist_find(list, "giraffe.slight.ewidth");
1544  config->ewidth = cpl_parameter_get_double(p);
1545 
1546  p = cpl_parameterlist_find(list, "giraffe.slight.iswidth");
1547  config->iswidth = cpl_parameter_get_int(p);
1548 
1549  p = cpl_parameterlist_find(list, "giraffe.slight.istrim");
1550  config->istrim = cpl_parameter_get_bool(p);
1551 
1552  p = cpl_parameterlist_find(list, "giraffe.slight.phffcorrection");
1553  config->phffcor = cpl_parameter_get_bool(p);
1554 
1555  p = cpl_parameterlist_find(list, "giraffe.slight.remove");
1556  config->remove = cpl_parameter_get_bool(p);
1557 
1558  return config;
1559 
1560 }
1561 
1562 
1576 void
1577 giraffe_slight_config_destroy(GiSLightConfig *config)
1578 {
1579 
1580  if (config != NULL) {
1581 
1582  if (config->model != NULL) {
1583  cx_free((cxchar*)config->model);
1584  config->model = NULL;
1585  }
1586 
1587  cx_free(config);
1588 
1589  }
1590 
1591  return;
1592 
1593 }
1594 
1595 
1608 void
1609 giraffe_slight_config_add(cpl_parameterlist* list)
1610 {
1611 
1612  cpl_parameter* p;
1613 
1614 
1615  if (list == NULL) {
1616  return;
1617  }
1618 
1619  p = cpl_parameter_new_enum("giraffe.slight.model.name",
1620  CPL_TYPE_STRING,
1621  "Name of the scattered light model to use.",
1622  "giraffe.slight",
1623  "polynom", 2, "polynom", "polyfrac");
1624  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "slight-model");
1625  cpl_parameterlist_append(list, p);
1626 
1627 
1628  p = cpl_parameter_new_value("giraffe.slight.model.order",
1629  CPL_TYPE_STRING,
1630  "Scattered light model fit X and Y order.",
1631  "giraffe.slight",
1632  "4,2");
1633  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "slight-order");
1634  cpl_parameterlist_append(list, p);
1635 
1636 
1637  p = cpl_parameter_new_value("giraffe.slight.xstep",
1638  CPL_TYPE_INT,
1639  "Interspectrum region sampling step along "
1640  "the dispersion direction.",
1641  "giraffe.slight",
1642  10);
1643  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "slight-xstep");
1644  cpl_parameterlist_append(list, p);
1645 
1646 
1647  p = cpl_parameter_new_value("giraffe.slight.ystep",
1648  CPL_TYPE_INT,
1649  "Interspectrum region sampling step along "
1650  "the spatial direction.",
1651  "giraffe.slight",
1652  1);
1653  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "slight-ystep");
1654  cpl_parameterlist_append(list, p);
1655 
1656 
1657  p = cpl_parameter_new_value("giraffe.slight.xslice",
1658  CPL_TYPE_STRING,
1659  "Interspectrum region sampling step along "
1660  "the dispersion direction for a specific "
1661  "region. This overrides 'xstep' for the "
1662  "given region.",
1663  "giraffe.slight",
1664  "none");
1665  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "slight-xslice");
1666  cpl_parameterlist_append(list, p);
1667 
1668 
1669  p = cpl_parameter_new_value("giraffe.slight.ewidth",
1670  CPL_TYPE_DOUBLE,
1671  "Extra width [pixels] added to both sides "
1672  "of a spectrum trace.",
1673  "giraffe.slight",
1674  0.5);
1675  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "slight-ewidth");
1676  cpl_parameterlist_append(list, p);
1677 
1678 
1679  p = cpl_parameter_new_value("giraffe.slight.iswidth",
1680  CPL_TYPE_INT,
1681  "Minimum width [pixels] required for "
1682  "interspectrum regions.",
1683  "giraffe.slight",
1684  2);
1685  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "slight-iswidth");
1686  cpl_parameterlist_append(list, p);
1687 
1688 
1689  p = cpl_parameter_new_value("giraffe.slight.istrim",
1690  CPL_TYPE_BOOL,
1691  "Turn off using the first and last "
1692  "interspectrum region.",
1693  "giraffe.slight",
1694  TRUE);
1695  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "slight-istrim");
1696  cpl_parameterlist_append(list, p);
1697 
1698 
1699  p = cpl_parameter_new_value("giraffe.slight.phffcorrection",
1700  CPL_TYPE_BOOL,
1701  "Use photometric flat field correction.",
1702  "giraffe.slight",
1703  FALSE);
1704  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "slight-phff");
1705  cpl_parameterlist_append(list, p);
1706 
1707 
1708  p = cpl_parameter_new_value("giraffe.slight.remove",
1709  CPL_TYPE_BOOL,
1710  "Remove scattered light from the input "
1711  "frame.",
1712  "giraffe.slight",
1713  FALSE);
1714  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "slight-remove");
1715  cpl_parameterlist_append(list, p);
1716 
1717  return;
1718 
1719 }
cxint giraffe_image_set(GiImage *self, cpl_image *image)
Sets the image data.
Definition: giimage.c:252
cxint giraffe_adjust_scattered_light(GiImage *result, const GiImage *image, const GiLocalization *localization, const GiImage *bpixel, GiImage *phff, const GiSLightConfig *config)
Compute a scattered light model for a given image.
Definition: gislight.c:1205
cpl_image * giraffe_image_get(const GiImage *self)
Gets the image data.
Definition: giimage.c:226
cpl_matrix * giraffe_matrix_leastsq(const cpl_matrix *mA, const cpl_matrix *mB)
Computes the solution of an equation using a pseudo-inverse.
Definition: gimatrix.c:511
cxint giraffe_image_set_properties(GiImage *self, cpl_propertylist *properties)
Attaches a property list to an image.
Definition: giimage.c:320
GiSLightConfig * giraffe_slight_config_create(cpl_parameterlist *list)
Creates a setup structure for the scattered light computation.
Definition: gislight.c:1387
cpl_propertylist * giraffe_image_get_properties(const GiImage *self)
Get the properties of an image.
Definition: giimage.c:290
void giraffe_slight_config_destroy(GiSLightConfig *config)
Destroys a scattered light setup structure.
Definition: gislight.c:1577
void giraffe_slight_config_add(cpl_parameterlist *list)
Adds parameters for the scattered light computation.
Definition: gislight.c:1609

This file is part of the GIRAFFE Pipeline Reference Manual 2.14.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Wed Mar 11 2015 13:19:42 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2004