GIRAFFE Pipeline Reference Manual

giwavecalibration.c
1/*
2 * This file is part of the GIRAFFE Pipeline
3 * Copyright (C) 2002-2019 European Southern Observatory
4 *
5 * This program 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, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21# include <config.h>
22#endif
23
24#include <math.h>
25
26#include <cxtypes.h>
27#include <cxmemory.h>
28#include <cxmessages.h>
29
30#include <cpl_recipe.h>
31#include <cpl_plugininfo.h>
32#include <cpl_parameterlist.h>
33#include <cpl_frameset.h>
34#include <cpl_propertylist.h>
35
36#include "gialias.h"
37#include "gierror.h"
38#include "giframe.h"
39#include "giwindow.h"
40#include "gifibers.h"
41#include "gislitgeometry.h"
42#include "gipsfdata.h"
43#include "gifiberutils.h"
44#include "gibias.h"
45#include "giextract.h"
46#include "giqclog.h"
47#include "giutils.h"
48#include "giwlcalibration.h"
49#include "girebinning.h"
50#include "gisgcalibration.h"
51
52
53static cxint giwavecalibration(cpl_parameterlist* config, cpl_frameset* set);
54static cxint giqcwavecalibration(cpl_parameterlist* config, cpl_frameset* set);
55
56
57/*
58 * Create the recipe instance, i.e. setup the parameter list for this
59 * recipe and make it available to the application using the interface.
60 */
61
62static cxint
63giwavecalibration_create(cpl_plugin* plugin)
64{
65
66 cpl_recipe* recipe = (cpl_recipe*)plugin;
67
68 cpl_parameter* p;
69
70
71 giraffe_error_init();
72
73
74 /*
75 * We have to provide the options we accept to the application. We
76 * need to setup our parameter list and hook it into the recipe
77 * interface.
78 */
79
80 recipe->parameters = cpl_parameterlist_new();
81 cx_assert(recipe->parameters != NULL);
82
83 /*
84 * Fill the parameter list.
85 */
86
87 /* Bias Removal */
88
89 giraffe_bias_config_add(recipe->parameters);
90
91 /* Flat Fielding */
92 /* Not Yet Implemented */
93
94 /* Spectrum Extraction */
95
96 giraffe_extract_config_add(recipe->parameters);
97
98 /* Wavelength Calibration */
99
100 giraffe_wlcalibration_config_add(recipe->parameters);
101
102 /* Arc-lamp spectrum rebinning */
103
104 p = cpl_parameter_new_value("giraffe.wcal.rebin",
105 CPL_TYPE_BOOL,
106 "Rebin extracted arc-lamp spectra.",
107 "giraffe.wcal",
108 TRUE);
109
110 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "wcal-rebin");
111 cpl_parameterlist_append(recipe->parameters, p);
112
113 giraffe_rebin_config_add(recipe->parameters);
114
115 /* Slit geometry calibration */
116
117 p = cpl_parameter_new_value("giraffe.wcal.slitgeometry",
118 CPL_TYPE_BOOL,
119 "Controls the slit geometry calibration.",
120 "giraffe.wcal",
121 FALSE);
122
123 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "wcal-slit");
124 cpl_parameterlist_append(recipe->parameters, p);
125
126 giraffe_sgcalibration_config_add(recipe->parameters);
127
128 /* SIMLAMP QC parameter generation */
129
130 p = cpl_parameter_new_value("giraffe.wcal.qc.simlamp", CPL_TYPE_BOOL,
131 "Controls creation of SIMLAMP QC parameters.",
132 "giraffe.wcal", FALSE);
133
134 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "wcal-qcsim");
135 cpl_parameterlist_append(recipe->parameters, p);
136
137 giraffe_sgcalibration_config_add(recipe->parameters);
138
139 return 0;
140
141}
142
143/*
144 * Execute the plugin instance given by the interface.
145 */
146
147static cxint
148giwavecalibration_exec(cpl_plugin* plugin)
149{
150
151 cpl_recipe* recipe = (cpl_recipe*)plugin;
152
153 cxint status = 0;
154
155
156 if (recipe->parameters == NULL || recipe->frames == NULL) {
157 return 1;
158 }
159
160 status = giwavecalibration(recipe->parameters, recipe->frames);
161
162 if (status != 0) {
163 return 1;
164 }
165
166 status = giqcwavecalibration(recipe->parameters, recipe->frames);
167
168 if (status != 0) {
169 return 1;
170 }
171
172 return 0;
173
174}
175
176
177static cxint
178giwavecalibration_destroy(cpl_plugin* plugin)
179{
180
181 cpl_recipe* recipe = (cpl_recipe*)plugin;
182
183
184 /*
185 * We just destroy what was created during the plugin initialization
186 * phase, i.e. the parameter list. The frame set is managed by the
187 * application which called us, so we must not touch it,
188 */
189
190 cpl_parameterlist_delete(recipe->parameters); recipe->parameters = NULL;
191
192 giraffe_error_clear();
193
194 return 0;
195
196}
197
198/*
199 * The actual recipe starts here.
200 */
201
202static cxint
203giwavecalibration(cpl_parameterlist* config, cpl_frameset* set)
204{
205
206 const cxchar* const fctid = "giwavecalibration";
207
208
209 const cxchar* filename = NULL;
210
211 cxbool rebin = FALSE;
212 cxbool slitgeometry = FALSE;
213
214 cxint status = 0;
215 cxint narcspectrum = 0;
216
217 const cpl_propertylist* properties = NULL;
218
219 cpl_frame* arcspec_frame = NULL;
220 cpl_frame* bpixel_frame = NULL;
221 cpl_frame* mbias_frame = NULL;
222 cpl_frame* mlocy_frame = NULL;
223 cpl_frame* mlocw_frame = NULL;
224 cpl_frame* psfdata_frame = NULL;
225 cpl_frame* slight_frame = NULL;
226 cpl_frame* grating_frame = NULL;
227 cpl_frame* slitgeo_frame = NULL;
228 cpl_frame* lines_frame = NULL;
229 cpl_frame* wcal_frame = NULL;
230 cpl_frame* ldata_frame = NULL;
231 cpl_frame* scal_frame = NULL;
232 cpl_frame* sext_frame = NULL;
233
234 cpl_parameter* p = NULL;
235
236 cpl_matrix* biasareas = NULL;
237
238 GiImage* arcspectrum = NULL;
239 GiImage* bsarcspectrum = NULL;
240 GiImage* slight = NULL;
241 GiImage* mbias = NULL;
242 GiImage* bpixel = NULL;
243
244 GiLocalization* localization = NULL;
245 GiExtraction* extraction = NULL;
246 GiRebinning* rebinning = NULL;
247 GiWCalData* wlsolution = NULL;
248
249 GiTable* fibers = NULL;
250 GiTable* grating = NULL;
251 GiTable* slitgeo = NULL;
252 GiTable* wavelengths = NULL;
253 GiTable* wcal_initial = NULL;
254
255// GiWcalSolution* wcal_solution = NULL;
256
257 GiBiasConfig* bias_config = NULL;
258 GiExtractConfig* extract_config = NULL;
259 GiWCalConfig* wcal_config = NULL;
260
261 GiFrameCreator creator = NULL;
262
263 GiRecipeInfo info = {(cxchar*)fctid, 1, NULL, config};
264
265 GiGroupInfo groups[] = {
266 {GIFRAME_ARC_SPECTRUM, CPL_FRAME_GROUP_RAW},
267 {GIFRAME_BADPIXEL_MAP, CPL_FRAME_GROUP_CALIB},
268 {GIFRAME_BIAS_MASTER, CPL_FRAME_GROUP_CALIB},
269 {GIFRAME_SCATTERED_LIGHT_MODEL, CPL_FRAME_GROUP_CALIB},
270 {GIFRAME_LOCALIZATION_CENTROID, CPL_FRAME_GROUP_CALIB},
271 {GIFRAME_LOCALIZATION_WIDTH, CPL_FRAME_GROUP_CALIB},
272 {GIFRAME_PSF_CENTROID, CPL_FRAME_GROUP_CALIB},
273 {GIFRAME_PSF_WIDTH, CPL_FRAME_GROUP_CALIB},
274 {GIFRAME_PSF_DATA, CPL_FRAME_GROUP_CALIB},
275 {GIFRAME_WAVELENGTH_SOLUTION, CPL_FRAME_GROUP_CALIB},
276 {GIFRAME_SLITSETUP, CPL_FRAME_GROUP_CALIB},
277 {GIFRAME_SLITMASTER, CPL_FRAME_GROUP_CALIB},
278 {GIFRAME_GRATING, CPL_FRAME_GROUP_CALIB},
279 {GIFRAME_LINE_CATALOG, CPL_FRAME_GROUP_CALIB},
280 {GIFRAME_LINE_MASK, CPL_FRAME_GROUP_CALIB},
281 {NULL, CPL_FRAME_GROUP_NONE}
282 };
283
284
285
286 cpl_parameter * simcalp = cpl_parameterlist_find(config, "giraffe.wcal.qc.simlamp");
287
288 cxbool qc_simlamp_flag = FALSE;
289
290 if (simcalp != NULL) {
291 qc_simlamp_flag = cpl_parameter_get_bool(simcalp);
292 }
293
294 char* giframe_arc_lamp_extspectra = GIFRAME_ARC_LAMP_EXTSPECTRA;
295 char* giframe_arc_lamp_exterrors = GIFRAME_ARC_LAMP_EXTERRORS;
296 char* giframe_arc_lamp_extpixels = GIFRAME_ARC_LAMP_EXTPIXELS;
297 char* giframe_arc_lamp_exttrace = GIFRAME_ARC_LAMP_EXTTRACE;
298 char* giframe_arc_lamp_rbnspectra = GIFRAME_ARC_LAMP_RBNSPECTRA;
299 char* giframe_arc_lamp_rbnerrors = GIFRAME_ARC_LAMP_RBNERRORS;
300 char* giframe_line_data = GIFRAME_LINE_DATA;
301 char* giframe_wavelength_solution = GIFRAME_WAVELENGTH_SOLUTION;
302
303 if(qc_simlamp_flag) {
304 giframe_arc_lamp_extspectra = GIFRAME_ARC_LAMP_EXTSPECTRA_SIM;
305 giframe_arc_lamp_exterrors = GIFRAME_ARC_LAMP_EXTERRORS_SIM;
306 giframe_arc_lamp_extpixels = GIFRAME_ARC_LAMP_EXTPIXELS_SIM;
307 giframe_arc_lamp_exttrace = GIFRAME_ARC_LAMP_EXTTRACE_SIM;
308 giframe_arc_lamp_rbnspectra = GIFRAME_ARC_LAMP_RBNSPECTRA_SIM;
309 giframe_arc_lamp_rbnerrors = GIFRAME_ARC_LAMP_RBNERRORS_SIM;
310 giframe_line_data = GIFRAME_LINE_DATA_SIM;
311 giframe_wavelength_solution = GIFRAME_WAVELENGTH_SOLUTION_SIM;
312 }
313
314
315
316 if (!config) {
317 cpl_msg_error(fctid, "Invalid parameter list! Aborting ...");
318 return 1;
319 }
320
321 if (!set) {
322 cpl_msg_error(fctid, "Invalid frame set! Aborting ...");
323 return 1;
324 }
325
326 p = cpl_parameterlist_find(config, "giraffe.wcal.rebin");
327
328 if (p != NULL) {
329 rebin = cpl_parameter_get_bool(p);
330 }
331
332 p = cpl_parameterlist_find(config, "giraffe.wcal.slitgeometry");
333
334 if (p != NULL) {
335 slitgeometry = cpl_parameter_get_bool(p);
336 }
337
338 status = giraffe_frameset_set_groups(set, groups);
339
340 if (status != 0) {
341 cpl_msg_error(fctid, "Setting frame group information failed!");
342 return 1;
343 }
344
345
346 /*************************************************************************
347 Preprocessing
348 *************************************************************************/
349
350 cpl_msg_info(fctid, "Recipe Step : Initialization");
351
352 /*
353 * Verify the frame set contents
354 */
355
356 narcspectrum = cpl_frameset_count_tags(set, GIFRAME_ARC_SPECTRUM);
357
358 if (narcspectrum > 1) {
359 cpl_msg_error(fctid, "Only one arc spectrum frame allowed! "
360 "Aborting...");
361 return 1;
362 }
363 else if (narcspectrum < 1) {
364 cpl_msg_error(fctid, "Arc spectrum frame is missing! "
365 "Aborting...");
366 return 1;
367 }
368
369 arcspec_frame = cpl_frameset_find(set, GIFRAME_ARC_SPECTRUM);
370 bpixel_frame = cpl_frameset_find(set, GIFRAME_BADPIXEL_MAP);
371
372 if (!bpixel_frame) {
373 cpl_msg_info(fctid, "No bad pixel map present in frame set.");
374 }
375
376 mbias_frame = cpl_frameset_find(set, GIFRAME_BIAS_MASTER);
377
378 if (!mbias_frame) {
379 cpl_msg_info(fctid, "No master bias present in frame set.");
380 }
381
382 mlocy_frame = cpl_frameset_find(set, GIFRAME_PSF_CENTROID);
383
384 if (mlocy_frame == NULL) {
385
386 mlocy_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_CENTROID);
387
388 if (mlocy_frame == NULL) {
389 cpl_msg_info(fctid, "No master localization (centroid position) "
390 "present in frame set. Aborting ...");
391 return 1;
392 }
393
394 }
395
396 mlocw_frame = cpl_frameset_find(set, GIFRAME_PSF_WIDTH);
397
398 if (mlocw_frame == NULL) {
399
400 mlocw_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_WIDTH);
401
402 if (mlocw_frame == NULL) {
403 cpl_msg_info(fctid, "No master localization (spectrum width) "
404 "present in frame set. Aborting ...");
405 return 1;
406 }
407
408 }
409
410 psfdata_frame = cpl_frameset_find(set, GIFRAME_PSF_DATA);
411
412 if (!psfdata_frame) {
413 cpl_msg_info(fctid, "No PSF profile parameters present in frame set.");
414 }
415
416 slight_frame = cpl_frameset_find(set, GIFRAME_SCATTERED_LIGHT_MODEL);
417
418 if (!slight_frame) {
419 cpl_msg_info(fctid, "No scattered light model present in frame set.");
420 }
421
422 grating_frame = cpl_frameset_find(set, GIFRAME_GRATING);
423
424 if (!grating_frame) {
425 cpl_msg_error(fctid, "No grating table present in frame set, "
426 "aborting...");
427 return 1;
428 }
429
430 slitgeo_frame = giraffe_get_slitgeometry(set);
431
432 if (!slitgeo_frame) {
433 cpl_msg_error(fctid, "No slit geometry table present in frame "
434 "set, aborting...");
435 return 1;
436 }
437
438 lines_frame = cpl_frameset_find(set, GIFRAME_LINE_CATALOG);
439
440 if (!lines_frame) {
441 cpl_msg_error(fctid, "No wavelength table present in frame set, "
442 "aborting...");
443 return 1;
444 }
445
446 wcal_frame = cpl_frameset_find(set, GIFRAME_WAVELENGTH_SOLUTION);
447
448 if (!wcal_frame) {
449 cpl_msg_info(fctid, "No wavelength solution present in frame set.");
450 }
451
452 scal_frame = cpl_frameset_find(set, GIFRAME_LINE_MASK);
453
454 if (!scal_frame) {
455
456 if (slitgeometry == TRUE) {
457 cpl_msg_error(fctid, "No line mask present in frame "
458 "set. Aborting ...");
459 return 1;
460 }
461 else {
462 cpl_msg_info(fctid, "No slit geometry mask present in frame "
463 "set.");
464 }
465
466 }
467
468
469 /*************************************************************************
470 Processing
471 *************************************************************************/
472
473 /*
474 * Load bad pixel map if it is present in the frame set.
475 */
476
477 if (bpixel_frame) {
478
479 filename = cpl_frame_get_filename(bpixel_frame);
480
481 bpixel = giraffe_image_new(CPL_TYPE_INT);
482 status = giraffe_image_load(bpixel, filename, 0);
483
484 if (status) {
485 cpl_msg_error(fctid, "Cannot load bad pixel map from '%s'. "
486 "Aborting ...", filename);
487
488 giraffe_image_delete(bpixel);
489 return 1;
490 }
491 }
492
493
494 /*
495 * Load arc spectrum
496 */
497
498 //status = 0;
499 filename = cpl_frame_get_filename(arcspec_frame);
500
501 arcspectrum = giraffe_image_new(CPL_TYPE_DOUBLE);
502 status = giraffe_image_load(arcspectrum, filename, 0);
503
504 if (status) {
505 cpl_msg_error(fctid, "Cannot load arc spectrum from '%s'. "
506 "Aborting...", filename);
507
508 giraffe_image_delete(bpixel);
509 giraffe_image_delete(arcspectrum);
510 return 1;
511 }
512
513
514 /*
515 * Prepare bias subtraction
516 */
517
518 cpl_msg_info(fctid, "Recipe Step : Bias Removal");
519
520 bias_config = giraffe_bias_config_create(config);
521
522 /*
523 * Setup user defined areas to use for the bias computation
524 */
525
526 if (bias_config->method == GIBIAS_METHOD_MASTER ||
527 bias_config->method == GIBIAS_METHOD_ZMASTER) {
528
529 if (!mbias_frame) {
530 cpl_msg_error(fctid, "Missing master bias frame! Selected bias "
531 "removal method requires a master bias "
532 "frame!");
533
534 giraffe_image_delete(bpixel);
535 giraffe_image_delete(arcspectrum);
536 giraffe_bias_config_destroy(bias_config);
537
538 return 1;
539 }
540 else {
541
542 //status = 0;
543 filename = cpl_frame_get_filename(mbias_frame);
544
545 mbias = giraffe_image_new(CPL_TYPE_DOUBLE);
546 status = giraffe_image_load(mbias, filename, 0);
547
548 if (status) {
549 cpl_msg_error(fctid, "Cannot load master bias from '%s'. "
550 "Aborting ...", filename);
551
552 giraffe_image_delete(bpixel);
553 giraffe_image_delete(arcspectrum);
555 giraffe_bias_config_destroy(bias_config);
556
557 return 1;
558 }
559 }
560 }
561
562
563 /*
564 * Compute and remove the bias from the stacked flat field frame.
565 */
566
567 bsarcspectrum = giraffe_image_new(CPL_TYPE_DOUBLE);
568
569 status = giraffe_bias_remove(bsarcspectrum, arcspectrum, mbias, bpixel,
570 biasareas, bias_config);
571
572 giraffe_image_delete(arcspectrum);
573 arcspectrum = NULL;
574
575 if (mbias) {
577 mbias = NULL;
578 }
579
580 giraffe_bias_config_destroy(bias_config);
581 bias_config = NULL;
582
583 if (status) {
584 cpl_msg_error(fctid, "Bias removal failed. Aborting ...");
585
586 giraffe_image_delete(bpixel);
587 giraffe_image_delete(bsarcspectrum);
588 return 1;
589 }
590
591
592 /*
593 * Determine fiber setup
594 */
595
596 cpl_msg_info(fctid, "Recipe Step : Fiber Setup");
597
598 cpl_msg_info(fctid, "Building fiber setup for frame '%s'.",
599 cpl_frame_get_filename(arcspec_frame));
600
601 fibers = giraffe_fibers_setup(arcspec_frame, mlocy_frame);
602
603 if (!fibers) {
604 cpl_msg_error(fctid, "Cannot create fiber setup for frame '%s'! "
605 "Aborting ...", cpl_frame_get_filename(arcspec_frame));
606
607 giraffe_image_delete(bpixel);
608 giraffe_image_delete(bsarcspectrum);
609
610 return 1;
611 }
612
613 cpl_msg_info(fctid, "Fiber reference setup taken from localization "
614 "frame '%s'.", cpl_frame_get_filename(mlocy_frame));
615
616
617 /*
618 * Load spectrum localization.
619 */
620
621 localization = giraffe_localization_new();
622
623 filename = cpl_frame_get_filename(mlocy_frame);
624 //status = 0;
625
626 localization->locy = giraffe_image_new(CPL_TYPE_DOUBLE);
627 status = giraffe_image_load(localization->locy, filename, 0);
628
629 if (status) {
630 cpl_msg_error(fctid, "Cannot load localization (centroid "
631 "position) frame from '%s'. Aborting ...",
632 filename);
633
634 giraffe_localization_destroy(localization);
635 giraffe_image_delete(bpixel);
636 giraffe_image_delete(bsarcspectrum);
637 giraffe_table_delete(fibers);
638
639 return 1;
640
641 }
642
643
644 filename = cpl_frame_get_filename(mlocw_frame);
645 //status = 0;
646
647 localization->locw = giraffe_image_new(CPL_TYPE_DOUBLE);
648 status = giraffe_image_load(localization->locw, filename, 0);
649
650 if (status) {
651 cpl_msg_error(fctid, "Cannot load localization (spectrum width) "
652 "frame from '%s'. Aborting ...", filename);
653
654 giraffe_localization_destroy(localization);
655 giraffe_image_delete(bpixel);
656 giraffe_image_delete(bsarcspectrum);
657 giraffe_table_delete(fibers);
658
659 return 1;
660
661 }
662
663
664 /*
665 * Perform spectrum extraction on the master flat field.
666 */
667
668 cpl_msg_info(fctid, "Recipe Step : Spectrum Extraction");
669
670 if (slight_frame) {
671
672 filename = cpl_frame_get_filename(slight_frame);
673 //status = 0;
674
675 slight = giraffe_image_new(CPL_TYPE_DOUBLE);
676 status = giraffe_image_load(slight, filename, 0);
677
678 if (status) {
679 cpl_msg_error(fctid, "Cannot load scattered light model from "
680 "'%s'. Aborting ...", filename);
681
682 giraffe_image_delete(bpixel);
683 giraffe_image_delete(bsarcspectrum);
684 giraffe_table_delete(fibers);
685 giraffe_localization_destroy(localization);
686 giraffe_image_delete(slight);
687
688 return 1;
689
690 }
691
692 }
693
694 extract_config = giraffe_extract_config_create(config);
695
696 if ((extract_config->emethod == GIEXTRACT_OPTIMAL) ||
697 (extract_config->emethod == GIEXTRACT_HORNE)) {
698
699 if (psfdata_frame == NULL) {
700
701 const cxchar* emethod = "Optimal";
702
703 if (extract_config->emethod == GIEXTRACT_HORNE) {
704 emethod = "Horne";
705 }
706
707 cpl_msg_error(fctid, "%s spectrum extraction requires PSF "
708 "profile data. Aborting ...", emethod);
709
710 giraffe_extract_config_destroy(extract_config);
711 extract_config = NULL;
712
713 if (slight != NULL) {
714 giraffe_image_delete(slight);
715 slight = NULL;
716 }
717
718 giraffe_localization_destroy(localization);
719 localization = NULL;
720
721 if (bpixel) {
722 giraffe_image_delete(bpixel);
723 bpixel = NULL;
724 }
725
726 giraffe_table_delete(fibers);
727 fibers = NULL;
728
729 giraffe_image_delete(bsarcspectrum);
730 bsarcspectrum = NULL;
731
732 return 1;
733
734 }
735 else {
736
737 filename = cpl_frame_get_filename(psfdata_frame);
738 //status = 0;
739
740 localization->psf = giraffe_psfdata_new();
741 status = giraffe_psfdata_load(localization->psf, filename);
742
743 if (status) {
744 cpl_msg_error(fctid, "Cannot load PSF profile data frame from "
745 "'%s'. Aborting ...", filename);
746
747 giraffe_extract_config_destroy(extract_config);
748 extract_config = NULL;
749
750 if (slight != NULL) {
751 giraffe_image_delete(slight);
752 slight = NULL;
753 }
754
755 giraffe_localization_destroy(localization);
756 localization = NULL;
757
758 if (bpixel) {
759 giraffe_image_delete(bpixel);
760 bpixel = NULL;
761 }
762
763 giraffe_table_delete(fibers);
764 fibers = NULL;
765
766 giraffe_image_delete(bsarcspectrum);
767 bsarcspectrum = NULL;
768
769 return 1;
770
771 }
772
773 }
774
775 }
776
777
778 extraction = giraffe_extraction_new();
779
780 status = giraffe_extract_spectra(extraction, bsarcspectrum, fibers,
781 localization, bpixel, slight,
782 extract_config);
783
784 if (status) {
785 cpl_msg_error(fctid, "Spectrum extraction failed! Aborting ...");
786
787 giraffe_image_delete(bpixel);
788 giraffe_image_delete(bsarcspectrum);
789 giraffe_table_delete(fibers);
790 giraffe_localization_destroy(localization);
791 giraffe_image_delete(slight);
792 giraffe_extract_config_destroy(extract_config);
793 giraffe_extraction_destroy(extraction);
794
795 return 1;
796 }
797
798 giraffe_image_delete(slight);
799 slight = NULL;
800
801 giraffe_image_delete(bpixel);
802 bpixel = NULL;
803
804 giraffe_image_delete(bsarcspectrum);
805 bsarcspectrum = NULL;
806
807 giraffe_extract_config_destroy(extract_config);
808 extract_config = NULL;
809
810 /*
811 * Save the spectrum extraction results and register them as
812 * products.
813 */
814
815 cpl_msg_info(fctid, "Writing extracted spectra ...");
816
817 /* Extracted spectra */
818
819 giraffe_image_add_info(extraction->spectra, &info, set);
820
821 sext_frame = giraffe_frame_create_image(extraction->spectra,
822 giframe_arc_lamp_extspectra,
823 CPL_FRAME_LEVEL_INTERMEDIATE,
824 TRUE, TRUE);
825
826 if (sext_frame == NULL) {
827 cpl_msg_error(fctid, "Cannot create local file! Aborting ...");
828
829 giraffe_table_delete(fibers);
830
831 giraffe_localization_destroy(localization);
832 giraffe_extraction_destroy(extraction);
833
834 return 1;
835 }
836
837 status = giraffe_fiberlist_attach(sext_frame, fibers);
838
839 if (status) {
840 cpl_msg_error(fctid, "Cannot attach fiber setup to local file '%s'! "
841 "Aborting ...", cpl_frame_get_filename(sext_frame));
842
843 cpl_frame_delete(sext_frame);
844
845 giraffe_table_delete(fibers);
846
847 giraffe_localization_destroy(localization);
848 giraffe_extraction_destroy(extraction);
849
850 return 1;
851 }
852
853 cpl_frameset_insert(set, sext_frame);
854
855 /* Extracted spectra errors */
856
857 giraffe_image_add_info(extraction->error, &info, set);
858
859 sext_frame = giraffe_frame_create_image(extraction->error,
860 giframe_arc_lamp_exterrors,
861 CPL_FRAME_LEVEL_INTERMEDIATE,
862 TRUE, TRUE);
863
864 if (sext_frame == NULL) {
865 cpl_msg_error(fctid, "Cannot create local file! Aborting ...");
866
867 giraffe_table_delete(fibers);
868
869 giraffe_localization_destroy(localization);
870 giraffe_extraction_destroy(extraction);
871
872 return 1;
873 }
874
875 status = giraffe_fiberlist_attach(sext_frame, fibers);
876
877 if (status) {
878 cpl_msg_error(fctid, "Cannot attach fiber setup to local file '%s'! "
879 "Aborting ...", cpl_frame_get_filename(sext_frame));
880
881 cpl_frame_delete(sext_frame);
882
883 giraffe_table_delete(fibers);
884
885 giraffe_localization_destroy(localization);
886 giraffe_extraction_destroy(extraction);
887
888 return 1;
889 }
890
891 cpl_frameset_insert(set, sext_frame);
892
893 /* Extracted spectra pixels */
894
895 if (extraction->npixels != NULL) {
896
897 giraffe_image_add_info(extraction->npixels, &info, set);
898
899 sext_frame = giraffe_frame_create_image(extraction->npixels,
900 giframe_arc_lamp_extpixels,
901 CPL_FRAME_LEVEL_INTERMEDIATE,
902 TRUE, TRUE);
903
904 if (sext_frame == NULL) {
905 cpl_msg_error(fctid, "Cannot create local file! Aborting ...");
906
907 giraffe_table_delete(fibers);
908
909 giraffe_localization_destroy(localization);
910 giraffe_extraction_destroy(extraction);
911
912 return 1;
913 }
914
915 status = giraffe_fiberlist_attach(sext_frame, fibers);
916
917 if (status) {
918 cpl_msg_error(fctid, "Cannot attach fiber setup to local file '%s'! "
919 "Aborting ...", cpl_frame_get_filename(sext_frame));
920
921 cpl_frame_delete(sext_frame);
922
923 giraffe_table_delete(fibers);
924
925 giraffe_localization_destroy(localization);
926 giraffe_extraction_destroy(extraction);
927
928 return 1;
929 }
930
931 cpl_frameset_insert(set, sext_frame);
932
933 }
934
935 /* Extracted spectra centroids */
936
937 giraffe_image_add_info(extraction->centroid, &info, set);
938
939 sext_frame = giraffe_frame_create_image(extraction->centroid,
940 giframe_arc_lamp_exttrace,
941 CPL_FRAME_LEVEL_INTERMEDIATE,
942 TRUE, TRUE);
943
944 if (sext_frame == NULL) {
945 cpl_msg_error(fctid, "Cannot create local file! Aborting ...");
946
947 giraffe_table_delete(fibers);
948
949 giraffe_localization_destroy(localization);
950 giraffe_extraction_destroy(extraction);
951
952 return 1;
953 }
954
955 status = giraffe_fiberlist_attach(sext_frame, fibers);
956
957 if (status) {
958 cpl_msg_error(fctid, "Cannot attach fiber setup to local file '%s'! "
959 "Aborting ...", cpl_frame_get_filename(sext_frame));
960
961 cpl_frame_delete(sext_frame);
962
963 giraffe_table_delete(fibers);
964
965 giraffe_localization_destroy(localization);
966 giraffe_extraction_destroy(extraction);
967
968 return 1;
969 }
970
971 cpl_frameset_insert(set, sext_frame);
972
973 /* Extraction model spectra */
974
975 if (extraction->model != NULL) {
976
977 giraffe_image_add_info(extraction->model, &info, set);
978
979 sext_frame = giraffe_frame_create_image(extraction->model,
980 GIFRAME_ARC_LAMP_EXTMODEL,
981 CPL_FRAME_LEVEL_FINAL,
982 TRUE, TRUE);
983
984 if (sext_frame == NULL) {
985 cpl_msg_error(fctid, "Cannot create local file! Aborting ...");
986
987 giraffe_table_delete(fibers);
988
989 giraffe_localization_destroy(localization);
990 giraffe_extraction_destroy(extraction);
991
992 return 1;
993 }
994
995 status = giraffe_fiberlist_attach(sext_frame, fibers);
996
997 if (status != 0) {
998 cpl_msg_error(fctid, "Cannot attach fiber setup to local file '%s'! "
999 "Aborting ...", cpl_frame_get_filename(sext_frame));
1000
1001 cpl_frame_delete(sext_frame);
1002
1003 giraffe_table_delete(fibers);
1004
1005 giraffe_localization_destroy(localization);
1006 giraffe_extraction_destroy(extraction);
1007
1008 return 1;
1009 }
1010
1011 cpl_frameset_insert(set, sext_frame);
1012
1013 }
1014
1015 /*
1016 * Perform Wavelength Calibration
1017 */
1018
1019 cpl_msg_info(fctid, "Recipe Step : Wavelength Calibration");
1020
1021 filename = cpl_frame_get_filename(grating_frame);
1022 //status = 0;
1023
1024 grating = giraffe_table_new();
1025 status = giraffe_table_load(grating, filename, 1, NULL);
1026
1027 if (status) {
1028 cpl_msg_error(fctid, "Cannot load grating table from '%s'. "
1029 "Aborting ...", filename);
1030
1031 giraffe_table_delete(fibers);
1032 giraffe_localization_destroy(localization);
1033 giraffe_extraction_destroy(extraction);
1034
1035 return 1;
1036 }
1037
1038
1039 filename = cpl_frame_get_filename(slitgeo_frame);
1040
1041 slitgeo = giraffe_slitgeometry_load(fibers, filename, 1, NULL);
1042
1043 if (slitgeo == NULL) {
1044 cpl_msg_error(fctid, "Cannot load slit geometry table from '%s'. "
1045 "Aborting ...", filename);
1046
1047 giraffe_table_delete(fibers);
1048 giraffe_localization_destroy(localization);
1049 giraffe_extraction_destroy(extraction);
1050 giraffe_table_delete(grating);
1051
1052 return 1;
1053 }
1054 else {
1055
1056 /*
1057 * Check whether the contains the positions for all fibers
1058 * provided by the fiber setup. If this is not the case
1059 * this is an error.
1060 */
1061
1062 if (giraffe_fiberlist_compare(slitgeo, fibers) != 1) {
1063 cpl_msg_error(fctid, "Slit geometry data from '%s' is not "
1064 "applicable for current fiber setup! "
1065 "Aborting ...", filename);
1066
1067 giraffe_table_delete(slitgeo);
1068 giraffe_table_delete(fibers);
1069 giraffe_localization_destroy(localization);
1070 giraffe_extraction_destroy(extraction);
1071 giraffe_table_delete(grating);
1072
1073 return 1;
1074 }
1075
1076 }
1077
1078
1079 filename = cpl_frame_get_filename(lines_frame);
1080 //status = 0;
1081
1082 wavelengths = giraffe_table_new();
1083 status = giraffe_table_load(wavelengths, filename, 1, NULL);
1084
1085 if (status) {
1086 cpl_msg_error(fctid, "Cannot load arc-line data from '%s'. "
1087 "Aborting ...", filename);
1088
1089 giraffe_table_delete(fibers);
1090 giraffe_localization_destroy(localization);
1091 giraffe_extraction_destroy(extraction);
1092 giraffe_table_delete(grating);
1093 giraffe_table_delete(slitgeo);
1094
1095 return 1;
1096
1097 }
1098
1099 if (wcal_frame != NULL) {
1100
1101 wcal_initial = giraffe_table_new();
1102
1103 filename = cpl_frame_get_filename(wcal_frame);
1104 status = giraffe_table_load(wcal_initial, filename, 1, NULL);
1105
1106 if (status) {
1107 cpl_msg_error(fctid, "Cannot load initial wavelength solution "
1108 "from '%s'. Aborting ...", filename);
1109
1110 giraffe_table_delete(wcal_initial);
1111
1112 giraffe_table_delete(fibers);
1113 giraffe_localization_destroy(localization);
1114 giraffe_extraction_destroy(extraction);
1115 giraffe_table_delete(grating);
1116 giraffe_table_delete(slitgeo);
1117
1118 return 1;
1119
1120 }
1121
1122 }
1123
1124 wcal_config = giraffe_wlcalibration_config_create(config);
1125
1126 if (wcal_config == NULL) {
1127
1128 cpl_msg_error(fctid, "Could not create wavelength calibration "
1129 "setup: error parsing configuration parameters! "
1130 "Aborting ...");
1131 giraffe_table_delete(fibers);
1132 giraffe_localization_destroy(localization);
1133 giraffe_extraction_destroy(extraction);
1134 giraffe_table_delete(grating);
1135 giraffe_table_delete(slitgeo);
1136 giraffe_table_delete(wavelengths);
1137 giraffe_table_delete(wcal_initial);
1138
1139 return 1;
1140
1141 }
1142
1143 wlsolution = giraffe_wcaldata_new();
1144
1145 status = giraffe_calibrate_wavelength(wlsolution, extraction,
1146 localization, fibers, slitgeo,
1147 grating, wavelengths, wcal_initial,
1148 wcal_config);
1149
1150 if (status) {
1151 cpl_msg_error(fctid, "Error during wavelength calibration, "
1152 "aborting...");
1153
1154 giraffe_table_delete(fibers);
1155 giraffe_localization_destroy(localization);
1156 giraffe_extraction_destroy(extraction);
1157 giraffe_table_delete(grating);
1158 giraffe_table_delete(slitgeo);
1159 giraffe_table_delete(wavelengths);
1160 giraffe_table_delete(wcal_initial);
1161
1162 giraffe_wcaldata_delete(wlsolution);
1164
1165 return 1;
1166
1167 }
1168
1170 wcal_config = NULL;
1171
1172 giraffe_table_delete(wcal_initial);
1173 wcal_initial = NULL;
1174
1175 giraffe_table_delete(wavelengths);
1176 wavelengths = NULL;
1177
1178
1179 /*
1180 * Save and register the wavelength calibration results.
1181 */
1182
1183 /* Coefficients of the x-residuals fit */
1184
1185
1186 giraffe_table_add_info(wlsolution->coeffs, &info, set);
1187
1188 wcal_frame = giraffe_frame_create_table(wlsolution->coeffs,
1189 giframe_wavelength_solution,
1190 CPL_FRAME_LEVEL_FINAL,
1191 TRUE, TRUE);
1192
1193 if (wcal_frame == NULL) {
1194
1195 cpl_msg_error(fctid, "Cannot create local file! Aborting ...");
1196
1197 giraffe_table_delete(fibers);
1198 giraffe_localization_destroy(localization);
1199 giraffe_extraction_destroy(extraction);
1200 giraffe_table_delete(grating);
1201 giraffe_table_delete(slitgeo);
1202
1203 giraffe_wcaldata_delete(wlsolution);
1204
1205 return 1;
1206
1207 }
1208
1209 cpl_frameset_insert(set, wcal_frame);
1210
1211 /* Lines data */
1212
1213 properties = giraffe_table_get_properties(wlsolution->coeffs);
1214 creator = (GiFrameCreator)giraffe_linedata_writer;
1215
1216 ldata_frame = giraffe_frame_create(giframe_line_data,
1217 CPL_FRAME_LEVEL_FINAL,
1218 properties, wlsolution->linedata,
1219 NULL,
1220 creator);
1221
1222 if (ldata_frame == NULL) {
1223
1224 cpl_msg_error(fctid, "Cannot create local file! Aborting ...");
1225
1226 giraffe_table_delete(fibers);
1227 giraffe_localization_destroy(localization);
1228 giraffe_extraction_destroy(extraction);
1229 giraffe_table_delete(grating);
1230 giraffe_table_delete(slitgeo);
1231
1232 giraffe_wcaldata_delete(wlsolution);
1233
1234 properties = NULL;
1235
1236 return 1;
1237
1238 }
1239
1240 properties = NULL;
1241
1242 giraffe_linedata_delete(wlsolution->linedata);
1243 wlsolution->linedata = NULL;
1244
1245 cpl_frameset_insert(set, ldata_frame);
1246
1247
1248 /*
1249 * Optional slit geometry calibration. Note that this step requires a
1250 * rebinned arc-lamp frame as input!
1251 */
1252
1253 if (slitgeometry == TRUE) {
1254
1255 cpl_frame* slit_frame = NULL;
1256
1257 GiSGCalConfig* scal_config = NULL;
1258
1259 GiTable* mask = NULL;
1260 GiTable* slit = NULL;
1261
1262
1263 cpl_msg_info(fctid, "Calibrating slit geometry ...");
1264
1265 scal_config = giraffe_sgcalibration_config_create(config);
1266
1267
1268 filename = cpl_frame_get_filename(scal_frame);
1269
1270 mask = giraffe_table_new();
1271 status = giraffe_table_load(mask, filename, 1, NULL);
1272
1273 if (status != 0) {
1274 cpl_msg_error(fctid, "Cannot load slit geometry mask from '%s'. "
1275 "Aborting ...", filename);
1276
1278
1280
1281 giraffe_wcaldata_delete(wlsolution);
1282
1283 giraffe_localization_destroy(localization);
1284 giraffe_extraction_destroy(extraction);
1285
1286 giraffe_table_delete(fibers);
1287 giraffe_table_delete(grating);
1288 giraffe_table_delete(slitgeo);
1289
1290 return 1;
1291
1292 }
1293
1294 slit = giraffe_table_new();
1295
1296 status = giraffe_calibrate_slit(slit, extraction, localization, fibers,
1297 wlsolution->coeffs, slitgeo, grating,
1298 mask, scal_config);
1299
1300 if (status != 0) {
1301 cpl_msg_error(fctid, "Slit geometry calibration failed! "
1302 "Aborting ...");
1303
1305
1308
1309 giraffe_wcaldata_delete(wlsolution);
1310
1311 giraffe_localization_destroy(localization);
1312 giraffe_extraction_destroy(extraction);
1313
1314 giraffe_table_delete(fibers);
1315 giraffe_table_delete(grating);
1316 giraffe_table_delete(slitgeo);
1317
1318 return 1;
1319
1320 }
1321
1322
1323 /*
1324 * Save and register the slit geometry calibration results.
1325 */
1326
1327
1328 giraffe_table_add_info(slit, &info, set);
1329
1330 slit_frame = giraffe_slitgeometry_save(slit);
1331
1332 if (!slit_frame) {
1333
1334 cpl_msg_error(fctid, "Cannot create local file! Aborting ...");
1335
1337
1340
1341 giraffe_wcaldata_delete(wlsolution);
1342
1343 giraffe_localization_destroy(localization);
1344 giraffe_extraction_destroy(extraction);
1345
1346 giraffe_table_delete(fibers);
1347 giraffe_table_delete(grating);
1348 giraffe_table_delete(slitgeo);
1349
1350 return 1;
1351 }
1352
1353 cpl_frameset_insert(set, slit_frame);
1354
1357
1358
1359 /*
1360 * Replace the slit geometry table with the new one.
1361 */
1362
1363 giraffe_table_delete(slitgeo);
1364 slitgeo = slit;
1365
1366 }
1367
1368
1369 /*
1370 * Optional rebinning of the previously extracted arc-lamp spectra.
1371 */
1372
1373 if (rebin == TRUE) {
1374
1375 cpl_frame* rbin_frame = NULL;
1376
1377 GiRebinConfig* rebin_config;
1378
1379
1380 cpl_msg_info(fctid, "Recipe Step : Spectrum Rebinning");
1381
1382 rebin_config = giraffe_rebin_config_create(config);
1383
1384 rebinning = giraffe_rebinning_new();
1385
1386 status = giraffe_rebin_spectra(rebinning, extraction, fibers,
1387 localization, grating, slitgeo,
1388 wlsolution->coeffs, rebin_config);
1389
1390 if (status) {
1391 cpl_msg_error(fctid, "Rebinning of arc-lamp spectra failed! "
1392 "Aborting...");
1393
1394 giraffe_wcaldata_delete(wlsolution);
1395
1396 giraffe_rebinning_destroy(rebinning);
1397 giraffe_localization_destroy(localization);
1398 giraffe_extraction_destroy(extraction);
1399
1400 giraffe_table_delete(grating);
1401 giraffe_table_delete(slitgeo);
1402 giraffe_table_delete(fibers);
1403
1404 giraffe_rebin_config_destroy(rebin_config);
1405
1406 return 1;
1407
1408 }
1409
1410 giraffe_rebin_config_destroy(rebin_config);
1411
1412 /*
1413 * Save and register the results of the spectrum rebinning.
1414 */
1415
1416 /* Rebinned spectra */
1417
1418 giraffe_image_add_info(rebinning->spectra, &info, set);
1419
1420 rbin_frame = giraffe_frame_create_image(rebinning->spectra,
1421 giframe_arc_lamp_rbnspectra,
1422 CPL_FRAME_LEVEL_FINAL,
1423 TRUE, TRUE);
1424
1425 if (rbin_frame == NULL) {
1426
1427 cpl_msg_error(fctid, "Cannot create local file! Aborting ...");
1428
1429 giraffe_wcaldata_delete(wlsolution);
1430
1431 giraffe_rebinning_destroy(rebinning);
1432 giraffe_localization_destroy(localization);
1433 giraffe_extraction_destroy(extraction);
1434
1435 giraffe_table_delete(grating);
1436 giraffe_table_delete(slitgeo);
1437 giraffe_table_delete(fibers);
1438
1439 return 1;
1440
1441 }
1442
1443 status = giraffe_fiberlist_attach(rbin_frame, fibers);
1444
1445 if (status) {
1446 cpl_msg_error(fctid, "Cannot attach fiber setup to local "
1447 "file '%s'! Aborting ...",
1448 cpl_frame_get_filename(rbin_frame));
1449
1450 giraffe_wcaldata_delete(wlsolution);
1451
1452 giraffe_rebinning_destroy(rebinning);
1453 giraffe_localization_destroy(localization);
1454 giraffe_extraction_destroy(extraction);
1455
1456 giraffe_table_delete(grating);
1457 giraffe_table_delete(slitgeo);
1458 giraffe_table_delete(fibers);
1459
1460 cpl_frame_delete(rbin_frame);
1461
1462 return 1;
1463
1464 }
1465
1466 cpl_frameset_insert(set, rbin_frame);
1467
1468 /* Rebinned spectra errors */
1469
1470 giraffe_image_add_info(rebinning->errors, &info, set);
1471
1472 rbin_frame = giraffe_frame_create_image(rebinning->errors,
1473 giframe_arc_lamp_rbnerrors,
1474 CPL_FRAME_LEVEL_FINAL,
1475 TRUE, TRUE);
1476
1477 if (rbin_frame == NULL) {
1478
1479 cpl_msg_error(fctid, "Cannot create local file! Aborting ...");
1480
1481 giraffe_wcaldata_delete(wlsolution);
1482
1483 giraffe_rebinning_destroy(rebinning);
1484 giraffe_localization_destroy(localization);
1485 giraffe_extraction_destroy(extraction);
1486
1487 giraffe_table_delete(grating);
1488 giraffe_table_delete(slitgeo);
1489 giraffe_table_delete(fibers);
1490
1491 return 1;
1492
1493 }
1494
1495 status = giraffe_fiberlist_attach(rbin_frame, fibers);
1496
1497 if (status) {
1498
1499 cpl_msg_error(fctid, "Cannot attach fiber setup to local "
1500 "file '%s'! Aborting ...",
1501 cpl_frame_get_filename(rbin_frame));
1502
1503 giraffe_wcaldata_delete(wlsolution);
1504
1505 giraffe_rebinning_destroy(rebinning);
1506 giraffe_localization_destroy(localization);
1507 giraffe_extraction_destroy(extraction);
1508
1509 giraffe_table_delete(grating);
1510 giraffe_table_delete(slitgeo);
1511 giraffe_table_delete(fibers);
1512
1513 cpl_frame_delete(rbin_frame);
1514
1515 return 1;
1516
1517 }
1518
1519 cpl_frameset_insert(set, rbin_frame);
1520
1521 }
1522
1523
1524 /*
1525 * Postprocessing
1526 */
1527
1528 giraffe_table_delete(fibers);
1529 fibers = NULL;
1530
1531 giraffe_localization_destroy(localization);
1532 localization = NULL;
1533
1534 giraffe_extraction_destroy(extraction);
1535 extraction = NULL;
1536
1537 if (rebinning != NULL) {
1538 giraffe_rebinning_destroy(rebinning);
1539 rebinning = NULL;
1540 }
1541
1542 giraffe_table_delete(grating);
1543 grating = NULL;
1544
1545 giraffe_table_delete(slitgeo);
1546 slitgeo = NULL;
1547
1548 giraffe_wcaldata_delete(wlsolution);
1549 wlsolution = NULL;
1550
1551 return 0;
1552
1553}
1554
1555
1556static cxint
1557giqcwavecalibration(cpl_parameterlist* config, cpl_frameset* set)
1558{
1559
1560 const cxchar* const fctid = "giqcwavecalibration";
1561
1562
1563 cxint i = 0;
1564 cxint j = 0;
1565 cxint nx = 0;
1566 cxint ny = 0;
1567 cxint npx;
1568 cxint npy;
1569 cxint npixel = 0;
1570 cxint nsaturated = 0;
1571 cxint status = 0;
1572 cxint wslnaccept;
1573
1574 const cxdouble rmsscale = 3.;
1575 const cxdouble saturation = 60000.;
1576 const cxdouble* pixels = NULL;
1577 const cxdouble* xpos = NULL;
1578 const cxdouble* ypos = NULL;
1579 const cxdouble* flux = NULL;
1580
1581 cxdouble efficiency[2] = {0., 0.};
1582 cxdouble wlcenter = 0.;
1583 cxdouble mean = 0.;
1584 cxdouble rms = 0.;
1585 cxdouble std;
1586 cxdouble pixel2nm = 1.;
1587 cxdouble fwhm_domain[2] = {0., 100.};
1588 cxdouble* _tdata = NULL;
1589 cxdouble* _tdata_fib3 = NULL;
1590
1591 cpl_propertylist* properties = NULL;
1592 cpl_propertylist* qclog = NULL;
1593
1594 cpl_parameter* p = NULL;
1595
1596 cpl_frame* rframe = NULL;
1597 cpl_frame* pframe = NULL;
1598
1599 const cpl_image* _pimage = NULL;
1600 const cpl_image* _qimage = NULL;
1601 const cpl_image* _rimage = NULL;
1602 const cpl_image* _simage = NULL;
1603
1604 cpl_image* _test = NULL;
1605 cpl_image* _test0 = NULL;
1606 cpl_image* _test1 = NULL;
1607
1608 cpl_image* _test_fib3 = NULL;
1609 cpl_image* _test0_fib3 = NULL;
1610 cpl_image* _test1_fib3 = NULL;
1611
1612 cpl_table* _ptable = NULL;
1613
1614 GiImage* rimage = NULL;
1615 GiImage* pimage = NULL;
1616
1617 GiTable* ptable = NULL;
1618
1619 GiLineData* plines = NULL;
1620
1621 GiPaf* qc = NULL;
1622
1623 GiWindow w;
1624
1625
1626 cpl_parameter * simcalp = cpl_parameterlist_find(config, "giraffe.wcal.qc.simlamp");
1627
1628 cxbool qc_simlamp_flag = FALSE;
1629
1630 if (simcalp != NULL) {
1631 qc_simlamp_flag = cpl_parameter_get_bool(simcalp);
1632 }
1633
1634 char* giframe_arc_lamp_extspectra = GIFRAME_ARC_LAMP_EXTSPECTRA;
1635 char* giframe_arc_lamp_rbnspectra = GIFRAME_ARC_LAMP_RBNSPECTRA;
1636 char* giframe_line_data = GIFRAME_LINE_DATA;
1637 char* giframe_wavelength_solution = GIFRAME_WAVELENGTH_SOLUTION;
1638
1639 if(qc_simlamp_flag) {
1640 giframe_arc_lamp_extspectra = GIFRAME_ARC_LAMP_EXTSPECTRA_SIM;
1641 giframe_arc_lamp_rbnspectra = GIFRAME_ARC_LAMP_RBNSPECTRA_SIM;
1642 giframe_line_data = GIFRAME_LINE_DATA_SIM;
1643 giframe_wavelength_solution = GIFRAME_WAVELENGTH_SOLUTION_SIM;
1644 }
1645
1646
1647 cpl_msg_info(fctid, "Computing QC1 parameters ...");
1648
1649
1650 /*
1651 * Compute lamp efficiencies from the rebinned frame if
1652 * it is available. If not the efficiencies are set to 0.
1653 */
1654
1655 pframe = giraffe_get_frame(set, giframe_arc_lamp_extspectra,
1656 CPL_FRAME_GROUP_PRODUCT);
1657
1658 if (pframe == NULL) {
1659
1660 cpl_msg_warning(fctid, "Product '%s' not found.",
1661 giframe_arc_lamp_extspectra);
1662
1663 cpl_msg_warning(fctid, "Setting lamp efficiencies (%s, %s) to 0.",
1664 GIALIAS_QCLAMP, GIALIAS_QCLAMP_SIMCAL);
1665
1666 efficiency[0] = 0.;
1667 efficiency[1] = 0.;
1668
1669 }
1670
1671
1672 pimage = giraffe_image_new(CPL_TYPE_DOUBLE);
1673 status = giraffe_image_load(pimage, cpl_frame_get_filename(pframe), 0);
1674
1675 if (status != 0) {
1676 cpl_msg_error(fctid, "Could not load extracted spectra '%s'!",
1677 cpl_frame_get_filename(pframe));
1678
1679 giraffe_image_delete(pimage);
1680 pimage = NULL;
1681
1682 giraffe_paf_delete(qc);
1683 qc = NULL;
1684
1685 return 1;
1686 }
1687
1688 _pimage = giraffe_image_get(pimage);
1689 cx_assert(_pimage != NULL);
1690
1691
1692 ptable = giraffe_table_new();
1693 status = giraffe_table_load(ptable, cpl_frame_get_filename(pframe), 1,
1694 NULL);
1695
1696 if (status != 0) {
1697 cpl_msg_error(fctid, "Could not load extracted spectra fiber setup!");
1698
1699 giraffe_table_delete(ptable);
1700 ptable = NULL;
1701
1702 giraffe_image_delete(pimage);
1703 pimage = NULL;
1704
1705 giraffe_paf_delete(qc);
1706 qc = NULL;
1707
1708 return 1;
1709 }
1710
1711 _ptable = giraffe_table_get(ptable);
1712 cx_assert(_ptable != NULL);
1713
1714 if (cpl_table_has_column(_ptable, "RP") == FALSE) {
1715
1716 cpl_msg_warning(fctid, "Column 'RP' not found in fiber setup table!");
1717 cpl_msg_warning(fctid, "Setting lamp efficiencies (%s, %s) to 0.",
1718 GIALIAS_QCLAMP, GIALIAS_QCLAMP_SIMCAL);
1719
1720 efficiency[0] = 0.;
1721 efficiency[1] = 0.;
1722
1723 }
1724 else {
1725
1726 properties = giraffe_image_get_properties(pimage);
1727 cx_assert(properties != NULL);
1728
1729 if (cpl_propertylist_has(properties, GIALIAS_EXPTIME) == FALSE) {
1730
1731 cpl_msg_warning(fctid, "Property '%s' not found in '%s'.",
1732 GIALIAS_EXPTIME, cpl_frame_get_filename(rframe));
1733 cpl_msg_warning(fctid, "Setting lamp efficiencies (%s, %s) to 0.",
1734 GIALIAS_QCLAMP, GIALIAS_QCLAMP_SIMCAL);
1735
1736 efficiency[0] = 0.;
1737 efficiency[1] = 0.;
1738
1739 }
1740 else {
1741
1742 cxint fiber = 0;
1743 cxint nb = cpl_image_get_size_y(_pimage);
1744 cxint nf[2] = {0, 0};
1745
1746 cxdouble exptime = cpl_propertylist_get_double(properties,
1747 GIALIAS_EXPTIME);
1748 cxdouble* _sum = NULL;
1749
1750 cpl_image* sum = NULL;
1751
1752
1753 sum = cpl_image_collapse_create(_pimage, 0);
1754 _sum = cpl_image_get_data_double(sum);
1755
1756 for (fiber = 0; fiber < cpl_table_get_nrow(_ptable); ++fiber) {
1757
1758 cxint rp = cpl_table_get_int(_ptable, "RP", fiber, NULL);
1759
1760 if (rp == -1) {
1761 efficiency[1] += _sum[fiber];
1762 ++nf[1];
1763 }
1764 else {
1765 efficiency[0] += _sum[fiber];
1766 ++nf[0];
1767 }
1768
1769 }
1770
1771 _sum = NULL;
1772
1773 cpl_image_delete(sum);
1774 sum = NULL;
1775
1776 if (nf[0] == 0) {
1777 cpl_msg_warning(fctid, "No OzPoz fibers found in the "
1778 "current fiber setup.");
1779 cpl_msg_warning(fctid, "Setting lamp efficiency (%s) to 0.",
1780 GIALIAS_QCLAMP);
1781 efficiency[0] = 0.;
1782 }
1783 else {
1784 efficiency[0] /= nf[0] * nb * exptime;
1785 }
1786
1787 if (nf[1] == 0) {
1788 cpl_msg_warning(fctid, "No simultaneous calibration fibers "
1789 "found in the current fiber setup.");
1790 cpl_msg_warning(fctid, "Setting lamp efficiency (%s) to 0.",
1791 GIALIAS_QCLAMP_SIMCAL);
1792 efficiency[1] = 0.;
1793 }
1794 else {
1795 efficiency[1] /= nf[1] * nb * exptime;
1796 }
1797
1798 }
1799
1800 properties = NULL;
1801
1802 }
1803
1804 _ptable = NULL;
1805 _pimage = NULL;
1806
1807 giraffe_table_delete(ptable);
1808 ptable = NULL;
1809
1810 giraffe_image_delete(pimage);
1811 pimage = NULL;
1812
1813
1814 /*
1815 * Load first raw image as reference
1816 */
1817
1818 rframe = cpl_frameset_find(set, GIFRAME_ARC_SPECTRUM);
1819
1820 if (rframe == NULL) {
1821 cpl_msg_error(fctid, "Missing raw frame (%s)", GIFRAME_ARC_SPECTRUM);
1822
1823 giraffe_paf_delete(qc);
1824 qc = NULL;
1825
1826 return 1;
1827 }
1828
1829 cpl_msg_info(fctid, "Processing reference frame '%s' (%s)",
1830 cpl_frame_get_filename(rframe), cpl_frame_get_tag(rframe));
1831
1832 rimage = giraffe_image_new(CPL_TYPE_DOUBLE);
1833 status = giraffe_image_load(rimage, cpl_frame_get_filename(rframe), 0);
1834
1835 if (status != 0) {
1836
1837 cpl_msg_error(fctid, "Could not load arc-lamp spectra '%s'!",
1838 cpl_frame_get_filename(rframe));
1839
1840 giraffe_image_delete(rimage);
1841 rimage = NULL;
1842
1843 giraffe_paf_delete(qc);
1844 qc = NULL;
1845
1846 return 1;
1847
1848 }
1849
1850 _rimage = giraffe_image_get(rimage);
1851 cx_assert(_rimage != NULL);
1852
1853
1854 /*
1855 * Compute mean level of the first raw frame and count the number
1856 * of saturated pixels.
1857 */
1858
1859 properties = giraffe_image_get_properties(rimage);
1860 cx_assert(properties != NULL);
1861
1862 if (cpl_propertylist_has(properties, GIALIAS_OVSCX)) {
1863
1864 cxint _ox = cpl_propertylist_get_int(properties, GIALIAS_OVSCX);
1865 cxint _nx = cpl_image_get_size_x(_rimage) - 2 * CX_MAX(0, _ox) - 1;
1866
1867 w.x0 = CX_MAX(0, _ox) + 1;
1868 w.x1 = w.x0 + _nx;
1869
1870 }
1871
1872 if (cpl_propertylist_has(properties, GIALIAS_OVSCY)) {
1873
1874 cxint _oy = cpl_propertylist_get_int(properties, GIALIAS_OVSCY);
1875 cxint _ny = cpl_image_get_size_y(_rimage) - 2 * CX_MAX(0, _oy) - 1;
1876
1877 w.y0 = CX_MAX(0, _oy) + 1;
1878 w.y1 = w.y0 + _ny;
1879
1880 }
1881
1882 mean = cpl_image_get_mean_window(_rimage, w.x0, w.y0, w.x1, w.y1);
1883
1884 pixels = cpl_image_get_data_const(_rimage);
1885 npixel = cpl_image_get_size_x(_rimage) * cpl_image_get_size_y(_rimage);
1886
1887 for (i = 0; i < npixel; i++) {
1888 if (pixels[i] > saturation) {
1889 ++nsaturated;
1890 }
1891 }
1892
1893
1894 /*
1895 * Process dispersion solution
1896 */
1897
1898 qc = giraffe_qclog_open(0);
1899
1900 if (qc == NULL) {
1901 cpl_msg_error(fctid, "Cannot create QC1 log!");
1902
1903 giraffe_image_delete(rimage);
1904 rimage = NULL;
1905
1906 return 1;
1907 }
1908
1909 qclog = giraffe_paf_get_properties(qc);
1910 cx_assert(qclog != NULL);
1911
1912 pframe = giraffe_get_frame(set, giframe_wavelength_solution,
1913 CPL_FRAME_GROUP_PRODUCT);
1914
1915 if (pframe == NULL) {
1916 cpl_msg_error(fctid, "Missing product frame (%s)",
1917 giframe_wavelength_solution);
1918
1919 giraffe_paf_delete(qc);
1920 qc = NULL;
1921
1922 giraffe_image_delete(rimage);
1923 rimage = NULL;
1924
1925 return 1;
1926 }
1927
1928 cpl_msg_info(fctid, "Processing product frame '%s' (%s)",
1929 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
1930
1931 ptable = giraffe_table_new();
1932 status = giraffe_table_load(ptable, cpl_frame_get_filename(pframe), 1,
1933 NULL);
1934
1935 if (status != 0) {
1936 cpl_msg_error(fctid, "Could not load dispersion solution '%s'!",
1937 cpl_frame_get_filename(pframe));
1938
1939 giraffe_table_delete(ptable);
1940 ptable = NULL;
1941
1942 giraffe_image_delete(rimage);
1943 rimage = NULL;
1944
1945 giraffe_paf_delete(qc);
1946 qc = NULL;
1947
1948 return 1;
1949 }
1950
1951 properties = giraffe_image_get_properties(rimage);
1952 cx_assert(properties != NULL);
1953
1954 giraffe_propertylist_copy(qclog, "ARCFILE", properties, GIALIAS_ARCFILE);
1955 giraffe_propertylist_copy(qclog, "TPL.ID", properties, GIALIAS_TPLID);
1956 giraffe_propertylist_copy(qclog, "INS.EXP.MODE", properties,
1957 GIALIAS_SETUPNAME);
1958 giraffe_propertylist_copy(qclog, "INS.SLIT.NAME", properties,
1959 GIALIAS_SLITNAME);
1960 giraffe_propertylist_copy(qclog, "INS.GRAT.NAME", properties,
1961 GIALIAS_GRATNAME);
1962 giraffe_propertylist_copy(qclog, "INS.GRAT.WLEN", properties,
1963 GIALIAS_GRATWLEN);
1964 giraffe_propertylist_copy(qclog, "INS.GRAT.ENC", properties,
1965 GIALIAS_GRATPOS);
1966
1967 cpl_propertylist_update_string(qclog, "PRO.CATG",
1968 cpl_frame_get_tag(pframe));
1969 cpl_propertylist_set_comment(qclog, "PRO.CATG",
1970 "Pipeline product category");
1971
1972 properties = giraffe_table_get_properties(ptable);
1973 cx_assert(properties != NULL);
1974
1975 wslnaccept = cpl_propertylist_get_int(properties, GIALIAS_WSOL_NACCEPT);
1976
1977 giraffe_propertylist_copy(qclog, "PRO.WSOL.RMS", properties,
1978 GIALIAS_WSOL_RMS);
1979 giraffe_propertylist_copy(qclog, "PRO.WSOL.NLINES", properties,
1980 GIALIAS_WSOL_NLINES);
1981 giraffe_propertylist_copy(qclog, "PRO.WSOL.NACCEPT", properties,
1982 GIALIAS_WSOL_NACCEPT);
1983 giraffe_propertylist_copy(qclog, "PRO.WSOL.NREJECT", properties,
1984 GIALIAS_WSOL_NREJECT);
1985 giraffe_propertylist_copy(qclog, "PRO.SLIT.NFIBRES", properties,
1986 GIALIAS_NFIBERS);
1987
1988
1989 giraffe_table_delete(ptable);
1990 ptable = NULL;
1991
1992 giraffe_qclog_close(qc);
1993 qc = NULL;
1994
1995
1996 /*
1997 * Process rebinned arc-lamp spectrum
1998 */
1999
2000 cxbool rebin = TRUE;
2001
2002 cpl_parameter * rebinp = cpl_parameterlist_find(config, "giraffe.wcal.rebin");
2003
2004 if (rebinp != NULL) {
2005 rebin = cpl_parameter_get_bool(rebinp);
2006 }
2007
2008 if(rebin){
2009
2010 qc = giraffe_qclog_open(1);
2011
2012 if (qc == NULL) {
2013 cpl_msg_error(fctid, "Cannot create QC1 log!");
2014 return 1;
2015 }
2016
2017 qclog = giraffe_paf_get_properties(qc);
2018 cx_assert(qclog != NULL);
2019
2020 pframe = giraffe_get_frame(set, giframe_arc_lamp_rbnspectra,
2021 CPL_FRAME_GROUP_PRODUCT);
2022
2023 if (pframe == NULL) {
2024 cpl_msg_error(fctid, "Missing product frame (%s)",
2025 giframe_arc_lamp_rbnspectra);
2026
2027 giraffe_image_delete(rimage);
2028 rimage = NULL;
2029
2030 giraffe_paf_delete(qc);
2031 qc = NULL;
2032
2033 return 1;
2034 }
2035
2036 cpl_msg_info(fctid, "Processing product frame '%s' (%s)",
2037 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
2038
2039 pimage = giraffe_image_new(CPL_TYPE_DOUBLE);
2040 status = giraffe_image_load(pimage, cpl_frame_get_filename(pframe), 0);
2041
2042 if (status != 0) {
2043 cpl_msg_error(fctid, "Could not load rebinned arc-lamp spectra '%s'!",
2044 cpl_frame_get_filename(pframe));
2045
2046 giraffe_image_delete(pimage);
2047 pimage = NULL;
2048
2049 giraffe_image_delete(rimage);
2050 rimage = NULL;
2051
2052 giraffe_paf_delete(qc);
2053 qc = NULL;
2054
2055 return 1;
2056 }
2057
2058 ptable = giraffe_table_new();
2059 status = giraffe_table_load(ptable, cpl_frame_get_filename(pframe), 1,
2060 NULL);
2061
2062 if (status != 0) {
2063 cpl_msg_error(fctid, "Could not load rebinned arc-lamp spectra '%s'!",
2064 cpl_frame_get_filename(pframe));
2065
2066 giraffe_table_delete(ptable);
2067 ptable = NULL;
2068
2069 giraffe_image_delete(pimage);
2070 pimage = NULL;
2071
2072 giraffe_image_delete(rimage);
2073 rimage = NULL;
2074
2075 giraffe_paf_delete(qc);
2076 qc = NULL;
2077
2078 return 1;
2079 }
2080
2081 properties = giraffe_image_get_properties(rimage);
2082 cx_assert(properties != NULL);
2083
2084 giraffe_propertylist_copy(qclog, "ARCFILE", properties, GIALIAS_ARCFILE);
2085 giraffe_propertylist_copy(qclog, "TPL.ID", properties, GIALIAS_TPLID);
2086 giraffe_propertylist_copy(qclog, "INS.EXP.MODE", properties,
2087 GIALIAS_SETUPNAME);
2088 giraffe_propertylist_copy(qclog, "INS.SLIT.NAME", properties,
2089 GIALIAS_SLITNAME);
2090 giraffe_propertylist_copy(qclog, "INS.GRAT.NAME", properties,
2091 GIALIAS_GRATNAME);
2092 giraffe_propertylist_copy(qclog, "INS.GRAT.WLEN", properties,
2093 GIALIAS_GRATWLEN);
2094
2095 cpl_propertylist_update_string(qclog, "PRO.CATG",
2096 cpl_frame_get_tag(pframe));
2097 cpl_propertylist_set_comment(qclog, "PRO.CATG",
2098 "Pipeline product category");
2099
2100 properties = giraffe_image_get_properties(pimage);
2101 cx_assert(properties != NULL);
2102
2103 giraffe_propertylist_copy(qclog, "PRO.DATAAVG", properties,
2104 GIALIAS_DATAMEAN);
2105 giraffe_propertylist_copy(qclog, "PRO.DATARMS", properties,
2106 GIALIAS_DATASIG);
2107 giraffe_propertylist_copy(qclog, "PRO.DATAMED", properties,
2108 GIALIAS_DATAMEDI);
2109 giraffe_propertylist_copy(qclog, "PRO.SLIT.NFIBRES", properties,
2110 GIALIAS_NFIBERS);
2111
2112 cxint binwns = cpl_propertylist_get_int(properties, GIALIAS_BINWNS);
2113
2114 if (binwns != 0 && wslnaccept != 0) {
2115 cpl_propertylist_update_double(properties, GIALIAS_QCNLINACC,
2116 (double)wslnaccept / binwns);
2117 }
2118 else {
2119 cpl_propertylist_update_double(properties, GIALIAS_QCNLINACC, 0.);
2120 }
2121
2122
2123 cpl_propertylist_update_double(properties, GIALIAS_QCMEAN, mean);
2124 cpl_propertylist_set_comment(properties, GIALIAS_QCMEAN, "Mean level of "
2125 "first raw frame");
2126
2127 giraffe_propertylist_copy(qclog, "QC.OUT1.MEAN.RAW", properties,
2128 GIALIAS_QCMEAN);
2129
2130
2131 cpl_propertylist_update_int(properties, GIALIAS_QCNSAT, nsaturated);
2132 cpl_propertylist_set_comment(properties, GIALIAS_QCNSAT, "Number of "
2133 "saturated pixels in the first raw frame");
2134
2135 giraffe_propertylist_copy(qclog, "QC.OUT1.NSAT.RAW", properties,
2136 GIALIAS_QCNSAT);
2137
2138
2139 /*
2140 * Calibration lamp monitoring
2141 */
2142
2143 cpl_propertylist_update_double(properties, GIALIAS_QCLAMP, efficiency[0]);
2144 cpl_propertylist_set_comment(properties, GIALIAS_QCLAMP,
2145 "Calibration lamp efficiency");
2146
2147 giraffe_propertylist_copy(qclog, "QC.LAMP.EFFIC", properties,
2148 GIALIAS_QCLAMP);
2149
2150 cpl_propertylist_update_double(properties, GIALIAS_QCLAMP_SIMCAL,
2151 efficiency[1]);
2152 cpl_propertylist_set_comment(properties, GIALIAS_QCLAMP_SIMCAL,
2153 "SIMCAL lamp efficiency");
2154
2155 giraffe_propertylist_copy(qclog, "QC.LAMP.EFFIC1", properties,
2156 GIALIAS_QCLAMP_SIMCAL);
2157
2158
2159 /* Compute rebinned emission line straightness. */
2160
2161 _pimage = giraffe_image_get(pimage);
2162
2163 _test = cpl_image_duplicate(_pimage);
2164 _tdata = cpl_image_get_data(_test);
2165
2166 _test_fib3 = cpl_image_duplicate(_pimage);
2167 _tdata_fib3 = cpl_image_get_data(_test_fib3);
2168
2169 nx = cpl_image_get_size_x(_test);
2170 ny = cpl_image_get_size_y(_test);
2171
2172 for (i = 0; i < nx * ny; i++) {
2173 _tdata[i] = _tdata[i] > 0. ? log(_tdata[i]) : 0.;
2174 _tdata_fib3[i] = _tdata_fib3[i] > 0. ? log10(_tdata_fib3[i]) : 0.;
2175 }
2176
2177 _tdata = NULL;
2178
2179 _test0 = cpl_image_extract(_test, 4, 1, 4, ny);
2180
2181 _test1 = cpl_image_collapse_create(_test, 1);
2182 cpl_image_divide_scalar(_test1, nx);
2183
2184 cpl_image_delete(_test);
2185 _test = NULL;
2186
2187
2188 _test = cpl_image_subtract_create(_test0, _test1);
2189
2190 cpl_image_delete(_test0);
2191 _test0 = NULL;
2192
2193 cpl_image_delete(_test1);
2194 _test1 = NULL;
2195
2196 _tdata_fib3 = NULL;
2197
2198 _test0_fib3 = cpl_image_extract(_test_fib3, 4, 1, 4, ny);
2199
2200 _ptable = giraffe_table_get(ptable);
2201 cx_assert(_ptable != NULL);
2202
2203 int nfib = nx;
2204
2205 if (cpl_table_has_column(_ptable, "OBJECT") == FALSE) {
2206 cpl_msg_warning(fctid,
2207 "Column 'OBJECT' not found in fiber setup table!");
2208 cpl_msg_warning(fctid, "CALSIM fibres may be included in QC params");
2209 }
2210 else {
2211 for (i = 0; i < nx; i++) {
2212 const char *objs = cpl_table_get_string(_ptable, "OBJECT", i);
2213 if (!strcmp(objs, "CALSIM")) {
2214 cpl_image_fill_window(_test_fib3, i + 1, 1, i + 1, ny, 0);
2215 nfib--;
2216 }
2217 }
2218 }
2219
2220 _test1_fib3 = cpl_image_collapse_create(_test_fib3, 1);
2221 cpl_image_divide_scalar(_test1_fib3, nfib);
2222
2223
2224 cpl_image_delete(_test_fib3);
2225 _test_fib3 = NULL;
2226
2227 _test_fib3 = cpl_image_subtract_create(_test0_fib3, _test1_fib3);
2228
2229 cpl_image_delete(_test0_fib3);
2230 _test0_fib3 = NULL;
2231
2232 cpl_image_delete(_test1_fib3);
2233 _test1_fib3 = NULL;
2234
2235
2236 _tdata = cpl_image_get_data(_test);
2237
2238 rms = 0;
2239
2240 for (i = 0; i < ny; i++) {
2241 _tdata[i] = exp(_tdata[i]);
2242 rms += pow(_tdata[i], 2.);
2243 }
2244
2245 rms = sqrt(rms / (ny - 1));
2246
2247 std = cpl_image_get_stdev_window(_test_fib3, 1, 1, 1, (cpl_size) ((1-0.045) * ny));
2248
2249 cpl_image_delete(_test);
2250 _test = NULL;
2251 cpl_image_delete(_test_fib3);
2252 _test_fib3 = NULL;
2253
2254 cpl_propertylist_update_double(properties, GIALIAS_QCRBRMS, rms);
2255 cpl_propertylist_set_comment(properties, GIALIAS_QCRBRMS,
2256 "RMS of rebinned arc-lamp spectra");
2257
2258 giraffe_propertylist_copy(qclog, "QC.WSOL.REBIN.RMS", properties,
2259 GIALIAS_QCRBRMS);
2260
2261 cpl_propertylist_update_double(properties, GIALIAS_QCFIB3 , std);
2262 cpl_propertylist_set_comment(properties, GIALIAS_QCFIB3 ,
2263 "STDEV of fibre 3 - mean");
2264
2265 giraffe_propertylist_copy(qclog, "QC.FIB3.RMS", properties,
2266 GIALIAS_QCFIB3 );
2267
2268
2269 status = giraffe_image_save(pimage, cpl_frame_get_filename(pframe));
2270
2271 if (status != 0) {
2272 cpl_msg_error(fctid, "Could not save rebinned arc-lamp spectra "
2273 "'%s'!", cpl_frame_get_filename(pframe));
2274
2275 giraffe_table_delete(ptable);
2276 ptable = NULL;
2277
2278 giraffe_image_delete(pimage);
2279 pimage = NULL;
2280
2281 giraffe_image_delete(rimage);
2282 rimage = NULL;
2283
2284 giraffe_paf_delete(qc);
2285 qc = NULL;
2286
2287 return 1;
2288 }
2289
2290 status = giraffe_table_attach(ptable, cpl_frame_get_filename(pframe),
2291 1, NULL);
2292
2293 if (status != 0) {
2294 cpl_msg_error(fctid, "Could not save rebinned arc-lamp spectra "
2295 "'%s'!", cpl_frame_get_filename(pframe));
2296
2297 giraffe_table_delete(ptable);
2298 ptable = NULL;
2299
2300 giraffe_image_delete(pimage);
2301 pimage = NULL;
2302
2303 giraffe_image_delete(rimage);
2304 rimage = NULL;
2305
2306 giraffe_paf_delete(qc);
2307 qc = NULL;
2308
2309 return 1;
2310 }
2311
2312 giraffe_image_delete(pimage);
2313 pimage = NULL;
2314
2315 giraffe_table_delete(ptable);
2316 ptable = NULL;
2317
2318 giraffe_qclog_close(qc);
2319 qc = NULL;
2320
2321}
2322
2323 /*
2324 * Process line data
2325 */
2326
2327 qc = giraffe_qclog_open(2);
2328
2329 if (qc == NULL) {
2330 cpl_msg_error(fctid, "Cannot create QC1 log!");
2331 return 1;
2332 }
2333
2334 qclog = giraffe_paf_get_properties(qc);
2335 cx_assert(qclog != NULL);
2336
2337 pframe = giraffe_get_frame(set, giframe_line_data,
2338 CPL_FRAME_GROUP_PRODUCT);
2339
2340 if (pframe == NULL) {
2341 cpl_msg_error(fctid, "Missing product frame (%s)",
2342 giframe_line_data);
2343
2344 giraffe_image_delete(rimage);
2345 rimage = NULL;
2346
2347 giraffe_paf_delete(qc);
2348 qc = NULL;
2349
2350 return 1;
2351 }
2352
2353 cpl_msg_info(fctid, "Processing product frame '%s' (%s)",
2354 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
2355
2356
2357 /*
2358 * Load line data
2359 */
2360
2361 plines = giraffe_linedata_new();
2362
2363 status = giraffe_linedata_load(plines, cpl_frame_get_filename(pframe));
2364
2365 if (status != 0) {
2366 cpl_msg_error(fctid, "Could not load line data '%s'!",
2367 cpl_frame_get_filename(pframe));
2368
2369 giraffe_linedata_delete(plines);
2370 plines = NULL;
2371
2372 giraffe_image_delete(rimage);
2373 rimage = NULL;
2374
2375 giraffe_paf_delete(qc);
2376 qc = NULL;
2377
2378 return 1;
2379 }
2380
2381 properties = giraffe_image_get_properties(rimage);
2382 cx_assert(properties != NULL);
2383
2384 giraffe_propertylist_copy(qclog, "ARCFILE", properties, GIALIAS_ARCFILE);
2385 giraffe_propertylist_copy(qclog, "TPL.ID", properties, GIALIAS_TPLID);
2386 giraffe_propertylist_copy(qclog, "INS.EXP.MODE", properties,
2387 GIALIAS_SETUPNAME);
2388 giraffe_propertylist_copy(qclog, "INS.SLIT.NAME", properties,
2389 GIALIAS_SLITNAME);
2390 giraffe_propertylist_copy(qclog, "INS.GRAT.NAME", properties,
2391 GIALIAS_GRATNAME);
2392 giraffe_propertylist_copy(qclog, "INS.GRAT.WLEN", properties,
2393 GIALIAS_GRATWLEN);
2394
2395 cpl_propertylist_update_string(qclog, "PRO.CATG",
2396 cpl_frame_get_tag(pframe));
2397 cpl_propertylist_set_comment(qclog, "PRO.CATG",
2398 "Pipeline product category");
2399
2400
2401 _pimage = giraffe_linedata_get_data(plines, "FWHM");
2402
2403 if (_pimage == NULL) {
2404 cpl_msg_error(fctid, "FWHM line data not found!");
2405
2406 giraffe_linedata_delete(plines);
2407 plines = NULL;
2408
2409 giraffe_image_delete(rimage);
2410 rimage = NULL;
2411
2412 giraffe_paf_delete(qc);
2413 qc = NULL;
2414
2415 return 1;
2416 }
2417
2418 nx = cpl_image_get_size_x(_pimage);
2419 ny = cpl_image_get_size_y(_pimage);
2420
2421 pixels = cpl_image_get_data_const(_pimage);
2422
2423 for (j = 0; j < 2; ++j) {
2424
2425 register cxint ndata = nx * ny;
2426
2427 npixel = 0;
2428 mean = 0.;
2429 rms = 0.;
2430
2431 for (i = 0; i < ndata; ++i) {
2432
2433 if ((pixels[i] >= fwhm_domain[0]) &&
2434 (pixels[i] < fwhm_domain[1])) {
2435 mean += pixels[i];
2436 ++npixel;
2437 }
2438
2439 }
2440
2441 if (npixel == 0) {
2442 cpl_msg_error(fctid, "All line FWHM data are invalid!");
2443
2444 giraffe_linedata_delete(plines);
2445 plines = NULL;
2446
2447 giraffe_image_delete(rimage);
2448 rimage = NULL;
2449
2450 giraffe_paf_delete(qc);
2451 qc = NULL;
2452
2453 return 1;
2454 }
2455
2456 mean /= npixel;
2457
2458 for (i = 0; i < ndata; ++i) {
2459
2460 if ((pixels[i] >= fwhm_domain[0]) &&
2461 (pixels[i] < fwhm_domain[1])) {
2462 rms += pow(pixels[i] - mean, 2.);
2463 }
2464
2465 }
2466
2467 if (npixel > 1) {
2468 rms = sqrt(rms / (npixel - 1));
2469 }
2470
2471 fwhm_domain[0] = CX_MAX(mean - rmsscale * rms, 0.);
2472 fwhm_domain[1] = CX_MIN(mean + rmsscale * rms, 100.);
2473
2474 }
2475
2476 /*
2477 * Calculation of average X and Y offsets and Flux for simlamp QC's
2478 */
2479
2480 double x_total = 0.;
2481 double y_total = 0.;
2482 double flux_total = 0.;
2483
2484 cx_string *slit_name = NULL;
2485 cx_string *grat_name = NULL;
2486
2487
2488 if (qc_simlamp_flag) {
2489 _pimage = giraffe_linedata_get_data(plines, "Xccd");
2490
2491 if (_pimage == NULL) {
2492 cpl_msg_error(fctid, "Xccd line data not found!");
2493
2494 giraffe_linedata_delete(plines);
2495 plines = NULL;
2496
2497 giraffe_image_delete(rimage);
2498 rimage = NULL;
2499
2500 giraffe_paf_delete(qc);
2501 qc = NULL;
2502
2503 return 1;
2504 }
2505
2506 _qimage = giraffe_linedata_get_data(plines, "Yccd");
2507
2508 if (_qimage == NULL) {
2509 cpl_msg_error(fctid, "Yccd line data not found!");
2510
2511 giraffe_linedata_delete(plines);
2512 plines = NULL;
2513
2514 giraffe_image_delete(rimage);
2515 rimage = NULL;
2516
2517 giraffe_paf_delete(qc);
2518 qc = NULL;
2519
2520 return 1;
2521 }
2522
2523 nx = cpl_image_get_size_x(_rimage);
2524 ny = cpl_image_get_size_y(_rimage);
2525
2526 npx = cpl_image_get_size_x(_pimage);
2527 npy = cpl_image_get_size_y(_pimage);
2528
2529 pixels = cpl_image_get_data_const(_rimage);
2530 xpos = cpl_image_get_data_const(_pimage);
2531 ypos = cpl_image_get_data_const(_qimage);
2532
2533 int prscx = 0;
2534
2535 if (cpl_propertylist_has(properties, GIALIAS_PRSCX)) {
2536 prscx = cpl_propertylist_get_int(properties, GIALIAS_PRSCX);
2537 }
2538
2539 /*
2540 * xpos and ypos contain the X and Y positions of the lines in the raw
2541 * frame. Note X is defined as the dispersion direction. The X values
2542 * are already accurate as they are derived from the line fit, the Y
2543 * values are taken from the provided flat field, so need to be redone
2544 * for the arc frame
2545 */
2546
2547 int npxi = 0;
2548 int npyi;
2549
2550 int cwidth = 11;
2551 int cmid = floor(cwidth / 2);
2552
2553 for (npxi = 0; npxi < npx; npxi++) {
2554 for (npyi = 0; npyi < npy; npyi++) {
2555 int y = 0;
2556 double pixval = 0.;
2557 double max_val = 0.;
2558 int max_index = 0;
2559 int pixpos_init = 0;
2560 int pixpos = 0;
2561
2562 /*
2563 * First search for maximum in cwidth pixels around the flat Y
2564 * position.
2565 */
2566
2567 pixpos_init = (int)floor(ypos[npxi + npyi * npx]) + prscx +
2568 nx * (int)floor(xpos[npxi + npyi * npx]) - cmid;
2569
2570 for (y = 0; y < cwidth; y++) {
2571 pixpos = pixpos_init + y;
2572 if (pixpos >= 0 && pixpos < ny * nx) {
2573 pixval = pixels[pixpos];
2574 if (pixval > max_val) {
2575 max_val = pixval;
2576 max_index = y;
2577 }
2578 }
2579 }
2580
2581 /* Then do a centroid of cwidth pixels around the maximum */
2582
2583 double zz = 0.;
2584 double yy = 0.;
2585
2586 for (y = 0; y < cwidth; y++) {
2587 pixpos = pixpos_init + y - (cmid - max_index);
2588 if (pixpos >= 0 && pixpos < ny * nx) {
2589 pixval = pixels[pixpos];
2590 yy += pixval * y;
2591 zz += pixval;
2592 flux_total += pixval;
2593 }
2594 }
2595
2596 x_total += xpos[npxi + npyi * npx];
2597 y_total += (int)floor(ypos[npxi + npyi * npx]) + prscx -
2598 (cmid - max_index) - cmid + yy / zz;
2599 }
2600 }
2601
2602 x_total = x_total / (npx * npy);
2603 y_total = y_total / (npx * npy);
2604 flux_total = flux_total / (npx * npy) / cwidth;
2605
2606 if (cpl_propertylist_has(properties, GIALIAS_SLITNAME) == FALSE) {
2607 cpl_msg_error(fctid,
2608 "SLit name property '%s' not "
2609 "found!",
2610 GIALIAS_SLITNAME);
2611
2612 cpl_propertylist_delete(properties);
2613 properties = NULL;
2614
2615 giraffe_linedata_delete(plines);
2616 plines = NULL;
2617
2618 giraffe_image_delete(rimage);
2619 rimage = NULL;
2620
2621 giraffe_paf_delete(qc);
2622 qc = NULL;
2623
2624 return 1;
2625 }
2626
2627 slit_name = cx_string_create(
2628 cpl_propertylist_get_string(properties, GIALIAS_SLITNAME));
2629
2630 if (cpl_propertylist_has(properties, GIALIAS_GRATNAME) == FALSE) {
2631 cpl_msg_error(fctid,
2632 "Grating name property '%s' not "
2633 "found!",
2634 GIALIAS_GRATNAME);
2635
2636 cpl_propertylist_delete(properties);
2637 properties = NULL;
2638
2639 giraffe_linedata_delete(plines);
2640 plines = NULL;
2641
2642 giraffe_image_delete(rimage);
2643 rimage = NULL;
2644
2645 giraffe_paf_delete(qc);
2646 qc = NULL;
2647
2648 return 1;
2649 }
2650
2651 grat_name = cx_string_create(
2652 cpl_propertylist_get_string(properties, GIALIAS_GRATNAME));
2653
2654 cx_string_append(slit_name, cx_string_get(grat_name));
2655
2656 /*
2657 * Adding magic numbers so that QC parameters are scaled to match
2658 * those from the original system. Note that the x_total offset is
2659 * dependent on the value of wlcalibration.line.widths in the
2660 * reduction, these values are correct for
2661 * wlcalibration.line.widths=12
2662 */
2663
2664 y_total = 1003.66 - y_total;
2665 x_total = 1719.13 - x_total;
2666
2667 if (strcmp(cx_string_get(slit_name), "Medusa1HR") == 0) {
2668 y_total = 1.019 * y_total + 0.016;
2669 x_total = 0.986 * x_total - 0.073;
2670 flux_total = 1.334 * flux_total - 506.565;
2671 }
2672 else if (strcmp(cx_string_get(slit_name), "Medusa1LR") == 0) {
2673 y_total = 1.038 * y_total + 3.322;
2674 x_total = 1.194 * x_total + 434.818;
2675 flux_total = 0.243 * flux_total - 121.36;
2676 }
2677 else if (strcmp(cx_string_get(slit_name), "Medusa2HR") == 0) {
2678 y_total = 0.989 * y_total - 1.067;
2679 x_total = 1.0 * x_total - 10;
2680 flux_total = 1.397 * flux_total - 465.637;
2681 }
2682 else if (strcmp(cx_string_get(slit_name), "IFU1HR") == 0) {
2683 y_total = 0.977 * y_total - 107.426;
2684 x_total = 0.96 * x_total - 4.968;
2685 flux_total = 1.661 * flux_total - 512.41;
2686 }
2687 else if (strcmp(cx_string_get(slit_name), "IFU2HR") == 0) {
2688 y_total = 0.956 * y_total - 103.017;
2689 x_total = 0.942 * x_total + 0.22;
2690 flux_total = 0.786 * flux_total - 247.967;
2691 }
2692 else if (strcmp(cx_string_get(slit_name), "ArgusHR") == 0) {
2693 y_total = 0.954 * y_total + 152.569;
2694 x_total = 0.928 * x_total - 12.441;
2695 flux_total = 1.219 * flux_total - 329.05;
2696 }
2697 else {
2698 cpl_msg_error(
2699 fctid, "Slit and grating name '%s' not recognized for SIMLAMP!",
2700 cx_string_get(slit_name));
2701
2702 cpl_propertylist_delete(properties);
2703 properties = NULL;
2704
2705 giraffe_linedata_delete(plines);
2706 plines = NULL;
2707
2708 giraffe_image_delete(rimage);
2709 rimage = NULL;
2710
2711 giraffe_paf_delete(qc);
2712 qc = NULL;
2713
2714 return 1;
2715 }
2716
2717 cx_string_delete(slit_name);
2718 cx_string_delete(grat_name);
2719 }
2720
2721 properties = cpl_propertylist_load_regexp(cpl_frame_get_filename(pframe),
2722 0, "^COMMENT$", TRUE);
2723
2724 cx_assert(properties != NULL);
2725
2726 if (cpl_propertylist_has(properties, GIALIAS_GRATWLEN) == FALSE) {
2727 cpl_msg_error(fctid, "Grating central wavelength property '%s' not "
2728 "found!", GIALIAS_GRATWLEN);
2729
2730 cpl_propertylist_delete(properties);
2731 properties = NULL;
2732
2733 giraffe_linedata_delete(plines);
2734 plines = NULL;
2735
2736 giraffe_image_delete(rimage);
2737 rimage = NULL;
2738
2739 giraffe_paf_delete(qc);
2740 qc = NULL;
2741
2742 return 1;
2743 }
2744
2745 if (cpl_propertylist_has(properties, GIALIAS_WSOL_SCALE) == FALSE) {
2746 cpl_msg_error(fctid, "Line data property '%s' not found!",
2747 GIALIAS_WSOL_SCALE);
2748
2749 cpl_propertylist_delete(properties);
2750 properties = NULL;
2751
2752 giraffe_linedata_delete(plines);
2753 plines = NULL;
2754
2755 giraffe_image_delete(rimage);
2756 rimage = NULL;
2757
2758 giraffe_paf_delete(qc);
2759 qc = NULL;
2760
2761 return 1;
2762 }
2763
2764 wlcenter = cpl_propertylist_get_double(properties, GIALIAS_GRATWLEN);
2765 pixel2nm = cpl_propertylist_get_double(properties, GIALIAS_WSOL_SCALE);
2766
2767 mean *= pixel2nm;
2768 rms *= pixel2nm;
2769
2770 /*
2771 * Adding QC XPOS, YPOS and FLUX values for SIMLAMP frames, note switch
2772 * between giwavecalibration and QC definitions of X/Y axes.
2773 */
2774
2775 if (qc_simlamp_flag) {
2776 cpl_propertylist_update_double(properties, GIALIAS_QCSIMCALX, y_total);
2777 cpl_propertylist_set_comment(properties, GIALIAS_QCSIMCALX,
2778 "Average X of SIMCAL lines");
2779
2780 cpl_propertylist_update_double(properties, GIALIAS_QCSIMCALY, x_total);
2781 cpl_propertylist_set_comment(properties, GIALIAS_QCSIMCALY,
2782 "Average Y of SIMCAL lines");
2783
2784 cpl_propertylist_update_double(properties, GIALIAS_QCSIMCALF,
2785 flux_total);
2786 cpl_propertylist_set_comment(properties, GIALIAS_QCSIMCALF,
2787 "Average flux of SIMCAL lines");
2788 }
2789
2790 cpl_propertylist_update_double(properties, GIALIAS_QCRESOLAVG, mean);
2791 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLAVG,
2792 "Average line FWHM [nm]");
2793
2794 cpl_propertylist_update_double(properties, GIALIAS_QCRESOLRMS, rms);
2795 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLRMS,
2796 "RMS of line FWHM [nm]");
2797
2798 cpl_propertylist_update_int(properties, GIALIAS_QCRESOLTOT, nx * ny);
2799 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLTOT,
2800 "Total number of lines available for FWHM RMS "
2801 "computation");
2802
2803 cpl_propertylist_update_int(properties, GIALIAS_QCRESOLLIN, npixel);
2804 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLLIN,
2805 "Number of lines used for FWHM RMS "
2806 "computation");
2807
2808 cpl_propertylist_update_double(properties, GIALIAS_QCRESOLPWR,
2809 wlcenter / mean);
2810 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLPWR,
2811 "Resolving power");
2812
2813 giraffe_propertylist_copy(qclog, "QC.RESOL.MEAN", properties,
2814 GIALIAS_QCRESOLAVG);
2815 giraffe_propertylist_copy(qclog, "QC.RESOL.RMS", properties,
2816 GIALIAS_QCRESOLRMS);
2817 giraffe_propertylist_copy(qclog, "QC.RESOL.NTOTAL", properties,
2818 GIALIAS_QCRESOLTOT);
2819 giraffe_propertylist_copy(qclog, "QC.RESOL.NLINES", properties,
2820 GIALIAS_QCRESOLLIN);
2821 giraffe_propertylist_copy(qclog, "QC.RESOL.POWER", properties,
2822 GIALIAS_QCRESOLPWR);
2823
2824
2825 status = giraffe_linedata_save(plines, properties,
2826 cpl_frame_get_filename(pframe));
2827
2828 if (status != 0) {
2829 cpl_msg_error(fctid, "Could not save line data "
2830 "'%s'!", cpl_frame_get_filename(pframe));
2831
2832 cpl_propertylist_delete(properties);
2833 properties = NULL;
2834
2835 giraffe_linedata_delete(plines);
2836 plines = NULL;
2837
2838 giraffe_image_delete(rimage);
2839 rimage = NULL;
2840
2841 giraffe_paf_delete(qc);
2842 qc = NULL;
2843
2844 return 1;
2845 }
2846
2847 cpl_propertylist_delete(properties);
2848 properties = NULL;
2849
2850 giraffe_qclog_close(qc);
2851 qc = NULL;
2852
2853
2854 /*
2855 * Cleanup
2856 */
2857
2858 giraffe_image_delete(rimage);
2859 giraffe_linedata_delete(plines);
2860 plines = NULL;
2861
2862 return 0;
2863
2864}
2865
2866
2867/*
2868 * Build table of contents, i.e. the list of available plugins, for
2869 * this module. This function is exported.
2870 */
2871
2872int
2873cpl_plugin_get_info(cpl_pluginlist* list)
2874{
2875
2876 cpl_recipe* recipe = cx_calloc(1, sizeof *recipe);
2877 cpl_plugin* plugin = &recipe->interface;
2878
2879 cpl_plugin_init(plugin,
2880 CPL_PLUGIN_API,
2881 GIRAFFE_BINARY_VERSION,
2882 CPL_PLUGIN_TYPE_RECIPE,
2883 "giwavecalibration",
2884 "Compute dispersion solution from an arc-lamp spectrum.",
2885 "For detailed information please refer to the "
2886 "GIRAFFE pipeline user manual.\nIt is available at "
2887 "http://www.eso.org/pipelines.",
2888 "Giraffe Pipeline",
2889 PACKAGE_BUGREPORT,
2891 giwavecalibration_create,
2892 giwavecalibration_exec,
2893 giwavecalibration_destroy);
2894
2895 cpl_pluginlist_append(list, plugin);
2896
2897 return 0;
2898
2899}
GiBiasConfig * giraffe_bias_config_create(cpl_parameterlist *list)
Creates a setup structure for a bias removal task.
Definition: gibias.c:3439
void giraffe_bias_config_add(cpl_parameterlist *list)
Adds parameters for the bias removal.
Definition: gibias.c:3598
cxint giraffe_bias_remove(GiImage *result, const GiImage *raw, const GiImage *master_bias, const GiImage *bad_pixels, const cpl_matrix *biaslimits, const GiBiasConfig *config)
Removes the bias from an image.
Definition: gibias.c:3107
void giraffe_bias_config_destroy(GiBiasConfig *config)
Destroys a bias removal setup structure.
Definition: gibias.c:3570
void giraffe_extract_config_add(cpl_parameterlist *list)
Adds parameters for the spectrum extraction.
Definition: giextract.c:3509
cxint giraffe_extract_spectra(GiExtraction *result, GiImage *image, GiTable *fibers, GiLocalization *sloc, GiImage *bpixel, GiImage *slight, GiExtractConfig *config)
Extracts the spectra from a preprocessed frame.
Definition: giextract.c:2480
GiExtractConfig * giraffe_extract_config_create(cpl_parameterlist *list)
Creates a setup structure for the spectrum extraction.
Definition: giextract.c:3405
void giraffe_extract_config_destroy(GiExtractConfig *config)
Destroys a spectrum extraction setup structure.
Definition: giextract.c:3479
GiTable * giraffe_fibers_setup(const cpl_frame *frame, const cpl_frame *reference)
Setup a fiber list.
Definition: gifibers.c:218
cxint giraffe_fiberlist_compare(const GiTable *fibers, const GiTable *reference)
Compare two fiber lists.
Definition: gifiberutils.c:952
cxint giraffe_fiberlist_attach(cpl_frame *frame, GiTable *fibers)
Attach a fiber table to a frame.
Definition: gifiberutils.c:884
cpl_frame * giraffe_get_frame(const cpl_frameset *set, const cxchar *tag, cpl_frame_group group)
Get a frame from a frame set.
Definition: giframe.c:739
cpl_frame * giraffe_frame_create(const cxchar *tag, cpl_frame_level level, const cpl_propertylist *properties, cxcptr object, cxcptr data, GiFrameCreator creator)
Create a product frame using a provided frame creator.
Definition: giframe.c:239
cpl_frame * giraffe_frame_create_image(GiImage *image, const cxchar *tag, cpl_frame_level level, cxbool save, cxbool update)
Create an image product frame.
Definition: giframe.c:395
cpl_frame * giraffe_get_slitgeometry(const cpl_frameset *set)
Get the slit geometry frame from a frame set.
Definition: giframe.c:786
cpl_frame * giraffe_frame_create_table(GiTable *table, const cxchar *tag, cpl_frame_level level, cxbool save, cxbool update)
Create a table product frame.
Definition: giframe.c:543
cpl_image * giraffe_image_get(const GiImage *self)
Gets the image data.
Definition: giimage.c:218
cpl_propertylist * giraffe_image_get_properties(const GiImage *self)
Get the properties of an image.
Definition: giimage.c:282
void giraffe_image_delete(GiImage *self)
Destroys an image.
Definition: giimage.c:181
cxint giraffe_image_add_info(GiImage *image, const GiRecipeInfo *info, const cpl_frameset *set)
Add additional frame information to an image.
Definition: giimage.c:773
cxint giraffe_image_save(GiImage *self, const cxchar *filename)
Write a Giraffe image to a file.
Definition: giimage.c:570
GiImage * giraffe_image_new(cpl_type type)
Creates an empty image container.
Definition: giimage.c:65
cxint giraffe_image_load(GiImage *self, const cxchar *filename, cxint position)
Gets image data and properties from a file.
Definition: giimage.c:536
void giraffe_rebin_config_destroy(GiRebinConfig *config)
Destroys a spectrum extraction setup structure.
Definition: girebinning.c:4926
cxint giraffe_rebin_spectra(GiRebinning *rebinning, const GiExtraction *extraction, const GiTable *fibers, const GiLocalization *localization, const GiTable *grating, const GiTable *slitgeo, const GiTable *solution, const GiRebinConfig *config)
Rebin an Extracted Spectra Frame and associated Errors Frame.
Definition: girebinning.c:4052
GiRebinConfig * giraffe_rebin_config_create(cpl_parameterlist *list)
Creates a setup structure for the rebinning.
Definition: girebinning.c:4826
GiRebinning * giraffe_rebinning_new(void)
Create an empty rebinning results container.
Definition: girebinning.c:4694
void giraffe_rebinning_destroy(GiRebinning *rebinning)
Destroys a rebinning results container and its contents.
Definition: girebinning.c:4788
void giraffe_rebin_config_add(cpl_parameterlist *list)
Adds parameters for the rebinning.
Definition: girebinning.c:4950
GiSGCalConfig * giraffe_sgcalibration_config_create(cpl_parameterlist *list)
Creates a setup structure for the slit geometry calibration.
void giraffe_sgcalibration_config_destroy(GiSGCalConfig *config)
Destroys a sgcalibration field setup structure.
void giraffe_sgcalibration_config_add(cpl_parameterlist *list)
Adds parameters for the sgcalibration correction computation.
cxint giraffe_calibrate_slit(GiTable *result, const GiExtraction *extraction, const GiLocalization *localization, const GiTable *fibers, const GiTable *wlsolution, const GiTable *slitgeometry, const GiTable *grating, const GiTable *mask, const GiSGCalConfig *config)
Compute a slit geometry corresponding to the given rebinned spectrum.
GiTable * giraffe_slitgeometry_load(const GiTable *fibers, const cxchar *filename, cxint pos, const cxchar *tag)
Load the slit geometry information for a given fiber setup.
GiTable * giraffe_table_new(void)
Creates a new, empty Giraffe table.
Definition: gitable.c:85
cxint giraffe_table_load(GiTable *self, const cxchar *filename, cxint position, const cxchar *id)
Reads a data set from a file into a Giraffe table.
Definition: gitable.c:562
cxint giraffe_table_attach(GiTable *self, const cxchar *filename, cxint position, const cxchar *id)
Attach a Giraffe table to a file.
Definition: gitable.c:749
void giraffe_table_delete(GiTable *self)
Destroys a Giraffe table.
Definition: gitable.c:154
cpl_table * giraffe_table_get(const GiTable *self)
Get the table data from a Giraffe table.
Definition: gitable.c:433
cpl_propertylist * giraffe_table_get_properties(const GiTable *self)
Gets the table properties.
Definition: gitable.c:489
cxint giraffe_table_add_info(GiTable *table, const GiRecipeInfo *info, const cpl_frameset *set)
Add additional frame information to a table.
Definition: gitable.c:836
cxint giraffe_propertylist_copy(cpl_propertylist *self, const cxchar *name, const cpl_propertylist *other, const cxchar *othername)
Copy a property from one list to another.
Definition: giutils.c:1108
const cxchar * giraffe_get_license(void)
Get the pipeline copyright and license.
Definition: giutils.c:422
void giraffe_wlcalibration_config_add(cpl_parameterlist *list)
Adds parameters for the wavelength calibration.
cxint giraffe_calibrate_wavelength(GiWCalData *result, GiExtraction *extraction, GiLocalization *localization, GiTable *fibers, GiTable *slitgeometry, GiTable *grating, GiTable *lines, GiTable *initial, GiWCalConfig *config)
Compute the wavelength solution for the given extracted arc-lamp spectra.
GiWCalConfig * giraffe_wlcalibration_config_create(cpl_parameterlist *list)
Creates a setup structure for the wavelength calibration.
void giraffe_wlcalibration_config_destroy(GiWCalConfig *config)
Destroys a wavelength calibration setup structure.
Slit geometry calibration configuration data structure.
Wavelength calibration configuration data structure.

This file is part of the GIRAFFE Pipeline Reference Manual 2.19.4.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Fri Feb 6 2026 11:30:08 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2004