GIRAFFE Pipeline Reference Manual

gistandard.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 <cxslist.h>
27
28#include <cpl_recipe.h>
29#include <cpl_plugininfo.h>
30#include <cpl_parameterlist.h>
31#include <cpl_frameset.h>
32#include <cpl_msg.h>
33#include <cpl_errorstate.h>
34
35#include "gialias.h"
36#include "giframe.h"
37#include "gifibers.h"
38#include "gifiberutils.h"
39#include "gislitgeometry.h"
40#include "gipsfdata.h"
41#include "gibias.h"
42#include "gidark.h"
43#include "giextract.h"
44#include "giflat.h"
45#include "gitransmission.h"
46#include "girebinning.h"
47#include "gifov.h"
48#include "gifxcalibration.h"
49#include "gimessages.h"
50#include "gierror.h"
51#include "giqclog.h"
52#include "giutils.h"
53
54
55static cxint gistandard(cpl_parameterlist* config, cpl_frameset* set);
56static cxint giqcstandard(cpl_frameset* set);
57
58
59
60/*
61 * Create the recipe instance, i.e. setup the parameter list for this
62 * recipe and make it available to the application using the interface.
63 */
64
65static cxint
66gistandard_create(cpl_plugin* plugin)
67{
68
69 cpl_recipe* recipe = (cpl_recipe*)plugin;
70
71 cpl_parameter* p = NULL;
72
73
74 giraffe_error_init();
75
76
77 /*
78 * We have to provide the option we accept to the application. We
79 * need to setup our parameter list and hook it into the recipe
80 * interface.
81 */
82
83 recipe->parameters = cpl_parameterlist_new();
84 cx_assert(recipe->parameters != NULL);
85
86
87 /*
88 * Fill the parameter list.
89 */
90
91 /* Bias removal */
92
93 giraffe_bias_config_add(recipe->parameters);
94
95 /* Dark subtraction */
96
97 /* TBD */
98
99 /* Spectrum extraction */
100
101 giraffe_extract_config_add(recipe->parameters);
102
103 /* Flat fielding and relative fiber transmission correction */
104
105 giraffe_flat_config_add(recipe->parameters);
106
107 p = cpl_parameterlist_find(recipe->parameters, "giraffe.flat.apply");
108 cx_assert(p != NULL);
109
110 cpl_parameter_set_default_bool(p, FALSE);
111
112 /* Spectrum rebinning */
113
114 giraffe_rebin_config_add(recipe->parameters);
115
116 p = cpl_parameterlist_find(recipe->parameters,
117 "giraffe.rebinning.range");
118 cx_assert(p != NULL);
119
120 cpl_parameter_set_default_string(p, "common");
121
122 /* Image reconstruction (IFU and Argus only) */
123
124 giraffe_fov_config_add(recipe->parameters);
125
126 /* Flux calibration */
127
128 giraffe_fxcalibration_config_add(recipe->parameters);
129
130 return 0;
131
132}
133
134
135/*
136 * Execute the plugin instance given by the interface.
137 */
138
139static cxint
140gistandard_exec(cpl_plugin* plugin)
141{
142
143 cxint status = 0;
144
145 cpl_recipe* recipe = (cpl_recipe*)plugin;
146
147
148 cx_assert(recipe->parameters != NULL);
149 cx_assert(recipe->frames != NULL);
150
151 status = gistandard(recipe->parameters, recipe->frames);
152
153 if (status != 0) {
154 return 1;
155 }
156
157 status = giqcstandard(recipe->frames);
158
159 if (status != 0) {
160 return 1;
161 }
162
163 return 0;
164
165}
166
167
168static cxint
169gistandard_destroy(cpl_plugin* plugin)
170{
171
172 cpl_recipe* recipe = (cpl_recipe*)plugin;
173
174
175 /*
176 * We just destroy what was created during the plugin initialization
177 * phase, i.e. the parameter list. The frame set is managed by the
178 * application which called us, so we must not touch it,
179 */
180
181 cpl_parameterlist_delete(recipe->parameters);
182
183 giraffe_error_clear();
184
185 return 0;
186
187}
188
189
190/*
191 * The actual recipe starts here.
192 */
193
194static cxint
195gistandard(cpl_parameterlist* config, cpl_frameset* set)
196{
197
198 const cxchar* const _id = "gistandard";
199
200
201 const cxchar* filename = NULL;
202
203 cxint status = 0;
204
205 cxlong i;
206 cxlong nstandard = 0;
207
208 cxdouble exptime = 0.;
209
210 cx_slist* slist = NULL;
211
212 cpl_propertylist* properties = NULL;
213
214 cpl_matrix* biasareas = NULL;
215
216 cpl_frame* standard_frame = NULL;
217 cpl_frame* mbias_frame = NULL;
218 cpl_frame* mdark_frame = NULL;
219 cpl_frame* bpixel_frame = NULL;
220 cpl_frame* slight_frame = NULL;
221 cpl_frame* locy_frame = NULL;
222 cpl_frame* locw_frame = NULL;
223 cpl_frame* flat_frame = NULL;
224 cpl_frame* psfdata_frame = NULL;
225 cpl_frame* grating_frame = NULL;
226 cpl_frame* slit_frame = NULL;
227 cpl_frame* wcal_frame = NULL;
228 cpl_frame* rstandard_frame = NULL;
229 cpl_frame* sext_frame = NULL;
230 cpl_frame* rbin_frame = NULL;
231 cpl_frame* atmext_frame = NULL;
232 cpl_frame* flxstd_frame = NULL;
233 cpl_frame* rsp_frame = NULL;
234
235 GiImage* mbias = NULL;
236 GiImage* mdark = NULL;
237 GiImage* bpixel = NULL;
238 GiImage* slight = NULL;
239 GiImage* sstandard = NULL;
240 GiImage* rstandard = NULL;
241
242 GiTable* fibers = NULL;
243 GiTable* slitgeometry = NULL;
244 GiTable* grating = NULL;
245 GiTable* wcalcoeff = NULL;
246 GiTable* atmext = NULL;
247 GiTable* flxstd = NULL;
248 GiTable* refflx = NULL;
249
250 GiLocalization* localization = NULL;
251 GiExtraction* extraction = NULL;
252 GiRebinning* rebinning = NULL;
253 GiResponse* response = NULL;
254
255 GiBiasConfig* bias_config = NULL;
256 GiExtractConfig* extract_config = NULL;
257 GiFlatConfig* flat_config = NULL;
258 GiRebinConfig* rebin_config = NULL;
259 GiFxCalibrationConfig* fxcal_config = NULL;
260
261
262 GiInstrumentMode mode;
263
264 GiRecipeInfo info = {(cxchar*)_id, 1, NULL, config};
265
266 GiGroupInfo groups[] = {
267 {GIFRAME_STANDARD, CPL_FRAME_GROUP_RAW},
268 {GIFRAME_BADPIXEL_MAP, CPL_FRAME_GROUP_CALIB},
269 {GIFRAME_BIAS_MASTER, CPL_FRAME_GROUP_CALIB},
270 {GIFRAME_DARK_MASTER, CPL_FRAME_GROUP_CALIB},
271 {GIFRAME_FIBER_FLAT_EXTSPECTRA, CPL_FRAME_GROUP_CALIB},
272 {GIFRAME_FIBER_FLAT_EXTERRORS, CPL_FRAME_GROUP_CALIB},
273 {GIFRAME_SCATTERED_LIGHT_MODEL, CPL_FRAME_GROUP_CALIB},
274 {GIFRAME_LOCALIZATION_CENTROID, CPL_FRAME_GROUP_CALIB},
275 {GIFRAME_LOCALIZATION_WIDTH, CPL_FRAME_GROUP_CALIB},
276 {GIFRAME_PSF_CENTROID, CPL_FRAME_GROUP_CALIB},
277 {GIFRAME_PSF_WIDTH, CPL_FRAME_GROUP_CALIB},
278 {GIFRAME_PSF_DATA, CPL_FRAME_GROUP_CALIB},
279 {GIFRAME_WAVELENGTH_SOLUTION, CPL_FRAME_GROUP_CALIB},
280 {GIFRAME_SLITSETUP, CPL_FRAME_GROUP_CALIB},
281 {GIFRAME_SLITMASTER, CPL_FRAME_GROUP_CALIB},
282 {GIFRAME_GRATING, CPL_FRAME_GROUP_CALIB},
283 {GIFRAME_EXTINCTION, CPL_FRAME_GROUP_CALIB},
284 {GIFRAME_FLUX_STANDARDS, CPL_FRAME_GROUP_CALIB},
285 {NULL, CPL_FRAME_GROUP_NONE}
286 };
287
288
289
290 if (!config) {
291 cpl_msg_error(_id, "Invalid parameter list! Aborting ...");
292 return 1;
293 }
294
295 if (!set) {
296 cpl_msg_error(_id, "Invalid frame set! Aborting ...");
297 return 1;
298 }
299
300 status = giraffe_frameset_set_groups(set, groups);
301
302 if (status != 0) {
303 cpl_msg_error(_id, "Setting frame group information failed!");
304 return 1;
305 }
306
307
308 /*
309 * Verify the frame set contents
310 */
311
312 nstandard = cpl_frameset_count_tags(set, GIFRAME_STANDARD);
313
314 if (nstandard < 1) {
315 cpl_msg_error(_id, "Too few (%ld) raw frames (%s) present in "
316 "frame set! Aborting ...", nstandard, GIFRAME_STANDARD);
317 return 1;
318 }
319
320 locy_frame = cpl_frameset_find(set, GIFRAME_PSF_CENTROID);
321
322 if (locy_frame == NULL) {
323
324 locy_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_CENTROID);
325
326 if (locy_frame == NULL) {
327 cpl_msg_info(_id, "No master localization (centroid position) "
328 "present in frame set. Aborting ...");
329 return 1;
330 }
331
332 }
333
334 locw_frame = cpl_frameset_find(set, GIFRAME_PSF_WIDTH);
335
336 if (locw_frame == NULL) {
337
338 locw_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_WIDTH);
339
340 if (locw_frame == NULL) {
341 cpl_msg_info(_id, "No master localization (spectrum width) "
342 "present in frame set. Aborting ...");
343 return 1;
344 }
345
346 }
347
348 flat_frame = cpl_frameset_find(set, GIFRAME_FIBER_FLAT_EXTSPECTRA);
349
350 if (flat_frame == NULL) {
351
352 cpl_msg_error(_id, "No extracted flat field spectra frame present in frame set. "
353 "Aborting ...");
354 return 1;
355
356 }
357
358 grating_frame = cpl_frameset_find(set, GIFRAME_GRATING);
359
360 if (!grating_frame) {
361 cpl_msg_error(_id, "No grating data present in frame set. "
362 "Aborting ...");
363 return 1;
364 }
365
366 slit_frame = giraffe_get_slitgeometry(set);
367
368 if (!slit_frame) {
369 cpl_msg_error(_id, "No slit geometry present in frame set. "
370 "Aborting ...");
371 return 1;
372 }
373
374 wcal_frame = cpl_frameset_find(set, GIFRAME_WAVELENGTH_SOLUTION);
375
376 if (!wcal_frame) {
377 cpl_msg_error(_id, "No dispersion solution present in frame set. "
378 "Aborting ...");
379 return 1;
380 }
381
382 atmext_frame = cpl_frameset_find(set, GIFRAME_EXTINCTION);
383
384 if (!atmext_frame) {
385 cpl_msg_error(_id, "No atmospheric extinction table present in "
386 "frame set. Aborting ...");
387 return 1;
388 }
389
390 flxstd_frame = cpl_frameset_find(set, GIFRAME_FLUX_STANDARDS);
391
392 if (!flxstd_frame) {
393 cpl_msg_error(_id, "No flux standards present in frame set. "
394 "Aborting ...");
395 return 1;
396 }
397
398 bpixel_frame = cpl_frameset_find(set, GIFRAME_BADPIXEL_MAP);
399
400 if (!bpixel_frame) {
401 cpl_msg_info(_id, "No bad pixel map present in frame set.");
402 }
403
404 mbias_frame = cpl_frameset_find(set, GIFRAME_BIAS_MASTER);
405
406 if (!mbias_frame) {
407 cpl_msg_info(_id, "No master bias present in frame set.");
408 }
409
410 mdark_frame = cpl_frameset_find(set, GIFRAME_DARK_MASTER);
411
412 if (!mdark_frame) {
413 cpl_msg_info(_id, "No master dark 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(_id, "No scattered light model present in frame set.");
420 }
421
422 psfdata_frame = cpl_frameset_find(set, GIFRAME_PSF_DATA);
423
424 if (!psfdata_frame) {
425 cpl_msg_info(_id, "No PSF profile parameters present in frame set.");
426 }
427
428
429 /*
430 * Load raw images
431 */
432
433 slist = cx_slist_new();
434
435 standard_frame = cpl_frameset_find(set, GIFRAME_STANDARD);
436
437 for (i = 0; i < nstandard; i++) {
438
439 filename = cpl_frame_get_filename(standard_frame);
440
441 GiImage* raw = giraffe_image_new(CPL_TYPE_DOUBLE);
442
443
444 status = giraffe_image_load(raw, filename, 0);
445
446 if (status) {
447 cpl_msg_error(_id, "Cannot load raw standard frame from '%s'. "
448 "Aborting ...", filename);
449
450 cx_slist_destroy(slist, (cx_free_func) giraffe_image_delete);
451
452 return 1;
453 }
454
455 cx_slist_push_back(slist, raw);
456
457 standard_frame = cpl_frameset_find(set, NULL);
458
459 }
460
461 nstandard = (cxint)cx_slist_size(slist);
462 sstandard = cx_slist_pop_front(slist);
463
464 properties = giraffe_image_get_properties(sstandard);
465 cx_assert(properties != NULL);
466
467 if (nstandard > 1) {
468
469 /*
470 * Create a stacked image from the list of raw images.
471 * Each raw image is disposed when it is no longer needed.
472 */
473
474 cpl_msg_info(_id, "Averaging standard star observations ...");
475
476 exptime = cpl_propertylist_get_double(properties, GIALIAS_EXPTIME);
477
478 for (i = 1; i < nstandard; i++) {
479
480 cpl_propertylist* _properties;
481
482 GiImage* standard = cx_slist_pop_front(slist);
483
484
485 cpl_image_add(giraffe_image_get(sstandard),
486 giraffe_image_get(standard));
487
488 _properties = giraffe_image_get_properties(standard);
489 cx_assert(_properties != NULL);
490
491 exptime += cpl_propertylist_get_double(_properties,
492 GIALIAS_EXPTIME);
493
494 giraffe_image_delete(standard);
495
496 }
497
498 cpl_image_divide_scalar(giraffe_image_get(sstandard), nstandard);
499 }
500
501 cx_assert(cx_slist_empty(slist));
502 cx_slist_delete(slist);
503 slist = NULL;
504
505
506 if (nstandard > 1) {
507
508 /*
509 * Update stacked standard star image properties
510 */
511
512 cpl_msg_info(_id, "Updating stacked standard star image "
513 "properties ...");
514
515 cpl_propertylist_set_double(properties, GIALIAS_EXPTIME,
516 exptime / nstandard);
517
518 cpl_propertylist_append_double(properties, GIALIAS_EXPTTOT, exptime);
519 cpl_propertylist_set_comment(properties, GIALIAS_EXPTTOT,
520 "Total exposure time of all frames "
521 "combined");
522
523
524 cpl_propertylist_erase(properties, GIALIAS_TPLEXPNO);
525
526 }
527
528 cpl_propertylist_append_int(properties, GIALIAS_DATANCOM, nstandard);
529 cpl_propertylist_set_comment(properties, GIALIAS_DATANCOM, "Number of "
530 "combined frames");
531
532
533 /*
534 * Prepare for bias subtraction
535 */
536
537 bias_config = giraffe_bias_config_create(config);
538
539 /*
540 * Setup user defined areas to use for the bias computation
541 */
542
543 if (bias_config->method == GIBIAS_METHOD_MASTER ||
544 bias_config->method == GIBIAS_METHOD_ZMASTER) {
545
546 if (!mbias_frame) {
547 cpl_msg_error(_id, "Missing master bias frame! Selected bias "
548 "removal method requires a master bias frame!");
549
550 giraffe_bias_config_destroy(bias_config);
551 giraffe_image_delete(sstandard);
552
553 return 1;
554 }
555 else {
556 filename = cpl_frame_get_filename(mbias_frame);
557
558
559 mbias = giraffe_image_new(CPL_TYPE_DOUBLE);
560 status = giraffe_image_load(mbias, filename, 0);
561
562 if (status) {
563 cpl_msg_error(_id, "Cannot load master bias from '%s'. "
564 "Aborting ...", filename);
565
566 giraffe_bias_config_destroy(bias_config);
567 giraffe_image_delete(sstandard);
568
569 return 1;
570 }
571 }
572 }
573
574
575 /*
576 * Load bad pixel map if it is present in the frame set.
577 */
578
579 if (bpixel_frame) {
580
581 filename = cpl_frame_get_filename(bpixel_frame);
582
583
584 bpixel = giraffe_image_new(CPL_TYPE_INT);
585 status = giraffe_image_load(bpixel, filename, 0);
586
587 if (status) {
588 cpl_msg_error(_id, "Cannot load bad pixel map from '%s'. "
589 "Aborting ...", filename);
590
591 giraffe_image_delete(bpixel);
592 bpixel = NULL;
593
594 if (mbias != NULL) {
596 mbias = NULL;
597 }
598
599 giraffe_bias_config_destroy(bias_config);
600 bias_config = NULL;
601
602 giraffe_image_delete(sstandard);
603 sstandard = NULL;
604
605 return 1;
606 }
607
608 }
609
610
611 /*
612 * Compute and remove the bias from the stacked flat field frame.
613 */
614
615 rstandard = giraffe_image_new(CPL_TYPE_DOUBLE);
616
617 status = giraffe_bias_remove(rstandard, sstandard, mbias, bpixel,
618 biasareas, bias_config);
619
620 giraffe_image_delete(sstandard);
621
622 if (mbias) {
624 mbias = NULL;
625 }
626
627 giraffe_bias_config_destroy(bias_config);
628
629 if (status) {
630 cpl_msg_error(_id, "Bias removal failed. Aborting ...");
631
632 giraffe_image_delete(rstandard);
633 rstandard = NULL;
634
635 if (bpixel != NULL) {
636 giraffe_image_delete(bpixel);
637 bpixel = NULL;
638 }
639
640 return 1;
641 }
642
643
644 /*
645 * Load master dark if it is present in the frame set and correct
646 * the master flat field for the dark current.
647 */
648
649 if (mdark_frame) {
650
651 GiDarkConfig dark_config = {GIDARK_METHOD_ZMASTER, 0.};
652
653
654 cpl_msg_info(_id, "Correcting for dark current ...");
655
656 filename = cpl_frame_get_filename(mdark_frame);
657
658 mdark = giraffe_image_new(CPL_TYPE_DOUBLE);
659 status = giraffe_image_load(mdark, filename, 0);
660
661 if (status != 0) {
662 cpl_msg_error(_id, "Cannot load master dark from '%s'. "
663 "Aborting ...", filename);
664
665 giraffe_image_delete(rstandard);
666 rstandard = NULL;
667
668 if (bpixel != NULL) {
669 giraffe_image_delete(bpixel);
670 bpixel = NULL;
671 }
672
673 return 1;
674 }
675
676 status = giraffe_subtract_dark(rstandard, mdark, bpixel, NULL,
677 &dark_config);
678
679 if (status != 0) {
680 cpl_msg_error(_id, "Dark subtraction failed! Aborting ...");
681
683 mdark = NULL;
684
685 giraffe_image_delete(rstandard);
686 rstandard = NULL;
687
688 if (bpixel != NULL) {
689 giraffe_image_delete(bpixel);
690 bpixel = NULL;
691 }
692
693 return 1;
694 }
695
697 mdark = NULL;
698
699 }
700
701
702 /*
703 * Update the reduced standard star observation properties, save the
704 * reduced standard star frame and register it as product.
705 */
706
707 cpl_msg_info(_id, "Writing pre-processed standard star image ...");
708
709 giraffe_image_add_info(rstandard, &info, set);
710
711 rstandard_frame = giraffe_frame_create_image(rstandard,
712 GIFRAME_STANDARD_REDUCED,
713 CPL_FRAME_LEVEL_INTERMEDIATE,
714 TRUE, TRUE);
715
716 if (rstandard_frame == NULL) {
717 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
718
719 giraffe_image_delete(rstandard);
720
721 return 1;
722 }
723
724 cpl_frameset_insert(set, rstandard_frame);
725
726
727 /*
728 * Determine fiber setup
729 */
730
731 standard_frame = cpl_frameset_find(set, GIFRAME_STANDARD);
732
733 cpl_msg_info(_id, "Building fiber setup for frame '%s'.",
734 cpl_frame_get_filename(standard_frame));
735
736 fibers = giraffe_fibers_setup(standard_frame, locy_frame);
737
738 if (!fibers) {
739 cpl_msg_error(_id, "Cannot create fiber setup for frame '%s'! "
740 "Aborting ...", cpl_frame_get_filename(standard_frame));
741
742 if (bpixel) {
743 giraffe_image_delete(bpixel);
744 bpixel = NULL;
745 }
746
747 giraffe_image_delete(rstandard);
748
749 return 1;
750 }
751
752 cpl_msg_info(_id, "Fiber reference setup taken from localization "
753 "frame '%s'.", cpl_frame_get_filename(locy_frame));
754
755
756 /*
757 * Load fiber localization
758 */
759
760 localization = giraffe_localization_new();
761
762 filename = cpl_frame_get_filename(locy_frame);
763 status = 0;
764
765 localization->locy = giraffe_image_new(CPL_TYPE_DOUBLE);
766 status = giraffe_image_load(localization->locy, filename, 0);
767
768 if (status) {
769 cpl_msg_error(_id, "Cannot load localization (centroid "
770 "position) frame from '%s'. Aborting ...",
771 filename);
772
773 giraffe_localization_destroy(localization);
774
775 if (bpixel) {
776 giraffe_image_delete(bpixel);
777 bpixel = NULL;
778 }
779
780 giraffe_table_delete(fibers);
781 giraffe_image_delete(rstandard);
782
783 return 1;
784 }
785
786
787 filename = cpl_frame_get_filename(locw_frame);
788 status = 0;
789
790 localization->locw = giraffe_image_new(CPL_TYPE_DOUBLE);
791 status = giraffe_image_load(localization->locw, filename, 0);
792
793 if (status) {
794 cpl_msg_error(_id, "Cannot load localization (spectrum width) "
795 "frame from '%s'. Aborting ...", filename);
796
797 giraffe_localization_destroy(localization);
798
799 if (bpixel) {
800 giraffe_image_delete(bpixel);
801 bpixel = NULL;
802 }
803
804 giraffe_table_delete(fibers);
805 giraffe_image_delete(rstandard);
806
807 return 1;
808 }
809
810
811 /*
812 * Spectrum extraction
813 */
814
815 if (slight_frame) {
816
817 filename = cpl_frame_get_filename(slight_frame);
818
819
820 slight = giraffe_image_new(CPL_TYPE_DOUBLE);
821 status = giraffe_image_load(slight, filename, 0);
822
823 if (status) {
824 cpl_msg_error(_id, "Cannot load scattered light model from '%s'. "
825 "Aborting ...", filename);
826
827 giraffe_image_delete(slight);
828
829 giraffe_localization_destroy(localization);
830
831 if (bpixel) {
832 giraffe_image_delete(bpixel);
833 bpixel = NULL;
834 }
835
836 giraffe_table_delete(fibers);
837 giraffe_image_delete(rstandard);
838
839 return 1;
840
841 }
842
843 }
844
845
846 extract_config = giraffe_extract_config_create(config);
847
848 if ((extract_config->emethod == GIEXTRACT_OPTIMAL) ||
849 (extract_config->emethod == GIEXTRACT_HORNE)) {
850
851 if (psfdata_frame == NULL) {
852
853 const cxchar* emethod = "Optimal";
854
855 if (extract_config->emethod == GIEXTRACT_HORNE) {
856 emethod = "Horne";
857 }
858
859 cpl_msg_error(_id, "%s spectrum extraction requires PSF "
860 "profile data. Aborting ...", emethod);
861
862 giraffe_extract_config_destroy(extract_config);
863 extract_config = NULL;
864
865 if (slight != NULL) {
866 giraffe_image_delete(slight);
867 slight = NULL;
868 }
869
870 giraffe_localization_destroy(localization);
871 localization = NULL;
872
873 if (bpixel) {
874 giraffe_image_delete(bpixel);
875 bpixel = NULL;
876 }
877
878 giraffe_table_delete(fibers);
879 fibers = NULL;
880
881 giraffe_image_delete(rstandard);
882 rstandard = NULL;
883
884 return 1;
885
886 }
887 else {
888
889 filename = cpl_frame_get_filename(psfdata_frame);
890 status = 0;
891
892 localization->psf = giraffe_psfdata_new();
893 status = giraffe_psfdata_load(localization->psf, filename);
894
895 if (status) {
896 cpl_msg_error(_id, "Cannot load PSF profile data frame from "
897 "'%s'. Aborting ...", filename);
898
899 giraffe_extract_config_destroy(extract_config);
900 extract_config = NULL;
901
902 if (slight != NULL) {
903 giraffe_image_delete(slight);
904 slight = NULL;
905 }
906
907 giraffe_localization_destroy(localization);
908 localization = NULL;
909
910 if (bpixel) {
911 giraffe_image_delete(bpixel);
912 bpixel = NULL;
913 }
914
915 giraffe_table_delete(fibers);
916 fibers = NULL;
917
918 giraffe_image_delete(rstandard);
919 rstandard = NULL;
920
921 return 1;
922
923 }
924
925 }
926
927 }
928
929
930 extraction = giraffe_extraction_new();
931
932 status = giraffe_extract_spectra(extraction, rstandard, fibers,
933 localization, bpixel, slight,
934 extract_config);
935
936 if (status) {
937 cpl_msg_error(_id, "Spectrum extraction failed! Aborting ...");
938
939 giraffe_extraction_destroy(extraction);
940 giraffe_extract_config_destroy(extract_config);
941
942 giraffe_image_delete(slight);
943
944 giraffe_localization_destroy(localization);
945
946 if (bpixel) {
947 giraffe_image_delete(bpixel);
948 bpixel = NULL;
949 }
950
951 giraffe_table_delete(fibers);
952 giraffe_image_delete(rstandard);
953
954 return 1;
955 }
956
957 giraffe_image_delete(slight);
958 slight = NULL;
959
960 if (bpixel) {
961 giraffe_image_delete(bpixel);
962 bpixel = NULL;
963 }
964
965 giraffe_image_delete(rstandard);
966 rstandard = NULL;
967
968 giraffe_extract_config_destroy(extract_config);
969
970
971 /*
972 * Get the relative fiber transmission data from the extracted flat
973 * field and add it to the fiber table.
974 */
975
976 filename = cpl_frame_get_filename(flat_frame);
977
978 cpl_msg_info(_id, "Loading relative fiber transmission data from '%s'.",
979 filename);
980
981 status = giraffe_transmission_attach(fibers, filename);
982
983 if (status != 0) {
984
985 giraffe_extraction_destroy(extraction);
986 giraffe_localization_destroy(localization);
987
988 giraffe_table_delete(grating);
989 giraffe_table_delete(fibers);
990
991 cpl_msg_error(_id, "Cannot load relative fiber transmission data "
992 "from '%s'. Aborting ...", filename);
993
994 return 1;
995
996 }
997
998
999 /*
1000 * Apply flat field and/or the relative fiber transmission correction.
1001 */
1002
1003 flat_config = giraffe_flat_config_create(config);
1004
1005 if (flat_config->apply == TRUE) {
1006
1007 const cpl_frame* flat_errors_frame = NULL;
1008
1009 GiImage* flat = NULL;
1010 GiImage* errors = NULL;
1011
1012
1013 filename = cpl_frame_get_filename(flat_frame);
1014
1015 flat = giraffe_image_new(CPL_TYPE_DOUBLE);
1016 status = giraffe_image_load(flat, filename, 0);
1017
1018 if (status) {
1019 cpl_msg_error(_id, "Cannot load flat field spectra from '%s'. "
1020 "Aborting ...", filename);
1021
1023
1024 giraffe_flat_config_destroy(flat_config);
1025
1026 giraffe_extraction_destroy(extraction);
1027 giraffe_localization_destroy(localization);
1028
1029 giraffe_table_delete(grating);
1030 giraffe_table_delete(fibers);
1031
1032 return 1;
1033 }
1034
1035
1036 flat_errors_frame =
1037 cpl_frameset_find(set, GIFRAME_FIBER_FLAT_EXTERRORS);
1038
1039 if (flat_errors_frame == NULL) {
1040 cpl_msg_warning(_id, "Missing flat field spectra errors "
1041 "frame!");
1042 }
1043 else {
1044
1045 filename = cpl_frame_get_filename(flat_errors_frame);
1046
1047 errors = giraffe_image_new(CPL_TYPE_DOUBLE);
1048 status = giraffe_image_load(errors, filename, 0);
1049
1050 if (status) {
1051 cpl_msg_error(_id, "Cannot load flat field spectra "
1052 "errors from '%s'. Aborting ...",
1053 filename);
1054
1055 giraffe_image_delete(errors);
1057
1058 giraffe_flat_config_destroy(flat_config);
1059
1060 giraffe_extraction_destroy(extraction);
1061 giraffe_localization_destroy(localization);
1062
1063 giraffe_table_delete(grating);
1064 giraffe_table_delete(fibers);
1065
1066 return 1;
1067 }
1068
1069 }
1070
1071 cpl_msg_info(_id, "Applying flat field correction ...");
1072
1073 status = giraffe_flat_apply(extraction, fibers, flat, errors,
1074 flat_config);
1075
1076 if (status) {
1077 cpl_msg_error(_id, "Flat field correction failed! "
1078 "Aborting ...");
1079
1080 giraffe_image_delete(errors);
1082
1083 giraffe_flat_config_destroy(flat_config);
1084
1085 giraffe_extraction_destroy(extraction);
1086 giraffe_localization_destroy(localization);
1087
1088 giraffe_table_delete(grating);
1089 giraffe_table_delete(fibers);
1090
1091 return 1;
1092 }
1093
1094 giraffe_image_delete(errors);
1095 errors = NULL;
1096
1098 flat = NULL;
1099
1100 }
1101
1102 if (flat_config->transmission == TRUE) {
1103
1104 cpl_msg_info(_id, "Applying relative fiber transmission "
1105 "correction");
1106
1107 status = giraffe_transmission_apply(extraction, fibers);
1108
1109 if (status) {
1110
1111 cpl_msg_error(_id, "Relative transmission correction failed! "
1112 "Aborting ...");
1113
1114 giraffe_flat_config_destroy(flat_config);
1115 flat_config = NULL;
1116
1117 giraffe_extraction_destroy(extraction);
1118 giraffe_localization_destroy(localization);
1119
1120 giraffe_table_delete(grating);
1121 giraffe_table_delete(fibers);
1122
1123 return 1;
1124
1125 }
1126
1127 }
1128
1129 giraffe_flat_config_destroy(flat_config);
1130 flat_config = NULL;
1131
1132
1133 /*
1134 * Save the spectrum extraction results and register them as
1135 * products.
1136 */
1137
1138 cpl_msg_info(_id, "Writing extracted spectra ...");
1139
1140 /* Extracted spectra */
1141
1142 giraffe_image_add_info(extraction->spectra, &info, set);
1143
1144 sext_frame = giraffe_frame_create_image(extraction->spectra,
1145 GIFRAME_STANDARD_EXTSPECTRA,
1146 CPL_FRAME_LEVEL_FINAL,
1147 TRUE, TRUE);
1148
1149 if (sext_frame == NULL) {
1150 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
1151
1152 giraffe_extraction_destroy(extraction);
1153 giraffe_localization_destroy(localization);
1154
1155 giraffe_table_delete(grating);
1156 giraffe_table_delete(fibers);
1157
1158 return 1;
1159 }
1160
1161 status = giraffe_fiberlist_attach(sext_frame, fibers);
1162
1163 if (status) {
1164 cpl_msg_error(_id, "Cannot attach fiber setup to local file '%s'! "
1165 "Aborting ...", cpl_frame_get_filename(sext_frame));
1166
1167 cpl_frame_delete(sext_frame);
1168
1169 giraffe_extraction_destroy(extraction);
1170 giraffe_localization_destroy(localization);
1171
1172 giraffe_table_delete(grating);
1173 giraffe_table_delete(fibers);
1174
1175 return 1;
1176 }
1177
1178 cpl_frameset_insert(set, sext_frame);
1179
1180 /* Extracted spectra errors */
1181
1182 giraffe_image_add_info(extraction->error, &info, set);
1183
1184 sext_frame = giraffe_frame_create_image(extraction->error,
1185 GIFRAME_STANDARD_EXTERRORS,
1186 CPL_FRAME_LEVEL_FINAL,
1187 TRUE, TRUE);
1188
1189 if (sext_frame == NULL) {
1190 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
1191
1192 giraffe_extraction_destroy(extraction);
1193 giraffe_localization_destroy(localization);
1194
1195 giraffe_table_delete(grating);
1196 giraffe_table_delete(fibers);
1197
1198 return 1;
1199 }
1200
1201 status = giraffe_fiberlist_attach(sext_frame, fibers);
1202
1203 if (status) {
1204 cpl_msg_error(_id, "Cannot attach fiber setup to local file '%s'! "
1205 "Aborting ...", cpl_frame_get_filename(sext_frame));
1206
1207 cpl_frame_delete(sext_frame);
1208
1209 giraffe_extraction_destroy(extraction);
1210 giraffe_localization_destroy(localization);
1211
1212 giraffe_table_delete(grating);
1213 giraffe_table_delete(fibers);
1214
1215 return 1;
1216 }
1217
1218 cpl_frameset_insert(set, sext_frame);
1219
1220 /* Extracted spectra pixels */
1221
1222 if (extraction->npixels != NULL) {
1223
1224 giraffe_image_add_info(extraction->npixels, &info, set);
1225
1226 sext_frame = giraffe_frame_create_image(extraction->npixels,
1227 GIFRAME_STANDARD_EXTPIXELS,
1228 CPL_FRAME_LEVEL_FINAL,
1229 TRUE, TRUE);
1230
1231 if (sext_frame == NULL) {
1232 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
1233
1234 giraffe_extraction_destroy(extraction);
1235 giraffe_localization_destroy(localization);
1236
1237 giraffe_table_delete(grating);
1238 giraffe_table_delete(fibers);
1239
1240 return 1;
1241 }
1242
1243 status = giraffe_fiberlist_attach(sext_frame, fibers);
1244
1245 if (status) {
1246 cpl_msg_error(_id, "Cannot attach fiber setup to local file "
1247 "'%s'! Aborting ...",
1248 cpl_frame_get_filename(sext_frame));
1249
1250 cpl_frame_delete(sext_frame);
1251
1252 giraffe_extraction_destroy(extraction);
1253 giraffe_localization_destroy(localization);
1254
1255 giraffe_table_delete(grating);
1256 giraffe_table_delete(fibers);
1257
1258 return 1;
1259 }
1260
1261 cpl_frameset_insert(set, sext_frame);
1262
1263 }
1264
1265 /* Extracted spectra centroids */
1266
1267 giraffe_image_add_info(extraction->centroid, &info, set);
1268
1269 sext_frame = giraffe_frame_create_image(extraction->centroid,
1270 GIFRAME_STANDARD_EXTTRACE,
1271 CPL_FRAME_LEVEL_FINAL,
1272 TRUE, TRUE);
1273
1274 if (sext_frame == NULL) {
1275 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
1276
1277 giraffe_extraction_destroy(extraction);
1278 giraffe_localization_destroy(localization);
1279
1280 giraffe_table_delete(grating);
1281 giraffe_table_delete(fibers);
1282
1283 return 1;
1284 }
1285
1286 status = giraffe_fiberlist_attach(sext_frame, fibers);
1287
1288 if (status) {
1289 cpl_msg_error(_id, "Cannot attach fiber setup to local file '%s'! "
1290 "Aborting ...", cpl_frame_get_filename(sext_frame));
1291
1292 cpl_frame_delete(sext_frame);
1293
1294 giraffe_extraction_destroy(extraction);
1295 giraffe_localization_destroy(localization);
1296
1297 giraffe_table_delete(grating);
1298 giraffe_table_delete(fibers);
1299
1300 return 1;
1301 }
1302
1303 cpl_frameset_insert(set, sext_frame);
1304
1305 /* Extraction model spectra */
1306
1307 if (extraction->model != NULL) {
1308
1309 giraffe_image_add_info(extraction->model, &info, set);
1310
1311 sext_frame = giraffe_frame_create_image(extraction->model,
1312 GIFRAME_STANDARD_EXTMODEL,
1313 CPL_FRAME_LEVEL_FINAL,
1314 TRUE, TRUE);
1315
1316 if (sext_frame == NULL) {
1317 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
1318
1319 giraffe_extraction_destroy(extraction);
1320 giraffe_localization_destroy(localization);
1321
1322 giraffe_table_delete(grating);
1323 giraffe_table_delete(fibers);
1324
1325 return 1;
1326 }
1327
1328 status = giraffe_fiberlist_attach(sext_frame, fibers);
1329
1330 if (status != 0) {
1331 cpl_msg_error(_id, "Cannot attach fiber setup to local file '%s'! "
1332 "Aborting ...", cpl_frame_get_filename(sext_frame));
1333
1334 cpl_frame_delete(sext_frame);
1335
1336 giraffe_extraction_destroy(extraction);
1337 giraffe_localization_destroy(localization);
1338
1339 giraffe_table_delete(grating);
1340 giraffe_table_delete(fibers);
1341
1342 return 1;
1343 }
1344
1345 cpl_frameset_insert(set, sext_frame);
1346
1347 }
1348
1349
1350 /*
1351 * Load dispersion solution
1352 */
1353
1354
1355 filename = (cxchar *)cpl_frame_get_filename(wcal_frame);
1356
1357 wcalcoeff = giraffe_table_new();
1358 status = giraffe_table_load(wcalcoeff, filename, 1, NULL);
1359
1360 if (status) {
1361 cpl_msg_error(_id, "Cannot load dispersion solution from "
1362 "'%s'. Aborting ...", filename);
1363
1364 giraffe_extraction_destroy(extraction);
1365 giraffe_localization_destroy(localization);
1366
1367 giraffe_table_delete(wcalcoeff);
1368
1369 giraffe_table_delete(grating);
1370 giraffe_table_delete(fibers);
1371
1372 return 1;
1373 }
1374
1375
1376 /*
1377 * Load grating data
1378 */
1379
1380 filename = (cxchar *)cpl_frame_get_filename(grating_frame);
1381
1382 status = 0;
1383
1384 grating = giraffe_table_new();
1385 status = giraffe_table_load(grating, filename, 1, NULL);
1386
1387 if (status) {
1388 cpl_msg_error(_id, "Cannot load grating data from '%s'. "
1389 "Aborting ...", filename);
1390
1391 giraffe_extraction_destroy(extraction);
1392 giraffe_localization_destroy(localization);
1393
1394 giraffe_table_delete(wcalcoeff);
1395
1396 giraffe_table_delete(grating);
1397 giraffe_table_delete(fibers);
1398
1399 return 1;
1400 }
1401
1402
1403 /*
1404 * Load slit geometry data
1405 */
1406
1407
1408 filename = (cxchar *)cpl_frame_get_filename(slit_frame);
1409
1410 slitgeometry = giraffe_slitgeometry_load(fibers, filename, 1, NULL);
1411
1412 if (slitgeometry == NULL) {
1413 cpl_msg_error(_id, "Cannot load slit geometry data from '%s'. "
1414 "Aborting ...", filename);
1415
1416 giraffe_table_delete(wcalcoeff);
1417
1418 giraffe_extraction_destroy(extraction);
1419 giraffe_localization_destroy(localization);
1420
1421 giraffe_table_delete(wcalcoeff);
1422
1423 giraffe_table_delete(grating);
1424 giraffe_table_delete(fibers);
1425
1426 return 1;
1427 }
1428 else {
1429
1430 /*
1431 * Check whether the contains the positions for all fibers
1432 * provided by the fiber setup. If this is not the case
1433 * this is an error.
1434 */
1435
1436 if (giraffe_fiberlist_compare(slitgeometry, fibers) != 1) {
1437 cpl_msg_error(_id, "Slit geometry data from '%s' is not "
1438 "applicable for current fiber setup! "
1439 "Aborting ...", filename);
1440
1441 giraffe_table_delete(slitgeometry);
1442 giraffe_table_delete(wcalcoeff);
1443
1444 giraffe_extraction_destroy(extraction);
1445 giraffe_localization_destroy(localization);
1446
1447 giraffe_table_delete(wcalcoeff);
1448
1449 giraffe_table_delete(grating);
1450 giraffe_table_delete(fibers);
1451
1452 return 1;
1453 }
1454
1455 }
1456
1457
1458 /*
1459 * Spectrum rebinning
1460 */
1461
1462 cpl_msg_info(_id, "Spectrum rebinning");
1463
1464 rebin_config = giraffe_rebin_config_create(config);
1465
1466 rebinning = giraffe_rebinning_new();
1467
1468 status = 0;
1469
1470 status = giraffe_rebin_spectra(rebinning, extraction, fibers,
1471 localization, grating, slitgeometry,
1472 wcalcoeff, rebin_config);
1473
1474 if (status) {
1475 cpl_msg_error(_id, "Rebinning of standard spectra failed! "
1476 "Aborting...");
1477
1478 giraffe_rebinning_destroy(rebinning);
1479
1480 giraffe_extraction_destroy(extraction);
1481 giraffe_localization_destroy(localization);
1482
1483 giraffe_table_delete(wcalcoeff);
1484
1485 giraffe_table_delete(slitgeometry);
1486 giraffe_table_delete(grating);
1487 giraffe_table_delete(fibers);
1488
1489 giraffe_rebin_config_destroy(rebin_config);
1490
1491 return 1;
1492
1493 }
1494
1495 giraffe_extraction_destroy(extraction);
1496 extraction = NULL;
1497
1498 giraffe_localization_destroy(localization);
1499 localization = NULL;
1500
1501 giraffe_rebin_config_destroy(rebin_config);
1502 rebin_config = NULL;
1503
1504
1505 /*
1506 * Save and register the results of the spectrum rebinning.
1507 */
1508
1509 /* Rebinned spectra */
1510
1511 giraffe_image_add_info(rebinning->spectra, &info, set);
1512
1513 rbin_frame = giraffe_frame_create_image(rebinning->spectra,
1514 GIFRAME_STANDARD_RBNSPECTRA,
1515 CPL_FRAME_LEVEL_FINAL,
1516 TRUE, TRUE);
1517
1518 if (rbin_frame == NULL) {
1519 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
1520
1521 giraffe_rebinning_destroy(rebinning);
1522
1523 giraffe_table_delete(wcalcoeff);
1524
1525 giraffe_table_delete(slitgeometry);
1526 giraffe_table_delete(grating);
1527 giraffe_table_delete(fibers);
1528
1529 return 1;
1530 }
1531
1532 status = giraffe_fiberlist_attach(rbin_frame, fibers);
1533
1534 if (status) {
1535 cpl_msg_error(_id, "Cannot attach fiber setup to local "
1536 "file '%s'! Aborting ...",
1537 cpl_frame_get_filename(rbin_frame));
1538
1539 giraffe_rebinning_destroy(rebinning);
1540 giraffe_table_delete(wcalcoeff);
1541
1542 giraffe_table_delete(slitgeometry);
1543 giraffe_table_delete(grating);
1544 giraffe_table_delete(fibers);
1545
1546 cpl_frame_delete(rbin_frame);
1547
1548 return 1;
1549 }
1550
1551 cpl_frameset_insert(set, rbin_frame);
1552
1553 /* Rebinned spectra errors */
1554
1555 giraffe_image_add_info(rebinning->errors, &info, set);
1556
1557 rbin_frame = giraffe_frame_create_image(rebinning->errors,
1558 GIFRAME_STANDARD_RBNERRORS,
1559 CPL_FRAME_LEVEL_FINAL,
1560 TRUE, TRUE);
1561
1562 if (rbin_frame == NULL) {
1563 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
1564
1565 giraffe_rebinning_destroy(rebinning);
1566
1567 giraffe_table_delete(wcalcoeff);
1568
1569 giraffe_table_delete(slitgeometry);
1570 giraffe_table_delete(grating);
1571 giraffe_table_delete(fibers);
1572
1573 return 1;
1574 }
1575
1576 status = giraffe_fiberlist_attach(rbin_frame, fibers);
1577
1578 if (status) {
1579 cpl_msg_error(_id, "Cannot attach fiber setup to local "
1580 "file '%s'! Aborting ...",
1581 cpl_frame_get_filename(rbin_frame));
1582
1583 giraffe_rebinning_destroy(rebinning);
1584
1585 giraffe_table_delete(wcalcoeff);
1586
1587 giraffe_table_delete(slitgeometry);
1588 giraffe_table_delete(grating);
1589 giraffe_table_delete(fibers);
1590
1591 cpl_frame_delete(rbin_frame);
1592
1593 return 1;
1594 }
1595
1596 cpl_frameset_insert(set, rbin_frame);
1597
1598
1599 /*
1600 * Optional image and data cube construction (only for IFU and Argus)
1601 */
1602
1603 properties = giraffe_image_get_properties(rebinning->spectra);
1604 mode = giraffe_get_mode(properties);
1605
1606
1607 if (mode == GIMODE_IFU || mode == GIMODE_ARGUS) {
1608
1609 cpl_frame* rimg_frame = NULL;
1610
1611 GiFieldOfView* fov = NULL;
1612
1613 GiFieldOfViewConfig* fov_config = NULL;
1614
1615 GiFieldOfViewCubeFormat cube_format = GIFOV_FORMAT_ESO3D;
1616
1617
1618 fov_config = giraffe_fov_config_create(config);
1619
1620 cube_format = fov_config->format;
1621
1622
1623 cpl_msg_info(_id, "Reconstructing image and data cube from rebinned "
1624 "spectra ...");
1625
1626 fov = giraffe_fov_new();
1627
1628 status = giraffe_fov_build(fov, rebinning, fibers, wcalcoeff, grating,
1629 slitgeometry, fov_config);
1630
1631 if (status) {
1632
1633 if (status == -2) {
1634 cpl_msg_warning(_id, "No reconstructed image was built. "
1635 "Fiber list has no fiber position "
1636 "information.");
1637 }
1638 else {
1639 cpl_msg_error(_id, "Image reconstruction failed! Aborting...");
1640
1641 giraffe_fov_delete(fov);
1642 giraffe_rebinning_destroy(rebinning);
1643
1644 giraffe_table_delete(wcalcoeff);
1645
1646 giraffe_table_delete(slitgeometry);
1647 giraffe_table_delete(grating);
1648 giraffe_table_delete(fibers);
1649
1650 giraffe_fov_config_destroy(fov_config);
1651
1652 return 1;
1653 }
1654
1655 }
1656
1657 giraffe_fov_config_destroy(fov_config);
1658
1659 /*
1660 * Calculate QC params and add to header.
1661 */
1662
1663 cpl_errorstate tempes = cpl_errorstate_get();
1664
1665 double fovFlux = 0.0;
1666 double badcolFlux = 0.0;
1667 double meanFlux = 0.0;
1668 cpl_image* fovimage = giraffe_image_get(fov->fov.spectra);
1669 cpl_propertylist* fovprop = giraffe_image_get_properties(fov->fov.spectra);
1670 int fovnx = cpl_image_get_size_x(fovimage);
1671 int fovny = cpl_image_get_size_y(fovimage);
1672
1673 fovFlux = cpl_image_get_flux(fovimage);
1674 badcolFlux = cpl_image_get_flux_window(fovimage, fovnx- 1, 1, fovnx - 1, fovny);
1675
1676 meanFlux = (fovFlux - badcolFlux) / ((fovnx -1) * fovny);
1677
1678
1679
1680
1681 cpl_propertylist_update_double(fovprop, GIALIAS_QCSIGMEAN, meanFlux);
1682 cpl_propertylist_set_comment(fovprop, GIALIAS_QCSIGMEAN, "Mean of "
1683 "FOV image without bad row");
1684
1685 cpl_errorstate_set(tempes);
1686
1687 /*
1688 * Save and register the results of the image reconstruction.
1689 */
1690
1691 /* Reconstructed image */
1692
1693 giraffe_image_add_info(fov->fov.spectra, &info, set);
1694
1695 rimg_frame = giraffe_frame_create_image(fov->fov.spectra,
1696 GIFRAME_STANDARD_RCSPECTRA,
1697 CPL_FRAME_LEVEL_FINAL,
1698 TRUE, TRUE);
1699
1700 if (rimg_frame == NULL) {
1701 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
1702
1703 giraffe_fov_delete(fov);
1704 giraffe_rebinning_destroy(rebinning);
1705
1706 giraffe_table_delete(wcalcoeff);
1707
1708 giraffe_table_delete(slitgeometry);
1709 giraffe_table_delete(grating);
1710 giraffe_table_delete(fibers);
1711
1712 return 1;
1713 }
1714
1715 cpl_frameset_insert(set, rimg_frame);
1716
1717
1718 /* Reconstructed image errors */
1719
1720 giraffe_image_add_info(fov->fov.errors, &info, set);
1721
1722 rimg_frame = giraffe_frame_create_image(fov->fov.errors,
1723 GIFRAME_STANDARD_RCERRORS,
1724 CPL_FRAME_LEVEL_FINAL,
1725 TRUE, TRUE);
1726
1727 if (rimg_frame == NULL) {
1728 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
1729
1730 giraffe_fov_delete(fov);
1731 giraffe_rebinning_destroy(rebinning);
1732
1733 giraffe_table_delete(wcalcoeff);
1734
1735 giraffe_table_delete(slitgeometry);
1736 giraffe_table_delete(grating);
1737 giraffe_table_delete(fibers);
1738
1739 return 1;
1740 }
1741
1742 cpl_frameset_insert(set, rimg_frame);
1743
1744
1745 /* Save data cubes according to format selection */
1746
1747 if (cube_format == GIFOV_FORMAT_SINGLE) {
1748
1749 /* Spectrum cube */
1750
1751 if (fov->cubes.spectra != NULL) {
1752
1753 cxint component = 0;
1754
1755 GiFrameCreator creator = (GiFrameCreator) giraffe_fov_save_cubes;
1756
1757
1758 properties = giraffe_image_get_properties(rebinning->spectra);
1759 properties = cpl_propertylist_duplicate(properties);
1760
1761 giraffe_add_frameset_info(properties, set, info.sequence);
1762
1763 rimg_frame = giraffe_frame_create(GIFRAME_STANDARD_CUBE_SPECTRA,
1764 CPL_FRAME_LEVEL_FINAL,
1765 properties,
1766 fov,
1767 &component,
1768 creator);
1769
1770 cpl_propertylist_delete(properties);
1771 properties = NULL;
1772
1773 if (rimg_frame == NULL) {
1774 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
1775
1776 giraffe_fov_delete(fov);
1777 fov = NULL;
1778
1779 giraffe_rebinning_destroy(rebinning);
1780 rebinning = NULL;
1781
1782 giraffe_table_delete(wcalcoeff);
1783 wcalcoeff = NULL;
1784
1785 giraffe_table_delete(slitgeometry);
1786 slitgeometry = NULL;
1787
1788 giraffe_table_delete(grating);
1789 grating = NULL;
1790
1791 giraffe_table_delete(fibers);
1792 fibers = NULL;
1793
1794 return 1;
1795 }
1796
1797 status = giraffe_fiberlist_attach(rimg_frame, fibers);
1798
1799 if (status != 0) {
1800 cpl_msg_error(_id, "Cannot attach fiber setup to local "
1801 "file '%s'! Aborting ...",
1802 cpl_frame_get_filename(rimg_frame));
1803
1804 cpl_frame_delete(rimg_frame);
1805
1806 giraffe_fov_delete(fov);
1807 fov = NULL;
1808
1809 giraffe_rebinning_destroy(rebinning);
1810 rebinning = NULL;
1811
1812 giraffe_table_delete(wcalcoeff);
1813 wcalcoeff = NULL;
1814
1815 giraffe_table_delete(slitgeometry);
1816 slitgeometry = NULL;
1817
1818 giraffe_table_delete(grating);
1819 grating = NULL;
1820
1821 giraffe_table_delete(fibers);
1822 fibers = NULL;
1823
1824 return 1;
1825 }
1826
1827 cpl_frameset_insert(set, rimg_frame);
1828
1829 }
1830
1831 /* Error cube */
1832
1833 if (fov->cubes.errors != NULL) {
1834
1835 cxint component = 1;
1836
1837 GiFrameCreator creator = (GiFrameCreator) giraffe_fov_save_cubes;
1838
1839
1840 properties = giraffe_image_get_properties(rebinning->errors);
1841 properties = cpl_propertylist_duplicate(properties);
1842
1843 giraffe_add_frameset_info(properties, set, info.sequence);
1844
1845 rimg_frame = giraffe_frame_create(GIFRAME_STANDARD_CUBE_ERRORS,
1846 CPL_FRAME_LEVEL_FINAL,
1847 properties,
1848 fov,
1849 &component,
1850 creator);
1851
1852 cpl_propertylist_delete(properties);
1853 properties = NULL;
1854
1855 if (rimg_frame == NULL) {
1856 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
1857
1858 giraffe_fov_delete(fov);
1859 fov = NULL;
1860
1861 giraffe_rebinning_destroy(rebinning);
1862 rebinning = NULL;
1863
1864 giraffe_table_delete(wcalcoeff);
1865 wcalcoeff = NULL;
1866
1867 giraffe_table_delete(slitgeometry);
1868 slitgeometry = NULL;
1869
1870 giraffe_table_delete(grating);
1871 grating = NULL;
1872
1873 giraffe_table_delete(fibers);
1874 fibers = NULL;
1875
1876 return 1;
1877 }
1878
1879 status = giraffe_fiberlist_attach(rimg_frame, fibers);
1880
1881 if (status != 0) {
1882 cpl_msg_error(_id, "Cannot attach fiber setup to local "
1883 "file '%s'! Aborting ...",
1884 cpl_frame_get_filename(rimg_frame));
1885
1886 cpl_frame_delete(rimg_frame);
1887
1888 giraffe_fov_delete(fov);
1889 fov = NULL;
1890
1891 giraffe_rebinning_destroy(rebinning);
1892 rebinning = NULL;
1893
1894 giraffe_table_delete(wcalcoeff);
1895 wcalcoeff = NULL;
1896
1897 giraffe_table_delete(slitgeometry);
1898 slitgeometry = NULL;
1899
1900 giraffe_table_delete(grating);
1901 grating = NULL;
1902
1903 giraffe_table_delete(fibers);
1904 fibers = NULL;
1905
1906 return 1;
1907 }
1908
1909 cpl_frameset_insert(set, rimg_frame);
1910 }
1911
1912 }
1913 else {
1914
1915 /* Data Cube (ESO 3D format) */
1916
1917 GiFrameCreator creator = (GiFrameCreator) giraffe_fov_save_cubes_eso3d;
1918
1919 properties = giraffe_image_get_properties(rebinning->spectra);
1920 properties = cpl_propertylist_duplicate(properties);
1921
1922 giraffe_add_frameset_info(properties, set, info.sequence);
1923
1924 rimg_frame = giraffe_frame_create(GIFRAME_STANDARD_CUBE,
1925 CPL_FRAME_LEVEL_FINAL,
1926 properties,
1927 fov,
1928 NULL,
1929 creator);
1930
1931 cpl_propertylist_delete(properties);
1932 properties = NULL;
1933
1934 if (rimg_frame == NULL) {
1935 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
1936
1937 giraffe_fov_delete(fov);
1938 fov = NULL;
1939
1940 giraffe_rebinning_destroy(rebinning);
1941 rebinning = NULL;
1942
1943 giraffe_table_delete(wcalcoeff);
1944 wcalcoeff = NULL;
1945
1946 giraffe_table_delete(slitgeometry);
1947 slitgeometry = NULL;
1948
1949 giraffe_table_delete(grating);
1950 grating = NULL;
1951
1952 giraffe_table_delete(fibers);
1953 fibers = NULL;
1954
1955 return 1;
1956 }
1957
1958 status = giraffe_fiberlist_attach(rimg_frame, fibers);
1959
1960 if (status != 0) {
1961 cpl_msg_error(_id, "Cannot attach fiber setup to local "
1962 "file '%s'! Aborting ...",
1963 cpl_frame_get_filename(rimg_frame));
1964
1965 cpl_frame_delete(rimg_frame);
1966
1967 giraffe_fov_delete(fov);
1968 fov = NULL;
1969
1970 giraffe_rebinning_destroy(rebinning);
1971 rebinning = NULL;
1972
1973 giraffe_table_delete(wcalcoeff);
1974 wcalcoeff = NULL;
1975
1976 giraffe_table_delete(slitgeometry);
1977 slitgeometry = NULL;
1978
1979 giraffe_table_delete(grating);
1980 grating = NULL;
1981
1982 giraffe_table_delete(fibers);
1983 fibers = NULL;
1984
1985 return 1;
1986 }
1987
1988 cpl_frameset_insert(set, rimg_frame);
1989
1990 }
1991
1992 giraffe_fov_delete(fov);
1993 fov = NULL;
1994
1995 }
1996
1997
1998 /*
1999 * Response computation
2000 */
2001
2002 cpl_msg_info(_id, "Computing instrument response function...");
2003
2004 filename = cpl_frame_get_filename(flxstd_frame);
2005
2006 flxstd = giraffe_table_new();
2007 status = giraffe_table_load(flxstd, filename, 1, NULL);
2008
2009 cpl_msg_info(_id, "Flux table loaded ...");
2010
2011 if (status != 0) {
2012 cpl_msg_error(_id, "Cannot load flux standards catalog from "
2013 "'%s'. Aborting ...", filename);
2014
2015 giraffe_rebinning_destroy(rebinning);
2016 rebinning = NULL;
2017
2018 giraffe_table_delete(wcalcoeff);
2019 wcalcoeff = NULL;
2020
2021 giraffe_table_delete(slitgeometry);
2022 slitgeometry = NULL;
2023
2024 giraffe_table_delete(grating);
2025 grating = NULL;
2026
2027 giraffe_table_delete(fibers);
2028 fibers = NULL;
2029
2030 return 1;
2031 }
2032
2033
2034 fxcal_config = giraffe_fxcalibration_config_create(config);
2035
2036 /*
2037 * Search the flux standard catalog for the observed flux standard
2038 * object.
2039 */
2040
2041 refflx = giraffe_select_flux_standard(flxstd, rebinning->spectra, fxcal_config->max_dist);
2042
2043
2044 if (refflx == NULL) {
2045 cpl_msg_error(_id, "No matching flux standard found in the "
2046 "catalog '%s'! Aborting ...", filename);
2047
2048 giraffe_table_delete(flxstd);
2049 flxstd = NULL;
2050
2051 giraffe_rebinning_destroy(rebinning);
2052 rebinning = NULL;
2053
2054 giraffe_table_delete(wcalcoeff);
2055 wcalcoeff = NULL;
2056
2057 giraffe_table_delete(slitgeometry);
2058 slitgeometry = NULL;
2059
2060 giraffe_table_delete(grating);
2061 grating = NULL;
2062
2063 giraffe_table_delete(fibers);
2064 fibers = NULL;
2065
2066 return 1;
2067 }
2068
2069 giraffe_table_delete(flxstd);
2070 flxstd = NULL;
2071
2072
2073 filename = cpl_frame_get_filename(atmext_frame);
2074
2075 atmext = giraffe_table_new();
2076 status = giraffe_table_load(atmext, filename, 1, NULL);
2077
2078 if (status != 0) {
2079 cpl_msg_error(_id, "Cannot load atmospheric extinction data from "
2080 "'%s'. Aborting ...", filename);
2081
2082 giraffe_table_delete(refflx);
2083 refflx = NULL;
2084
2085 giraffe_rebinning_destroy(rebinning);
2086 rebinning = NULL;
2087
2088 giraffe_table_delete(wcalcoeff);
2089 wcalcoeff = NULL;
2090
2091 giraffe_table_delete(slitgeometry);
2092 slitgeometry = NULL;
2093
2094 giraffe_table_delete(grating);
2095 grating = NULL;
2096
2097 giraffe_table_delete(fibers);
2098 fibers = NULL;
2099
2100 return 1;
2101 }
2102
2103 response = giraffe_response_new();
2104
2105 status = giraffe_calibrate_flux(response, rebinning, fibers, NULL,
2106 refflx, atmext, fxcal_config);
2107
2108 if (status != 0) {
2109
2110 cpl_msg_error(_id, "Instrument response computation failed!");
2111
2112 giraffe_response_delete(response);
2113 response = NULL;
2114
2116 fxcal_config = NULL;
2117
2118 giraffe_table_delete(atmext);
2119 atmext = NULL;
2120
2121 giraffe_table_delete(refflx);
2122 refflx = NULL;
2123
2124 giraffe_rebinning_destroy(rebinning);
2125 rebinning = NULL;
2126
2127 giraffe_table_delete(wcalcoeff);
2128 wcalcoeff = NULL;
2129
2130 giraffe_table_delete(slitgeometry);
2131 slitgeometry = NULL;
2132
2133 giraffe_table_delete(grating);
2134 grating = NULL;
2135
2136 giraffe_table_delete(fibers);
2137 fibers = NULL;
2138
2139 return 1;
2140
2141 }
2142
2144 fxcal_config = NULL;
2145
2146 giraffe_table_delete(refflx);
2147 refflx = NULL;
2148
2149 giraffe_table_delete(atmext);
2150 atmext = NULL;
2151
2152
2153 /*
2154 * Save and register the instrument response product
2155 */
2156
2157 giraffe_image_add_info(response->response, &info, set);
2158
2159 rsp_frame = giraffe_frame_create_image(response->response,
2160 GIFRAME_INSTRUMENT_RESPONSE,
2161 CPL_FRAME_LEVEL_FINAL,
2162 TRUE, TRUE);
2163
2164 if (rsp_frame == NULL) {
2165
2166 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
2167
2168 giraffe_response_delete(response);
2169 response = NULL;
2170
2171 giraffe_rebinning_destroy(rebinning);
2172 rebinning = NULL;
2173
2174 giraffe_table_delete(wcalcoeff);
2175 wcalcoeff = NULL;
2176
2177 giraffe_table_delete(slitgeometry);
2178 slitgeometry = NULL;
2179
2180 giraffe_table_delete(grating);
2181 grating = NULL;
2182
2183 giraffe_table_delete(fibers);
2184 fibers = NULL;
2185
2186 return 1;
2187
2188 }
2189
2190 cpl_frameset_insert(set, rsp_frame);
2191
2192
2193 /*
2194 * Save and register the efficiency curve product
2195 */
2196
2197 giraffe_table_add_info(response->efficiency, &info, set);
2198
2199 rsp_frame = giraffe_frame_create_table(response->efficiency,
2200 GIFRAME_EFFICIENCY_CURVE,
2201 CPL_FRAME_LEVEL_FINAL,
2202 TRUE, TRUE);
2203
2204 if (rsp_frame == NULL) {
2205
2206 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
2207
2208 giraffe_response_delete(response);
2209 response = NULL;
2210
2211 giraffe_rebinning_destroy(rebinning);
2212 rebinning = NULL;
2213
2214 giraffe_table_delete(wcalcoeff);
2215 wcalcoeff = NULL;
2216
2217 giraffe_table_delete(slitgeometry);
2218 slitgeometry = NULL;
2219
2220 giraffe_table_delete(grating);
2221 grating = NULL;
2222
2223 giraffe_table_delete(fibers);
2224 fibers = NULL;
2225
2226 return 1;
2227
2228 }
2229
2230 cpl_frameset_insert(set, rsp_frame);
2231
2232 giraffe_response_delete(response);
2233 response = NULL;
2234
2235
2236 /*
2237 * Cleanup
2238 */
2239
2240 giraffe_table_delete(wcalcoeff);
2241
2242 giraffe_table_delete(slitgeometry);
2243 giraffe_table_delete(grating);
2244 giraffe_table_delete(fibers);
2245
2246 giraffe_rebinning_destroy(rebinning);
2247
2248 return 0;
2249
2250}
2251
2252
2253static cxint
2254giqcstandard(cpl_frameset* set)
2255{
2256
2257 const cxchar* const fctid = "giqcstandard";
2258
2259
2260 const cxdouble saturation = 60000.;
2261 const cxdouble wlscale = 0.1;
2262
2263 cxint i = 0;
2264 cxint status = 0;
2265 cxint nbin = 0;
2266 cxint npixel = 0;
2267 cxint nsaturated = 0;
2268
2269 const cxdouble* pixels = NULL;
2270
2271 cxdouble wlmin = 0.;
2272 cxdouble wlmax = 0.;
2273 cxdouble efficiency = 0.;
2274
2275 cpl_propertylist* properties = NULL;
2276 cpl_propertylist* _properties = NULL;
2277 cpl_propertylist* qclog = NULL;
2278
2279 cpl_frame* rframe = NULL;
2280 cpl_frame* pframe = NULL;
2281
2282 cpl_image* _rimage = NULL;
2283
2284 cpl_table* _ptable = NULL;
2285
2286 GiImage* rimage = NULL;
2287
2288 GiTable* ptable = NULL;
2289
2290 GiPaf* qc = NULL;
2291
2292
2293 cpl_msg_info(fctid, "Computing QC1 parameters ...");
2294
2295 qc = giraffe_qclog_open(0);
2296
2297 if (qc == NULL) {
2298 cpl_msg_error(fctid, "Cannot create QC1 log!");
2299 return 1;
2300 }
2301
2302 qclog = giraffe_paf_get_properties(qc);
2303 cx_assert(qclog != NULL);
2304
2305
2306 /*
2307 * Process efficiency table
2308 */
2309
2310 pframe = giraffe_get_frame(set, GIFRAME_EFFICIENCY_CURVE,
2311 CPL_FRAME_GROUP_PRODUCT);
2312
2313 if (pframe == NULL) {
2314 cpl_msg_error(fctid, "Missing product frame (%s)",
2315 GIFRAME_EFFICIENCY_CURVE);
2316
2317 giraffe_paf_delete(qc);
2318 qc = NULL;
2319
2320 return 1;
2321 }
2322
2323 cpl_msg_info(fctid, "Processing product frame '%s' (%s)",
2324 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
2325
2326 ptable = giraffe_table_new();
2327 status = giraffe_table_load(ptable, cpl_frame_get_filename(pframe), 1,
2328 "EFFICIENCY_CURVE");
2329
2330 if (status != 0) {
2331 cpl_msg_error(fctid, "Could not load efficiency table '%s'! "
2332 "Aborting ...", cpl_frame_get_filename(pframe));
2333
2334 giraffe_table_delete(ptable);
2335 ptable = NULL;
2336
2337 giraffe_paf_delete(qc);
2338 qc = NULL;
2339
2340 return 1;
2341 }
2342
2343
2344 /*
2345 * Load first raw image as reference
2346 */
2347
2348 rframe = cpl_frameset_find(set, GIFRAME_STANDARD);
2349
2350 if (rframe == NULL) {
2351 cpl_msg_error(fctid, "Missing raw frame (%s)", GIFRAME_STANDARD);
2352
2353 giraffe_table_delete(ptable);
2354 ptable = NULL;
2355
2356 giraffe_paf_delete(qc);
2357 qc = NULL;
2358
2359 return 1;
2360 }
2361
2362 rimage = giraffe_image_new(CPL_TYPE_DOUBLE);
2363 status = giraffe_image_load(rimage, cpl_frame_get_filename(rframe), 0);
2364
2365 if (status != 0) {
2366 cpl_msg_error(fctid, "Could not load standard star observation '%s'!",
2367 cpl_frame_get_filename(rframe));
2368
2369 giraffe_image_delete(rimage);
2370 rimage = NULL;
2371
2372 giraffe_table_delete(ptable);
2373 ptable = NULL;
2374
2375 giraffe_paf_delete(qc);
2376 qc = NULL;
2377
2378 return 1;
2379
2380 }
2381
2382 _rimage = giraffe_image_get(rimage);
2383 cx_assert(_rimage != NULL);
2384
2385 properties = giraffe_image_get_properties(rimage);
2386 cx_assert(properties != NULL);
2387
2388 giraffe_propertylist_copy(qclog, "ARCFILE", properties, GIALIAS_ARCFILE);
2389 giraffe_propertylist_copy(qclog, "TPL.ID", properties, GIALIAS_TPLID);
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 /*
2398 * Count the number of saturated pixels in the raw frame
2399 */
2400
2401 pixels = cpl_image_get_data(_rimage);
2402 npixel = cpl_image_get_size_x(_rimage) * cpl_image_get_size_y(_rimage);
2403
2404 _rimage = NULL;
2405
2406 for (i = 0; i < npixel; i++) {
2407 if (pixels[i] > saturation) {
2408 ++nsaturated;
2409 }
2410 }
2411
2412 pixels = NULL;
2413
2414 giraffe_image_delete(rimage);
2415 rimage = NULL;
2416
2417
2418 /*
2419 * Compute mean efficiency from a wavelength range around the
2420 * central wavelength.
2421 */
2422
2423 _ptable = giraffe_table_get(ptable);
2424 cx_assert(_ptable != NULL);
2425
2426 properties = giraffe_table_get_properties(ptable);
2427 cx_assert(properties != NULL);
2428
2429 if (cpl_propertylist_has(properties, GIALIAS_GRATWLEN) == FALSE) {
2430
2431 giraffe_table_delete(ptable);
2432 ptable = NULL;
2433
2434 giraffe_paf_delete(qc);
2435 qc = NULL;
2436
2437 cpl_msg_error(fctid, "Missing property '%s'", GIALIAS_GRATWLEN);
2438
2439 return 1;
2440
2441 }
2442 else {
2443
2444 cxdouble wlband = 0.;
2445 cxdouble wl0 = cpl_propertylist_get_double(properties,
2446 GIALIAS_GRATWLEN);
2447
2448
2449 wlmin = cpl_propertylist_get_double(properties, GIALIAS_BINWLMIN);
2450 wlmax = cpl_propertylist_get_double(properties, GIALIAS_BINWLMAX);
2451
2452 cx_assert((wlmin < wl0) && (wl0 < wlmax));
2453
2454 wlband = wlscale * fabs(wlmax - wlmin);
2455
2456 wlmin = CX_MAX(wlmin, (wl0 - wlband));
2457 wlmax = CX_MIN(wlmax, (wl0 + wlband));
2458
2459 cpl_msg_info(fctid, "Computing spectrograph efficiency from "
2460 "wavelength range ]%.1f, %.1f[", wlmin, wlmax);
2461
2462 }
2463
2464 nbin = 0;
2465
2466 for (i = 0; i < cpl_table_get_nrow(_ptable); ++i) {
2467
2468 cxdouble wavelength = cpl_table_get_double(_ptable, "WLEN", i, NULL);
2469
2470 if ((wavelength > wlmin) && (wavelength < wlmax)) {
2471
2472 efficiency += cpl_table_get_double(_ptable, "EFFICIENCY",
2473 i, NULL);
2474 ++nbin;
2475
2476 }
2477
2478 }
2479
2480 efficiency /= (cxdouble)nbin;
2481
2482
2483 cpl_propertylist_update_int(properties, GIALIAS_QCNSAT, nsaturated);
2484 cpl_propertylist_set_comment(properties, GIALIAS_QCNSAT, "Number of "
2485 "saturated pixels in the first raw frame");
2486
2487 giraffe_propertylist_copy(qclog, "QC.OUT1.NSAT.RAW", properties,
2488 GIALIAS_QCNSAT);
2489
2490
2491 cpl_propertylist_update_double(properties, GIALIAS_QCEFFICIENCY,
2492 efficiency);
2493 cpl_propertylist_set_comment(properties, GIALIAS_QCEFFICIENCY,
2494 "Efficiency of the spectrograph.");
2495
2496 giraffe_propertylist_copy(qclog, "QC.EFFICIENCY.MEAN", properties,
2497 GIALIAS_QCEFFICIENCY);
2498
2499
2500 if (cpl_propertylist_has(properties, GIALIAS_SKY_LEVEL) == TRUE) {
2501
2502 cxdouble mean_sky = cpl_propertylist_get_double(properties,
2503 GIALIAS_SKY_LEVEL);
2504
2505 cpl_propertylist_update_double(properties, GIALIAS_QCSKYLEVEL,
2506 mean_sky);
2507 cpl_propertylist_set_comment(properties, GIALIAS_QCSKYLEVEL,
2508 "Mean sky level [ADU]");
2509
2510 giraffe_propertylist_copy(qclog, "QC.SKY.MEAN", properties,
2511 GIALIAS_QCSKYLEVEL);
2512
2513 }
2514
2515
2516 /*
2517 * Write QC1 log and save updated product.
2518 */
2519
2520 _properties = cpl_propertylist_load_regexp(cpl_frame_get_filename(pframe),
2521 0, "^COMMENT$", TRUE);
2522
2523 cpl_propertylist_erase_regexp(_properties, "ESO QC.*", 0);
2524
2525
2526 giraffe_propertylist_copy(_properties, GIALIAS_QCEFFICM, properties,
2527 GIALIAS_QCEFFICIENCY);
2528
2529 giraffe_propertylist_copy(_properties, GIALIAS_QCNUMSAT, properties,
2530 GIALIAS_QCNSAT);
2531
2532 giraffe_qc_airm_see_avg(_properties);
2533
2534 cpl_image_save(NULL, cpl_frame_get_filename(pframe), CPL_BPP_8_UNSIGNED,
2535 _properties, CPL_IO_CREATE);
2536
2537 cpl_propertylist_delete(_properties);
2538 _properties = NULL;
2539
2540 giraffe_table_attach(ptable, cpl_frame_get_filename(pframe), 1, NULL);
2541
2542 giraffe_table_delete(ptable);
2543 ptable = NULL;
2544
2545 giraffe_qclog_close(qc);
2546 qc = NULL;
2547
2548 return 0;
2549
2550}
2551
2552
2553/*
2554 * Build table of contents, i.e. the list of available plugins, for
2555 * this module. This function is exported.
2556 */
2557
2558int
2559cpl_plugin_get_info(cpl_pluginlist* list)
2560{
2561
2562 cpl_recipe* recipe = cx_calloc(1, sizeof *recipe);
2563 cpl_plugin* plugin = &recipe->interface;
2564
2565
2566 cpl_plugin_init(plugin,
2567 CPL_PLUGIN_API,
2568 GIRAFFE_BINARY_VERSION,
2569 CPL_PLUGIN_TYPE_RECIPE,
2570 "gistandard",
2571 "Process a spectro-photometric standard star "
2572 "observation and compute the instrument response curve.",
2573 "For detailed information please refer to the "
2574 "GIRAFFE pipeline user manual.\nIt is available at "
2575 "http://www.eso.org/pipelines.",
2576 "Giraffe Pipeline",
2577 PACKAGE_BUGREPORT,
2579 gistandard_create,
2580 gistandard_exec,
2581 gistandard_destroy);
2582
2583 cpl_pluginlist_append(list, plugin);
2584
2585 return 0;
2586
2587}
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
cxint giraffe_subtract_dark(GiImage *image, const GiImage *dark, const GiImage *bpixel, GiDarkResults *data, const GiDarkConfig *config)
Subtract the dark current from a bias corrected image.
Definition: gidark.c:478
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
GiFlatConfig * giraffe_flat_config_create(cpl_parameterlist *list)
Creates a setup structure for the flat field correction.
Definition: giflat.c:302
void giraffe_flat_config_destroy(GiFlatConfig *config)
Destroys a flat field setup structure.
Definition: giflat.c:353
void giraffe_flat_config_add(cpl_parameterlist *list)
Adds parameters for the flat field correction.
Definition: giflat.c:376
cxint giraffe_flat_apply(GiExtraction *extraction, const GiTable *fibers, const GiImage *flat, const GiImage *errors, GiFlatConfig *config)
Apply the flat field correction to the given extracted spectra.
Definition: giflat.c:238
GiFieldOfViewConfig * giraffe_fov_config_create(cpl_parameterlist *list)
Creates a setup structure for the field of view reconstruction.
Definition: gifov.c:2012
void giraffe_fov_config_destroy(GiFieldOfViewConfig *config)
Destroys a field of view setup structure.
Definition: gifov.c:2067
GiFieldOfView * giraffe_fov_new(void)
Create an empty container for the results of the field of view reconstruction.
Definition: gifov.c:1393
cxint giraffe_fov_save_cubes_eso3d(const GiFieldOfView *self, cpl_propertylist *properties, const cxchar *filename, cxptr data)
Write the cube components of a field-of-view object to a file.
Definition: gifov.c:1673
void giraffe_fov_delete(GiFieldOfView *self)
Deallocate a field of view object and its contents.
Definition: gifov.c:1494
cxint giraffe_fov_build(GiFieldOfView *result, GiRebinning *rebinning, GiTable *fibers, GiTable *wsolution, GiTable *grating, GiTable *slitgeometry, GiFieldOfViewConfig *config)
Create and image and a data cube from extracted and rebinned spectra.
Definition: gifov.c:428
cxint giraffe_fov_save_cubes(const GiFieldOfView *self, cpl_propertylist *properties, const cxchar *filename, cxptr data)
Write the cube components of a field-of-view object to a file.
Definition: gifov.c:1530
void giraffe_fov_config_add(cpl_parameterlist *list)
Adds parameters for the image and data cube construction.
Definition: gifov.c:2089
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
void giraffe_fxcalibration_config_add(cpl_parameterlist *parameters)
Add flux calibration parameters to a parameter list.
cxint giraffe_calibrate_flux(GiResponse *result, const GiRebinning *spectra, const GiTable *fibers, const GiImage *flat, const GiTable *flux, const GiTable *extinction, const GiFxCalibrationConfig *config)
Compute the response and efficiency curves.
void giraffe_fxcalibration_config_destroy(GiFxCalibrationConfig *self)
Destroy a flux calibration setup structure.
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
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
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_transmission_attach(GiTable *fibers, const cxchar *filename)
Load relative fiber transmission data from a file and add it to a fiber table.
cxint giraffe_add_frameset_info(cpl_propertylist *plist, const cpl_frameset *set, cxint sequence)
Add frameset specific information to a property list.
Definition: giutils.c:784
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
GiInstrumentMode giraffe_get_mode(cpl_propertylist *properties)
Determines the instrument mode from a property list.
Definition: giutils.c:442

This file is part of the GIRAFFE Pipeline Reference Manual 2.17.1.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Wed Jun 11 2025 18:00:34 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2004