28 #include <cpl_recipe.h>
29 #include <cpl_plugininfo.h>
30 #include <cpl_parameterlist.h>
31 #include <cpl_frameset.h>
37 #include "gifiberutils.h"
38 #include "gislitgeometry.h"
39 #include "gipsfdata.h"
42 #include "giextract.h"
44 #include "gitransmission.h"
45 #include "girebinning.h"
47 #include "gifxcalibration.h"
48 #include "gimessages.h"
54 static cxint gistandard(cpl_parameterlist* config, cpl_frameset* set);
55 static cxint giqcstandard(cpl_frameset* set);
65 gistandard_create(cpl_plugin* plugin)
68 cpl_recipe* recipe = (cpl_recipe*)plugin;
70 cpl_parameter* p = NULL;
82 recipe->parameters = cpl_parameterlist_new();
83 cx_assert(recipe->parameters != NULL);
106 p = cpl_parameterlist_find(recipe->parameters,
"giraffe.flat.apply");
107 cx_assert(p != NULL);
109 cpl_parameter_set_default_bool(p, FALSE);
115 p = cpl_parameterlist_find(recipe->parameters,
116 "giraffe.rebinning.range");
117 cx_assert(p != NULL);
119 cpl_parameter_set_default_string(p,
"common");
139 gistandard_exec(cpl_plugin* plugin)
144 cpl_recipe* recipe = (cpl_recipe*)plugin;
147 cx_assert(recipe->parameters != NULL);
148 cx_assert(recipe->frames != NULL);
150 status = gistandard(recipe->parameters, recipe->frames);
156 status = giqcstandard(recipe->frames);
168 gistandard_destroy(cpl_plugin* plugin)
171 cpl_recipe* recipe = (cpl_recipe*)plugin;
180 cpl_parameterlist_delete(recipe->parameters);
182 giraffe_error_clear();
194 gistandard(cpl_parameterlist* config, cpl_frameset* set)
197 const cxchar*
const _id =
"gistandard";
200 const cxchar* filename = NULL;
205 cxlong nstandard = 0;
207 cxdouble exptime = 0.;
209 cx_slist* slist = NULL;
211 cpl_propertylist* properties = NULL;
213 cpl_matrix* biasareas = NULL;
215 cpl_frame* standard_frame = NULL;
216 cpl_frame* mbias_frame = NULL;
217 cpl_frame* mdark_frame = NULL;
218 cpl_frame* bpixel_frame = NULL;
219 cpl_frame* slight_frame = NULL;
220 cpl_frame* locy_frame = NULL;
221 cpl_frame* locw_frame = NULL;
222 cpl_frame* flat_frame = NULL;
223 cpl_frame* psfdata_frame = NULL;
224 cpl_frame* grating_frame = NULL;
225 cpl_frame* slit_frame = NULL;
226 cpl_frame* wcal_frame = NULL;
227 cpl_frame* rstandard_frame = NULL;
228 cpl_frame* sext_frame = NULL;
229 cpl_frame* rbin_frame = NULL;
230 cpl_frame* atmext_frame = NULL;
231 cpl_frame* flxstd_frame = NULL;
232 cpl_frame* rsp_frame = NULL;
234 GiImage* mbias = NULL;
235 GiImage* mdark = NULL;
236 GiImage* bpixel = NULL;
237 GiImage* slight = NULL;
238 GiImage* sstandard = NULL;
239 GiImage* rstandard = NULL;
241 GiTable* fibers = NULL;
242 GiTable* slitgeometry = NULL;
243 GiTable* grating = NULL;
244 GiTable* wcalcoeff = NULL;
245 GiTable* atmext = NULL;
246 GiTable* flxstd = NULL;
247 GiTable* refflx = NULL;
249 GiLocalization* localization = NULL;
250 GiExtraction* extraction = NULL;
251 GiRebinning* rebinning = NULL;
252 GiResponse* response = NULL;
254 GiBiasConfig* bias_config = NULL;
255 GiExtractConfig* extract_config = NULL;
256 GiFlatConfig* flat_config = NULL;
257 GiRebinConfig* rebin_config = NULL;
258 GiFxCalibrationConfig* fxcal_config = NULL;
261 GiInstrumentMode mode;
263 GiRecipeInfo info = {(cxchar*)_id, 1, NULL, config};
265 GiGroupInfo groups[] = {
266 {GIFRAME_STANDARD, CPL_FRAME_GROUP_RAW},
267 {GIFRAME_BADPIXEL_MAP, CPL_FRAME_GROUP_CALIB},
268 {GIFRAME_BIAS_MASTER, CPL_FRAME_GROUP_CALIB},
269 {GIFRAME_DARK_MASTER, CPL_FRAME_GROUP_CALIB},
270 {GIFRAME_FIBER_FLAT_EXTSPECTRA, CPL_FRAME_GROUP_CALIB},
271 {GIFRAME_FIBER_FLAT_EXTERRORS, CPL_FRAME_GROUP_CALIB},
272 {GIFRAME_SCATTERED_LIGHT_MODEL, CPL_FRAME_GROUP_CALIB},
273 {GIFRAME_LOCALIZATION_CENTROID, CPL_FRAME_GROUP_CALIB},
274 {GIFRAME_LOCALIZATION_WIDTH, CPL_FRAME_GROUP_CALIB},
275 {GIFRAME_PSF_CENTROID, CPL_FRAME_GROUP_CALIB},
276 {GIFRAME_PSF_WIDTH, CPL_FRAME_GROUP_CALIB},
277 {GIFRAME_PSF_DATA, CPL_FRAME_GROUP_CALIB},
278 {GIFRAME_WAVELENGTH_SOLUTION, CPL_FRAME_GROUP_CALIB},
279 {GIFRAME_SLITSETUP, CPL_FRAME_GROUP_CALIB},
280 {GIFRAME_SLITMASTER, CPL_FRAME_GROUP_CALIB},
281 {GIFRAME_GRATING, CPL_FRAME_GROUP_CALIB},
282 {GIFRAME_EXTINCTION, CPL_FRAME_GROUP_CALIB},
283 {GIFRAME_FLUX_STANDARDS, CPL_FRAME_GROUP_CALIB},
284 {NULL, CPL_FRAME_GROUP_NONE}
290 cpl_msg_error(_id,
"Invalid parameter list! Aborting ...");
295 cpl_msg_error(_id,
"Invalid frame set! Aborting ...");
299 status = giraffe_frameset_set_groups(set, groups);
302 cpl_msg_error(_id,
"Setting frame group information failed!");
311 nstandard = cpl_frameset_count_tags(set, GIFRAME_STANDARD);
314 cpl_msg_error(_id,
"Too few (%ld) raw frames (%s) present in "
315 "frame set! Aborting ...", nstandard, GIFRAME_STANDARD);
319 locy_frame = cpl_frameset_find(set, GIFRAME_PSF_CENTROID);
321 if (locy_frame == NULL) {
323 locy_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_CENTROID);
325 if (locy_frame == NULL) {
326 cpl_msg_info(_id,
"No master localization (centroid position) "
327 "present in frame set. Aborting ...");
333 locw_frame = cpl_frameset_find(set, GIFRAME_PSF_WIDTH);
335 if (locw_frame == NULL) {
337 locw_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_WIDTH);
339 if (locw_frame == NULL) {
340 cpl_msg_info(_id,
"No master localization (spectrum width) "
341 "present in frame set. Aborting ...");
347 flat_frame = cpl_frameset_find(set, GIFRAME_FIBER_FLAT_EXTSPECTRA);
349 if (flat_frame == NULL) {
351 cpl_msg_error(_id,
"No extracted flat field spectra frame present in frame set. "
357 grating_frame = cpl_frameset_find(set, GIFRAME_GRATING);
359 if (!grating_frame) {
360 cpl_msg_error(_id,
"No grating data present in frame set. "
368 cpl_msg_error(_id,
"No slit geometry present in frame set. "
373 wcal_frame = cpl_frameset_find(set, GIFRAME_WAVELENGTH_SOLUTION);
376 cpl_msg_error(_id,
"No dispersion solution present in frame set. "
381 atmext_frame = cpl_frameset_find(set, GIFRAME_EXTINCTION);
384 cpl_msg_error(_id,
"No atmospheric extinction table present in "
385 "frame set. Aborting ...");
389 flxstd_frame = cpl_frameset_find(set, GIFRAME_FLUX_STANDARDS);
392 cpl_msg_error(_id,
"No flux standards present in frame set. "
397 bpixel_frame = cpl_frameset_find(set, GIFRAME_BADPIXEL_MAP);
400 cpl_msg_info(_id,
"No bad pixel map present in frame set.");
403 mbias_frame = cpl_frameset_find(set, GIFRAME_BIAS_MASTER);
406 cpl_msg_info(_id,
"No master bias present in frame set.");
409 mdark_frame = cpl_frameset_find(set, GIFRAME_DARK_MASTER);
412 cpl_msg_info(_id,
"No master dark present in frame set.");
415 slight_frame = cpl_frameset_find(set, GIFRAME_SCATTERED_LIGHT_MODEL);
418 cpl_msg_info(_id,
"No scattered light model present in frame set.");
421 psfdata_frame = cpl_frameset_find(set, GIFRAME_PSF_DATA);
423 if (!psfdata_frame) {
424 cpl_msg_info(_id,
"No PSF profile parameters present in frame set.");
432 slist = cx_slist_new();
434 standard_frame = cpl_frameset_find(set, GIFRAME_STANDARD);
436 for (i = 0; i < nstandard; i++) {
438 filename = cpl_frame_get_filename(standard_frame);
446 cpl_msg_error(_id,
"Cannot load raw standard frame from '%s'. "
447 "Aborting ...", filename);
454 cx_slist_push_back(slist, raw);
456 standard_frame = cpl_frameset_find(set, NULL);
460 nstandard = (cxint)cx_slist_size(slist);
461 sstandard = cx_slist_pop_front(slist);
464 cx_assert(properties != NULL);
473 cpl_msg_info(_id,
"Averaging standard star observations ...");
475 exptime = cpl_propertylist_get_double(properties, GIALIAS_EXPTIME);
477 for (i = 1; i < nstandard; i++) {
479 cpl_propertylist* _properties;
481 GiImage* standard = cx_slist_pop_front(slist);
488 cx_assert(_properties != NULL);
490 exptime += cpl_propertylist_get_double(_properties,
500 cx_assert(cx_slist_empty(slist));
501 cx_slist_delete(slist);
511 cpl_msg_info(_id,
"Updating stacked standard star image "
514 cpl_propertylist_set_double(properties, GIALIAS_EXPTIME,
515 exptime / nstandard);
517 cpl_propertylist_append_double(properties, GIALIAS_EXPTTOT, exptime);
518 cpl_propertylist_set_comment(properties, GIALIAS_EXPTTOT,
519 "Total exposure time of all frames "
523 cpl_propertylist_erase(properties, GIALIAS_TPLEXPNO);
527 cpl_propertylist_append_int(properties, GIALIAS_DATANCOM, nstandard);
528 cpl_propertylist_set_comment(properties, GIALIAS_DATANCOM,
"Number of "
542 if (bias_config->method == GIBIAS_METHOD_MASTER ||
543 bias_config->method == GIBIAS_METHOD_ZMASTER) {
546 cpl_msg_error(_id,
"Missing master bias frame! Selected bias "
547 "removal method requires a master bias frame!");
555 filename = cpl_frame_get_filename(mbias_frame);
562 cpl_msg_error(_id,
"Cannot load master bias from '%s'. "
563 "Aborting ...", filename);
580 filename = cpl_frame_get_filename(bpixel_frame);
587 cpl_msg_error(_id,
"Cannot load bad pixel map from '%s'. "
588 "Aborting ...", filename);
617 biasareas, bias_config);
629 cpl_msg_error(_id,
"Bias removal failed. Aborting ...");
634 if (bpixel != NULL) {
650 GiDarkConfig dark_config = {GIDARK_METHOD_ZMASTER, 0.};
653 cpl_msg_info(_id,
"Correcting for dark current ...");
655 filename = cpl_frame_get_filename(mdark_frame);
661 cpl_msg_error(_id,
"Cannot load master dark from '%s'. "
662 "Aborting ...", filename);
667 if (bpixel != NULL) {
679 cpl_msg_error(_id,
"Dark subtraction failed! Aborting ...");
687 if (bpixel != NULL) {
706 cpl_msg_info(_id,
"Writing pre-processed standard star image ...");
711 GIFRAME_STANDARD_REDUCED,
712 CPL_FRAME_LEVEL_INTERMEDIATE,
715 if (rstandard_frame == NULL) {
716 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
723 cpl_frameset_insert(set, rstandard_frame);
730 standard_frame = cpl_frameset_find(set, GIFRAME_STANDARD);
732 cpl_msg_info(_id,
"Building fiber setup for frame '%s'.",
733 cpl_frame_get_filename(standard_frame));
738 cpl_msg_error(_id,
"Cannot create fiber setup for frame '%s'! "
739 "Aborting ...", cpl_frame_get_filename(standard_frame));
751 cpl_msg_info(_id,
"Fiber reference setup taken from localization "
752 "frame '%s'.", cpl_frame_get_filename(locy_frame));
759 localization = giraffe_localization_new();
761 filename = cpl_frame_get_filename(locy_frame);
768 cpl_msg_error(_id,
"Cannot load localization (centroid "
769 "position) frame from '%s'. Aborting ...",
772 giraffe_localization_destroy(localization);
786 filename = cpl_frame_get_filename(locw_frame);
793 cpl_msg_error(_id,
"Cannot load localization (spectrum width) "
794 "frame from '%s'. Aborting ...", filename);
796 giraffe_localization_destroy(localization);
816 filename = cpl_frame_get_filename(slight_frame);
823 cpl_msg_error(_id,
"Cannot load scattered light model from '%s'. "
824 "Aborting ...", filename);
828 giraffe_localization_destroy(localization);
847 if ((extract_config->emethod == GIEXTRACT_OPTIMAL) ||
848 (extract_config->emethod == GIEXTRACT_HORNE)) {
850 if (psfdata_frame == NULL) {
852 const cxchar* emethod =
"Optimal";
854 if (extract_config->emethod == GIEXTRACT_HORNE) {
858 cpl_msg_error(_id,
"%s spectrum extraction requires PSF "
859 "profile data. Aborting ...", emethod);
862 extract_config = NULL;
864 if (slight != NULL) {
869 giraffe_localization_destroy(localization);
888 filename = cpl_frame_get_filename(psfdata_frame);
891 localization->psf = giraffe_psfdata_new();
892 status = giraffe_psfdata_load(localization->psf, filename);
895 cpl_msg_error(_id,
"Cannot load PSF profile data frame from "
896 "'%s'. Aborting ...", filename);
899 extract_config = NULL;
901 if (slight != NULL) {
906 giraffe_localization_destroy(localization);
929 extraction = giraffe_extraction_new();
932 localization, bpixel, slight,
936 cpl_msg_error(_id,
"Spectrum extraction failed! Aborting ...");
938 giraffe_extraction_destroy(extraction);
943 giraffe_localization_destroy(localization);
975 filename = cpl_frame_get_filename(flat_frame);
977 cpl_msg_info(_id,
"Loading relative fiber transmission data from '%s'.",
984 giraffe_extraction_destroy(extraction);
985 giraffe_localization_destroy(localization);
990 cpl_msg_error(_id,
"Cannot load relative fiber transmission data "
991 "from '%s'. Aborting ...", filename);
1004 if (flat_config->apply == TRUE) {
1006 const cpl_frame* flat_errors_frame = NULL;
1008 GiImage* flat = NULL;
1009 GiImage* errors = NULL;
1012 filename = cpl_frame_get_filename(flat_frame);
1018 cpl_msg_error(_id,
"Cannot load flat field spectra from '%s'. "
1019 "Aborting ...", filename);
1025 giraffe_extraction_destroy(extraction);
1026 giraffe_localization_destroy(localization);
1036 cpl_frameset_find(set, GIFRAME_FIBER_FLAT_EXTERRORS);
1038 if (flat_errors_frame == NULL) {
1039 cpl_msg_warning(_id,
"Missing flat field spectra errors "
1044 filename = cpl_frame_get_filename(flat_errors_frame);
1050 cpl_msg_error(_id,
"Cannot load flat field spectra "
1051 "errors from '%s'. Aborting ...",
1059 giraffe_extraction_destroy(extraction);
1060 giraffe_localization_destroy(localization);
1070 cpl_msg_info(_id,
"Applying flat field correction ...");
1076 cpl_msg_error(_id,
"Flat field correction failed! "
1084 giraffe_extraction_destroy(extraction);
1085 giraffe_localization_destroy(localization);
1101 if (flat_config->transmission == TRUE) {
1103 cpl_msg_info(_id,
"Applying relative fiber transmission "
1106 status = giraffe_transmission_apply(extraction, fibers);
1110 cpl_msg_error(_id,
"Relative transmission correction failed! "
1116 giraffe_extraction_destroy(extraction);
1117 giraffe_localization_destroy(localization);
1137 cpl_msg_info(_id,
"Writing extracted spectra ...");
1144 GIFRAME_STANDARD_EXTSPECTRA,
1145 CPL_FRAME_LEVEL_FINAL,
1148 if (sext_frame == NULL) {
1149 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1151 giraffe_extraction_destroy(extraction);
1152 giraffe_localization_destroy(localization);
1163 cpl_msg_error(_id,
"Cannot attach fiber setup to local file '%s'! "
1164 "Aborting ...", cpl_frame_get_filename(sext_frame));
1166 cpl_frame_delete(sext_frame);
1168 giraffe_extraction_destroy(extraction);
1169 giraffe_localization_destroy(localization);
1177 cpl_frameset_insert(set, sext_frame);
1184 GIFRAME_STANDARD_EXTERRORS,
1185 CPL_FRAME_LEVEL_FINAL,
1188 if (sext_frame == NULL) {
1189 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1191 giraffe_extraction_destroy(extraction);
1192 giraffe_localization_destroy(localization);
1203 cpl_msg_error(_id,
"Cannot attach fiber setup to local file '%s'! "
1204 "Aborting ...", cpl_frame_get_filename(sext_frame));
1206 cpl_frame_delete(sext_frame);
1208 giraffe_extraction_destroy(extraction);
1209 giraffe_localization_destroy(localization);
1217 cpl_frameset_insert(set, sext_frame);
1221 if (extraction->npixels != NULL) {
1226 GIFRAME_STANDARD_EXTPIXELS,
1227 CPL_FRAME_LEVEL_FINAL,
1230 if (sext_frame == NULL) {
1231 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1233 giraffe_extraction_destroy(extraction);
1234 giraffe_localization_destroy(localization);
1245 cpl_msg_error(_id,
"Cannot attach fiber setup to local file "
1246 "'%s'! Aborting ...",
1247 cpl_frame_get_filename(sext_frame));
1249 cpl_frame_delete(sext_frame);
1251 giraffe_extraction_destroy(extraction);
1252 giraffe_localization_destroy(localization);
1260 cpl_frameset_insert(set, sext_frame);
1269 GIFRAME_STANDARD_EXTTRACE,
1270 CPL_FRAME_LEVEL_FINAL,
1273 if (sext_frame == NULL) {
1274 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1276 giraffe_extraction_destroy(extraction);
1277 giraffe_localization_destroy(localization);
1288 cpl_msg_error(_id,
"Cannot attach fiber setup to local file '%s'! "
1289 "Aborting ...", cpl_frame_get_filename(sext_frame));
1291 cpl_frame_delete(sext_frame);
1293 giraffe_extraction_destroy(extraction);
1294 giraffe_localization_destroy(localization);
1302 cpl_frameset_insert(set, sext_frame);
1306 if (extraction->model != NULL) {
1311 GIFRAME_STANDARD_EXTMODEL,
1312 CPL_FRAME_LEVEL_FINAL,
1315 if (sext_frame == NULL) {
1316 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1318 giraffe_extraction_destroy(extraction);
1319 giraffe_localization_destroy(localization);
1330 cpl_msg_error(_id,
"Cannot attach fiber setup to local file '%s'! "
1331 "Aborting ...", cpl_frame_get_filename(sext_frame));
1333 cpl_frame_delete(sext_frame);
1335 giraffe_extraction_destroy(extraction);
1336 giraffe_localization_destroy(localization);
1344 cpl_frameset_insert(set, sext_frame);
1354 filename = (cxchar *)cpl_frame_get_filename(wcal_frame);
1360 cpl_msg_error(_id,
"Cannot load dispersion solution from "
1361 "'%s'. Aborting ...", filename);
1363 giraffe_extraction_destroy(extraction);
1364 giraffe_localization_destroy(localization);
1379 filename = (cxchar *)cpl_frame_get_filename(grating_frame);
1387 cpl_msg_error(_id,
"Cannot load grating data from '%s'. "
1388 "Aborting ...", filename);
1390 giraffe_extraction_destroy(extraction);
1391 giraffe_localization_destroy(localization);
1407 filename = (cxchar *)cpl_frame_get_filename(slit_frame);
1411 if (slitgeometry == NULL) {
1412 cpl_msg_error(_id,
"Cannot load slit geometry data from '%s'. "
1413 "Aborting ...", filename);
1417 giraffe_extraction_destroy(extraction);
1418 giraffe_localization_destroy(localization);
1436 cpl_msg_error(_id,
"Slit geometry data from '%s' is not "
1437 "applicable for current fiber setup! "
1438 "Aborting ...", filename);
1443 giraffe_extraction_destroy(extraction);
1444 giraffe_localization_destroy(localization);
1461 cpl_msg_info(_id,
"Spectrum rebinning");
1470 localization, grating, slitgeometry,
1471 wcalcoeff, rebin_config);
1474 cpl_msg_error(_id,
"Rebinning of standard spectra failed! "
1479 giraffe_extraction_destroy(extraction);
1480 giraffe_localization_destroy(localization);
1494 giraffe_extraction_destroy(extraction);
1497 giraffe_localization_destroy(localization);
1498 localization = NULL;
1501 rebin_config = NULL;
1513 GIFRAME_STANDARD_RBNSPECTRA,
1514 CPL_FRAME_LEVEL_FINAL,
1517 if (rbin_frame == NULL) {
1518 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1534 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1535 "file '%s'! Aborting ...",
1536 cpl_frame_get_filename(rbin_frame));
1545 cpl_frame_delete(rbin_frame);
1550 cpl_frameset_insert(set, rbin_frame);
1557 GIFRAME_STANDARD_RBNERRORS,
1558 CPL_FRAME_LEVEL_FINAL,
1561 if (rbin_frame == NULL) {
1562 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1578 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1579 "file '%s'! Aborting ...",
1580 cpl_frame_get_filename(rbin_frame));
1590 cpl_frame_delete(rbin_frame);
1595 cpl_frameset_insert(set, rbin_frame);
1606 if (mode == GIMODE_IFU || mode == GIMODE_ARGUS) {
1608 cpl_frame* rimg_frame = NULL;
1610 GiFieldOfView* fov = NULL;
1612 GiFieldOfViewConfig* fov_config = NULL;
1614 GiFieldOfViewCubeFormat cube_format = GIFOV_FORMAT_ESO3D;
1619 cube_format = fov_config->format;
1622 cpl_msg_info(_id,
"Reconstructing image and data cube from rebinned "
1628 slitgeometry, fov_config);
1633 cpl_msg_warning(_id,
"No reconstructed image was built. "
1634 "Fiber list has no fiber position "
1638 cpl_msg_error(_id,
"Image reconstruction failed! Aborting...");
1668 GIFRAME_STANDARD_RCSPECTRA,
1669 CPL_FRAME_LEVEL_FINAL,
1672 if (rimg_frame == NULL) {
1673 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1687 cpl_frameset_insert(set, rimg_frame);
1695 GIFRAME_STANDARD_RCERRORS,
1696 CPL_FRAME_LEVEL_FINAL,
1699 if (rimg_frame == NULL) {
1700 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1714 cpl_frameset_insert(set, rimg_frame);
1719 if (cube_format == GIFOV_FORMAT_SINGLE) {
1723 if (fov->cubes.spectra != NULL) {
1725 cxint component = 0;
1731 properties = cpl_propertylist_duplicate(properties);
1736 CPL_FRAME_LEVEL_FINAL,
1742 cpl_propertylist_delete(properties);
1745 if (rimg_frame == NULL) {
1746 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1758 slitgeometry = NULL;
1772 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1773 "file '%s'! Aborting ...",
1774 cpl_frame_get_filename(rimg_frame));
1776 cpl_frame_delete(rimg_frame);
1788 slitgeometry = NULL;
1799 cpl_frameset_insert(set, rimg_frame);
1805 if (fov->cubes.errors != NULL) {
1807 cxint component = 1;
1813 properties = cpl_propertylist_duplicate(properties);
1818 CPL_FRAME_LEVEL_FINAL,
1824 cpl_propertylist_delete(properties);
1827 if (rimg_frame == NULL) {
1828 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1840 slitgeometry = NULL;
1854 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1855 "file '%s'! Aborting ...",
1856 cpl_frame_get_filename(rimg_frame));
1858 cpl_frame_delete(rimg_frame);
1870 slitgeometry = NULL;
1881 cpl_frameset_insert(set, rimg_frame);
1892 properties = cpl_propertylist_duplicate(properties);
1897 CPL_FRAME_LEVEL_FINAL,
1903 cpl_propertylist_delete(properties);
1906 if (rimg_frame == NULL) {
1907 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1919 slitgeometry = NULL;
1933 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1934 "file '%s'! Aborting ...",
1935 cpl_frame_get_filename(rimg_frame));
1937 cpl_frame_delete(rimg_frame);
1949 slitgeometry = NULL;
1960 cpl_frameset_insert(set, rimg_frame);
1974 cpl_msg_info(_id,
"Computing instrument response function...");
1976 filename = cpl_frame_get_filename(flxstd_frame);
1981 cpl_msg_info(_id,
"Flux table loaded ...");
1984 cpl_msg_error(_id,
"Cannot load flux standards catalog from "
1985 "'%s'. Aborting ...", filename);
1994 slitgeometry = NULL;
2006 fxcal_config = giraffe_fxcalibration_config_create(config);
2013 refflx = giraffe_select_flux_standard(flxstd, rebinning->spectra, fxcal_config->max_dist);
2016 if (refflx == NULL) {
2017 cpl_msg_error(_id,
"No matching flux standard found in the "
2018 "catalog '%s'! Aborting ...", filename);
2030 slitgeometry = NULL;
2045 filename = cpl_frame_get_filename(atmext_frame);
2051 cpl_msg_error(_id,
"Cannot load atmospheric extinction data from "
2052 "'%s'. Aborting ...", filename);
2064 slitgeometry = NULL;
2075 response = giraffe_response_new();
2078 refflx, atmext, fxcal_config);
2082 cpl_msg_error(_id,
"Instrument response computation failed!");
2084 giraffe_response_delete(response);
2088 fxcal_config = NULL;
2103 slitgeometry = NULL;
2116 fxcal_config = NULL;
2132 GIFRAME_INSTRUMENT_RESPONSE,
2133 CPL_FRAME_LEVEL_FINAL,
2136 if (rsp_frame == NULL) {
2138 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
2140 giraffe_response_delete(response);
2150 slitgeometry = NULL;
2162 cpl_frameset_insert(set, rsp_frame);
2172 GIFRAME_EFFICIENCY_CURVE,
2173 CPL_FRAME_LEVEL_FINAL,
2176 if (rsp_frame == NULL) {
2178 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
2180 giraffe_response_delete(response);
2190 slitgeometry = NULL;
2202 cpl_frameset_insert(set, rsp_frame);
2204 giraffe_response_delete(response);
2226 giqcstandard(cpl_frameset* set)
2229 const cxchar*
const fctid =
"giqcstandard";
2232 const cxdouble saturation = 60000.;
2233 const cxdouble wlscale = 0.1;
2239 cxint nsaturated = 0;
2241 const cxdouble* pixels = NULL;
2243 cxdouble wlmin = 0.;
2244 cxdouble wlmax = 0.;
2245 cxdouble efficiency = 0.;
2247 cpl_propertylist* properties = NULL;
2248 cpl_propertylist* _properties = NULL;
2249 cpl_propertylist* qclog = NULL;
2251 cpl_frame* rframe = NULL;
2252 cpl_frame* pframe = NULL;
2254 cpl_image* _rimage = NULL;
2256 cpl_table* _ptable = NULL;
2258 GiImage* rimage = NULL;
2260 GiTable* ptable = NULL;
2265 cpl_msg_info(fctid,
"Computing QC1 parameters ...");
2267 qc = giraffe_qclog_open(0);
2270 cpl_msg_error(fctid,
"Cannot create QC1 log!");
2274 qclog = giraffe_paf_get_properties(qc);
2275 cx_assert(qclog != NULL);
2283 CPL_FRAME_GROUP_PRODUCT);
2285 if (pframe == NULL) {
2286 cpl_msg_error(fctid,
"Missing product frame (%s)",
2287 GIFRAME_EFFICIENCY_CURVE);
2289 giraffe_paf_delete(qc);
2295 cpl_msg_info(fctid,
"Processing product frame '%s' (%s)",
2296 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
2300 "EFFICIENCY_CURVE");
2303 cpl_msg_error(fctid,
"Could not load efficiency table '%s'! "
2304 "Aborting ...", cpl_frame_get_filename(pframe));
2309 giraffe_paf_delete(qc);
2320 rframe = cpl_frameset_find(set, GIFRAME_STANDARD);
2322 if (rframe == NULL) {
2323 cpl_msg_error(fctid,
"Missing raw frame (%s)", GIFRAME_STANDARD);
2328 giraffe_paf_delete(qc);
2338 cpl_msg_error(fctid,
"Could not load standard star observation '%s'!",
2339 cpl_frame_get_filename(rframe));
2347 giraffe_paf_delete(qc);
2355 cx_assert(_rimage != NULL);
2358 cx_assert(properties != NULL);
2363 cpl_propertylist_update_string(qclog,
"PRO.CATG",
2364 cpl_frame_get_tag(pframe));
2365 cpl_propertylist_set_comment(qclog,
"PRO.CATG",
2366 "Pipeline product category");
2373 pixels = cpl_image_get_data(_rimage);
2374 npixel = cpl_image_get_size_x(_rimage) * cpl_image_get_size_y(_rimage);
2378 for (i = 0; i < npixel; i++) {
2379 if (pixels[i] > saturation) {
2396 cx_assert(_ptable != NULL);
2399 cx_assert(properties != NULL);
2401 if (cpl_propertylist_has(properties, GIALIAS_GRATWLEN) == FALSE) {
2406 giraffe_paf_delete(qc);
2409 cpl_msg_error(fctid,
"Missing property '%s'", GIALIAS_GRATWLEN);
2416 cxdouble wlband = 0.;
2417 cxdouble wl0 = cpl_propertylist_get_double(properties,
2421 wlmin = cpl_propertylist_get_double(properties, GIALIAS_BINWLMIN);
2422 wlmax = cpl_propertylist_get_double(properties, GIALIAS_BINWLMAX);
2424 cx_assert((wlmin < wl0) && (wl0 < wlmax));
2426 wlband = wlscale * fabs(wlmax - wlmin);
2428 wlmin = CX_MAX(wlmin, (wl0 - wlband));
2429 wlmax = CX_MIN(wlmax, (wl0 + wlband));
2431 cpl_msg_info(fctid,
"Computing spectrograph efficiency from "
2432 "wavelength range ]%.1f, %.1f[", wlmin, wlmax);
2438 for (i = 0; i < cpl_table_get_nrow(_ptable); ++i) {
2440 cxdouble wavelength = cpl_table_get_double(_ptable,
"WLEN", i, NULL);
2442 if ((wavelength > wlmin) && (wavelength < wlmax)) {
2444 efficiency += cpl_table_get_double(_ptable,
"EFFICIENCY",
2452 efficiency /= (cxdouble)nbin;
2455 cpl_propertylist_update_int(properties, GIALIAS_QCNSAT, nsaturated);
2456 cpl_propertylist_set_comment(properties, GIALIAS_QCNSAT,
"Number of "
2457 "saturated pixels in the first raw frame");
2463 cpl_propertylist_update_double(properties, GIALIAS_QCEFFICIENCY,
2465 cpl_propertylist_set_comment(properties, GIALIAS_QCEFFICIENCY,
2466 "Efficiency of the spectrograph.");
2469 GIALIAS_QCEFFICIENCY);
2472 if (cpl_propertylist_has(properties, GIALIAS_SKY_LEVEL) == TRUE) {
2474 cxdouble mean_sky = cpl_propertylist_get_double(properties,
2477 cpl_propertylist_update_double(properties, GIALIAS_QCSKYLEVEL,
2479 cpl_propertylist_set_comment(properties, GIALIAS_QCSKYLEVEL,
2480 "Mean sky level [ADU]");
2483 GIALIAS_QCSKYLEVEL);
2492 _properties = cpl_propertylist_load_regexp(cpl_frame_get_filename(pframe),
2493 0,
"^COMMENT$", TRUE);
2495 cpl_propertylist_erase_regexp(_properties,
"ESO QC.*", 0);
2497 cpl_image_save(NULL, cpl_frame_get_filename(pframe), CPL_BPP_8_UNSIGNED,
2498 _properties, CPL_IO_CREATE);
2500 cpl_propertylist_delete(_properties);
2508 giraffe_qclog_close(qc);
2522 cpl_plugin_get_info(cpl_pluginlist* list)
2525 cpl_recipe* recipe = cx_calloc(1,
sizeof *recipe);
2526 cpl_plugin* plugin = &recipe->interface;
2529 cpl_plugin_init(plugin,
2531 GIRAFFE_BINARY_VERSION,
2532 CPL_PLUGIN_TYPE_RECIPE,
2534 "Process a spectro-photometric standard star "
2535 "observation and compute the instrument response curve.",
2536 "For detailed information please refer to the "
2537 "GIRAFFE pipeline user manual.\nIt is available at "
2538 "http://www.eso.org/pipelines.",
2544 gistandard_destroy);
2546 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.
cxint giraffe_subtract_dark(GiImage *image, const GiImage *dark, const GiImage *bpixel, GiDarkResults *data, const GiDarkConfig *config)
Subtract the dark current from a bias corrected image.
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.
GiFlatConfig * giraffe_flat_config_create(cpl_parameterlist *list)
Creates a setup structure for the flat field correction.
void giraffe_flat_config_destroy(GiFlatConfig *config)
Destroys a flat field setup structure.
void giraffe_flat_config_add(cpl_parameterlist *list)
Adds parameters for the flat field correction.
cxint giraffe_flat_apply(GiExtraction *extraction, const GiTable *fibers, const GiImage *flat, const GiImage *errors, GiFlatConfig *config)
Apply the flat field correction to the given extracted spectra.
void giraffe_fov_config_destroy(GiFieldOfViewConfig *config)
Destroys a field of view setup structure.
GiFieldOfView * giraffe_fov_new(void)
Create an empty container for the results of the field of view reconstruction.
GiFieldOfViewConfig * giraffe_fov_config_create(cpl_parameterlist *list)
Creates a setup structure for the field of view reconstruction.
cxint giraffe_fov_save_cubes_eso3d(const GiFieldOfView *self, cpl_propertylist *properties, const cxchar *filename, cxptr data)
Write the cube components of a field-of-view object to a file.
void giraffe_fov_delete(GiFieldOfView *self)
Deallocate a field of view object and its contents.
cxint giraffe_fov_build(GiFieldOfView *result, GiRebinning *rebinning, GiTable *fibers, GiTable *wsolution, GiTable *grating, GiTable *slitgeometry, GiFieldOfViewConfig *config)
Create and image and a data cube from extracted and rebinned spectra.
cxint giraffe_fov_save_cubes(const GiFieldOfView *self, cpl_propertylist *properties, const cxchar *filename, cxptr data)
Write the cube components of a field-of-view object to a file.
void giraffe_fov_config_add(cpl_parameterlist *list)
Adds parameters for the image and data cube construction.
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_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_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.
void giraffe_fxcalibration_config_add(cpl_parameterlist *parameters)
Add flux calibration parameters to a parameter list.
cxint giraffe_calibrate_flux(GiResponse *result, const GiRebinning *spectra, const GiTable *fibers, const GiImage *flat, const GiTable *flux, const GiTable *extinction, const GiFxCalibrationConfig *config)
Compute the response and efficiency curves.
void giraffe_fxcalibration_config_destroy(GiFxCalibrationConfig *self)
Destroy a flux calibration setup structure.
void giraffe_image_delete(GiImage *self)
Destroys an image.
cpl_propertylist * giraffe_image_get_properties(const GiImage *self)
Get the properties of an image.
cxint giraffe_image_add_info(GiImage *image, const GiRecipeInfo *info, const cpl_frameset *set)
Add additional frame information to an image.
cpl_image * giraffe_image_get(const GiImage *self)
Gets the image data.
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.
void giraffe_rebinning_destroy(GiRebinning *rebinning)
Destroys a rebinning results container and its contents.
GiRebinning * giraffe_rebinning_new(void)
Create an empty rebinning results container.
GiRebinConfig * giraffe_rebin_config_create(cpl_parameterlist *list)
Creates a setup structure for the rebinning.
void giraffe_rebin_config_add(cpl_parameterlist *list)
Adds parameters for the rebinning.
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.
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.
cpl_propertylist * giraffe_table_get_properties(const GiTable *self)
Gets the table properties.
GiTable * giraffe_table_new(void)
Creates a new, empty Giraffe table.
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.
cxint giraffe_table_add_info(GiTable *table, const GiRecipeInfo *info, const cpl_frameset *set)
Add additional frame information to a table.
cxint giraffe_transmission_attach(GiTable *fibers, const cxchar *filename)
Load relative fiber transmission data from a file and add it to a fiber table.
cxint giraffe_add_frameset_info(cpl_propertylist *plist, const cpl_frameset *set, cxint sequence)
Add frameset specific information to a property list.
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.
GiInstrumentMode giraffe_get_mode(cpl_propertylist *properties)
Determines the instrument mode from a property list.