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