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
1580 cxdouble efficiency[2] = {0., 0.};
1581 cxdouble wlcenter = 0.;
1582 cxdouble mean = 0.;
1583 cxdouble rms = 0.;
1584 cxdouble std;
1585 cxdouble pixel2nm = 1.;
1586 cxdouble fwhm_domain[2] = {0., 100.};
1587 cxdouble* _tdata = NULL;
1588 cxdouble* _tdata_fib3 = NULL;
1589
1590 cpl_propertylist* properties = NULL;
1591 cpl_propertylist* qclog = NULL;
1592
1593 cpl_frame* rframe = NULL;
1594 cpl_frame* pframe = NULL;
1595
1596 const cpl_image* _pimage = NULL;
1597 const cpl_image* _qimage = NULL;
1598 const cpl_image* _rimage = NULL;
1599
1600 cpl_image* _test = NULL;
1601 cpl_image* _test0 = NULL;
1602 cpl_image* _test1 = NULL;
1603
1604 cpl_image* _test_fib3 = NULL;
1605 cpl_image* _test0_fib3 = NULL;
1606 cpl_image* _test1_fib3 = NULL;
1607
1608 cpl_table* _ptable = NULL;
1609
1610 GiImage* rimage = NULL;
1611 GiImage* pimage = NULL;
1612
1613 GiTable* ptable = NULL;
1614
1615 GiLineData* plines = NULL;
1616
1617 GiPaf* qc = NULL;
1618
1619 GiWindow w;
1620
1621
1622 cpl_parameter * simcalp = cpl_parameterlist_find(config, "giraffe.wcal.qc.simlamp");
1623
1624 cxbool qc_simlamp_flag = FALSE;
1625
1626 if (simcalp != NULL) {
1627 qc_simlamp_flag = cpl_parameter_get_bool(simcalp);
1628 }
1629
1630 char* giframe_arc_lamp_extspectra = GIFRAME_ARC_LAMP_EXTSPECTRA;
1631 char* giframe_arc_lamp_rbnspectra = GIFRAME_ARC_LAMP_RBNSPECTRA;
1632 char* giframe_line_data = GIFRAME_LINE_DATA;
1633 char* giframe_wavelength_solution = GIFRAME_WAVELENGTH_SOLUTION;
1634
1635 if(qc_simlamp_flag) {
1636 giframe_arc_lamp_extspectra = GIFRAME_ARC_LAMP_EXTSPECTRA_SIM;
1637 giframe_arc_lamp_rbnspectra = GIFRAME_ARC_LAMP_RBNSPECTRA_SIM;
1638 giframe_line_data = GIFRAME_LINE_DATA_SIM;
1639 giframe_wavelength_solution = GIFRAME_WAVELENGTH_SOLUTION_SIM;
1640 }
1641
1642
1643 cpl_msg_info(fctid, "Computing QC1 parameters ...");
1644
1645
1646 /*
1647 * Compute lamp efficiencies from the rebinned frame if
1648 * it is available. If not the efficiencies are set to 0.
1649 */
1650
1651 pframe = giraffe_get_frame(set, giframe_arc_lamp_extspectra,
1652 CPL_FRAME_GROUP_PRODUCT);
1653
1654 if (pframe == NULL) {
1655
1656 cpl_msg_warning(fctid, "Product '%s' not found.",
1657 giframe_arc_lamp_extspectra);
1658
1659 cpl_msg_warning(fctid, "Setting lamp efficiencies (%s, %s) to 0.",
1660 GIALIAS_QCLAMP, GIALIAS_QCLAMP_SIMCAL);
1661
1662 efficiency[0] = 0.;
1663 efficiency[1] = 0.;
1664
1665 }
1666
1667
1668 pimage = giraffe_image_new(CPL_TYPE_DOUBLE);
1669 status = giraffe_image_load(pimage, cpl_frame_get_filename(pframe), 0);
1670
1671 if (status != 0) {
1672 cpl_msg_error(fctid, "Could not load extracted spectra '%s'!",
1673 cpl_frame_get_filename(pframe));
1674
1675 giraffe_image_delete(pimage);
1676 pimage = NULL;
1677
1678 giraffe_paf_delete(qc);
1679 qc = NULL;
1680
1681 return 1;
1682 }
1683
1684 _pimage = giraffe_image_get(pimage);
1685 cx_assert(_pimage != NULL);
1686
1687
1688 ptable = giraffe_table_new();
1689 status = giraffe_table_load(ptable, cpl_frame_get_filename(pframe), 1,
1690 NULL);
1691
1692 if (status != 0) {
1693 cpl_msg_error(fctid, "Could not load extracted spectra fiber setup!");
1694
1695 giraffe_table_delete(ptable);
1696 ptable = NULL;
1697
1698 giraffe_image_delete(pimage);
1699 pimage = NULL;
1700
1701 giraffe_paf_delete(qc);
1702 qc = NULL;
1703
1704 return 1;
1705 }
1706
1707 _ptable = giraffe_table_get(ptable);
1708 cx_assert(_ptable != NULL);
1709
1710 if (cpl_table_has_column(_ptable, "RP") == FALSE) {
1711
1712 cpl_msg_warning(fctid, "Column 'RP' not found in fiber setup table!");
1713 cpl_msg_warning(fctid, "Setting lamp efficiencies (%s, %s) to 0.",
1714 GIALIAS_QCLAMP, GIALIAS_QCLAMP_SIMCAL);
1715
1716 efficiency[0] = 0.;
1717 efficiency[1] = 0.;
1718
1719 }
1720 else {
1721
1722 properties = giraffe_image_get_properties(pimage);
1723 cx_assert(properties != NULL);
1724
1725 if (cpl_propertylist_has(properties, GIALIAS_EXPTIME) == FALSE) {
1726
1727 cpl_msg_warning(fctid, "Property '%s' not found in '%s'.",
1728 GIALIAS_EXPTIME, cpl_frame_get_filename(rframe));
1729 cpl_msg_warning(fctid, "Setting lamp efficiencies (%s, %s) to 0.",
1730 GIALIAS_QCLAMP, GIALIAS_QCLAMP_SIMCAL);
1731
1732 efficiency[0] = 0.;
1733 efficiency[1] = 0.;
1734
1735 }
1736 else {
1737
1738 cxint fiber = 0;
1739 cxint nb = cpl_image_get_size_y(_pimage);
1740 cxint nf[2] = {0, 0};
1741
1742 cxdouble exptime = cpl_propertylist_get_double(properties,
1743 GIALIAS_EXPTIME);
1744 cxdouble* _sum = NULL;
1745
1746 cpl_image* sum = NULL;
1747
1748
1749 sum = cpl_image_collapse_create(_pimage, 0);
1750 _sum = cpl_image_get_data_double(sum);
1751
1752 for (fiber = 0; fiber < cpl_table_get_nrow(_ptable); ++fiber) {
1753
1754 cxint rp = cpl_table_get_int(_ptable, "RP", fiber, NULL);
1755
1756 if (rp == -1) {
1757 efficiency[1] += _sum[fiber];
1758 ++nf[1];
1759 }
1760 else {
1761 efficiency[0] += _sum[fiber];
1762 ++nf[0];
1763 }
1764
1765 }
1766
1767 _sum = NULL;
1768
1769 cpl_image_delete(sum);
1770 sum = NULL;
1771
1772 if (nf[0] == 0) {
1773 cpl_msg_warning(fctid, "No OzPoz fibers found in the "
1774 "current fiber setup.");
1775 cpl_msg_warning(fctid, "Setting lamp efficiency (%s) to 0.",
1776 GIALIAS_QCLAMP);
1777 efficiency[0] = 0.;
1778 }
1779 else {
1780 efficiency[0] /= nf[0] * nb * exptime;
1781 }
1782
1783 if (nf[1] == 0) {
1784 cpl_msg_warning(fctid, "No simultaneous calibration fibers "
1785 "found in the current fiber setup.");
1786 cpl_msg_warning(fctid, "Setting lamp efficiency (%s) to 0.",
1787 GIALIAS_QCLAMP_SIMCAL);
1788 efficiency[1] = 0.;
1789 }
1790 else {
1791 efficiency[1] /= nf[1] * nb * exptime;
1792 }
1793
1794 }
1795
1796 properties = NULL;
1797
1798 }
1799
1800 _ptable = NULL;
1801 _pimage = NULL;
1802
1803 giraffe_table_delete(ptable);
1804 ptable = NULL;
1805
1806 giraffe_image_delete(pimage);
1807 pimage = NULL;
1808
1809
1810 /*
1811 * Load first raw image as reference
1812 */
1813
1814 rframe = cpl_frameset_find(set, GIFRAME_ARC_SPECTRUM);
1815
1816 if (rframe == NULL) {
1817 cpl_msg_error(fctid, "Missing raw frame (%s)", GIFRAME_ARC_SPECTRUM);
1818
1819 giraffe_paf_delete(qc);
1820 qc = NULL;
1821
1822 return 1;
1823 }
1824
1825 cpl_msg_info(fctid, "Processing reference frame '%s' (%s)",
1826 cpl_frame_get_filename(rframe), cpl_frame_get_tag(rframe));
1827
1828 rimage = giraffe_image_new(CPL_TYPE_DOUBLE);
1829 status = giraffe_image_load(rimage, cpl_frame_get_filename(rframe), 0);
1830
1831 if (status != 0) {
1832
1833 cpl_msg_error(fctid, "Could not load arc-lamp spectra '%s'!",
1834 cpl_frame_get_filename(rframe));
1835
1836 giraffe_image_delete(rimage);
1837 rimage = NULL;
1838
1839 giraffe_paf_delete(qc);
1840 qc = NULL;
1841
1842 return 1;
1843
1844 }
1845
1846 _rimage = giraffe_image_get(rimage);
1847 cx_assert(_rimage != NULL);
1848
1849
1850 /*
1851 * Compute mean level of the first raw frame and count the number
1852 * of saturated pixels.
1853 */
1854
1855 properties = giraffe_image_get_properties(rimage);
1856 cx_assert(properties != NULL);
1857
1858 if (cpl_propertylist_has(properties, GIALIAS_OVSCX)) {
1859
1860 cxint _ox = cpl_propertylist_get_int(properties, GIALIAS_OVSCX);
1861 cxint _nx = cpl_image_get_size_x(_rimage) - 2 * CX_MAX(0, _ox) - 1;
1862
1863 w.x0 = CX_MAX(0, _ox) + 1;
1864 w.x1 = w.x0 + _nx;
1865
1866 }
1867
1868 if (cpl_propertylist_has(properties, GIALIAS_OVSCY)) {
1869
1870 cxint _oy = cpl_propertylist_get_int(properties, GIALIAS_OVSCY);
1871 cxint _ny = cpl_image_get_size_y(_rimage) - 2 * CX_MAX(0, _oy) - 1;
1872
1873 w.y0 = CX_MAX(0, _oy) + 1;
1874 w.y1 = w.y0 + _ny;
1875
1876 }
1877
1878 mean = cpl_image_get_mean_window(_rimage, w.x0, w.y0, w.x1, w.y1);
1879
1880 pixels = cpl_image_get_data_const(_rimage);
1881 npixel = cpl_image_get_size_x(_rimage) * cpl_image_get_size_y(_rimage);
1882
1883 for (i = 0; i < npixel; i++) {
1884 if (pixels[i] > saturation) {
1885 ++nsaturated;
1886 }
1887 }
1888
1889
1890 /*
1891 * Process dispersion solution
1892 */
1893
1894 qc = giraffe_qclog_open(0);
1895
1896 if (qc == NULL) {
1897 cpl_msg_error(fctid, "Cannot create QC1 log!");
1898
1899 giraffe_image_delete(rimage);
1900 rimage = NULL;
1901
1902 return 1;
1903 }
1904
1905 qclog = giraffe_paf_get_properties(qc);
1906 cx_assert(qclog != NULL);
1907
1908 pframe = giraffe_get_frame(set, giframe_wavelength_solution,
1909 CPL_FRAME_GROUP_PRODUCT);
1910
1911 if (pframe == NULL) {
1912 cpl_msg_error(fctid, "Missing product frame (%s)",
1913 giframe_wavelength_solution);
1914
1915 giraffe_paf_delete(qc);
1916 qc = NULL;
1917
1918 giraffe_image_delete(rimage);
1919 rimage = NULL;
1920
1921 return 1;
1922 }
1923
1924 cpl_msg_info(fctid, "Processing product frame '%s' (%s)",
1925 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
1926
1927 ptable = giraffe_table_new();
1928 status = giraffe_table_load(ptable, cpl_frame_get_filename(pframe), 1,
1929 NULL);
1930
1931 if (status != 0) {
1932 cpl_msg_error(fctid, "Could not load dispersion solution '%s'!",
1933 cpl_frame_get_filename(pframe));
1934
1935 giraffe_table_delete(ptable);
1936 ptable = NULL;
1937
1938 giraffe_image_delete(rimage);
1939 rimage = NULL;
1940
1941 giraffe_paf_delete(qc);
1942 qc = NULL;
1943
1944 return 1;
1945 }
1946
1947 properties = giraffe_image_get_properties(rimage);
1948 cx_assert(properties != NULL);
1949
1950 giraffe_propertylist_copy(qclog, "ARCFILE", properties, GIALIAS_ARCFILE);
1951 giraffe_propertylist_copy(qclog, "TPL.ID", properties, GIALIAS_TPLID);
1952 giraffe_propertylist_copy(qclog, "INS.EXP.MODE", properties,
1953 GIALIAS_SETUPNAME);
1954 giraffe_propertylist_copy(qclog, "INS.SLIT.NAME", properties,
1955 GIALIAS_SLITNAME);
1956 giraffe_propertylist_copy(qclog, "INS.GRAT.NAME", properties,
1957 GIALIAS_GRATNAME);
1958 giraffe_propertylist_copy(qclog, "INS.GRAT.WLEN", properties,
1959 GIALIAS_GRATWLEN);
1960 giraffe_propertylist_copy(qclog, "INS.GRAT.ENC", properties,
1961 GIALIAS_GRATPOS);
1962
1963 cpl_propertylist_update_string(qclog, "PRO.CATG",
1964 cpl_frame_get_tag(pframe));
1965 cpl_propertylist_set_comment(qclog, "PRO.CATG",
1966 "Pipeline product category");
1967
1968 properties = giraffe_table_get_properties(ptable);
1969 cx_assert(properties != NULL);
1970
1971 wslnaccept = cpl_propertylist_get_int(properties, GIALIAS_WSOL_NACCEPT);
1972
1973 giraffe_propertylist_copy(qclog, "PRO.WSOL.RMS", properties,
1974 GIALIAS_WSOL_RMS);
1975 giraffe_propertylist_copy(qclog, "PRO.WSOL.NLINES", properties,
1976 GIALIAS_WSOL_NLINES);
1977 giraffe_propertylist_copy(qclog, "PRO.WSOL.NACCEPT", properties,
1978 GIALIAS_WSOL_NACCEPT);
1979 giraffe_propertylist_copy(qclog, "PRO.WSOL.NREJECT", properties,
1980 GIALIAS_WSOL_NREJECT);
1981 giraffe_propertylist_copy(qclog, "PRO.SLIT.NFIBRES", properties,
1982 GIALIAS_NFIBERS);
1983
1984
1985 giraffe_table_delete(ptable);
1986 ptable = NULL;
1987
1988 giraffe_qclog_close(qc);
1989 qc = NULL;
1990
1991
1992 /*
1993 * Process rebinned arc-lamp spectrum
1994 */
1995
1996 cxbool rebin = TRUE;
1997
1998 cpl_parameter * rebinp = cpl_parameterlist_find(config, "giraffe.wcal.rebin");
1999
2000 if (rebinp != NULL) {
2001 rebin = cpl_parameter_get_bool(rebinp);
2002 }
2003
2004 if(rebin){
2005
2006 qc = giraffe_qclog_open(1);
2007
2008 if (qc == NULL) {
2009 cpl_msg_error(fctid, "Cannot create QC1 log!");
2010 return 1;
2011 }
2012
2013 qclog = giraffe_paf_get_properties(qc);
2014 cx_assert(qclog != NULL);
2015
2016 pframe = giraffe_get_frame(set, giframe_arc_lamp_rbnspectra,
2017 CPL_FRAME_GROUP_PRODUCT);
2018
2019 if (pframe == NULL) {
2020 cpl_msg_error(fctid, "Missing product frame (%s)",
2021 giframe_arc_lamp_rbnspectra);
2022
2023 giraffe_image_delete(rimage);
2024 rimage = NULL;
2025
2026 giraffe_paf_delete(qc);
2027 qc = NULL;
2028
2029 return 1;
2030 }
2031
2032 cpl_msg_info(fctid, "Processing product frame '%s' (%s)",
2033 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
2034
2035 pimage = giraffe_image_new(CPL_TYPE_DOUBLE);
2036 status = giraffe_image_load(pimage, cpl_frame_get_filename(pframe), 0);
2037
2038 if (status != 0) {
2039 cpl_msg_error(fctid, "Could not load rebinned arc-lamp spectra '%s'!",
2040 cpl_frame_get_filename(pframe));
2041
2042 giraffe_image_delete(pimage);
2043 pimage = NULL;
2044
2045 giraffe_image_delete(rimage);
2046 rimage = NULL;
2047
2048 giraffe_paf_delete(qc);
2049 qc = NULL;
2050
2051 return 1;
2052 }
2053
2054 ptable = giraffe_table_new();
2055 status = giraffe_table_load(ptable, cpl_frame_get_filename(pframe), 1,
2056 NULL);
2057
2058 if (status != 0) {
2059 cpl_msg_error(fctid, "Could not load rebinned arc-lamp spectra '%s'!",
2060 cpl_frame_get_filename(pframe));
2061
2062 giraffe_table_delete(ptable);
2063 ptable = NULL;
2064
2065 giraffe_image_delete(pimage);
2066 pimage = NULL;
2067
2068 giraffe_image_delete(rimage);
2069 rimage = NULL;
2070
2071 giraffe_paf_delete(qc);
2072 qc = NULL;
2073
2074 return 1;
2075 }
2076
2077 properties = giraffe_image_get_properties(rimage);
2078 cx_assert(properties != NULL);
2079
2080 giraffe_propertylist_copy(qclog, "ARCFILE", properties, GIALIAS_ARCFILE);
2081 giraffe_propertylist_copy(qclog, "TPL.ID", properties, GIALIAS_TPLID);
2082 giraffe_propertylist_copy(qclog, "INS.EXP.MODE", properties,
2083 GIALIAS_SETUPNAME);
2084 giraffe_propertylist_copy(qclog, "INS.SLIT.NAME", properties,
2085 GIALIAS_SLITNAME);
2086 giraffe_propertylist_copy(qclog, "INS.GRAT.NAME", properties,
2087 GIALIAS_GRATNAME);
2088 giraffe_propertylist_copy(qclog, "INS.GRAT.WLEN", properties,
2089 GIALIAS_GRATWLEN);
2090
2091 cpl_propertylist_update_string(qclog, "PRO.CATG",
2092 cpl_frame_get_tag(pframe));
2093 cpl_propertylist_set_comment(qclog, "PRO.CATG",
2094 "Pipeline product category");
2095
2096 properties = giraffe_image_get_properties(pimage);
2097 cx_assert(properties != NULL);
2098
2099 giraffe_propertylist_copy(qclog, "PRO.DATAAVG", properties,
2100 GIALIAS_DATAMEAN);
2101 giraffe_propertylist_copy(qclog, "PRO.DATARMS", properties,
2102 GIALIAS_DATASIG);
2103 giraffe_propertylist_copy(qclog, "PRO.DATAMED", properties,
2104 GIALIAS_DATAMEDI);
2105 giraffe_propertylist_copy(qclog, "PRO.SLIT.NFIBRES", properties,
2106 GIALIAS_NFIBERS);
2107
2108 cxint binwns = cpl_propertylist_get_int(properties, GIALIAS_BINWNS);
2109
2110 if (binwns != 0 && wslnaccept != 0) {
2111 cpl_propertylist_update_double(properties, GIALIAS_QCNLINACC,
2112 (double)wslnaccept / binwns);
2113 }
2114 else {
2115 cpl_propertylist_update_double(properties, GIALIAS_QCNLINACC, 0.);
2116 }
2117
2118
2119 cpl_propertylist_update_double(properties, GIALIAS_QCMEAN, mean);
2120 cpl_propertylist_set_comment(properties, GIALIAS_QCMEAN, "Mean level of "
2121 "first raw frame");
2122
2123 giraffe_propertylist_copy(qclog, "QC.OUT1.MEAN.RAW", properties,
2124 GIALIAS_QCMEAN);
2125
2126
2127 cpl_propertylist_update_int(properties, GIALIAS_QCNSAT, nsaturated);
2128 cpl_propertylist_set_comment(properties, GIALIAS_QCNSAT, "Number of "
2129 "saturated pixels in the first raw frame");
2130
2131 giraffe_propertylist_copy(qclog, "QC.OUT1.NSAT.RAW", properties,
2132 GIALIAS_QCNSAT);
2133
2134
2135 /*
2136 * Calibration lamp monitoring
2137 */
2138
2139 cpl_propertylist_update_double(properties, GIALIAS_QCLAMP, efficiency[0]);
2140 cpl_propertylist_set_comment(properties, GIALIAS_QCLAMP,
2141 "Calibration lamp efficiency");
2142
2143 giraffe_propertylist_copy(qclog, "QC.LAMP.EFFIC", properties,
2144 GIALIAS_QCLAMP);
2145
2146 cpl_propertylist_update_double(properties, GIALIAS_QCLAMP_SIMCAL,
2147 efficiency[1]);
2148 cpl_propertylist_set_comment(properties, GIALIAS_QCLAMP_SIMCAL,
2149 "SIMCAL lamp efficiency");
2150
2151 giraffe_propertylist_copy(qclog, "QC.LAMP.EFFIC1", properties,
2152 GIALIAS_QCLAMP_SIMCAL);
2153
2154
2155 /* Compute rebinned emission line straightness. */
2156
2157 _pimage = giraffe_image_get(pimage);
2158
2159 _test = cpl_image_duplicate(_pimage);
2160 _tdata = cpl_image_get_data(_test);
2161
2162 _test_fib3 = cpl_image_duplicate(_pimage);
2163 _tdata_fib3 = cpl_image_get_data(_test_fib3);
2164
2165 nx = cpl_image_get_size_x(_test);
2166 ny = cpl_image_get_size_y(_test);
2167
2168 for (i = 0; i < nx * ny; i++) {
2169 _tdata[i] = _tdata[i] > 0. ? log(_tdata[i]) : 0.;
2170 _tdata_fib3[i] = _tdata_fib3[i] > 0. ? log10(_tdata_fib3[i]) : 0.;
2171 }
2172
2173 _tdata = NULL;
2174
2175 _test0 = cpl_image_extract(_test, 4, 1, 4, ny);
2176
2177 _test1 = cpl_image_collapse_create(_test, 1);
2178 cpl_image_divide_scalar(_test1, nx);
2179
2180 cpl_image_delete(_test);
2181 _test = NULL;
2182
2183
2184 _test = cpl_image_subtract_create(_test0, _test1);
2185
2186 cpl_image_delete(_test0);
2187 _test0 = NULL;
2188
2189 cpl_image_delete(_test1);
2190 _test1 = NULL;
2191
2192 _tdata_fib3 = NULL;
2193
2194 _test0_fib3 = cpl_image_extract(_test_fib3, 4, 1, 4, ny);
2195
2196 _ptable = giraffe_table_get(ptable);
2197 cx_assert(_ptable != NULL);
2198
2199 int nfib = nx;
2200
2201 if (cpl_table_has_column(_ptable, "OBJECT") == FALSE) {
2202 cpl_msg_warning(fctid,
2203 "Column 'OBJECT' not found in fiber setup table!");
2204 cpl_msg_warning(fctid, "CALSIM fibres may be included in QC params");
2205 }
2206 else {
2207 for (i = 0; i < nx; i++) {
2208 const char *objs = cpl_table_get_string(_ptable, "OBJECT", i);
2209 if (!strcmp(objs, "CALSIM")) {
2210 cpl_image_fill_window(_test_fib3, i + 1, 1, i + 1, ny, 0);
2211 nfib--;
2212 }
2213 }
2214 }
2215
2216 _test1_fib3 = cpl_image_collapse_create(_test_fib3, 1);
2217 cpl_image_divide_scalar(_test1_fib3, nfib);
2218
2219
2220 cpl_image_delete(_test_fib3);
2221 _test_fib3 = NULL;
2222
2223 _test_fib3 = cpl_image_subtract_create(_test0_fib3, _test1_fib3);
2224
2225 cpl_image_delete(_test0_fib3);
2226 _test0_fib3 = NULL;
2227
2228 cpl_image_delete(_test1_fib3);
2229 _test1_fib3 = NULL;
2230
2231
2232 _tdata = cpl_image_get_data(_test);
2233
2234 rms = 0;
2235
2236 for (i = 0; i < ny; i++) {
2237 _tdata[i] = exp(_tdata[i]);
2238 rms += pow(_tdata[i], 2.);
2239 }
2240
2241 rms = sqrt(rms / (ny - 1));
2242
2243 std = cpl_image_get_stdev_window(_test_fib3, 1, 1, 1, (cpl_size) ((1-0.045) * ny));
2244
2245 cpl_image_delete(_test);
2246 _test = NULL;
2247 cpl_image_delete(_test_fib3);
2248 _test_fib3 = NULL;
2249
2250 cpl_propertylist_update_double(properties, GIALIAS_QCRBRMS, rms);
2251 cpl_propertylist_set_comment(properties, GIALIAS_QCRBRMS,
2252 "RMS of rebinned arc-lamp spectra");
2253
2254 giraffe_propertylist_copy(qclog, "QC.WSOL.REBIN.RMS", properties,
2255 GIALIAS_QCRBRMS);
2256
2257 cpl_propertylist_update_double(properties, GIALIAS_QCFIB3 , std);
2258 cpl_propertylist_set_comment(properties, GIALIAS_QCFIB3 ,
2259 "STDEV of fibre 3 - mean");
2260
2261 giraffe_propertylist_copy(qclog, "QC.FIB3.RMS", properties,
2262 GIALIAS_QCFIB3 );
2263
2264
2265 status = giraffe_image_save(pimage, cpl_frame_get_filename(pframe));
2266
2267 if (status != 0) {
2268 cpl_msg_error(fctid, "Could not save rebinned arc-lamp spectra "
2269 "'%s'!", cpl_frame_get_filename(pframe));
2270
2271 giraffe_table_delete(ptable);
2272 ptable = NULL;
2273
2274 giraffe_image_delete(pimage);
2275 pimage = NULL;
2276
2277 giraffe_image_delete(rimage);
2278 rimage = NULL;
2279
2280 giraffe_paf_delete(qc);
2281 qc = NULL;
2282
2283 return 1;
2284 }
2285
2286 status = giraffe_table_attach(ptable, cpl_frame_get_filename(pframe),
2287 1, NULL);
2288
2289 if (status != 0) {
2290 cpl_msg_error(fctid, "Could not save rebinned arc-lamp spectra "
2291 "'%s'!", cpl_frame_get_filename(pframe));
2292
2293 giraffe_table_delete(ptable);
2294 ptable = NULL;
2295
2296 giraffe_image_delete(pimage);
2297 pimage = NULL;
2298
2299 giraffe_image_delete(rimage);
2300 rimage = NULL;
2301
2302 giraffe_paf_delete(qc);
2303 qc = NULL;
2304
2305 return 1;
2306 }
2307
2308 giraffe_image_delete(pimage);
2309 pimage = NULL;
2310
2311 giraffe_table_delete(ptable);
2312 ptable = NULL;
2313
2314 giraffe_qclog_close(qc);
2315 qc = NULL;
2316
2317}
2318
2319 /*
2320 * Process line data
2321 */
2322
2323 qc = giraffe_qclog_open(2);
2324
2325 if (qc == NULL) {
2326 cpl_msg_error(fctid, "Cannot create QC1 log!");
2327 return 1;
2328 }
2329
2330 qclog = giraffe_paf_get_properties(qc);
2331 cx_assert(qclog != NULL);
2332
2333 pframe = giraffe_get_frame(set, giframe_line_data,
2334 CPL_FRAME_GROUP_PRODUCT);
2335
2336 if (pframe == NULL) {
2337 cpl_msg_error(fctid, "Missing product frame (%s)",
2338 giframe_line_data);
2339
2340 giraffe_image_delete(rimage);
2341 rimage = NULL;
2342
2343 giraffe_paf_delete(qc);
2344 qc = NULL;
2345
2346 return 1;
2347 }
2348
2349 cpl_msg_info(fctid, "Processing product frame '%s' (%s)",
2350 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
2351
2352
2353 /*
2354 * Load line data
2355 */
2356
2357 plines = giraffe_linedata_new();
2358
2359 status = giraffe_linedata_load(plines, cpl_frame_get_filename(pframe));
2360
2361 if (status != 0) {
2362 cpl_msg_error(fctid, "Could not load line data '%s'!",
2363 cpl_frame_get_filename(pframe));
2364
2365 giraffe_linedata_delete(plines);
2366 plines = NULL;
2367
2368 giraffe_image_delete(rimage);
2369 rimage = NULL;
2370
2371 giraffe_paf_delete(qc);
2372 qc = NULL;
2373
2374 return 1;
2375 }
2376
2377 properties = giraffe_image_get_properties(rimage);
2378 cx_assert(properties != NULL);
2379
2380 giraffe_propertylist_copy(qclog, "ARCFILE", properties, GIALIAS_ARCFILE);
2381 giraffe_propertylist_copy(qclog, "TPL.ID", properties, GIALIAS_TPLID);
2382 giraffe_propertylist_copy(qclog, "INS.EXP.MODE", properties,
2383 GIALIAS_SETUPNAME);
2384 giraffe_propertylist_copy(qclog, "INS.SLIT.NAME", properties,
2385 GIALIAS_SLITNAME);
2386 giraffe_propertylist_copy(qclog, "INS.GRAT.NAME", properties,
2387 GIALIAS_GRATNAME);
2388 giraffe_propertylist_copy(qclog, "INS.GRAT.WLEN", properties,
2389 GIALIAS_GRATWLEN);
2390
2391 cpl_propertylist_update_string(qclog, "PRO.CATG",
2392 cpl_frame_get_tag(pframe));
2393 cpl_propertylist_set_comment(qclog, "PRO.CATG",
2394 "Pipeline product category");
2395
2396
2397 _pimage = giraffe_linedata_get_data(plines, "FWHM");
2398
2399 if (_pimage == NULL) {
2400 cpl_msg_error(fctid, "FWHM line data not found!");
2401
2402 giraffe_linedata_delete(plines);
2403 plines = NULL;
2404
2405 giraffe_image_delete(rimage);
2406 rimage = NULL;
2407
2408 giraffe_paf_delete(qc);
2409 qc = NULL;
2410
2411 return 1;
2412 }
2413
2414 nx = cpl_image_get_size_x(_pimage);
2415 ny = cpl_image_get_size_y(_pimage);
2416
2417 pixels = cpl_image_get_data_const(_pimage);
2418
2419 for (j = 0; j < 2; ++j) {
2420
2421 register cxint ndata = nx * ny;
2422
2423 npixel = 0;
2424 mean = 0.;
2425 rms = 0.;
2426
2427 for (i = 0; i < ndata; ++i) {
2428
2429 if ((pixels[i] >= fwhm_domain[0]) &&
2430 (pixels[i] < fwhm_domain[1])) {
2431 mean += pixels[i];
2432 ++npixel;
2433 }
2434
2435 }
2436
2437 if (npixel == 0) {
2438 cpl_msg_error(fctid, "All line FWHM data are invalid!");
2439
2440 giraffe_linedata_delete(plines);
2441 plines = NULL;
2442
2443 giraffe_image_delete(rimage);
2444 rimage = NULL;
2445
2446 giraffe_paf_delete(qc);
2447 qc = NULL;
2448
2449 return 1;
2450 }
2451
2452 mean /= npixel;
2453
2454 for (i = 0; i < ndata; ++i) {
2455
2456 if ((pixels[i] >= fwhm_domain[0]) &&
2457 (pixels[i] < fwhm_domain[1])) {
2458 rms += pow(pixels[i] - mean, 2.);
2459 }
2460
2461 }
2462
2463 if (npixel > 1) {
2464 rms = sqrt(rms / (npixel - 1));
2465 }
2466
2467 fwhm_domain[0] = CX_MAX(mean - rmsscale * rms, 0.);
2468 fwhm_domain[1] = CX_MIN(mean + rmsscale * rms, 100.);
2469
2470 }
2471
2472 /*
2473 * Calculation of average X and Y offsets and Flux for simlamp QC's
2474 */
2475
2476 double x_total = 0.;
2477 double y_total = 0.;
2478 double flux_total = 0.;
2479
2480 cx_string *slit_name = NULL;
2481 cx_string *grat_name = NULL;
2482
2483
2484 if (qc_simlamp_flag) {
2485 _pimage = giraffe_linedata_get_data(plines, "Xccd");
2486
2487 if (_pimage == NULL) {
2488 cpl_msg_error(fctid, "Xccd line data not found!");
2489
2490 giraffe_linedata_delete(plines);
2491 plines = NULL;
2492
2493 giraffe_image_delete(rimage);
2494 rimage = NULL;
2495
2496 giraffe_paf_delete(qc);
2497 qc = NULL;
2498
2499 return 1;
2500 }
2501
2502 _qimage = giraffe_linedata_get_data(plines, "Yccd");
2503
2504 if (_qimage == NULL) {
2505 cpl_msg_error(fctid, "Yccd line data not found!");
2506
2507 giraffe_linedata_delete(plines);
2508 plines = NULL;
2509
2510 giraffe_image_delete(rimage);
2511 rimage = NULL;
2512
2513 giraffe_paf_delete(qc);
2514 qc = NULL;
2515
2516 return 1;
2517 }
2518
2519 nx = cpl_image_get_size_x(_rimage);
2520 ny = cpl_image_get_size_y(_rimage);
2521
2522 npx = cpl_image_get_size_x(_pimage);
2523 npy = cpl_image_get_size_y(_pimage);
2524
2525 pixels = cpl_image_get_data_const(_rimage);
2526 xpos = cpl_image_get_data_const(_pimage);
2527 ypos = cpl_image_get_data_const(_qimage);
2528
2529 int prscx = 0;
2530
2531 if (cpl_propertylist_has(properties, GIALIAS_PRSCX)) {
2532 prscx = cpl_propertylist_get_int(properties, GIALIAS_PRSCX);
2533 }
2534
2535 /*
2536 * xpos and ypos contain the X and Y positions of the lines in the raw
2537 * frame. Note X is defined as the dispersion direction. The X values
2538 * are already accurate as they are derived from the line fit, the Y
2539 * values are taken from the provided flat field, so need to be redone
2540 * for the arc frame
2541 */
2542
2543 int npxi = 0;
2544 int npyi;
2545
2546 int cwidth = 11;
2547 int cmid = floor(cwidth / 2);
2548
2549 for (npxi = 0; npxi < npx; npxi++) {
2550 for (npyi = 0; npyi < npy; npyi++) {
2551 int y = 0;
2552 double pixval = 0.;
2553 double max_val = 0.;
2554 int max_index = 0;
2555 int pixpos_init = 0;
2556 int pixpos = 0;
2557
2558 /*
2559 * First search for maximum in cwidth pixels around the flat Y
2560 * position.
2561 */
2562
2563 pixpos_init = (int)floor(ypos[npxi + npyi * npx]) + prscx +
2564 nx * (int)floor(xpos[npxi + npyi * npx]) - cmid;
2565
2566 for (y = 0; y < cwidth; y++) {
2567 pixpos = pixpos_init + y;
2568 if (pixpos >= 0 && pixpos < ny * nx) {
2569 pixval = pixels[pixpos];
2570 if (pixval > max_val) {
2571 max_val = pixval;
2572 max_index = y;
2573 }
2574 }
2575 }
2576
2577 /* Then do a centroid of cwidth pixels around the maximum */
2578
2579 double zz = 0.;
2580 double yy = 0.;
2581
2582 for (y = 0; y < cwidth; y++) {
2583 pixpos = pixpos_init + y - (cmid - max_index);
2584 if (pixpos >= 0 && pixpos < ny * nx) {
2585 pixval = pixels[pixpos];
2586 yy += pixval * y;
2587 zz += pixval;
2588 flux_total += pixval;
2589 }
2590 }
2591
2592 x_total += xpos[npxi + npyi * npx];
2593 y_total += (int)floor(ypos[npxi + npyi * npx]) + prscx -
2594 (cmid - max_index) - cmid + yy / zz;
2595 }
2596 }
2597
2598 x_total = x_total / (npx * npy);
2599 y_total = y_total / (npx * npy);
2600 flux_total = flux_total / (npx * npy) / cwidth;
2601
2602 if (cpl_propertylist_has(properties, GIALIAS_SLITNAME) == FALSE) {
2603 cpl_msg_error(fctid,
2604 "SLit name property '%s' not "
2605 "found!",
2606 GIALIAS_SLITNAME);
2607
2608 cpl_propertylist_delete(properties);
2609 properties = NULL;
2610
2611 giraffe_linedata_delete(plines);
2612 plines = NULL;
2613
2614 giraffe_image_delete(rimage);
2615 rimage = NULL;
2616
2617 giraffe_paf_delete(qc);
2618 qc = NULL;
2619
2620 return 1;
2621 }
2622
2623 slit_name = cx_string_create(
2624 cpl_propertylist_get_string(properties, GIALIAS_SLITNAME));
2625
2626 if (cpl_propertylist_has(properties, GIALIAS_GRATNAME) == FALSE) {
2627 cpl_msg_error(fctid,
2628 "Grating name property '%s' not "
2629 "found!",
2630 GIALIAS_GRATNAME);
2631
2632 cpl_propertylist_delete(properties);
2633 properties = NULL;
2634
2635 giraffe_linedata_delete(plines);
2636 plines = NULL;
2637
2638 giraffe_image_delete(rimage);
2639 rimage = NULL;
2640
2641 giraffe_paf_delete(qc);
2642 qc = NULL;
2643
2644 return 1;
2645 }
2646
2647 grat_name = cx_string_create(
2648 cpl_propertylist_get_string(properties, GIALIAS_GRATNAME));
2649
2650 cx_string_append(slit_name, cx_string_get(grat_name));
2651
2652 /*
2653 * Adding magic numbers so that QC parameters are scaled to match
2654 * those from the original system. Note that the x_total offset is
2655 * dependent on the value of wlcalibration.line.widths in the
2656 * reduction, these values are correct for
2657 * wlcalibration.line.widths=12
2658 */
2659
2660 y_total = 1003.66 - y_total;
2661 x_total = 1719.13 - x_total;
2662
2663 if (strcmp(cx_string_get(slit_name), "Medusa1HR") == 0) {
2664 y_total = 1.019 * y_total + 0.016;
2665 x_total = 0.986 * x_total - 0.073;
2666 flux_total = 1.334 * flux_total - 506.565;
2667 }
2668 else if (strcmp(cx_string_get(slit_name), "Medusa1LR") == 0) {
2669 y_total = 1.038 * y_total + 3.322;
2670 x_total = 1.194 * x_total + 434.818;
2671 flux_total = 0.243 * flux_total - 121.36;
2672 }
2673 else if (strcmp(cx_string_get(slit_name), "Medusa2HR") == 0) {
2674 y_total = 0.989 * y_total - 1.067;
2675 x_total = 1.0 * x_total - 10;
2676 flux_total = 1.397 * flux_total - 465.637;
2677 }
2678 else if (strcmp(cx_string_get(slit_name), "IFU1HR") == 0) {
2679 y_total = 0.977 * y_total - 107.426;
2680 x_total = 0.96 * x_total - 4.968;
2681 flux_total = 1.661 * flux_total - 512.41;
2682 }
2683 else if (strcmp(cx_string_get(slit_name), "IFU2HR") == 0) {
2684 y_total = 0.956 * y_total - 103.017;
2685 x_total = 0.942 * x_total + 0.22;
2686 flux_total = 0.786 * flux_total - 247.967;
2687 }
2688 else if (strcmp(cx_string_get(slit_name), "ArgusHR") == 0) {
2689 y_total = 0.954 * y_total + 152.569;
2690 x_total = 0.928 * x_total - 12.441;
2691 flux_total = 1.219 * flux_total - 329.05;
2692 }
2693 else {
2694 cpl_msg_error(
2695 fctid, "Slit and grating name '%s' not recognized for SIMLAMP!",
2696 cx_string_get(slit_name));
2697
2698 cpl_propertylist_delete(properties);
2699 properties = NULL;
2700
2701 giraffe_linedata_delete(plines);
2702 plines = NULL;
2703
2704 giraffe_image_delete(rimage);
2705 rimage = NULL;
2706
2707 giraffe_paf_delete(qc);
2708 qc = NULL;
2709
2710 return 1;
2711 }
2712
2713 cx_string_delete(slit_name);
2714 cx_string_delete(grat_name);
2715 }
2716
2717 properties = cpl_propertylist_load_regexp(cpl_frame_get_filename(pframe),
2718 0, "^COMMENT$", TRUE);
2719
2720 cx_assert(properties != NULL);
2721
2722 if (cpl_propertylist_has(properties, GIALIAS_GRATWLEN) == FALSE) {
2723 cpl_msg_error(fctid, "Grating central wavelength property '%s' not "
2724 "found!", GIALIAS_GRATWLEN);
2725
2726 cpl_propertylist_delete(properties);
2727 properties = NULL;
2728
2729 giraffe_linedata_delete(plines);
2730 plines = NULL;
2731
2732 giraffe_image_delete(rimage);
2733 rimage = NULL;
2734
2735 giraffe_paf_delete(qc);
2736 qc = NULL;
2737
2738 return 1;
2739 }
2740
2741 if (cpl_propertylist_has(properties, GIALIAS_WSOL_SCALE) == FALSE) {
2742 cpl_msg_error(fctid, "Line data property '%s' not found!",
2743 GIALIAS_WSOL_SCALE);
2744
2745 cpl_propertylist_delete(properties);
2746 properties = NULL;
2747
2748 giraffe_linedata_delete(plines);
2749 plines = NULL;
2750
2751 giraffe_image_delete(rimage);
2752 rimage = NULL;
2753
2754 giraffe_paf_delete(qc);
2755 qc = NULL;
2756
2757 return 1;
2758 }
2759
2760 wlcenter = cpl_propertylist_get_double(properties, GIALIAS_GRATWLEN);
2761 pixel2nm = cpl_propertylist_get_double(properties, GIALIAS_WSOL_SCALE);
2762
2763 mean *= pixel2nm;
2764 rms *= pixel2nm;
2765
2766 /*
2767 * Adding QC XPOS, YPOS and FLUX values for SIMLAMP frames, note switch
2768 * between giwavecalibration and QC definitions of X/Y axes.
2769 */
2770
2771 if (qc_simlamp_flag) {
2772 cpl_propertylist_update_double(properties, GIALIAS_QCSIMCALX, y_total);
2773 cpl_propertylist_set_comment(properties, GIALIAS_QCSIMCALX,
2774 "Average X of SIMCAL lines");
2775
2776 cpl_propertylist_update_double(properties, GIALIAS_QCSIMCALY, x_total);
2777 cpl_propertylist_set_comment(properties, GIALIAS_QCSIMCALY,
2778 "Average Y of SIMCAL lines");
2779
2780 cpl_propertylist_update_double(properties, GIALIAS_QCSIMCALF,
2781 flux_total);
2782 cpl_propertylist_set_comment(properties, GIALIAS_QCSIMCALF,
2783 "Average flux of SIMCAL lines");
2784 }
2785
2786 cpl_propertylist_update_double(properties, GIALIAS_QCRESOLAVG, mean);
2787 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLAVG,
2788 "Average line FWHM [nm]");
2789
2790 cpl_propertylist_update_double(properties, GIALIAS_QCRESOLRMS, rms);
2791 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLRMS,
2792 "RMS of line FWHM [nm]");
2793
2794 cpl_propertylist_update_int(properties, GIALIAS_QCRESOLTOT, nx * ny);
2795 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLTOT,
2796 "Total number of lines available for FWHM RMS "
2797 "computation");
2798
2799 cpl_propertylist_update_int(properties, GIALIAS_QCRESOLLIN, npixel);
2800 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLLIN,
2801 "Number of lines used for FWHM RMS "
2802 "computation");
2803
2804 cpl_propertylist_update_double(properties, GIALIAS_QCRESOLPWR,
2805 wlcenter / mean);
2806 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLPWR,
2807 "Resolving power");
2808
2809 giraffe_propertylist_copy(qclog, "QC.RESOL.MEAN", properties,
2810 GIALIAS_QCRESOLAVG);
2811 giraffe_propertylist_copy(qclog, "QC.RESOL.RMS", properties,
2812 GIALIAS_QCRESOLRMS);
2813 giraffe_propertylist_copy(qclog, "QC.RESOL.NTOTAL", properties,
2814 GIALIAS_QCRESOLTOT);
2815 giraffe_propertylist_copy(qclog, "QC.RESOL.NLINES", properties,
2816 GIALIAS_QCRESOLLIN);
2817 giraffe_propertylist_copy(qclog, "QC.RESOL.POWER", properties,
2818 GIALIAS_QCRESOLPWR);
2819
2820
2821 status = giraffe_linedata_save(plines, properties,
2822 cpl_frame_get_filename(pframe));
2823
2824 if (status != 0) {
2825 cpl_msg_error(fctid, "Could not save line data "
2826 "'%s'!", cpl_frame_get_filename(pframe));
2827
2828 cpl_propertylist_delete(properties);
2829 properties = NULL;
2830
2831 giraffe_linedata_delete(plines);
2832 plines = NULL;
2833
2834 giraffe_image_delete(rimage);
2835 rimage = NULL;
2836
2837 giraffe_paf_delete(qc);
2838 qc = NULL;
2839
2840 return 1;
2841 }
2842
2843 cpl_propertylist_delete(properties);
2844 properties = NULL;
2845
2846 giraffe_qclog_close(qc);
2847 qc = NULL;
2848
2849
2850 /*
2851 * Cleanup
2852 */
2853
2854 giraffe_image_delete(rimage);
2855 giraffe_linedata_delete(plines);
2856 plines = NULL;
2857
2858 return 0;
2859
2860}
2861
2862
2863/*
2864 * Build table of contents, i.e. the list of available plugins, for
2865 * this module. This function is exported.
2866 */
2867
2868int
2869cpl_plugin_get_info(cpl_pluginlist* list)
2870{
2871
2872 cpl_recipe* recipe = cx_calloc(1, sizeof *recipe);
2873 cpl_plugin* plugin = &recipe->interface;
2874
2875 cpl_plugin_init(plugin,
2876 CPL_PLUGIN_API,
2877 GIRAFFE_BINARY_VERSION,
2878 CPL_PLUGIN_TYPE_RECIPE,
2879 "giwavecalibration",
2880 "Compute dispersion solution from an arc-lamp spectrum.",
2881 "For detailed information please refer to the "
2882 "GIRAFFE pipeline user manual.\nIt is available at "
2883 "http://www.eso.org/pipelines.",
2884 "Giraffe Pipeline",
2885 PACKAGE_BUGREPORT,
2887 giwavecalibration_create,
2888 giwavecalibration_exec,
2889 giwavecalibration_destroy);
2890
2891 cpl_pluginlist_append(list, plugin);
2892
2893 return 0;
2894
2895}
GiBiasConfig * giraffe_bias_config_create(cpl_parameterlist *list)
Creates a setup structure for a bias removal task.
Definition: gibias.c:3436
void giraffe_bias_config_add(cpl_parameterlist *list)
Adds parameters for the bias removal.
Definition: gibias.c:3595
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:3104
void giraffe_bias_config_destroy(GiBiasConfig *config)
Destroys a bias removal setup structure.
Definition: gibias.c:3567
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 13:47:23 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2004