27#include <cxmessages.h>
29#include <cpl_recipe.h>
30#include <cpl_plugininfo.h>
31#include <cpl_parameterlist.h>
32#include <cpl_frameset.h>
33#include <cpl_propertylist.h>
40#include "gislitgeometry.h"
42#include "gifiberutils.h"
47#include "giwlcalibration.h"
48#include "girebinning.h"
49#include "gisgcalibration.h"
52static cxint giwavecalibration(cpl_parameterlist* config, cpl_frameset* set);
53static cxint giqcwavecalibration(cpl_parameterlist* config, cpl_frameset* set);
62giwavecalibration_create(cpl_plugin* plugin)
65 cpl_recipe* recipe = (cpl_recipe*)plugin;
79 recipe->parameters = cpl_parameterlist_new();
80 cx_assert(recipe->parameters != NULL);
103 p = cpl_parameter_new_value(
"giraffe.wcal.rebin",
105 "Rebin extracted arc-lamp spectra.",
109 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"wcal-rebin");
110 cpl_parameterlist_append(recipe->parameters, p);
116 p = cpl_parameter_new_value(
"giraffe.wcal.slitgeometry",
118 "Controls the slit geometry calibration.",
122 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"wcal-slit");
123 cpl_parameterlist_append(recipe->parameters, p);
129 p = cpl_parameter_new_value(
"giraffe.wcal.qc.simlamp", CPL_TYPE_BOOL,
130 "Controls creation of SIMLAMP QC parameters.",
131 "giraffe.wcal", FALSE);
133 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"wcal-qcsim");
134 cpl_parameterlist_append(recipe->parameters, p);
147giwavecalibration_exec(cpl_plugin* plugin)
150 cpl_recipe* recipe = (cpl_recipe*)plugin;
155 if (recipe->parameters == NULL || recipe->frames == NULL) {
159 status = giwavecalibration(recipe->parameters, recipe->frames);
165 status = giqcwavecalibration(recipe->parameters, recipe->frames);
177giwavecalibration_destroy(cpl_plugin* plugin)
180 cpl_recipe* recipe = (cpl_recipe*)plugin;
189 cpl_parameterlist_delete(recipe->parameters); recipe->parameters = NULL;
191 giraffe_error_clear();
202giwavecalibration(cpl_parameterlist* config, cpl_frameset* set)
205 const cxchar*
const fctid =
"giwavecalibration";
208 const cxchar* filename = NULL;
210 cxbool rebin = FALSE;
211 cxbool slitgeometry = FALSE;
214 cxint narcspectrum = 0;
216 const cpl_propertylist* properties = NULL;
218 cpl_frame* arcspec_frame = NULL;
219 cpl_frame* bpixel_frame = NULL;
220 cpl_frame* mbias_frame = NULL;
221 cpl_frame* mlocy_frame = NULL;
222 cpl_frame* mlocw_frame = NULL;
223 cpl_frame* psfdata_frame = NULL;
224 cpl_frame* slight_frame = NULL;
225 cpl_frame* grating_frame = NULL;
226 cpl_frame* slitgeo_frame = NULL;
227 cpl_frame* lines_frame = NULL;
228 cpl_frame* wcal_frame = NULL;
229 cpl_frame* ldata_frame = NULL;
230 cpl_frame* scal_frame = NULL;
231 cpl_frame* sext_frame = NULL;
233 cpl_parameter* p = NULL;
235 cpl_matrix* biasareas = NULL;
237 GiImage* arcspectrum = NULL;
238 GiImage* bsarcspectrum = NULL;
239 GiImage* slight = NULL;
240 GiImage* mbias = NULL;
241 GiImage* bpixel = NULL;
243 GiLocalization* localization = NULL;
244 GiExtraction* extraction = NULL;
245 GiRebinning* rebinning = NULL;
246 GiWCalData* wlsolution = NULL;
248 GiTable* fibers = NULL;
249 GiTable* grating = NULL;
250 GiTable* slitgeo = NULL;
251 GiTable* wavelengths = NULL;
252 GiTable* wcal_initial = NULL;
256 GiBiasConfig* bias_config = NULL;
257 GiExtractConfig* extract_config = NULL;
260 GiFrameCreator creator = NULL;
262 GiRecipeInfo info = {(cxchar*)fctid, 1, NULL, config};
264 GiGroupInfo groups[] = {
265 {GIFRAME_ARC_SPECTRUM, CPL_FRAME_GROUP_RAW},
266 {GIFRAME_BADPIXEL_MAP, CPL_FRAME_GROUP_CALIB},
267 {GIFRAME_BIAS_MASTER, CPL_FRAME_GROUP_CALIB},
268 {GIFRAME_SCATTERED_LIGHT_MODEL, CPL_FRAME_GROUP_CALIB},
269 {GIFRAME_LOCALIZATION_CENTROID, CPL_FRAME_GROUP_CALIB},
270 {GIFRAME_LOCALIZATION_WIDTH, CPL_FRAME_GROUP_CALIB},
271 {GIFRAME_PSF_CENTROID, CPL_FRAME_GROUP_CALIB},
272 {GIFRAME_PSF_WIDTH, CPL_FRAME_GROUP_CALIB},
273 {GIFRAME_PSF_DATA, CPL_FRAME_GROUP_CALIB},
274 {GIFRAME_WAVELENGTH_SOLUTION, CPL_FRAME_GROUP_CALIB},
275 {GIFRAME_SLITSETUP, CPL_FRAME_GROUP_CALIB},
276 {GIFRAME_SLITMASTER, CPL_FRAME_GROUP_CALIB},
277 {GIFRAME_GRATING, CPL_FRAME_GROUP_CALIB},
278 {GIFRAME_LINE_CATALOG, CPL_FRAME_GROUP_CALIB},
279 {GIFRAME_LINE_MASK, CPL_FRAME_GROUP_CALIB},
280 {NULL, CPL_FRAME_GROUP_NONE}
285 cpl_parameter * simcalp = cpl_parameterlist_find(config,
"giraffe.wcal.qc.simlamp");
287 cxbool qc_simlamp_flag = FALSE;
289 if (simcalp != NULL) {
290 qc_simlamp_flag = cpl_parameter_get_bool(simcalp);
293 char* giframe_arc_lamp_extspectra = GIFRAME_ARC_LAMP_EXTSPECTRA;
294 char* giframe_arc_lamp_exterrors = GIFRAME_ARC_LAMP_EXTERRORS;
295 char* giframe_arc_lamp_extpixels = GIFRAME_ARC_LAMP_EXTPIXELS;
296 char* giframe_arc_lamp_exttrace = GIFRAME_ARC_LAMP_EXTTRACE;
297 char* giframe_arc_lamp_rbnspectra = GIFRAME_ARC_LAMP_RBNSPECTRA;
298 char* giframe_arc_lamp_rbnerrors = GIFRAME_ARC_LAMP_RBNERRORS;
299 char* giframe_line_data = GIFRAME_LINE_DATA;
300 char* giframe_wavelength_solution = GIFRAME_WAVELENGTH_SOLUTION;
302 if(qc_simlamp_flag) {
303 giframe_arc_lamp_extspectra = GIFRAME_ARC_LAMP_EXTSPECTRA_SIM;
304 giframe_arc_lamp_exterrors = GIFRAME_ARC_LAMP_EXTERRORS_SIM;
305 giframe_arc_lamp_extpixels = GIFRAME_ARC_LAMP_EXTPIXELS_SIM;
306 giframe_arc_lamp_exttrace = GIFRAME_ARC_LAMP_EXTTRACE_SIM;
307 giframe_arc_lamp_rbnspectra = GIFRAME_ARC_LAMP_RBNSPECTRA_SIM;
308 giframe_arc_lamp_rbnerrors = GIFRAME_ARC_LAMP_RBNERRORS_SIM;
309 giframe_line_data = GIFRAME_LINE_DATA_SIM;
310 giframe_wavelength_solution = GIFRAME_WAVELENGTH_SOLUTION_SIM;
316 cpl_msg_error(fctid,
"Invalid parameter list! Aborting ...");
321 cpl_msg_error(fctid,
"Invalid frame set! Aborting ...");
325 p = cpl_parameterlist_find(config,
"giraffe.wcal.rebin");
328 rebin = cpl_parameter_get_bool(p);
331 p = cpl_parameterlist_find(config,
"giraffe.wcal.slitgeometry");
334 slitgeometry = cpl_parameter_get_bool(p);
337 status = giraffe_frameset_set_groups(set, groups);
340 cpl_msg_error(fctid,
"Setting frame group information failed!");
349 cpl_msg_info(fctid,
"Recipe Step : Initialization");
355 narcspectrum = cpl_frameset_count_tags(set, GIFRAME_ARC_SPECTRUM);
357 if (narcspectrum > 1) {
358 cpl_msg_error(fctid,
"Only one arc spectrum frame allowed! "
362 else if (narcspectrum < 1) {
363 cpl_msg_error(fctid,
"Arc spectrum frame is missing! "
368 arcspec_frame = cpl_frameset_find(set, GIFRAME_ARC_SPECTRUM);
369 bpixel_frame = cpl_frameset_find(set, GIFRAME_BADPIXEL_MAP);
372 cpl_msg_info(fctid,
"No bad pixel map present in frame set.");
375 mbias_frame = cpl_frameset_find(set, GIFRAME_BIAS_MASTER);
378 cpl_msg_info(fctid,
"No master bias present in frame set.");
381 mlocy_frame = cpl_frameset_find(set, GIFRAME_PSF_CENTROID);
383 if (mlocy_frame == NULL) {
385 mlocy_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_CENTROID);
387 if (mlocy_frame == NULL) {
388 cpl_msg_info(fctid,
"No master localization (centroid position) "
389 "present in frame set. Aborting ...");
395 mlocw_frame = cpl_frameset_find(set, GIFRAME_PSF_WIDTH);
397 if (mlocw_frame == NULL) {
399 mlocw_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_WIDTH);
401 if (mlocw_frame == NULL) {
402 cpl_msg_info(fctid,
"No master localization (spectrum width) "
403 "present in frame set. Aborting ...");
409 psfdata_frame = cpl_frameset_find(set, GIFRAME_PSF_DATA);
411 if (!psfdata_frame) {
412 cpl_msg_info(fctid,
"No PSF profile parameters present in frame set.");
415 slight_frame = cpl_frameset_find(set, GIFRAME_SCATTERED_LIGHT_MODEL);
418 cpl_msg_info(fctid,
"No scattered light model present in frame set.");
421 grating_frame = cpl_frameset_find(set, GIFRAME_GRATING);
423 if (!grating_frame) {
424 cpl_msg_error(fctid,
"No grating table present in frame set, "
431 if (!slitgeo_frame) {
432 cpl_msg_error(fctid,
"No slit geometry table present in frame "
437 lines_frame = cpl_frameset_find(set, GIFRAME_LINE_CATALOG);
440 cpl_msg_error(fctid,
"No wavelength table present in frame set, "
445 wcal_frame = cpl_frameset_find(set, GIFRAME_WAVELENGTH_SOLUTION);
448 cpl_msg_info(fctid,
"No wavelength solution present in frame set.");
451 scal_frame = cpl_frameset_find(set, GIFRAME_LINE_MASK);
455 if (slitgeometry == TRUE) {
456 cpl_msg_error(fctid,
"No line mask present in frame "
457 "set. Aborting ...");
461 cpl_msg_info(fctid,
"No slit geometry mask present in frame "
478 filename = cpl_frame_get_filename(bpixel_frame);
484 cpl_msg_error(fctid,
"Cannot load bad pixel map from '%s'. "
485 "Aborting ...", filename);
498 filename = cpl_frame_get_filename(arcspec_frame);
504 cpl_msg_error(fctid,
"Cannot load arc spectrum from '%s'. "
505 "Aborting...", filename);
517 cpl_msg_info(fctid,
"Recipe Step : Bias Removal");
525 if (bias_config->method == GIBIAS_METHOD_MASTER ||
526 bias_config->method == GIBIAS_METHOD_ZMASTER) {
529 cpl_msg_error(fctid,
"Missing master bias frame! Selected bias "
530 "removal method requires a master bias "
542 filename = cpl_frame_get_filename(mbias_frame);
548 cpl_msg_error(fctid,
"Cannot load master bias from '%s'. "
549 "Aborting ...", filename);
569 biasareas, bias_config);
583 cpl_msg_error(fctid,
"Bias removal failed. Aborting ...");
595 cpl_msg_info(fctid,
"Recipe Step : Fiber Setup");
597 cpl_msg_info(fctid,
"Building fiber setup for frame '%s'.",
598 cpl_frame_get_filename(arcspec_frame));
603 cpl_msg_error(fctid,
"Cannot create fiber setup for frame '%s'! "
604 "Aborting ...", cpl_frame_get_filename(arcspec_frame));
612 cpl_msg_info(fctid,
"Fiber reference setup taken from localization "
613 "frame '%s'.", cpl_frame_get_filename(mlocy_frame));
620 localization = giraffe_localization_new();
622 filename = cpl_frame_get_filename(mlocy_frame);
629 cpl_msg_error(fctid,
"Cannot load localization (centroid "
630 "position) frame from '%s'. Aborting ...",
633 giraffe_localization_destroy(localization);
643 filename = cpl_frame_get_filename(mlocw_frame);
650 cpl_msg_error(fctid,
"Cannot load localization (spectrum width) "
651 "frame from '%s'. Aborting ...", filename);
653 giraffe_localization_destroy(localization);
667 cpl_msg_info(fctid,
"Recipe Step : Spectrum Extraction");
671 filename = cpl_frame_get_filename(slight_frame);
678 cpl_msg_error(fctid,
"Cannot load scattered light model from "
679 "'%s'. Aborting ...", filename);
684 giraffe_localization_destroy(localization);
695 if ((extract_config->emethod == GIEXTRACT_OPTIMAL) ||
696 (extract_config->emethod == GIEXTRACT_HORNE)) {
698 if (psfdata_frame == NULL) {
700 const cxchar* emethod =
"Optimal";
702 if (extract_config->emethod == GIEXTRACT_HORNE) {
706 cpl_msg_error(fctid,
"%s spectrum extraction requires PSF "
707 "profile data. Aborting ...", emethod);
710 extract_config = NULL;
712 if (slight != NULL) {
717 giraffe_localization_destroy(localization);
729 bsarcspectrum = NULL;
736 filename = cpl_frame_get_filename(psfdata_frame);
739 localization->psf = giraffe_psfdata_new();
740 status = giraffe_psfdata_load(localization->psf, filename);
743 cpl_msg_error(fctid,
"Cannot load PSF profile data frame from "
744 "'%s'. Aborting ...", filename);
747 extract_config = NULL;
749 if (slight != NULL) {
754 giraffe_localization_destroy(localization);
766 bsarcspectrum = NULL;
777 extraction = giraffe_extraction_new();
780 localization, bpixel, slight,
784 cpl_msg_error(fctid,
"Spectrum extraction failed! Aborting ...");
789 giraffe_localization_destroy(localization);
792 giraffe_extraction_destroy(extraction);
804 bsarcspectrum = NULL;
807 extract_config = NULL;
814 cpl_msg_info(fctid,
"Writing extracted spectra ...");
821 giframe_arc_lamp_extspectra,
822 CPL_FRAME_LEVEL_INTERMEDIATE,
825 if (sext_frame == NULL) {
826 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
830 giraffe_localization_destroy(localization);
831 giraffe_extraction_destroy(extraction);
839 cpl_msg_error(fctid,
"Cannot attach fiber setup to local file '%s'! "
840 "Aborting ...", cpl_frame_get_filename(sext_frame));
842 cpl_frame_delete(sext_frame);
846 giraffe_localization_destroy(localization);
847 giraffe_extraction_destroy(extraction);
852 cpl_frameset_insert(set, sext_frame);
859 giframe_arc_lamp_exterrors,
860 CPL_FRAME_LEVEL_INTERMEDIATE,
863 if (sext_frame == NULL) {
864 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
868 giraffe_localization_destroy(localization);
869 giraffe_extraction_destroy(extraction);
877 cpl_msg_error(fctid,
"Cannot attach fiber setup to local file '%s'! "
878 "Aborting ...", cpl_frame_get_filename(sext_frame));
880 cpl_frame_delete(sext_frame);
884 giraffe_localization_destroy(localization);
885 giraffe_extraction_destroy(extraction);
890 cpl_frameset_insert(set, sext_frame);
894 if (extraction->npixels != NULL) {
899 giframe_arc_lamp_extpixels,
900 CPL_FRAME_LEVEL_INTERMEDIATE,
903 if (sext_frame == NULL) {
904 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
908 giraffe_localization_destroy(localization);
909 giraffe_extraction_destroy(extraction);
917 cpl_msg_error(fctid,
"Cannot attach fiber setup to local file '%s'! "
918 "Aborting ...", cpl_frame_get_filename(sext_frame));
920 cpl_frame_delete(sext_frame);
924 giraffe_localization_destroy(localization);
925 giraffe_extraction_destroy(extraction);
930 cpl_frameset_insert(set, sext_frame);
939 giframe_arc_lamp_exttrace,
940 CPL_FRAME_LEVEL_INTERMEDIATE,
943 if (sext_frame == NULL) {
944 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
948 giraffe_localization_destroy(localization);
949 giraffe_extraction_destroy(extraction);
957 cpl_msg_error(fctid,
"Cannot attach fiber setup to local file '%s'! "
958 "Aborting ...", cpl_frame_get_filename(sext_frame));
960 cpl_frame_delete(sext_frame);
964 giraffe_localization_destroy(localization);
965 giraffe_extraction_destroy(extraction);
970 cpl_frameset_insert(set, sext_frame);
974 if (extraction->model != NULL) {
979 GIFRAME_ARC_LAMP_EXTMODEL,
980 CPL_FRAME_LEVEL_FINAL,
983 if (sext_frame == NULL) {
984 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
988 giraffe_localization_destroy(localization);
989 giraffe_extraction_destroy(extraction);
997 cpl_msg_error(fctid,
"Cannot attach fiber setup to local file '%s'! "
998 "Aborting ...", cpl_frame_get_filename(sext_frame));
1000 cpl_frame_delete(sext_frame);
1004 giraffe_localization_destroy(localization);
1005 giraffe_extraction_destroy(extraction);
1010 cpl_frameset_insert(set, sext_frame);
1018 cpl_msg_info(fctid,
"Recipe Step : Wavelength Calibration");
1020 filename = cpl_frame_get_filename(grating_frame);
1027 cpl_msg_error(fctid,
"Cannot load grating table from '%s'. "
1028 "Aborting ...", filename);
1031 giraffe_localization_destroy(localization);
1032 giraffe_extraction_destroy(extraction);
1038 filename = cpl_frame_get_filename(slitgeo_frame);
1042 if (slitgeo == NULL) {
1043 cpl_msg_error(fctid,
"Cannot load slit geometry table from '%s'. "
1044 "Aborting ...", filename);
1047 giraffe_localization_destroy(localization);
1048 giraffe_extraction_destroy(extraction);
1062 cpl_msg_error(fctid,
"Slit geometry data from '%s' is not "
1063 "applicable for current fiber setup! "
1064 "Aborting ...", filename);
1068 giraffe_localization_destroy(localization);
1069 giraffe_extraction_destroy(extraction);
1078 filename = cpl_frame_get_filename(lines_frame);
1085 cpl_msg_error(fctid,
"Cannot load arc-line data from '%s'. "
1086 "Aborting ...", filename);
1089 giraffe_localization_destroy(localization);
1090 giraffe_extraction_destroy(extraction);
1098 if (wcal_frame != NULL) {
1102 filename = cpl_frame_get_filename(wcal_frame);
1106 cpl_msg_error(fctid,
"Cannot load initial wavelength solution "
1107 "from '%s'. Aborting ...", filename);
1112 giraffe_localization_destroy(localization);
1113 giraffe_extraction_destroy(extraction);
1125 if (wcal_config == NULL) {
1127 cpl_msg_error(fctid,
"Could not create wavelength calibration "
1128 "setup: error parsing configuration parameters! "
1131 giraffe_localization_destroy(localization);
1132 giraffe_extraction_destroy(extraction);
1142 wlsolution = giraffe_wcaldata_new();
1145 localization, fibers, slitgeo,
1146 grating, wavelengths, wcal_initial,
1150 cpl_msg_error(fctid,
"Error during wavelength calibration, "
1154 giraffe_localization_destroy(localization);
1155 giraffe_extraction_destroy(extraction);
1161 giraffe_wcaldata_delete(wlsolution);
1172 wcal_initial = NULL;
1188 giframe_wavelength_solution,
1189 CPL_FRAME_LEVEL_FINAL,
1192 if (wcal_frame == NULL) {
1194 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
1197 giraffe_localization_destroy(localization);
1198 giraffe_extraction_destroy(extraction);
1202 giraffe_wcaldata_delete(wlsolution);
1208 cpl_frameset_insert(set, wcal_frame);
1213 creator = (GiFrameCreator)giraffe_linedata_writer;
1216 CPL_FRAME_LEVEL_FINAL,
1217 properties, wlsolution->linedata,
1221 if (ldata_frame == NULL) {
1223 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
1226 giraffe_localization_destroy(localization);
1227 giraffe_extraction_destroy(extraction);
1231 giraffe_wcaldata_delete(wlsolution);
1241 giraffe_linedata_delete(wlsolution->linedata);
1242 wlsolution->linedata = NULL;
1244 cpl_frameset_insert(set, ldata_frame);
1252 if (slitgeometry == TRUE) {
1254 cpl_frame* slit_frame = NULL;
1258 GiTable* mask = NULL;
1259 GiTable* slit = NULL;
1262 cpl_msg_info(fctid,
"Calibrating slit geometry ...");
1267 filename = cpl_frame_get_filename(scal_frame);
1273 cpl_msg_error(fctid,
"Cannot load slit geometry mask from '%s'. "
1274 "Aborting ...", filename);
1280 giraffe_wcaldata_delete(wlsolution);
1282 giraffe_localization_destroy(localization);
1283 giraffe_extraction_destroy(extraction);
1296 wlsolution->coeffs, slitgeo, grating,
1300 cpl_msg_error(fctid,
"Slit geometry calibration failed! "
1308 giraffe_wcaldata_delete(wlsolution);
1310 giraffe_localization_destroy(localization);
1311 giraffe_extraction_destroy(extraction);
1329 slit_frame = giraffe_slitgeometry_save(slit);
1333 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
1340 giraffe_wcaldata_delete(wlsolution);
1342 giraffe_localization_destroy(localization);
1343 giraffe_extraction_destroy(extraction);
1352 cpl_frameset_insert(set, slit_frame);
1372 if (rebin == TRUE) {
1374 cpl_frame* rbin_frame = NULL;
1376 GiRebinConfig* rebin_config;
1379 cpl_msg_info(fctid,
"Recipe Step : Spectrum Rebinning");
1386 localization, grating, slitgeo,
1387 wlsolution->coeffs, rebin_config);
1390 cpl_msg_error(fctid,
"Rebinning of arc-lamp spectra failed! "
1393 giraffe_wcaldata_delete(wlsolution);
1396 giraffe_localization_destroy(localization);
1397 giraffe_extraction_destroy(extraction);
1420 giframe_arc_lamp_rbnspectra,
1421 CPL_FRAME_LEVEL_FINAL,
1424 if (rbin_frame == NULL) {
1426 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
1428 giraffe_wcaldata_delete(wlsolution);
1431 giraffe_localization_destroy(localization);
1432 giraffe_extraction_destroy(extraction);
1445 cpl_msg_error(fctid,
"Cannot attach fiber setup to local "
1446 "file '%s'! Aborting ...",
1447 cpl_frame_get_filename(rbin_frame));
1449 giraffe_wcaldata_delete(wlsolution);
1452 giraffe_localization_destroy(localization);
1453 giraffe_extraction_destroy(extraction);
1459 cpl_frame_delete(rbin_frame);
1465 cpl_frameset_insert(set, rbin_frame);
1472 giframe_arc_lamp_rbnerrors,
1473 CPL_FRAME_LEVEL_FINAL,
1476 if (rbin_frame == NULL) {
1478 cpl_msg_error(fctid,
"Cannot create local file! Aborting ...");
1480 giraffe_wcaldata_delete(wlsolution);
1483 giraffe_localization_destroy(localization);
1484 giraffe_extraction_destroy(extraction);
1498 cpl_msg_error(fctid,
"Cannot attach fiber setup to local "
1499 "file '%s'! Aborting ...",
1500 cpl_frame_get_filename(rbin_frame));
1502 giraffe_wcaldata_delete(wlsolution);
1505 giraffe_localization_destroy(localization);
1506 giraffe_extraction_destroy(extraction);
1512 cpl_frame_delete(rbin_frame);
1518 cpl_frameset_insert(set, rbin_frame);
1530 giraffe_localization_destroy(localization);
1531 localization = NULL;
1533 giraffe_extraction_destroy(extraction);
1536 if (rebinning != NULL) {
1547 giraffe_wcaldata_delete(wlsolution);
1556giqcwavecalibration(cpl_parameterlist* config, cpl_frameset* set)
1559 const cxchar*
const fctid =
"giqcwavecalibration";
1569 cxint nsaturated = 0;
1573 const cxdouble rmsscale = 3.;
1574 const cxdouble saturation = 60000.;
1575 const cxdouble* pixels = NULL;
1576 const cxdouble* xpos = NULL;
1577 const cxdouble* ypos = NULL;
1578 const cxdouble* flux = NULL;
1580 cxdouble efficiency[2] = {0., 0.};
1581 cxdouble wlcenter = 0.;
1585 cxdouble pixel2nm = 1.;
1586 cxdouble fwhm_domain[2] = {0., 100.};
1587 cxdouble* _tdata = NULL;
1588 cxdouble* _tdata_fib3 = NULL;
1590 cpl_propertylist* properties = NULL;
1591 cpl_propertylist* qclog = NULL;
1593 cpl_parameter* p = NULL;
1595 cpl_frame* rframe = NULL;
1596 cpl_frame* pframe = NULL;
1598 const cpl_image* _pimage = NULL;
1599 const cpl_image* _qimage = NULL;
1600 const cpl_image* _rimage = NULL;
1601 const cpl_image* _simage = NULL;
1603 cpl_image* _test = NULL;
1604 cpl_image* _test0 = NULL;
1605 cpl_image* _test1 = NULL;
1607 cpl_image* _test_fib3 = NULL;
1608 cpl_image* _test0_fib3 = NULL;
1609 cpl_image* _test1_fib3 = NULL;
1611 cpl_table* _ptable = NULL;
1613 GiImage* rimage = NULL;
1614 GiImage* pimage = NULL;
1616 GiTable* ptable = NULL;
1618 GiLineData* plines = NULL;
1625 cpl_parameter * simcalp = cpl_parameterlist_find(config,
"giraffe.wcal.qc.simlamp");
1627 cxbool qc_simlamp_flag = FALSE;
1629 if (simcalp != NULL) {
1630 qc_simlamp_flag = cpl_parameter_get_bool(simcalp);
1633 char* giframe_arc_lamp_extspectra = GIFRAME_ARC_LAMP_EXTSPECTRA;
1634 char* giframe_arc_lamp_rbnspectra = GIFRAME_ARC_LAMP_RBNSPECTRA;
1635 char* giframe_line_data = GIFRAME_LINE_DATA;
1636 char* giframe_wavelength_solution = GIFRAME_WAVELENGTH_SOLUTION;
1638 if(qc_simlamp_flag) {
1639 giframe_arc_lamp_extspectra = GIFRAME_ARC_LAMP_EXTSPECTRA_SIM;
1640 giframe_arc_lamp_rbnspectra = GIFRAME_ARC_LAMP_RBNSPECTRA_SIM;
1641 giframe_line_data = GIFRAME_LINE_DATA_SIM;
1642 giframe_wavelength_solution = GIFRAME_WAVELENGTH_SOLUTION_SIM;
1646 cpl_msg_info(fctid,
"Computing QC1 parameters ...");
1655 CPL_FRAME_GROUP_PRODUCT);
1657 if (pframe == NULL) {
1659 cpl_msg_warning(fctid,
"Product '%s' not found.",
1660 giframe_arc_lamp_extspectra);
1662 cpl_msg_warning(fctid,
"Setting lamp efficiencies (%s, %s) to 0.",
1663 GIALIAS_QCLAMP, GIALIAS_QCLAMP_SIMCAL);
1675 cpl_msg_error(fctid,
"Could not load extracted spectra '%s'!",
1676 cpl_frame_get_filename(pframe));
1681 giraffe_paf_delete(qc);
1688 cx_assert(_pimage != NULL);
1696 cpl_msg_error(fctid,
"Could not load extracted spectra fiber setup!");
1704 giraffe_paf_delete(qc);
1711 cx_assert(_ptable != NULL);
1713 if (cpl_table_has_column(_ptable,
"RP") == FALSE) {
1715 cpl_msg_warning(fctid,
"Column 'RP' not found in fiber setup table!");
1716 cpl_msg_warning(fctid,
"Setting lamp efficiencies (%s, %s) to 0.",
1717 GIALIAS_QCLAMP, GIALIAS_QCLAMP_SIMCAL);
1726 cx_assert(properties != NULL);
1728 if (cpl_propertylist_has(properties, GIALIAS_EXPTIME) == FALSE) {
1730 cpl_msg_warning(fctid,
"Property '%s' not found in '%s'.",
1731 GIALIAS_EXPTIME, cpl_frame_get_filename(rframe));
1732 cpl_msg_warning(fctid,
"Setting lamp efficiencies (%s, %s) to 0.",
1733 GIALIAS_QCLAMP, GIALIAS_QCLAMP_SIMCAL);
1742 cxint nb = cpl_image_get_size_y(_pimage);
1743 cxint nf[2] = {0, 0};
1745 cxdouble exptime = cpl_propertylist_get_double(properties,
1747 cxdouble* _sum = NULL;
1749 cpl_image* sum = NULL;
1752 sum = cpl_image_collapse_create(_pimage, 0);
1753 _sum = cpl_image_get_data_double(sum);
1755 for (fiber = 0; fiber < cpl_table_get_nrow(_ptable); ++fiber) {
1757 cxint rp = cpl_table_get_int(_ptable,
"RP", fiber, NULL);
1760 efficiency[1] += _sum[fiber];
1764 efficiency[0] += _sum[fiber];
1772 cpl_image_delete(sum);
1776 cpl_msg_warning(fctid,
"No OzPoz fibers found in the "
1777 "current fiber setup.");
1778 cpl_msg_warning(fctid,
"Setting lamp efficiency (%s) to 0.",
1783 efficiency[0] /= nf[0] * nb * exptime;
1787 cpl_msg_warning(fctid,
"No simultaneous calibration fibers "
1788 "found in the current fiber setup.");
1789 cpl_msg_warning(fctid,
"Setting lamp efficiency (%s) to 0.",
1790 GIALIAS_QCLAMP_SIMCAL);
1794 efficiency[1] /= nf[1] * nb * exptime;
1817 rframe = cpl_frameset_find(set, GIFRAME_ARC_SPECTRUM);
1819 if (rframe == NULL) {
1820 cpl_msg_error(fctid,
"Missing raw frame (%s)", GIFRAME_ARC_SPECTRUM);
1822 giraffe_paf_delete(qc);
1828 cpl_msg_info(fctid,
"Processing reference frame '%s' (%s)",
1829 cpl_frame_get_filename(rframe), cpl_frame_get_tag(rframe));
1836 cpl_msg_error(fctid,
"Could not load arc-lamp spectra '%s'!",
1837 cpl_frame_get_filename(rframe));
1842 giraffe_paf_delete(qc);
1850 cx_assert(_rimage != NULL);
1859 cx_assert(properties != NULL);
1861 if (cpl_propertylist_has(properties, GIALIAS_OVSCX)) {
1863 cxint _ox = cpl_propertylist_get_int(properties, GIALIAS_OVSCX);
1864 cxint _nx = cpl_image_get_size_x(_rimage) - 2 * CX_MAX(0, _ox) - 1;
1866 w.x0 = CX_MAX(0, _ox) + 1;
1871 if (cpl_propertylist_has(properties, GIALIAS_OVSCY)) {
1873 cxint _oy = cpl_propertylist_get_int(properties, GIALIAS_OVSCY);
1874 cxint _ny = cpl_image_get_size_y(_rimage) - 2 * CX_MAX(0, _oy) - 1;
1876 w.y0 = CX_MAX(0, _oy) + 1;
1881 mean = cpl_image_get_mean_window(_rimage, w.x0, w.y0, w.x1, w.y1);
1883 pixels = cpl_image_get_data_const(_rimage);
1884 npixel = cpl_image_get_size_x(_rimage) * cpl_image_get_size_y(_rimage);
1886 for (i = 0; i < npixel; i++) {
1887 if (pixels[i] > saturation) {
1897 qc = giraffe_qclog_open(0);
1900 cpl_msg_error(fctid,
"Cannot create QC1 log!");
1908 qclog = giraffe_paf_get_properties(qc);
1909 cx_assert(qclog != NULL);
1912 CPL_FRAME_GROUP_PRODUCT);
1914 if (pframe == NULL) {
1915 cpl_msg_error(fctid,
"Missing product frame (%s)",
1916 giframe_wavelength_solution);
1918 giraffe_paf_delete(qc);
1927 cpl_msg_info(fctid,
"Processing product frame '%s' (%s)",
1928 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
1935 cpl_msg_error(fctid,
"Could not load dispersion solution '%s'!",
1936 cpl_frame_get_filename(pframe));
1944 giraffe_paf_delete(qc);
1951 cx_assert(properties != NULL);
1966 cpl_propertylist_update_string(qclog,
"PRO.CATG",
1967 cpl_frame_get_tag(pframe));
1968 cpl_propertylist_set_comment(qclog,
"PRO.CATG",
1969 "Pipeline product category");
1972 cx_assert(properties != NULL);
1974 wslnaccept = cpl_propertylist_get_int(properties, GIALIAS_WSOL_NACCEPT);
1979 GIALIAS_WSOL_NLINES);
1981 GIALIAS_WSOL_NACCEPT);
1983 GIALIAS_WSOL_NREJECT);
1991 giraffe_qclog_close(qc);
1999 cxbool rebin = TRUE;
2001 cpl_parameter * rebinp = cpl_parameterlist_find(config,
"giraffe.wcal.rebin");
2003 if (rebinp != NULL) {
2004 rebin = cpl_parameter_get_bool(rebinp);
2009 qc = giraffe_qclog_open(1);
2012 cpl_msg_error(fctid,
"Cannot create QC1 log!");
2016 qclog = giraffe_paf_get_properties(qc);
2017 cx_assert(qclog != NULL);
2020 CPL_FRAME_GROUP_PRODUCT);
2022 if (pframe == NULL) {
2023 cpl_msg_error(fctid,
"Missing product frame (%s)",
2024 giframe_arc_lamp_rbnspectra);
2029 giraffe_paf_delete(qc);
2035 cpl_msg_info(fctid,
"Processing product frame '%s' (%s)",
2036 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
2042 cpl_msg_error(fctid,
"Could not load rebinned arc-lamp spectra '%s'!",
2043 cpl_frame_get_filename(pframe));
2051 giraffe_paf_delete(qc);
2062 cpl_msg_error(fctid,
"Could not load rebinned arc-lamp spectra '%s'!",
2063 cpl_frame_get_filename(pframe));
2074 giraffe_paf_delete(qc);
2081 cx_assert(properties != NULL);
2094 cpl_propertylist_update_string(qclog,
"PRO.CATG",
2095 cpl_frame_get_tag(pframe));
2096 cpl_propertylist_set_comment(qclog,
"PRO.CATG",
2097 "Pipeline product category");
2100 cx_assert(properties != NULL);
2111 cxint binwns = cpl_propertylist_get_int(properties, GIALIAS_BINWNS);
2113 if (binwns != 0 && wslnaccept != 0) {
2114 cpl_propertylist_update_double(properties, GIALIAS_QCNLINACC,
2115 (
double)wslnaccept / binwns);
2118 cpl_propertylist_update_double(properties, GIALIAS_QCNLINACC, 0.);
2122 cpl_propertylist_update_double(properties, GIALIAS_QCMEAN, mean);
2123 cpl_propertylist_set_comment(properties, GIALIAS_QCMEAN,
"Mean level of "
2130 cpl_propertylist_update_int(properties, GIALIAS_QCNSAT, nsaturated);
2131 cpl_propertylist_set_comment(properties, GIALIAS_QCNSAT,
"Number of "
2132 "saturated pixels in the first raw frame");
2142 cpl_propertylist_update_double(properties, GIALIAS_QCLAMP, efficiency[0]);
2143 cpl_propertylist_set_comment(properties, GIALIAS_QCLAMP,
2144 "Calibration lamp efficiency");
2149 cpl_propertylist_update_double(properties, GIALIAS_QCLAMP_SIMCAL,
2151 cpl_propertylist_set_comment(properties, GIALIAS_QCLAMP_SIMCAL,
2152 "SIMCAL lamp efficiency");
2155 GIALIAS_QCLAMP_SIMCAL);
2162 _test = cpl_image_duplicate(_pimage);
2163 _tdata = cpl_image_get_data(_test);
2165 _test_fib3 = cpl_image_duplicate(_pimage);
2166 _tdata_fib3 = cpl_image_get_data(_test_fib3);
2168 nx = cpl_image_get_size_x(_test);
2169 ny = cpl_image_get_size_y(_test);
2171 for (i = 0; i < nx * ny; i++) {
2172 _tdata[i] = _tdata[i] > 0. ? log(_tdata[i]) : 0.;
2173 _tdata_fib3[i] = _tdata_fib3[i] > 0. ? log10(_tdata_fib3[i]) : 0.;
2178 _test0 = cpl_image_extract(_test, 4, 1, 4, ny);
2180 _test1 = cpl_image_collapse_create(_test, 1);
2181 cpl_image_divide_scalar(_test1, nx);
2183 cpl_image_delete(_test);
2187 _test = cpl_image_subtract_create(_test0, _test1);
2189 cpl_image_delete(_test0);
2192 cpl_image_delete(_test1);
2197 _test0_fib3 = cpl_image_extract(_test_fib3, 4, 1, 4, ny);
2200 cx_assert(_ptable != NULL);
2204 if (cpl_table_has_column(_ptable,
"OBJECT") == FALSE) {
2205 cpl_msg_warning(fctid,
2206 "Column 'OBJECT' not found in fiber setup table!");
2207 cpl_msg_warning(fctid,
"CALSIM fibres may be included in QC params");
2210 for (i = 0; i < nx; i++) {
2211 const char *objs = cpl_table_get_string(_ptable,
"OBJECT", i);
2212 if (!strcmp(objs,
"CALSIM")) {
2213 cpl_image_fill_window(_test_fib3, i + 1, 1, i + 1, ny, 0);
2219 _test1_fib3 = cpl_image_collapse_create(_test_fib3, 1);
2220 cpl_image_divide_scalar(_test1_fib3, nfib);
2223 cpl_image_delete(_test_fib3);
2226 _test_fib3 = cpl_image_subtract_create(_test0_fib3, _test1_fib3);
2228 cpl_image_delete(_test0_fib3);
2231 cpl_image_delete(_test1_fib3);
2235 _tdata = cpl_image_get_data(_test);
2239 for (i = 0; i < ny; i++) {
2240 _tdata[i] = exp(_tdata[i]);
2241 rms += pow(_tdata[i], 2.);
2244 rms = sqrt(rms / (ny - 1));
2246 std = cpl_image_get_stdev_window(_test_fib3, 1, 1, 1, (cpl_size) ((1-0.045) * ny));
2248 cpl_image_delete(_test);
2250 cpl_image_delete(_test_fib3);
2253 cpl_propertylist_update_double(properties, GIALIAS_QCRBRMS, rms);
2254 cpl_propertylist_set_comment(properties, GIALIAS_QCRBRMS,
2255 "RMS of rebinned arc-lamp spectra");
2260 cpl_propertylist_update_double(properties, GIALIAS_QCFIB3 , std);
2261 cpl_propertylist_set_comment(properties, GIALIAS_QCFIB3 ,
2262 "STDEV of fibre 3 - mean");
2271 cpl_msg_error(fctid,
"Could not save rebinned arc-lamp spectra "
2272 "'%s'!", cpl_frame_get_filename(pframe));
2283 giraffe_paf_delete(qc);
2293 cpl_msg_error(fctid,
"Could not save rebinned arc-lamp spectra "
2294 "'%s'!", cpl_frame_get_filename(pframe));
2305 giraffe_paf_delete(qc);
2317 giraffe_qclog_close(qc);
2326 qc = giraffe_qclog_open(2);
2329 cpl_msg_error(fctid,
"Cannot create QC1 log!");
2333 qclog = giraffe_paf_get_properties(qc);
2334 cx_assert(qclog != NULL);
2337 CPL_FRAME_GROUP_PRODUCT);
2339 if (pframe == NULL) {
2340 cpl_msg_error(fctid,
"Missing product frame (%s)",
2346 giraffe_paf_delete(qc);
2352 cpl_msg_info(fctid,
"Processing product frame '%s' (%s)",
2353 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
2360 plines = giraffe_linedata_new();
2362 status = giraffe_linedata_load(plines, cpl_frame_get_filename(pframe));
2365 cpl_msg_error(fctid,
"Could not load line data '%s'!",
2366 cpl_frame_get_filename(pframe));
2368 giraffe_linedata_delete(plines);
2374 giraffe_paf_delete(qc);
2381 cx_assert(properties != NULL);
2394 cpl_propertylist_update_string(qclog,
"PRO.CATG",
2395 cpl_frame_get_tag(pframe));
2396 cpl_propertylist_set_comment(qclog,
"PRO.CATG",
2397 "Pipeline product category");
2400 _pimage = giraffe_linedata_get_data(plines,
"FWHM");
2402 if (_pimage == NULL) {
2403 cpl_msg_error(fctid,
"FWHM line data not found!");
2405 giraffe_linedata_delete(plines);
2411 giraffe_paf_delete(qc);
2417 nx = cpl_image_get_size_x(_pimage);
2418 ny = cpl_image_get_size_y(_pimage);
2420 pixels = cpl_image_get_data_const(_pimage);
2422 for (j = 0; j < 2; ++j) {
2424 register cxint ndata = nx * ny;
2430 for (i = 0; i < ndata; ++i) {
2432 if ((pixels[i] >= fwhm_domain[0]) &&
2433 (pixels[i] < fwhm_domain[1])) {
2441 cpl_msg_error(fctid,
"All line FWHM data are invalid!");
2443 giraffe_linedata_delete(plines);
2449 giraffe_paf_delete(qc);
2457 for (i = 0; i < ndata; ++i) {
2459 if ((pixels[i] >= fwhm_domain[0]) &&
2460 (pixels[i] < fwhm_domain[1])) {
2461 rms += pow(pixels[i] - mean, 2.);
2467 rms = sqrt(rms / (npixel - 1));
2470 fwhm_domain[0] = CX_MAX(mean - rmsscale * rms, 0.);
2471 fwhm_domain[1] = CX_MIN(mean + rmsscale * rms, 100.);
2479 double x_total = 0.;
2480 double y_total = 0.;
2481 double flux_total = 0.;
2483 cx_string *slit_name = NULL;
2484 cx_string *grat_name = NULL;
2487 if (qc_simlamp_flag) {
2488 _pimage = giraffe_linedata_get_data(plines,
"Xccd");
2490 if (_pimage == NULL) {
2491 cpl_msg_error(fctid,
"Xccd line data not found!");
2493 giraffe_linedata_delete(plines);
2499 giraffe_paf_delete(qc);
2505 _qimage = giraffe_linedata_get_data(plines,
"Yccd");
2507 if (_qimage == NULL) {
2508 cpl_msg_error(fctid,
"Yccd line data not found!");
2510 giraffe_linedata_delete(plines);
2516 giraffe_paf_delete(qc);
2522 nx = cpl_image_get_size_x(_rimage);
2523 ny = cpl_image_get_size_y(_rimage);
2525 npx = cpl_image_get_size_x(_pimage);
2526 npy = cpl_image_get_size_y(_pimage);
2528 pixels = cpl_image_get_data_const(_rimage);
2529 xpos = cpl_image_get_data_const(_pimage);
2530 ypos = cpl_image_get_data_const(_qimage);
2534 if (cpl_propertylist_has(properties, GIALIAS_PRSCX)) {
2535 prscx = cpl_propertylist_get_int(properties, GIALIAS_PRSCX);
2550 int cmid = floor(cwidth / 2);
2552 for (npxi = 0; npxi < npx; npxi++) {
2553 for (npyi = 0; npyi < npy; npyi++) {
2556 double max_val = 0.;
2558 int pixpos_init = 0;
2566 pixpos_init = (int)floor(ypos[npxi + npyi * npx]) + prscx +
2567 nx * (int)floor(xpos[npxi + npyi * npx]) - cmid;
2569 for (y = 0; y < cwidth; y++) {
2570 pixpos = pixpos_init + y;
2571 if (pixpos >= 0 && pixpos < ny * nx) {
2572 pixval = pixels[pixpos];
2573 if (pixval > max_val) {
2585 for (y = 0; y < cwidth; y++) {
2586 pixpos = pixpos_init + y - (cmid - max_index);
2587 if (pixpos >= 0 && pixpos < ny * nx) {
2588 pixval = pixels[pixpos];
2591 flux_total += pixval;
2595 x_total += xpos[npxi + npyi * npx];
2596 y_total += (int)floor(ypos[npxi + npyi * npx]) + prscx -
2597 (cmid - max_index) - cmid + yy / zz;
2601 x_total = x_total / (npx * npy);
2602 y_total = y_total / (npx * npy);
2603 flux_total = flux_total / (npx * npy) / cwidth;
2605 if (cpl_propertylist_has(properties, GIALIAS_SLITNAME) == FALSE) {
2606 cpl_msg_error(fctid,
2607 "SLit name property '%s' not "
2611 cpl_propertylist_delete(properties);
2614 giraffe_linedata_delete(plines);
2620 giraffe_paf_delete(qc);
2626 slit_name = cx_string_create(
2627 cpl_propertylist_get_string(properties, GIALIAS_SLITNAME));
2629 if (cpl_propertylist_has(properties, GIALIAS_GRATNAME) == FALSE) {
2630 cpl_msg_error(fctid,
2631 "Grating name property '%s' not "
2635 cpl_propertylist_delete(properties);
2638 giraffe_linedata_delete(plines);
2644 giraffe_paf_delete(qc);
2650 grat_name = cx_string_create(
2651 cpl_propertylist_get_string(properties, GIALIAS_GRATNAME));
2653 cx_string_append(slit_name, cx_string_get(grat_name));
2663 y_total = 1003.66 - y_total;
2664 x_total = 1719.13 - x_total;
2666 if (strcmp(cx_string_get(slit_name),
"Medusa1HR") == 0) {
2667 y_total = 1.019 * y_total + 0.016;
2668 x_total = 0.986 * x_total - 0.073;
2669 flux_total = 1.334 * flux_total - 506.565;
2671 else if (strcmp(cx_string_get(slit_name),
"Medusa1LR") == 0) {
2672 y_total = 1.038 * y_total + 3.322;
2673 x_total = 1.194 * x_total + 434.818;
2674 flux_total = 0.243 * flux_total - 121.36;
2676 else if (strcmp(cx_string_get(slit_name),
"Medusa2HR") == 0) {
2677 y_total = 0.989 * y_total - 1.067;
2678 x_total = 1.0 * x_total - 10;
2679 flux_total = 1.397 * flux_total - 465.637;
2681 else if (strcmp(cx_string_get(slit_name),
"IFU1HR") == 0) {
2682 y_total = 0.977 * y_total - 107.426;
2683 x_total = 0.96 * x_total - 4.968;
2684 flux_total = 1.661 * flux_total - 512.41;
2686 else if (strcmp(cx_string_get(slit_name),
"IFU2HR") == 0) {
2687 y_total = 0.956 * y_total - 103.017;
2688 x_total = 0.942 * x_total + 0.22;
2689 flux_total = 0.786 * flux_total - 247.967;
2691 else if (strcmp(cx_string_get(slit_name),
"ArgusHR") == 0) {
2692 y_total = 0.954 * y_total + 152.569;
2693 x_total = 0.928 * x_total - 12.441;
2694 flux_total = 1.219 * flux_total - 329.05;
2698 fctid,
"Slit and grating name '%s' not recognized for SIMLAMP!",
2699 cx_string_get(slit_name));
2701 cpl_propertylist_delete(properties);
2704 giraffe_linedata_delete(plines);
2710 giraffe_paf_delete(qc);
2716 cx_string_delete(slit_name);
2717 cx_string_delete(grat_name);
2720 properties = cpl_propertylist_load_regexp(cpl_frame_get_filename(pframe),
2721 0,
"^COMMENT$", TRUE);
2723 cx_assert(properties != NULL);
2725 if (cpl_propertylist_has(properties, GIALIAS_GRATWLEN) == FALSE) {
2726 cpl_msg_error(fctid,
"Grating central wavelength property '%s' not "
2727 "found!", GIALIAS_GRATWLEN);
2729 cpl_propertylist_delete(properties);
2732 giraffe_linedata_delete(plines);
2738 giraffe_paf_delete(qc);
2744 if (cpl_propertylist_has(properties, GIALIAS_WSOL_SCALE) == FALSE) {
2745 cpl_msg_error(fctid,
"Line data property '%s' not found!",
2746 GIALIAS_WSOL_SCALE);
2748 cpl_propertylist_delete(properties);
2751 giraffe_linedata_delete(plines);
2757 giraffe_paf_delete(qc);
2763 wlcenter = cpl_propertylist_get_double(properties, GIALIAS_GRATWLEN);
2764 pixel2nm = cpl_propertylist_get_double(properties, GIALIAS_WSOL_SCALE);
2774 if (qc_simlamp_flag) {
2775 cpl_propertylist_update_double(properties, GIALIAS_QCSIMCALX, y_total);
2776 cpl_propertylist_set_comment(properties, GIALIAS_QCSIMCALX,
2777 "Average X of SIMCAL lines");
2779 cpl_propertylist_update_double(properties, GIALIAS_QCSIMCALY, x_total);
2780 cpl_propertylist_set_comment(properties, GIALIAS_QCSIMCALY,
2781 "Average Y of SIMCAL lines");
2783 cpl_propertylist_update_double(properties, GIALIAS_QCSIMCALF,
2785 cpl_propertylist_set_comment(properties, GIALIAS_QCSIMCALF,
2786 "Average flux of SIMCAL lines");
2789 cpl_propertylist_update_double(properties, GIALIAS_QCRESOLAVG, mean);
2790 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLAVG,
2791 "Average line FWHM [nm]");
2793 cpl_propertylist_update_double(properties, GIALIAS_QCRESOLRMS, rms);
2794 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLRMS,
2795 "RMS of line FWHM [nm]");
2797 cpl_propertylist_update_int(properties, GIALIAS_QCRESOLTOT, nx * ny);
2798 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLTOT,
2799 "Total number of lines available for FWHM RMS "
2802 cpl_propertylist_update_int(properties, GIALIAS_QCRESOLLIN, npixel);
2803 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLLIN,
2804 "Number of lines used for FWHM RMS "
2807 cpl_propertylist_update_double(properties, GIALIAS_QCRESOLPWR,
2809 cpl_propertylist_set_comment(properties, GIALIAS_QCRESOLPWR,
2813 GIALIAS_QCRESOLAVG);
2815 GIALIAS_QCRESOLRMS);
2817 GIALIAS_QCRESOLTOT);
2819 GIALIAS_QCRESOLLIN);
2821 GIALIAS_QCRESOLPWR);
2824 status = giraffe_linedata_save(plines, properties,
2825 cpl_frame_get_filename(pframe));
2828 cpl_msg_error(fctid,
"Could not save line data "
2829 "'%s'!", cpl_frame_get_filename(pframe));
2831 cpl_propertylist_delete(properties);
2834 giraffe_linedata_delete(plines);
2840 giraffe_paf_delete(qc);
2846 cpl_propertylist_delete(properties);
2849 giraffe_qclog_close(qc);
2858 giraffe_linedata_delete(plines);
2872cpl_plugin_get_info(cpl_pluginlist* list)
2875 cpl_recipe* recipe = cx_calloc(1,
sizeof *recipe);
2876 cpl_plugin* plugin = &recipe->interface;
2878 cpl_plugin_init(plugin,
2880 GIRAFFE_BINARY_VERSION,
2881 CPL_PLUGIN_TYPE_RECIPE,
2882 "giwavecalibration",
2883 "Compute dispersion solution from an arc-lamp spectrum.",
2884 "For detailed information please refer to the "
2885 "GIRAFFE pipeline user manual.\nIt is available at "
2886 "http://www.eso.org/pipelines.",
2890 giwavecalibration_create,
2891 giwavecalibration_exec,
2892 giwavecalibration_destroy);
2894 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.