28#include <cxmessages.h>
30#include <cpl_recipe.h>
31#include <cpl_plugininfo.h>
32#include <cpl_parameterlist.h>
33#include <cpl_frameset.h>
34#include <cpl_propertylist.h>
41#include "gislitgeometry.h"
43#include "gifiberutils.h"
48#include "giwlcalibration.h"
49#include "girebinning.h"
50#include "gisgcalibration.h"
53static cxint giwavecalibration(cpl_parameterlist* config, cpl_frameset* set);
54static cxint giqcwavecalibration(cpl_parameterlist* config, cpl_frameset* set);
63giwavecalibration_create(cpl_plugin* plugin)
66 cpl_recipe* recipe = (cpl_recipe*)plugin;
80 recipe->parameters = cpl_parameterlist_new();
81 cx_assert(recipe->parameters != NULL);
104 p = cpl_parameter_new_value(
"giraffe.wcal.rebin",
106 "Rebin extracted arc-lamp spectra.",
110 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"wcal-rebin");
111 cpl_parameterlist_append(recipe->parameters, p);
117 p = cpl_parameter_new_value(
"giraffe.wcal.slitgeometry",
119 "Controls the slit geometry calibration.",
123 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"wcal-slit");
124 cpl_parameterlist_append(recipe->parameters, p);
130 p = cpl_parameter_new_value(
"giraffe.wcal.qc.simlamp", CPL_TYPE_BOOL,
131 "Controls creation of SIMLAMP QC parameters.",
132 "giraffe.wcal", FALSE);
134 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"wcal-qcsim");
135 cpl_parameterlist_append(recipe->parameters, p);
148giwavecalibration_exec(cpl_plugin* plugin)
151 cpl_recipe* recipe = (cpl_recipe*)plugin;
156 if (recipe->parameters == NULL || recipe->frames == NULL) {
160 status = giwavecalibration(recipe->parameters, recipe->frames);
166 status = giqcwavecalibration(recipe->parameters, recipe->frames);
178giwavecalibration_destroy(cpl_plugin* plugin)
181 cpl_recipe* recipe = (cpl_recipe*)plugin;
190 cpl_parameterlist_delete(recipe->parameters); recipe->parameters = NULL;
192 giraffe_error_clear();
203giwavecalibration(cpl_parameterlist* config, cpl_frameset* set)
206 const cxchar*
const fctid =
"giwavecalibration";
209 const cxchar* filename = NULL;
211 cxbool rebin = FALSE;
212 cxbool slitgeometry = FALSE;
215 cxint narcspectrum = 0;
217 const cpl_propertylist* properties = NULL;
219 cpl_frame* arcspec_frame = NULL;
220 cpl_frame* bpixel_frame = NULL;
221 cpl_frame* mbias_frame = NULL;
222 cpl_frame* mlocy_frame = NULL;
223 cpl_frame* mlocw_frame = NULL;
224 cpl_frame* psfdata_frame = NULL;
225 cpl_frame* slight_frame = NULL;
226 cpl_frame* grating_frame = NULL;
227 cpl_frame* slitgeo_frame = NULL;
228 cpl_frame* lines_frame = NULL;
229 cpl_frame* wcal_frame = NULL;
230 cpl_frame* ldata_frame = NULL;
231 cpl_frame* scal_frame = NULL;
232 cpl_frame* sext_frame = NULL;
234 cpl_parameter* p = NULL;
236 cpl_matrix* biasareas = NULL;
238 GiImage* arcspectrum = NULL;
239 GiImage* bsarcspectrum = NULL;
240 GiImage* slight = NULL;
241 GiImage* mbias = NULL;
242 GiImage* bpixel = NULL;
244 GiLocalization* localization = NULL;
245 GiExtraction* extraction = NULL;
246 GiRebinning* rebinning = NULL;
247 GiWCalData* wlsolution = NULL;
249 GiTable* fibers = NULL;
250 GiTable* grating = NULL;
251 GiTable* slitgeo = NULL;
252 GiTable* wavelengths = NULL;
253 GiTable* wcal_initial = NULL;
257 GiBiasConfig* bias_config = NULL;
258 GiExtractConfig* extract_config = NULL;
261 GiFrameCreator creator = NULL;
263 GiRecipeInfo info = {(cxchar*)fctid, 1, NULL, config};
265 GiGroupInfo groups[] = {
266 {GIFRAME_ARC_SPECTRUM, CPL_FRAME_GROUP_RAW},
267 {GIFRAME_BADPIXEL_MAP, CPL_FRAME_GROUP_CALIB},
268 {GIFRAME_BIAS_MASTER, CPL_FRAME_GROUP_CALIB},
269 {GIFRAME_SCATTERED_LIGHT_MODEL, CPL_FRAME_GROUP_CALIB},
270 {GIFRAME_LOCALIZATION_CENTROID, CPL_FRAME_GROUP_CALIB},
271 {GIFRAME_LOCALIZATION_WIDTH, CPL_FRAME_GROUP_CALIB},
272 {GIFRAME_PSF_CENTROID, CPL_FRAME_GROUP_CALIB},
273 {GIFRAME_PSF_WIDTH, CPL_FRAME_GROUP_CALIB},
274 {GIFRAME_PSF_DATA, CPL_FRAME_GROUP_CALIB},
275 {GIFRAME_WAVELENGTH_SOLUTION, CPL_FRAME_GROUP_CALIB},
276 {GIFRAME_SLITSETUP, CPL_FRAME_GROUP_CALIB},
277 {GIFRAME_SLITMASTER, CPL_FRAME_GROUP_CALIB},
278 {GIFRAME_GRATING, CPL_FRAME_GROUP_CALIB},
279 {GIFRAME_LINE_CATALOG, CPL_FRAME_GROUP_CALIB},
280 {GIFRAME_LINE_MASK, CPL_FRAME_GROUP_CALIB},
281 {NULL, CPL_FRAME_GROUP_NONE}
286 cpl_parameter * simcalp = cpl_parameterlist_find(config,
"giraffe.wcal.qc.simlamp");
288 cxbool qc_simlamp_flag = FALSE;
290 if (simcalp != NULL) {
291 qc_simlamp_flag = cpl_parameter_get_bool(simcalp);
294 char* giframe_arc_lamp_extspectra = GIFRAME_ARC_LAMP_EXTSPECTRA;
295 char* giframe_arc_lamp_exterrors = GIFRAME_ARC_LAMP_EXTERRORS;
296 char* giframe_arc_lamp_extpixels = GIFRAME_ARC_LAMP_EXTPIXELS;
297 char* giframe_arc_lamp_exttrace = GIFRAME_ARC_LAMP_EXTTRACE;
298 char* giframe_arc_lamp_rbnspectra = GIFRAME_ARC_LAMP_RBNSPECTRA;
299 char* giframe_arc_lamp_rbnerrors = GIFRAME_ARC_LAMP_RBNERRORS;
300 char* giframe_line_data = GIFRAME_LINE_DATA;
301 char* giframe_wavelength_solution = GIFRAME_WAVELENGTH_SOLUTION;
303 if(qc_simlamp_flag) {
304 giframe_arc_lamp_extspectra = GIFRAME_ARC_LAMP_EXTSPECTRA_SIM;
305 giframe_arc_lamp_exterrors = GIFRAME_ARC_LAMP_EXTERRORS_SIM;
306 giframe_arc_lamp_extpixels = GIFRAME_ARC_LAMP_EXTPIXELS_SIM;
307 giframe_arc_lamp_exttrace = GIFRAME_ARC_LAMP_EXTTRACE_SIM;
308 giframe_arc_lamp_rbnspectra = GIFRAME_ARC_LAMP_RBNSPECTRA_SIM;
309 giframe_arc_lamp_rbnerrors = GIFRAME_ARC_LAMP_RBNERRORS_SIM;
310 giframe_line_data = GIFRAME_LINE_DATA_SIM;
311 giframe_wavelength_solution = GIFRAME_WAVELENGTH_SOLUTION_SIM;
317 cpl_msg_error(fctid,
"Invalid parameter list! Aborting ...");
322 cpl_msg_error(fctid,
"Invalid frame set! Aborting ...");
326 p = cpl_parameterlist_find(config,
"giraffe.wcal.rebin");
329 rebin = cpl_parameter_get_bool(p);
332 p = cpl_parameterlist_find(config,
"giraffe.wcal.slitgeometry");
335 slitgeometry = cpl_parameter_get_bool(p);
338 status = giraffe_frameset_set_groups(set, groups);
341 cpl_msg_error(fctid,
"Setting frame group information failed!");
350 cpl_msg_info(fctid,
"Recipe Step : Initialization");
356 narcspectrum = cpl_frameset_count_tags(set, GIFRAME_ARC_SPECTRUM);
358 if (narcspectrum > 1) {
359 cpl_msg_error(fctid,
"Only one arc spectrum frame allowed! "
363 else if (narcspectrum < 1) {
364 cpl_msg_error(fctid,
"Arc spectrum frame is missing! "
369 arcspec_frame = cpl_frameset_find(set, GIFRAME_ARC_SPECTRUM);
370 bpixel_frame = cpl_frameset_find(set, GIFRAME_BADPIXEL_MAP);
373 cpl_msg_info(fctid,
"No bad pixel map present in frame set.");
376 mbias_frame = cpl_frameset_find(set, GIFRAME_BIAS_MASTER);
379 cpl_msg_info(fctid,
"No master bias present in frame set.");
382 mlocy_frame = cpl_frameset_find(set, GIFRAME_PSF_CENTROID);
384 if (mlocy_frame == NULL) {
386 mlocy_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_CENTROID);
388 if (mlocy_frame == NULL) {
389 cpl_msg_info(fctid,
"No master localization (centroid position) "
390 "present in frame set. Aborting ...");
396 mlocw_frame = cpl_frameset_find(set, GIFRAME_PSF_WIDTH);
398 if (mlocw_frame == NULL) {
400 mlocw_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_WIDTH);
402 if (mlocw_frame == NULL) {
403 cpl_msg_info(fctid,
"No master localization (spectrum width) "
404 "present in frame set. Aborting ...");
410 psfdata_frame = cpl_frameset_find(set, GIFRAME_PSF_DATA);
412 if (!psfdata_frame) {
413 cpl_msg_info(fctid,
"No PSF profile parameters present in frame set.");
416 slight_frame = cpl_frameset_find(set, GIFRAME_SCATTERED_LIGHT_MODEL);
419 cpl_msg_info(fctid,
"No scattered light model present in frame set.");
422 grating_frame = cpl_frameset_find(set, GIFRAME_GRATING);
424 if (!grating_frame) {
425 cpl_msg_error(fctid,
"No grating table present in frame set, "
432 if (!slitgeo_frame) {
433 cpl_msg_error(fctid,
"No slit geometry table present in frame "
438 lines_frame = cpl_frameset_find(set, GIFRAME_LINE_CATALOG);
441 cpl_msg_error(fctid,
"No wavelength table present in frame set, "
446 wcal_frame = cpl_frameset_find(set, GIFRAME_WAVELENGTH_SOLUTION);
449 cpl_msg_info(fctid,
"No wavelength solution present in frame set.");
452 scal_frame = cpl_frameset_find(set, GIFRAME_LINE_MASK);
456 if (slitgeometry == TRUE) {
457 cpl_msg_error(fctid,
"No line mask present in frame "
458 "set. Aborting ...");
462 cpl_msg_info(fctid,
"No slit geometry mask present in frame "
479 filename = cpl_frame_get_filename(bpixel_frame);
485 cpl_msg_error(fctid,
"Cannot load bad pixel map from '%s'. "
486 "Aborting ...", filename);
499 filename = cpl_frame_get_filename(arcspec_frame);
505 cpl_msg_error(fctid,
"Cannot load arc spectrum from '%s'. "
506 "Aborting...", filename);
518 cpl_msg_info(fctid,
"Recipe Step : Bias Removal");
526 if (bias_config->method == GIBIAS_METHOD_MASTER ||
527 bias_config->method == GIBIAS_METHOD_ZMASTER) {
530 cpl_msg_error(fctid,
"Missing master bias frame! Selected bias "
531 "removal method requires a master bias "
543 filename = cpl_frame_get_filename(mbias_frame);
549 cpl_msg_error(fctid,
"Cannot load master bias from '%s'. "
550 "Aborting ...", filename);
570 biasareas, bias_config);
584 cpl_msg_error(fctid,
"Bias removal failed. Aborting ...");
596 cpl_msg_info(fctid,
"Recipe Step : Fiber Setup");
598 cpl_msg_info(fctid,
"Building fiber setup for frame '%s'.",
599 cpl_frame_get_filename(arcspec_frame));
604 cpl_msg_error(fctid,
"Cannot create fiber setup for frame '%s'! "
605 "Aborting ...", cpl_frame_get_filename(arcspec_frame));
613 cpl_msg_info(fctid,
"Fiber reference setup taken from localization "
614 "frame '%s'.", cpl_frame_get_filename(mlocy_frame));
621 localization = giraffe_localization_new();
623 filename = cpl_frame_get_filename(mlocy_frame);
630 cpl_msg_error(fctid,
"Cannot load localization (centroid "
631 "position) frame from '%s'. Aborting ...",
634 giraffe_localization_destroy(localization);
644 filename = cpl_frame_get_filename(mlocw_frame);
651 cpl_msg_error(fctid,
"Cannot load localization (spectrum width) "
652 "frame from '%s'. Aborting ...", filename);
654 giraffe_localization_destroy(localization);
668 cpl_msg_info(fctid,
"Recipe Step : Spectrum Extraction");
672 filename = cpl_frame_get_filename(slight_frame);
679 cpl_msg_error(fctid,
"Cannot load scattered light model from "
680 "'%s'. Aborting ...", filename);
685 giraffe_localization_destroy(localization);
696 if ((extract_config->emethod == GIEXTRACT_OPTIMAL) ||
697 (extract_config->emethod == GIEXTRACT_HORNE)) {
699 if (psfdata_frame == NULL) {
701 const cxchar* emethod =
"Optimal";
703 if (extract_config->emethod == GIEXTRACT_HORNE) {
707 cpl_msg_error(fctid,
"%s spectrum extraction requires PSF "
708 "profile data. Aborting ...", emethod);
711 extract_config = NULL;
713 if (slight != NULL) {
718 giraffe_localization_destroy(localization);
730 bsarcspectrum = NULL;
737 filename = cpl_frame_get_filename(psfdata_frame);
740 localization->psf = giraffe_psfdata_new();
741 status = giraffe_psfdata_load(localization->psf, filename);
744 cpl_msg_error(fctid,
"Cannot load PSF profile data frame from "
745 "'%s'. Aborting ...", filename);
748 extract_config = NULL;
750 if (slight != NULL) {
755 giraffe_localization_destroy(localization);
767 bsarcspectrum = NULL;
778 extraction = giraffe_extraction_new();
781 localization, bpixel, slight,
785 cpl_msg_error(fctid,
"Spectrum extraction failed! Aborting ...");
790 giraffe_localization_destroy(localization);
793 giraffe_extraction_destroy(extraction);
805 bsarcspectrum = NULL;
808 extract_config = NULL;
815 cpl_msg_info(fctid,
"Writing extracted spectra ...");
822 giframe_arc_lamp_extspectra,
823 CPL_FRAME_LEVEL_INTERMEDIATE,
826 if (sext_frame == NULL) {
827 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
831 giraffe_localization_destroy(localization);
832 giraffe_extraction_destroy(extraction);
840 cpl_msg_error(fctid,
"Cannot attach fiber setup to local file '%s'! "
841 "Aborting ...", cpl_frame_get_filename(sext_frame));
843 cpl_frame_delete(sext_frame);
847 giraffe_localization_destroy(localization);
848 giraffe_extraction_destroy(extraction);
853 cpl_frameset_insert(set, sext_frame);
860 giframe_arc_lamp_exterrors,
861 CPL_FRAME_LEVEL_INTERMEDIATE,
864 if (sext_frame == NULL) {
865 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
869 giraffe_localization_destroy(localization);
870 giraffe_extraction_destroy(extraction);
878 cpl_msg_error(fctid,
"Cannot attach fiber setup to local file '%s'! "
879 "Aborting ...", cpl_frame_get_filename(sext_frame));
881 cpl_frame_delete(sext_frame);
885 giraffe_localization_destroy(localization);
886 giraffe_extraction_destroy(extraction);
891 cpl_frameset_insert(set, sext_frame);
895 if (extraction->npixels != NULL) {
900 giframe_arc_lamp_extpixels,
901 CPL_FRAME_LEVEL_INTERMEDIATE,
904 if (sext_frame == NULL) {
905 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
909 giraffe_localization_destroy(localization);
910 giraffe_extraction_destroy(extraction);
918 cpl_msg_error(fctid,
"Cannot attach fiber setup to local file '%s'! "
919 "Aborting ...", cpl_frame_get_filename(sext_frame));
921 cpl_frame_delete(sext_frame);
925 giraffe_localization_destroy(localization);
926 giraffe_extraction_destroy(extraction);
931 cpl_frameset_insert(set, sext_frame);
940 giframe_arc_lamp_exttrace,
941 CPL_FRAME_LEVEL_INTERMEDIATE,
944 if (sext_frame == NULL) {
945 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
949 giraffe_localization_destroy(localization);
950 giraffe_extraction_destroy(extraction);
958 cpl_msg_error(fctid,
"Cannot attach fiber setup to local file '%s'! "
959 "Aborting ...", cpl_frame_get_filename(sext_frame));
961 cpl_frame_delete(sext_frame);
965 giraffe_localization_destroy(localization);
966 giraffe_extraction_destroy(extraction);
971 cpl_frameset_insert(set, sext_frame);
975 if (extraction->model != NULL) {
980 GIFRAME_ARC_LAMP_EXTMODEL,
981 CPL_FRAME_LEVEL_FINAL,
984 if (sext_frame == NULL) {
985 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
989 giraffe_localization_destroy(localization);
990 giraffe_extraction_destroy(extraction);
998 cpl_msg_error(fctid,
"Cannot attach fiber setup to local file '%s'! "
999 "Aborting ...", cpl_frame_get_filename(sext_frame));
1001 cpl_frame_delete(sext_frame);
1005 giraffe_localization_destroy(localization);
1006 giraffe_extraction_destroy(extraction);
1011 cpl_frameset_insert(set, sext_frame);
1019 cpl_msg_info(fctid,
"Recipe Step : Wavelength Calibration");
1021 filename = cpl_frame_get_filename(grating_frame);
1028 cpl_msg_error(fctid,
"Cannot load grating table from '%s'. "
1029 "Aborting ...", filename);
1032 giraffe_localization_destroy(localization);
1033 giraffe_extraction_destroy(extraction);
1039 filename = cpl_frame_get_filename(slitgeo_frame);
1043 if (slitgeo == NULL) {
1044 cpl_msg_error(fctid,
"Cannot load slit geometry table from '%s'. "
1045 "Aborting ...", filename);
1048 giraffe_localization_destroy(localization);
1049 giraffe_extraction_destroy(extraction);
1063 cpl_msg_error(fctid,
"Slit geometry data from '%s' is not "
1064 "applicable for current fiber setup! "
1065 "Aborting ...", filename);
1069 giraffe_localization_destroy(localization);
1070 giraffe_extraction_destroy(extraction);
1079 filename = cpl_frame_get_filename(lines_frame);
1086 cpl_msg_error(fctid,
"Cannot load arc-line data from '%s'. "
1087 "Aborting ...", filename);
1090 giraffe_localization_destroy(localization);
1091 giraffe_extraction_destroy(extraction);
1099 if (wcal_frame != NULL) {
1103 filename = cpl_frame_get_filename(wcal_frame);
1107 cpl_msg_error(fctid,
"Cannot load initial wavelength solution "
1108 "from '%s'. Aborting ...", filename);
1113 giraffe_localization_destroy(localization);
1114 giraffe_extraction_destroy(extraction);
1126 if (wcal_config == NULL) {
1128 cpl_msg_error(fctid,
"Could not create wavelength calibration "
1129 "setup: error parsing configuration parameters! "
1132 giraffe_localization_destroy(localization);
1133 giraffe_extraction_destroy(extraction);
1143 wlsolution = giraffe_wcaldata_new();
1146 localization, fibers, slitgeo,
1147 grating, wavelengths, wcal_initial,
1151 cpl_msg_error(fctid,
"Error during wavelength calibration, "
1155 giraffe_localization_destroy(localization);
1156 giraffe_extraction_destroy(extraction);
1162 giraffe_wcaldata_delete(wlsolution);
1173 wcal_initial = NULL;
1189 giframe_wavelength_solution,
1190 CPL_FRAME_LEVEL_FINAL,
1193 if (wcal_frame == NULL) {
1195 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
1198 giraffe_localization_destroy(localization);
1199 giraffe_extraction_destroy(extraction);
1203 giraffe_wcaldata_delete(wlsolution);
1209 cpl_frameset_insert(set, wcal_frame);
1214 creator = (GiFrameCreator)giraffe_linedata_writer;
1217 CPL_FRAME_LEVEL_FINAL,
1218 properties, wlsolution->linedata,
1222 if (ldata_frame == NULL) {
1224 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
1227 giraffe_localization_destroy(localization);
1228 giraffe_extraction_destroy(extraction);
1232 giraffe_wcaldata_delete(wlsolution);
1242 giraffe_linedata_delete(wlsolution->linedata);
1243 wlsolution->linedata = NULL;
1245 cpl_frameset_insert(set, ldata_frame);
1253 if (slitgeometry == TRUE) {
1255 cpl_frame* slit_frame = NULL;
1259 GiTable* mask = NULL;
1260 GiTable* slit = NULL;
1263 cpl_msg_info(fctid,
"Calibrating slit geometry ...");
1268 filename = cpl_frame_get_filename(scal_frame);
1274 cpl_msg_error(fctid,
"Cannot load slit geometry mask from '%s'. "
1275 "Aborting ...", filename);
1281 giraffe_wcaldata_delete(wlsolution);
1283 giraffe_localization_destroy(localization);
1284 giraffe_extraction_destroy(extraction);
1297 wlsolution->coeffs, slitgeo, grating,
1301 cpl_msg_error(fctid,
"Slit geometry calibration failed! "
1309 giraffe_wcaldata_delete(wlsolution);
1311 giraffe_localization_destroy(localization);
1312 giraffe_extraction_destroy(extraction);
1330 slit_frame = giraffe_slitgeometry_save(slit);
1334 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
1341 giraffe_wcaldata_delete(wlsolution);
1343 giraffe_localization_destroy(localization);
1344 giraffe_extraction_destroy(extraction);
1353 cpl_frameset_insert(set, slit_frame);
1373 if (rebin == TRUE) {
1375 cpl_frame* rbin_frame = NULL;
1377 GiRebinConfig* rebin_config;
1380 cpl_msg_info(fctid,
"Recipe Step : Spectrum Rebinning");
1387 localization, grating, slitgeo,
1388 wlsolution->coeffs, rebin_config);
1391 cpl_msg_error(fctid,
"Rebinning of arc-lamp spectra failed! "
1394 giraffe_wcaldata_delete(wlsolution);
1397 giraffe_localization_destroy(localization);
1398 giraffe_extraction_destroy(extraction);
1421 giframe_arc_lamp_rbnspectra,
1422 CPL_FRAME_LEVEL_FINAL,
1425 if (rbin_frame == NULL) {
1427 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
1429 giraffe_wcaldata_delete(wlsolution);
1432 giraffe_localization_destroy(localization);
1433 giraffe_extraction_destroy(extraction);
1446 cpl_msg_error(fctid,
"Cannot attach fiber setup to local "
1447 "file '%s'! Aborting ...",
1448 cpl_frame_get_filename(rbin_frame));
1450 giraffe_wcaldata_delete(wlsolution);
1453 giraffe_localization_destroy(localization);
1454 giraffe_extraction_destroy(extraction);
1460 cpl_frame_delete(rbin_frame);
1466 cpl_frameset_insert(set, rbin_frame);
1473 giframe_arc_lamp_rbnerrors,
1474 CPL_FRAME_LEVEL_FINAL,
1477 if (rbin_frame == NULL) {
1479 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
1481 giraffe_wcaldata_delete(wlsolution);
1484 giraffe_localization_destroy(localization);
1485 giraffe_extraction_destroy(extraction);
1499 cpl_msg_error(fctid,
"Cannot attach fiber setup to local "
1500 "file '%s'! Aborting ...",
1501 cpl_frame_get_filename(rbin_frame));
1503 giraffe_wcaldata_delete(wlsolution);
1506 giraffe_localization_destroy(localization);
1507 giraffe_extraction_destroy(extraction);
1513 cpl_frame_delete(rbin_frame);
1519 cpl_frameset_insert(set, rbin_frame);
1531 giraffe_localization_destroy(localization);
1532 localization = NULL;
1534 giraffe_extraction_destroy(extraction);
1537 if (rebinning != NULL) {
1548 giraffe_wcaldata_delete(wlsolution);
1557giqcwavecalibration(cpl_parameterlist* config, cpl_frameset* set)
1560 const cxchar*
const fctid =
"giqcwavecalibration";
1570 cxint nsaturated = 0;
1574 const cxdouble rmsscale = 3.;
1575 const cxdouble saturation = 60000.;
1576 const cxdouble* pixels = NULL;
1577 const cxdouble* xpos = NULL;
1578 const cxdouble* ypos = NULL;
1579 const cxdouble* flux = NULL;
1581 cxdouble efficiency[2] = {0., 0.};
1582 cxdouble wlcenter = 0.;
1586 cxdouble pixel2nm = 1.;
1587 cxdouble fwhm_domain[2] = {0., 100.};
1588 cxdouble* _tdata = NULL;
1589 cxdouble* _tdata_fib3 = NULL;
1591 cpl_propertylist* properties = NULL;
1592 cpl_propertylist* qclog = NULL;
1594 cpl_parameter* p = NULL;
1596 cpl_frame* rframe = NULL;
1597 cpl_frame* pframe = NULL;
1599 const cpl_image* _pimage = NULL;
1600 const cpl_image* _qimage = NULL;
1601 const cpl_image* _rimage = NULL;
1602 const cpl_image* _simage = NULL;
1604 cpl_image* _test = NULL;
1605 cpl_image* _test0 = NULL;
1606 cpl_image* _test1 = NULL;
1608 cpl_image* _test_fib3 = NULL;
1609 cpl_image* _test0_fib3 = NULL;
1610 cpl_image* _test1_fib3 = NULL;
1612 cpl_table* _ptable = NULL;
1614 GiImage* rimage = NULL;
1615 GiImage* pimage = NULL;
1617 GiTable* ptable = NULL;
1619 GiLineData* plines = NULL;
1626 cpl_parameter * simcalp = cpl_parameterlist_find(config,
"giraffe.wcal.qc.simlamp");
1628 cxbool qc_simlamp_flag = FALSE;
1630 if (simcalp != NULL) {
1631 qc_simlamp_flag = cpl_parameter_get_bool(simcalp);
1634 char* giframe_arc_lamp_extspectra = GIFRAME_ARC_LAMP_EXTSPECTRA;
1635 char* giframe_arc_lamp_rbnspectra = GIFRAME_ARC_LAMP_RBNSPECTRA;
1636 char* giframe_line_data = GIFRAME_LINE_DATA;
1637 char* giframe_wavelength_solution = GIFRAME_WAVELENGTH_SOLUTION;
1639 if(qc_simlamp_flag) {
1640 giframe_arc_lamp_extspectra = GIFRAME_ARC_LAMP_EXTSPECTRA_SIM;
1641 giframe_arc_lamp_rbnspectra = GIFRAME_ARC_LAMP_RBNSPECTRA_SIM;
1642 giframe_line_data = GIFRAME_LINE_DATA_SIM;
1643 giframe_wavelength_solution = GIFRAME_WAVELENGTH_SOLUTION_SIM;
1647 cpl_msg_info(fctid,
"Computing QC1 parameters ...");
1656 CPL_FRAME_GROUP_PRODUCT);
1658 if (pframe == NULL) {
1660 cpl_msg_warning(fctid,
"Product '%s' not found.",
1661 giframe_arc_lamp_extspectra);
1663 cpl_msg_warning(fctid,
"Setting lamp efficiencies (%s, %s) to 0.",
1664 GIALIAS_QCLAMP, GIALIAS_QCLAMP_SIMCAL);
1676 cpl_msg_error(fctid,
"Could not load extracted spectra '%s'!",
1677 cpl_frame_get_filename(pframe));
1682 giraffe_paf_delete(qc);
1689 cx_assert(_pimage != NULL);
1697 cpl_msg_error(fctid,
"Could not load extracted spectra fiber setup!");
1705 giraffe_paf_delete(qc);
1712 cx_assert(_ptable != NULL);
1714 if (cpl_table_has_column(_ptable,
"RP") == FALSE) {
1716 cpl_msg_warning(fctid,
"Column 'RP' not found in fiber setup table!");
1717 cpl_msg_warning(fctid,
"Setting lamp efficiencies (%s, %s) to 0.",
1718 GIALIAS_QCLAMP, GIALIAS_QCLAMP_SIMCAL);
1727 cx_assert(properties != NULL);
1729 if (cpl_propertylist_has(properties, GIALIAS_EXPTIME) == FALSE) {
1731 cpl_msg_warning(fctid,
"Property '%s' not found in '%s'.",
1732 GIALIAS_EXPTIME, cpl_frame_get_filename(rframe));
1733 cpl_msg_warning(fctid,
"Setting lamp efficiencies (%s, %s) to 0.",
1734 GIALIAS_QCLAMP, GIALIAS_QCLAMP_SIMCAL);
1743 cxint nb = cpl_image_get_size_y(_pimage);
1744 cxint nf[2] = {0, 0};
1746 cxdouble exptime = cpl_propertylist_get_double(properties,
1748 cxdouble* _sum = NULL;
1750 cpl_image* sum = NULL;
1753 sum = cpl_image_collapse_create(_pimage, 0);
1754 _sum = cpl_image_get_data_double(sum);
1756 for (fiber = 0; fiber < cpl_table_get_nrow(_ptable); ++fiber) {
1758 cxint rp = cpl_table_get_int(_ptable,
"RP", fiber, NULL);
1761 efficiency[1] += _sum[fiber];
1765 efficiency[0] += _sum[fiber];
1773 cpl_image_delete(sum);
1777 cpl_msg_warning(fctid,
"No OzPoz fibers found in the "
1778 "current fiber setup.");
1779 cpl_msg_warning(fctid,
"Setting lamp efficiency (%s) to 0.",
1784 efficiency[0] /= nf[0] * nb * exptime;
1788 cpl_msg_warning(fctid,
"No simultaneous calibration fibers "
1789 "found in the current fiber setup.");
1790 cpl_msg_warning(fctid,
"Setting lamp efficiency (%s) to 0.",
1791 GIALIAS_QCLAMP_SIMCAL);
1795 efficiency[1] /= nf[1] * nb * exptime;
1818 rframe = cpl_frameset_find(set, GIFRAME_ARC_SPECTRUM);
1820 if (rframe == NULL) {
1821 cpl_msg_error(fctid,
"Missing raw frame (%s)", GIFRAME_ARC_SPECTRUM);
1823 giraffe_paf_delete(qc);
1829 cpl_msg_info(fctid,
"Processing reference frame '%s' (%s)",
1830 cpl_frame_get_filename(rframe), cpl_frame_get_tag(rframe));
1837 cpl_msg_error(fctid,
"Could not load arc-lamp spectra '%s'!",
1838 cpl_frame_get_filename(rframe));
1843 giraffe_paf_delete(qc);
1851 cx_assert(_rimage != NULL);
1860 cx_assert(properties != NULL);
1862 if (cpl_propertylist_has(properties, GIALIAS_OVSCX)) {
1864 cxint _ox = cpl_propertylist_get_int(properties, GIALIAS_OVSCX);
1865 cxint _nx = cpl_image_get_size_x(_rimage) - 2 * CX_MAX(0, _ox) - 1;
1867 w.x0 = CX_MAX(0, _ox) + 1;
1872 if (cpl_propertylist_has(properties, GIALIAS_OVSCY)) {
1874 cxint _oy = cpl_propertylist_get_int(properties, GIALIAS_OVSCY);
1875 cxint _ny = cpl_image_get_size_y(_rimage) - 2 * CX_MAX(0, _oy) - 1;
1877 w.y0 = CX_MAX(0, _oy) + 1;
1882 mean = cpl_image_get_mean_window(_rimage, w.x0, w.y0, w.x1, w.y1);
1884 pixels = cpl_image_get_data_const(_rimage);
1885 npixel = cpl_image_get_size_x(_rimage) * cpl_image_get_size_y(_rimage);
1887 for (i = 0; i < npixel; i++) {
1888 if (pixels[i] > saturation) {
1898 qc = giraffe_qclog_open(0);
1901 cpl_msg_error(fctid,
"Cannot create QC1 log!");
1909 qclog = giraffe_paf_get_properties(qc);
1910 cx_assert(qclog != NULL);
1913 CPL_FRAME_GROUP_PRODUCT);
1915 if (pframe == NULL) {
1916 cpl_msg_error(fctid,
"Missing product frame (%s)",
1917 giframe_wavelength_solution);
1919 giraffe_paf_delete(qc);
1928 cpl_msg_info(fctid,
"Processing product frame '%s' (%s)",
1929 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
1936 cpl_msg_error(fctid,
"Could not load dispersion solution '%s'!",
1937 cpl_frame_get_filename(pframe));
1945 giraffe_paf_delete(qc);
1952 cx_assert(properties != NULL);
1967 cpl_propertylist_update_string(qclog,
"PRO.CATG",
1968 cpl_frame_get_tag(pframe));
1969 cpl_propertylist_set_comment(qclog,
"PRO.CATG",
1970 "Pipeline product category");
1973 cx_assert(properties != NULL);
1975 wslnaccept = cpl_propertylist_get_int(properties, GIALIAS_WSOL_NACCEPT);
1980 GIALIAS_WSOL_NLINES);
1982 GIALIAS_WSOL_NACCEPT);
1984 GIALIAS_WSOL_NREJECT);
1992 giraffe_qclog_close(qc);
2000 cxbool rebin = TRUE;
2002 cpl_parameter * rebinp = cpl_parameterlist_find(config,
"giraffe.wcal.rebin");
2004 if (rebinp != NULL) {
2005 rebin = cpl_parameter_get_bool(rebinp);
2010 qc = giraffe_qclog_open(1);
2013 cpl_msg_error(fctid,
"Cannot create QC1 log!");
2017 qclog = giraffe_paf_get_properties(qc);
2018 cx_assert(qclog != NULL);
2021 CPL_FRAME_GROUP_PRODUCT);
2023 if (pframe == NULL) {
2024 cpl_msg_error(fctid,
"Missing product frame (%s)",
2025 giframe_arc_lamp_rbnspectra);
2030 giraffe_paf_delete(qc);
2036 cpl_msg_info(fctid,
"Processing product frame '%s' (%s)",
2037 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
2043 cpl_msg_error(fctid,
"Could not load rebinned arc-lamp spectra '%s'!",
2044 cpl_frame_get_filename(pframe));
2052 giraffe_paf_delete(qc);
2063 cpl_msg_error(fctid,
"Could not load rebinned arc-lamp spectra '%s'!",
2064 cpl_frame_get_filename(pframe));
2075 giraffe_paf_delete(qc);
2082 cx_assert(properties != NULL);
2095 cpl_propertylist_update_string(qclog,
"PRO.CATG",
2096 cpl_frame_get_tag(pframe));
2097 cpl_propertylist_set_comment(qclog,
"PRO.CATG",
2098 "Pipeline product category");
2101 cx_assert(properties != NULL);
2112 cxint binwns = cpl_propertylist_get_int(properties, GIALIAS_BINWNS);
2114 if (binwns != 0 && wslnaccept != 0) {
2115 cpl_propertylist_update_double(properties, GIALIAS_QCNLINACC,
2116 (
double)wslnaccept / binwns);
2119 cpl_propertylist_update_double(properties, GIALIAS_QCNLINACC, 0.);
2123 cpl_propertylist_update_double(properties, GIALIAS_QCMEAN, mean);
2124 cpl_propertylist_set_comment(properties, GIALIAS_QCMEAN,
"Mean level of "
2131 cpl_propertylist_update_int(properties, GIALIAS_QCNSAT, nsaturated);
2132 cpl_propertylist_set_comment(properties, GIALIAS_QCNSAT,
"Number of "
2133 "saturated pixels in the first raw frame");
2143 cpl_propertylist_update_double(properties, GIALIAS_QCLAMP, efficiency[0]);
2144 cpl_propertylist_set_comment(properties, GIALIAS_QCLAMP,
2145 "Calibration lamp efficiency");
2150 cpl_propertylist_update_double(properties, GIALIAS_QCLAMP_SIMCAL,
2152 cpl_propertylist_set_comment(properties, GIALIAS_QCLAMP_SIMCAL,
2153 "SIMCAL lamp efficiency");
2156 GIALIAS_QCLAMP_SIMCAL);
2163 _test = cpl_image_duplicate(_pimage);
2164 _tdata = cpl_image_get_data(_test);
2166 _test_fib3 = cpl_image_duplicate(_pimage);
2167 _tdata_fib3 = cpl_image_get_data(_test_fib3);
2169 nx = cpl_image_get_size_x(_test);
2170 ny = cpl_image_get_size_y(_test);
2172 for (i = 0; i < nx * ny; i++) {
2173 _tdata[i] = _tdata[i] > 0. ? log(_tdata[i]) : 0.;
2174 _tdata_fib3[i] = _tdata_fib3[i] > 0. ? log10(_tdata_fib3[i]) : 0.;
2179 _test0 = cpl_image_extract(_test, 4, 1, 4, ny);
2181 _test1 = cpl_image_collapse_create(_test, 1);
2182 cpl_image_divide_scalar(_test1, nx);
2184 cpl_image_delete(_test);
2188 _test = cpl_image_subtract_create(_test0, _test1);
2190 cpl_image_delete(_test0);
2193 cpl_image_delete(_test1);
2198 _test0_fib3 = cpl_image_extract(_test_fib3, 4, 1, 4, ny);
2201 cx_assert(_ptable != NULL);
2205 if (cpl_table_has_column(_ptable,
"OBJECT") == FALSE) {
2206 cpl_msg_warning(fctid,
2207 "Column 'OBJECT' not found in fiber setup table!");
2208 cpl_msg_warning(fctid,
"CALSIM fibres may be included in QC params");
2211 for (i = 0; i < nx; i++) {
2212 const char *objs = cpl_table_get_string(_ptable,
"OBJECT", i);
2213 if (!strcmp(objs,
"CALSIM")) {
2214 cpl_image_fill_window(_test_fib3, i + 1, 1, i + 1, ny, 0);
2220 _test1_fib3 = cpl_image_collapse_create(_test_fib3, 1);
2221 cpl_image_divide_scalar(_test1_fib3, nfib);
2224 cpl_image_delete(_test_fib3);
2227 _test_fib3 = cpl_image_subtract_create(_test0_fib3, _test1_fib3);
2229 cpl_image_delete(_test0_fib3);
2232 cpl_image_delete(_test1_fib3);
2236 _tdata = cpl_image_get_data(_test);
2240 for (i = 0; i < ny; i++) {
2241 _tdata[i] = exp(_tdata[i]);
2242 rms += pow(_tdata[i], 2.);
2245 rms = sqrt(rms / (ny - 1));
2247 std = cpl_image_get_stdev_window(_test_fib3, 1, 1, 1, (cpl_size) ((1-0.045) * ny));
2249 cpl_image_delete(_test);
2251 cpl_image_delete(_test_fib3);
2254 cpl_propertylist_update_double(properties, GIALIAS_QCRBRMS, rms);
2255 cpl_propertylist_set_comment(properties, GIALIAS_QCRBRMS,
2256 "RMS of rebinned arc-lamp spectra");
2261 cpl_propertylist_update_double(properties, GIALIAS_QCFIB3 , std);
2262 cpl_propertylist_set_comment(properties, GIALIAS_QCFIB3 ,
2263 "STDEV of fibre 3 - mean");
2272 cpl_msg_error(fctid,
"Could not save rebinned arc-lamp spectra "
2273 "'%s'!", cpl_frame_get_filename(pframe));
2284 giraffe_paf_delete(qc);
2294 cpl_msg_error(fctid,
"Could not save rebinned arc-lamp spectra "
2295 "'%s'!", cpl_frame_get_filename(pframe));
2306 giraffe_paf_delete(qc);
2318 giraffe_qclog_close(qc);
2327 qc = giraffe_qclog_open(2);
2330 cpl_msg_error(fctid,
"Cannot create QC1 log!");
2334 qclog = giraffe_paf_get_properties(qc);
2335 cx_assert(qclog != NULL);
2338 CPL_FRAME_GROUP_PRODUCT);
2340 if (pframe == NULL) {
2341 cpl_msg_error(fctid,
"Missing product frame (%s)",
2347 giraffe_paf_delete(qc);
2353 cpl_msg_info(fctid,
"Processing product frame '%s' (%s)",
2354 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
2361 plines = giraffe_linedata_new();
2363 status = giraffe_linedata_load(plines, cpl_frame_get_filename(pframe));
2366 cpl_msg_error(fctid,
"Could not load line data '%s'!",
2367 cpl_frame_get_filename(pframe));
2369 giraffe_linedata_delete(plines);
2375 giraffe_paf_delete(qc);
2382 cx_assert(properties != NULL);
2395 cpl_propertylist_update_string(qclog,
"PRO.CATG",
2396 cpl_frame_get_tag(pframe));
2397 cpl_propertylist_set_comment(qclog,
"PRO.CATG",
2398 "Pipeline product category");
2401 _pimage = giraffe_linedata_get_data(plines,
"FWHM");
2403 if (_pimage == NULL) {
2404 cpl_msg_error(fctid,
"FWHM line data not found!");
2406 giraffe_linedata_delete(plines);
2412 giraffe_paf_delete(qc);
2418 nx = cpl_image_get_size_x(_pimage);
2419 ny = cpl_image_get_size_y(_pimage);
2421 pixels = cpl_image_get_data_const(_pimage);
2423 for (j = 0; j < 2; ++j) {
2425 register cxint ndata = nx * ny;
2431 for (i = 0; i < ndata; ++i) {
2433 if ((pixels[i] >= fwhm_domain[0]) &&
2434 (pixels[i] < fwhm_domain[1])) {
2442 cpl_msg_error(fctid,
"All line FWHM data are invalid!");
2444 giraffe_linedata_delete(plines);
2450 giraffe_paf_delete(qc);
2458 for (i = 0; i < ndata; ++i) {
2460 if ((pixels[i] >= fwhm_domain[0]) &&
2461 (pixels[i] < fwhm_domain[1])) {
2462 rms += pow(pixels[i] - mean, 2.);
2468 rms = sqrt(rms / (npixel - 1));
2471 fwhm_domain[0] = CX_MAX(mean - rmsscale * rms, 0.);
2472 fwhm_domain[1] = CX_MIN(mean + rmsscale * rms, 100.);
2480 double x_total = 0.;
2481 double y_total = 0.;
2482 double flux_total = 0.;
2484 cx_string *slit_name = NULL;
2485 cx_string *grat_name = NULL;
2488 if (qc_simlamp_flag) {
2489 _pimage = giraffe_linedata_get_data(plines,
"Xccd");
2491 if (_pimage == NULL) {
2492 cpl_msg_error(fctid,
"Xccd line data not found!");
2494 giraffe_linedata_delete(plines);
2500 giraffe_paf_delete(qc);
2506 _qimage = giraffe_linedata_get_data(plines,
"Yccd");
2508 if (_qimage == NULL) {
2509 cpl_msg_error(fctid,
"Yccd line data not found!");
2511 giraffe_linedata_delete(plines);
2517 giraffe_paf_delete(qc);
2523 nx = cpl_image_get_size_x(_rimage);
2524 ny = cpl_image_get_size_y(_rimage);
2526 npx = cpl_image_get_size_x(_pimage);
2527 npy = cpl_image_get_size_y(_pimage);
2529 pixels = cpl_image_get_data_const(_rimage);
2530 xpos = cpl_image_get_data_const(_pimage);
2531 ypos = cpl_image_get_data_const(_qimage);
2535 if (cpl_propertylist_has(properties, GIALIAS_PRSCX)) {
2536 prscx = cpl_propertylist_get_int(properties, GIALIAS_PRSCX);
2551 int cmid = floor(cwidth / 2);
2553 for (npxi = 0; npxi < npx; npxi++) {
2554 for (npyi = 0; npyi < npy; npyi++) {
2557 double max_val = 0.;
2559 int pixpos_init = 0;
2567 pixpos_init = (int)floor(ypos[npxi + npyi * npx]) + prscx +
2568 nx * (int)floor(xpos[npxi + npyi * npx]) - cmid;
2570 for (y = 0; y < cwidth; y++) {
2571 pixpos = pixpos_init + y;
2572 if (pixpos >= 0 && pixpos < ny * nx) {
2573 pixval = pixels[pixpos];
2574 if (pixval > max_val) {
2586 for (y = 0; y < cwidth; y++) {
2587 pixpos = pixpos_init + y - (cmid - max_index);
2588 if (pixpos >= 0 && pixpos < ny * nx) {
2589 pixval = pixels[pixpos];
2592 flux_total += pixval;
2596 x_total += xpos[npxi + npyi * npx];
2597 y_total += (int)floor(ypos[npxi + npyi * npx]) + prscx -
2598 (cmid - max_index) - cmid + yy / zz;
2602 x_total = x_total / (npx * npy);
2603 y_total = y_total / (npx * npy);
2604 flux_total = flux_total / (npx * npy) / cwidth;
2606 if (cpl_propertylist_has(properties, GIALIAS_SLITNAME) == FALSE) {
2607 cpl_msg_error(fctid,
2608 "SLit name property '%s' not "
2612 cpl_propertylist_delete(properties);
2615 giraffe_linedata_delete(plines);
2621 giraffe_paf_delete(qc);
2627 slit_name = cx_string_create(
2628 cpl_propertylist_get_string(properties, GIALIAS_SLITNAME));
2630 if (cpl_propertylist_has(properties, GIALIAS_GRATNAME) == FALSE) {
2631 cpl_msg_error(fctid,
2632 "Grating name property '%s' not "
2636 cpl_propertylist_delete(properties);
2639 giraffe_linedata_delete(plines);
2645 giraffe_paf_delete(qc);
2651 grat_name = cx_string_create(
2652 cpl_propertylist_get_string(properties, GIALIAS_GRATNAME));
2654 cx_string_append(slit_name, cx_string_get(grat_name));
2664 y_total = 1003.66 - y_total;
2665 x_total = 1719.13 - x_total;
2667 if (strcmp(cx_string_get(slit_name),
"Medusa1HR") == 0) {
2668 y_total = 1.019 * y_total + 0.016;
2669 x_total = 0.986 * x_total - 0.073;
2670 flux_total = 1.334 * flux_total - 506.565;
2672 else if (strcmp(cx_string_get(slit_name),
"Medusa1LR") == 0) {
2673 y_total = 1.038 * y_total + 3.322;
2674 x_total = 1.194 * x_total + 434.818;
2675 flux_total = 0.243 * flux_total - 121.36;
2677 else if (strcmp(cx_string_get(slit_name),
"Medusa2HR") == 0) {
2678 y_total = 0.989 * y_total - 1.067;
2679 x_total = 1.0 * x_total - 10;
2680 flux_total = 1.397 * flux_total - 465.637;
2682 else if (strcmp(cx_string_get(slit_name),
"IFU1HR") == 0) {
2683 y_total = 0.977 * y_total - 107.426;
2684 x_total = 0.96 * x_total - 4.968;
2685 flux_total = 1.661 * flux_total - 512.41;
2687 else if (strcmp(cx_string_get(slit_name),
"IFU2HR") == 0) {
2688 y_total = 0.956 * y_total - 103.017;
2689 x_total = 0.942 * x_total + 0.22;
2690 flux_total = 0.786 * flux_total - 247.967;
2692 else if (strcmp(cx_string_get(slit_name),
"ArgusHR") == 0) {
2693 y_total = 0.954 * y_total + 152.569;
2694 x_total = 0.928 * x_total - 12.441;
2695 flux_total = 1.219 * flux_total - 329.05;
2699 fctid,
"Slit and grating name '%s' not recognized for SIMLAMP!",
2700 cx_string_get(slit_name));
2702 cpl_propertylist_delete(properties);
2705 giraffe_linedata_delete(plines);
2711 giraffe_paf_delete(qc);
2717 cx_string_delete(slit_name);
2718 cx_string_delete(grat_name);
2721 properties = cpl_propertylist_load_regexp(cpl_frame_get_filename(pframe),
2722 0,
"^COMMENT$", TRUE);
2724 cx_assert(properties != NULL);
2726 if (cpl_propertylist_has(properties, GIALIAS_GRATWLEN) == FALSE) {
2727 cpl_msg_error(fctid,
"Grating central wavelength property '%s' not "
2728 "found!", GIALIAS_GRATWLEN);
2730 cpl_propertylist_delete(properties);
2733 giraffe_linedata_delete(plines);
2739 giraffe_paf_delete(qc);
2745 if (cpl_propertylist_has(properties, GIALIAS_WSOL_SCALE) == FALSE) {
2746 cpl_msg_error(fctid,
"Line data property '%s' not found!",
2747 GIALIAS_WSOL_SCALE);
2749 cpl_propertylist_delete(properties);
2752 giraffe_linedata_delete(plines);
2758 giraffe_paf_delete(qc);
2764 wlcenter = cpl_propertylist_get_double(properties, GIALIAS_GRATWLEN);
2765 pixel2nm = cpl_propertylist_get_double(properties, GIALIAS_WSOL_SCALE);
2775 if (qc_simlamp_flag) {
2776 cpl_propertylist_update_double(properties, GIALIAS_QCSIMCALX, y_total);
2777 cpl_propertylist_set_comment(properties, GIALIAS_QCSIMCALX,
2778 "Average X of SIMCAL lines");
2780 cpl_propertylist_update_double(properties, GIALIAS_QCSIMCALY, x_total);
2781 cpl_propertylist_set_comment(properties, GIALIAS_QCSIMCALY,
2782 "Average Y of SIMCAL lines");
2784 cpl_propertylist_update_double(properties, GIALIAS_QCSIMCALF,
2786 cpl_propertylist_set_comment(properties, GIALIAS_QCSIMCALF,
2787 "Average flux of SIMCAL lines");
2790 cpl_propertylist_update_double(properties, GIALIAS_QCRESOLAVG, mean);
2791 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLAVG,
2792 "Average line FWHM [nm]");
2794 cpl_propertylist_update_double(properties, GIALIAS_QCRESOLRMS, rms);
2795 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLRMS,
2796 "RMS of line FWHM [nm]");
2798 cpl_propertylist_update_int(properties, GIALIAS_QCRESOLTOT, nx * ny);
2799 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLTOT,
2800 "Total number of lines available for FWHM RMS "
2803 cpl_propertylist_update_int(properties, GIALIAS_QCRESOLLIN, npixel);
2804 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLLIN,
2805 "Number of lines used for FWHM RMS "
2808 cpl_propertylist_update_double(properties, GIALIAS_QCRESOLPWR,
2810 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLPWR,
2814 GIALIAS_QCRESOLAVG);
2816 GIALIAS_QCRESOLRMS);
2818 GIALIAS_QCRESOLTOT);
2820 GIALIAS_QCRESOLLIN);
2822 GIALIAS_QCRESOLPWR);
2825 status = giraffe_linedata_save(plines, properties,
2826 cpl_frame_get_filename(pframe));
2829 cpl_msg_error(fctid,
"Could not save line data "
2830 "'%s'!", cpl_frame_get_filename(pframe));
2832 cpl_propertylist_delete(properties);
2835 giraffe_linedata_delete(plines);
2841 giraffe_paf_delete(qc);
2847 cpl_propertylist_delete(properties);
2850 giraffe_qclog_close(qc);
2859 giraffe_linedata_delete(plines);
2873cpl_plugin_get_info(cpl_pluginlist* list)
2876 cpl_recipe* recipe = cx_calloc(1,
sizeof *recipe);
2877 cpl_plugin* plugin = &recipe->interface;
2879 cpl_plugin_init(plugin,
2881 GIRAFFE_BINARY_VERSION,
2882 CPL_PLUGIN_TYPE_RECIPE,
2883 "giwavecalibration",
2884 "Compute dispersion solution from an arc-lamp spectrum.",
2885 "For detailed information please refer to the "
2886 "GIRAFFE pipeline user manual.\nIt is available at "
2887 "http://www.eso.org/pipelines.",
2891 giwavecalibration_create,
2892 giwavecalibration_exec,
2893 giwavecalibration_destroy);
2895 cpl_pluginlist_append(list, plugin);
GiBiasConfig * giraffe_bias_config_create(cpl_parameterlist *list)
Creates a setup structure for a bias removal task.
void giraffe_bias_config_add(cpl_parameterlist *list)
Adds parameters for the bias removal.
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.
void giraffe_bias_config_destroy(GiBiasConfig *config)
Destroys a bias removal setup structure.
GiTable * giraffe_fibers_setup(const cpl_frame *frame, const cpl_frame *reference)
Setup a fiber list.
cxint giraffe_fiberlist_compare(const GiTable *fibers, const GiTable *reference)
Compare two fiber lists.
cxint giraffe_fiberlist_attach(cpl_frame *frame, GiTable *fibers)
Attach a fiber table to a frame.
cpl_frame * giraffe_get_frame(const cpl_frameset *set, const cxchar *tag, cpl_frame_group group)
Get a frame from a frame set.
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.
cpl_frame * giraffe_frame_create_image(GiImage *image, const cxchar *tag, cpl_frame_level level, cxbool save, cxbool update)
Create an image product frame.
cpl_frame * giraffe_get_slitgeometry(const cpl_frameset *set)
Get the slit geometry frame from a frame set.
cpl_frame * giraffe_frame_create_table(GiTable *table, const cxchar *tag, cpl_frame_level level, cxbool save, cxbool update)
Create a table product frame.
cpl_image * giraffe_image_get(const GiImage *self)
Gets the image data.
cpl_propertylist * giraffe_image_get_properties(const GiImage *self)
Get the properties of an image.
void giraffe_image_delete(GiImage *self)
Destroys an image.
cxint giraffe_image_add_info(GiImage *image, const GiRecipeInfo *info, const cpl_frameset *set)
Add additional frame information to an image.
cxint giraffe_image_save(GiImage *self, const cxchar *filename)
Write a Giraffe image to a file.
GiImage * giraffe_image_new(cpl_type type)
Creates an empty image container.
cxint giraffe_image_load(GiImage *self, const cxchar *filename, cxint position)
Gets image data and properties from a file.
void giraffe_rebin_config_destroy(GiRebinConfig *config)
Destroys a spectrum extraction setup structure.
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.
GiRebinConfig * giraffe_rebin_config_create(cpl_parameterlist *list)
Creates a setup structure for the rebinning.
GiRebinning * giraffe_rebinning_new(void)
Create an empty rebinning results container.
void giraffe_rebinning_destroy(GiRebinning *rebinning)
Destroys a rebinning results container and its contents.
void giraffe_rebin_config_add(cpl_parameterlist *list)
Adds parameters for the rebinning.
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.
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.
cxint giraffe_table_attach(GiTable *self, const cxchar *filename, cxint position, const cxchar *id)
Attach a Giraffe table to a file.
void giraffe_table_delete(GiTable *self)
Destroys a Giraffe table.
cpl_table * giraffe_table_get(const GiTable *self)
Get the table data from a Giraffe table.
cpl_propertylist * giraffe_table_get_properties(const GiTable *self)
Gets the table properties.
cxint giraffe_table_add_info(GiTable *table, const GiRecipeInfo *info, const cpl_frameset *set)
Add additional frame information to a table.
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.
const cxchar * giraffe_get_license(void)
Get the pipeline copyright and license.
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.