36 #include <cpl_recipe.h>
37 #include <cpl_plugininfo.h>
38 #include <cpl_parameterlist.h>
39 #include <cpl_frameset.h>
45 #include "gifiberutils.h"
46 #include "gislitgeometry.h"
47 #include "gipsfdata.h"
50 #include "giextract.h"
52 #include "gitransmission.h"
53 #include "girebinning.h"
55 #include "gifxcalibration.h"
56 #include "gimessages.h"
62 static cxint gistandard(cpl_parameterlist* config, cpl_frameset* set);
63 static cxint giqcstandard(cpl_frameset* set);
73 gistandard_create(cpl_plugin* plugin)
76 cpl_recipe* recipe = (cpl_recipe*)plugin;
78 cpl_parameter* p = NULL;
90 recipe->parameters = cpl_parameterlist_new();
91 cx_assert(recipe->parameters != NULL);
114 p = cpl_parameterlist_find(recipe->parameters,
"giraffe.flat.apply");
115 cx_assert(p != NULL);
117 cpl_parameter_set_default_bool(p, FALSE);
123 p = cpl_parameterlist_find(recipe->parameters,
124 "giraffe.rebinning.range");
125 cx_assert(p != NULL);
127 cpl_parameter_set_default_string(p,
"common");
147 gistandard_exec(cpl_plugin* plugin)
152 cpl_recipe* recipe = (cpl_recipe*)plugin;
155 cx_assert(recipe->parameters != NULL);
156 cx_assert(recipe->frames != NULL);
158 status = gistandard(recipe->parameters, recipe->frames);
164 status = giqcstandard(recipe->frames);
176 gistandard_destroy(cpl_plugin* plugin)
179 cpl_recipe* recipe = (cpl_recipe*)plugin;
188 cpl_parameterlist_delete(recipe->parameters);
190 giraffe_error_clear();
202 gistandard(cpl_parameterlist* config, cpl_frameset* set)
205 const cxchar*
const _id =
"gistandard";
208 const cxchar* filename = NULL;
213 cxlong nstandard = 0;
215 cxdouble exptime = 0.;
217 cx_slist* slist = NULL;
219 cpl_propertylist* properties = NULL;
221 cpl_matrix* biasareas = NULL;
223 cpl_frame* standard_frame = NULL;
224 cpl_frame* mbias_frame = NULL;
225 cpl_frame* mdark_frame = NULL;
226 cpl_frame* bpixel_frame = NULL;
227 cpl_frame* slight_frame = NULL;
228 cpl_frame* locy_frame = NULL;
229 cpl_frame* locw_frame = NULL;
230 cpl_frame* flat_frame = NULL;
231 cpl_frame* psfdata_frame = NULL;
232 cpl_frame* grating_frame = NULL;
233 cpl_frame* slit_frame = NULL;
234 cpl_frame* wcal_frame = NULL;
235 cpl_frame* rstandard_frame = NULL;
236 cpl_frame* sext_frame = NULL;
237 cpl_frame* rbin_frame = NULL;
238 cpl_frame* atmext_frame = NULL;
239 cpl_frame* flxstd_frame = NULL;
240 cpl_frame* rsp_frame = NULL;
242 GiImage* mbias = NULL;
243 GiImage* mdark = NULL;
244 GiImage* bpixel = NULL;
245 GiImage* slight = NULL;
246 GiImage* sstandard = NULL;
247 GiImage* rstandard = NULL;
249 GiTable* fibers = NULL;
250 GiTable* slitgeometry = NULL;
251 GiTable* grating = NULL;
252 GiTable* wcalcoeff = NULL;
253 GiTable* atmext = NULL;
254 GiTable* flxstd = NULL;
255 GiTable* refflx = NULL;
257 GiLocalization* localization = NULL;
258 GiExtraction* extraction = NULL;
259 GiRebinning* rebinning = NULL;
260 GiResponse* response = NULL;
262 GiBiasConfig* bias_config = NULL;
263 GiExtractConfig* extract_config = NULL;
264 GiFlatConfig* flat_config = NULL;
265 GiRebinConfig* rebin_config = NULL;
266 GiFxCalibrationConfig* fxcal_config = NULL;
269 GiInstrumentMode mode;
271 GiRecipeInfo info = {(cxchar*)_id, 1, NULL};
273 GiGroupInfo groups[] = {
274 {GIFRAME_STANDARD, CPL_FRAME_GROUP_RAW},
275 {GIFRAME_BADPIXEL_MAP, CPL_FRAME_GROUP_CALIB},
276 {GIFRAME_BIAS_MASTER, CPL_FRAME_GROUP_CALIB},
277 {GIFRAME_DARK_MASTER, CPL_FRAME_GROUP_CALIB},
278 {GIFRAME_FIBER_FLAT_EXTSPECTRA, CPL_FRAME_GROUP_CALIB},
279 {GIFRAME_FIBER_FLAT_EXTERRORS, CPL_FRAME_GROUP_CALIB},
280 {GIFRAME_SCATTERED_LIGHT_MODEL, CPL_FRAME_GROUP_CALIB},
281 {GIFRAME_LOCALIZATION_CENTROID, CPL_FRAME_GROUP_CALIB},
282 {GIFRAME_LOCALIZATION_WIDTH, CPL_FRAME_GROUP_CALIB},
283 {GIFRAME_PSF_CENTROID, CPL_FRAME_GROUP_CALIB},
284 {GIFRAME_PSF_WIDTH, CPL_FRAME_GROUP_CALIB},
285 {GIFRAME_PSF_DATA, CPL_FRAME_GROUP_CALIB},
286 {GIFRAME_WAVELENGTH_SOLUTION, CPL_FRAME_GROUP_CALIB},
287 {GIFRAME_SLITSETUP, CPL_FRAME_GROUP_CALIB},
288 {GIFRAME_SLITMASTER, CPL_FRAME_GROUP_CALIB},
289 {GIFRAME_GRATING, CPL_FRAME_GROUP_CALIB},
290 {GIFRAME_EXTINCTION, CPL_FRAME_GROUP_CALIB},
291 {GIFRAME_FLUX_STANDARDS, CPL_FRAME_GROUP_CALIB},
292 {NULL, CPL_FRAME_GROUP_NONE}
298 cpl_msg_error(_id,
"Invalid parameter list! Aborting ...");
303 cpl_msg_error(_id,
"Invalid frame set! Aborting ...");
307 status = giraffe_frameset_set_groups(set, groups);
310 cpl_msg_error(_id,
"Setting frame group information failed!");
319 nstandard = cpl_frameset_count_tags(set, GIFRAME_STANDARD);
322 cpl_msg_error(_id,
"Too few (%ld) raw frames (%s) present in "
323 "frame set! Aborting ...", nstandard, GIFRAME_STANDARD);
327 locy_frame = cpl_frameset_find(set, GIFRAME_PSF_CENTROID);
329 if (locy_frame == NULL) {
331 locy_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_CENTROID);
333 if (locy_frame == NULL) {
334 cpl_msg_info(_id,
"No master localization (centroid position) "
335 "present in frame set. Aborting ...");
341 locw_frame = cpl_frameset_find(set, GIFRAME_PSF_WIDTH);
343 if (locw_frame == NULL) {
345 locw_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_WIDTH);
347 if (locw_frame == NULL) {
348 cpl_msg_info(_id,
"No master localization (spectrum width) "
349 "present in frame set. Aborting ...");
355 flat_frame = cpl_frameset_find(set, GIFRAME_FIBER_FLAT_EXTSPECTRA);
357 if (flat_frame == NULL) {
359 cpl_msg_error(_id,
"No extracted flat field spectra frame present in frame set. "
365 grating_frame = cpl_frameset_find(set, GIFRAME_GRATING);
367 if (!grating_frame) {
368 cpl_msg_error(_id,
"No grating data present in frame set. "
376 cpl_msg_error(_id,
"No slit geometry present in frame set. "
381 wcal_frame = cpl_frameset_find(set, GIFRAME_WAVELENGTH_SOLUTION);
384 cpl_msg_error(_id,
"No dispersion solution present in frame set. "
389 atmext_frame = cpl_frameset_find(set, GIFRAME_EXTINCTION);
392 cpl_msg_error(_id,
"No atmospheric extinction table present in "
393 "frame set. Aborting ...");
397 flxstd_frame = cpl_frameset_find(set, GIFRAME_FLUX_STANDARDS);
400 cpl_msg_error(_id,
"No flux standards present in frame set. "
405 bpixel_frame = cpl_frameset_find(set, GIFRAME_BADPIXEL_MAP);
408 cpl_msg_info(_id,
"No bad pixel map present in frame set.");
411 mbias_frame = cpl_frameset_find(set, GIFRAME_BIAS_MASTER);
414 cpl_msg_info(_id,
"No master bias present in frame set.");
417 mdark_frame = cpl_frameset_find(set, GIFRAME_DARK_MASTER);
420 cpl_msg_info(_id,
"No master dark present in frame set.");
423 slight_frame = cpl_frameset_find(set, GIFRAME_SCATTERED_LIGHT_MODEL);
426 cpl_msg_info(_id,
"No scattered light model present in frame set.");
429 psfdata_frame = cpl_frameset_find(set, GIFRAME_PSF_DATA);
431 if (!psfdata_frame) {
432 cpl_msg_info(_id,
"No PSF profile parameters present in frame set.");
440 slist = cx_slist_new();
442 standard_frame = cpl_frameset_find(set, GIFRAME_STANDARD);
444 for (i = 0; i < nstandard; i++) {
446 filename = cpl_frame_get_filename(standard_frame);
454 cpl_msg_error(_id,
"Cannot load raw standard frame from '%s'. "
455 "Aborting ...", filename);
462 cx_slist_push_back(slist, raw);
464 standard_frame = cpl_frameset_find(set, NULL);
468 nstandard = (cxint)cx_slist_size(slist);
469 sstandard = cx_slist_pop_front(slist);
472 cx_assert(properties != NULL);
481 cpl_msg_info(_id,
"Averaging standard star observations ...");
483 exptime = cpl_propertylist_get_double(properties, GIALIAS_EXPTIME);
485 for (i = 1; i < nstandard; i++) {
487 cpl_propertylist* _properties;
489 GiImage* standard = cx_slist_pop_front(slist);
496 cx_assert(_properties != NULL);
498 exptime += cpl_propertylist_get_double(_properties,
508 cx_assert(cx_slist_empty(slist));
509 cx_slist_delete(slist);
519 cpl_msg_info(_id,
"Updating stacked standard star image "
522 cpl_propertylist_set_double(properties, GIALIAS_EXPTIME,
523 exptime / nstandard);
525 cpl_propertylist_append_double(properties, GIALIAS_EXPTTOT, exptime);
526 cpl_propertylist_set_comment(properties, GIALIAS_EXPTTOT,
527 "Total exposure time of all frames "
530 cpl_propertylist_append_int(properties, GIALIAS_DATANCOM, nstandard);
531 cpl_propertylist_set_comment(properties, GIALIAS_DATANCOM,
"Number of "
534 cpl_propertylist_erase(properties, GIALIAS_TPLEXPNO);
549 if (bias_config->method == GIBIAS_METHOD_MASTER ||
550 bias_config->method == GIBIAS_METHOD_ZMASTER) {
553 cpl_msg_error(_id,
"Missing master bias frame! Selected bias "
554 "removal method requires a master bias frame!");
562 filename = cpl_frame_get_filename(mbias_frame);
569 cpl_msg_error(_id,
"Cannot load master bias from '%s'. "
570 "Aborting ...", filename);
587 filename = cpl_frame_get_filename(bpixel_frame);
594 cpl_msg_error(_id,
"Cannot load bad pixel map from '%s'. "
595 "Aborting ...", filename);
624 biasareas, bias_config);
636 cpl_msg_error(_id,
"Bias removal failed. Aborting ...");
641 if (bpixel != NULL) {
657 GiDarkConfig dark_config = {GIDARK_METHOD_ZMASTER, 0.};
660 cpl_msg_info(_id,
"Correcting for dark current ...");
662 filename = cpl_frame_get_filename(mdark_frame);
668 cpl_msg_error(_id,
"Cannot load master dark from '%s'. "
669 "Aborting ...", filename);
674 if (bpixel != NULL) {
686 cpl_msg_error(_id,
"Dark subtraction failed! Aborting ...");
694 if (bpixel != NULL) {
713 cpl_msg_info(_id,
"Writing pre-processed standard star image ...");
718 GIFRAME_STANDARD_REDUCED,
719 CPL_FRAME_LEVEL_INTERMEDIATE,
722 if (rstandard_frame == NULL) {
723 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
730 cpl_frameset_insert(set, rstandard_frame);
737 standard_frame = cpl_frameset_find(set, GIFRAME_STANDARD);
739 cpl_msg_info(_id,
"Building fiber setup for frame '%s'.",
740 cpl_frame_get_filename(standard_frame));
745 cpl_msg_error(_id,
"Cannot create fiber setup for frame '%s'! "
746 "Aborting ...", cpl_frame_get_filename(standard_frame));
758 cpl_msg_info(_id,
"Fiber reference setup taken from localization "
759 "frame '%s'.", cpl_frame_get_filename(locy_frame));
766 localization = giraffe_localization_new();
768 filename = cpl_frame_get_filename(locy_frame);
775 cpl_msg_error(_id,
"Cannot load localization (centroid "
776 "position) frame from '%s'. Aborting ...",
779 giraffe_localization_destroy(localization);
793 filename = cpl_frame_get_filename(locw_frame);
800 cpl_msg_error(_id,
"Cannot load localization (spectrum width) "
801 "frame from '%s'. Aborting ...", filename);
803 giraffe_localization_destroy(localization);
823 filename = cpl_frame_get_filename(slight_frame);
830 cpl_msg_error(_id,
"Cannot load scattered light model from '%s'. "
831 "Aborting ...", filename);
835 giraffe_localization_destroy(localization);
854 if ((extract_config->emethod == GIEXTRACT_OPTIMAL) ||
855 (extract_config->emethod == GIEXTRACT_HORNE)) {
857 if (psfdata_frame == NULL) {
859 const cxchar* emethod =
"Optimal";
861 if (extract_config->emethod == GIEXTRACT_HORNE) {
865 cpl_msg_error(_id,
"%s spectrum extraction requires PSF "
866 "profile data. Aborting ...", emethod);
869 extract_config = NULL;
871 if (slight != NULL) {
876 giraffe_localization_destroy(localization);
895 filename = cpl_frame_get_filename(psfdata_frame);
898 localization->psf = giraffe_psfdata_new();
899 status = giraffe_psfdata_load(localization->psf, filename);
902 cpl_msg_error(_id,
"Cannot load PSF profile data frame from "
903 "'%s'. Aborting ...", filename);
906 extract_config = NULL;
908 if (slight != NULL) {
913 giraffe_localization_destroy(localization);
936 extraction = giraffe_extraction_new();
939 localization, bpixel, slight,
943 cpl_msg_error(_id,
"Spectrum extraction failed! Aborting ...");
945 giraffe_extraction_destroy(extraction);
950 giraffe_localization_destroy(localization);
982 filename = cpl_frame_get_filename(flat_frame);
984 cpl_msg_info(_id,
"Loading relative fiber transmission data from '%s'.",
991 giraffe_extraction_destroy(extraction);
992 giraffe_localization_destroy(localization);
997 cpl_msg_error(_id,
"Cannot load relative fiber transmission data "
998 "from '%s'. Aborting ...", filename);
1011 if (flat_config->apply == TRUE) {
1013 const cpl_frame* flat_errors_frame = NULL;
1015 GiImage* flat = NULL;
1016 GiImage* errors = NULL;
1019 filename = cpl_frame_get_filename(flat_frame);
1025 cpl_msg_error(_id,
"Cannot load flat field spectra from '%s'. "
1026 "Aborting ...", filename);
1032 giraffe_extraction_destroy(extraction);
1033 giraffe_localization_destroy(localization);
1043 cpl_frameset_find(set, GIFRAME_FIBER_FLAT_EXTERRORS);
1045 if (flat_errors_frame == NULL) {
1046 cpl_msg_warning(_id,
"Missing flat field spectra errors "
1051 filename = cpl_frame_get_filename(flat_errors_frame);
1057 cpl_msg_error(_id,
"Cannot load flat field spectra "
1058 "errors from '%s'. Aborting ...",
1066 giraffe_extraction_destroy(extraction);
1067 giraffe_localization_destroy(localization);
1077 cpl_msg_info(_id,
"Applying flat field correction ...");
1083 cpl_msg_error(_id,
"Flat field correction failed! "
1091 giraffe_extraction_destroy(extraction);
1092 giraffe_localization_destroy(localization);
1108 if (flat_config->transmission == TRUE) {
1110 cpl_msg_info(_id,
"Applying relative fiber transmission "
1113 status = giraffe_transmission_apply(extraction, fibers);
1117 cpl_msg_error(_id,
"Relative transmission correction failed! "
1123 giraffe_extraction_destroy(extraction);
1124 giraffe_localization_destroy(localization);
1144 cpl_msg_info(_id,
"Writing extracted spectra ...");
1151 GIFRAME_STANDARD_EXTSPECTRA,
1152 CPL_FRAME_LEVEL_FINAL,
1155 if (sext_frame == NULL) {
1156 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1158 giraffe_extraction_destroy(extraction);
1159 giraffe_localization_destroy(localization);
1170 cpl_msg_error(_id,
"Cannot attach fiber setup to local file '%s'! "
1171 "Aborting ...", cpl_frame_get_filename(sext_frame));
1173 cpl_frame_delete(sext_frame);
1175 giraffe_extraction_destroy(extraction);
1176 giraffe_localization_destroy(localization);
1184 cpl_frameset_insert(set, sext_frame);
1191 GIFRAME_STANDARD_EXTERRORS,
1192 CPL_FRAME_LEVEL_FINAL,
1195 if (sext_frame == NULL) {
1196 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1198 giraffe_extraction_destroy(extraction);
1199 giraffe_localization_destroy(localization);
1210 cpl_msg_error(_id,
"Cannot attach fiber setup to local file '%s'! "
1211 "Aborting ...", cpl_frame_get_filename(sext_frame));
1213 cpl_frame_delete(sext_frame);
1215 giraffe_extraction_destroy(extraction);
1216 giraffe_localization_destroy(localization);
1224 cpl_frameset_insert(set, sext_frame);
1228 if (extraction->npixels != NULL) {
1233 GIFRAME_STANDARD_EXTPIXELS,
1234 CPL_FRAME_LEVEL_FINAL,
1237 if (sext_frame == NULL) {
1238 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1240 giraffe_extraction_destroy(extraction);
1241 giraffe_localization_destroy(localization);
1252 cpl_msg_error(_id,
"Cannot attach fiber setup to local file "
1253 "'%s'! Aborting ...",
1254 cpl_frame_get_filename(sext_frame));
1256 cpl_frame_delete(sext_frame);
1258 giraffe_extraction_destroy(extraction);
1259 giraffe_localization_destroy(localization);
1267 cpl_frameset_insert(set, sext_frame);
1276 GIFRAME_STANDARD_EXTTRACE,
1277 CPL_FRAME_LEVEL_FINAL,
1280 if (sext_frame == NULL) {
1281 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1283 giraffe_extraction_destroy(extraction);
1284 giraffe_localization_destroy(localization);
1295 cpl_msg_error(_id,
"Cannot attach fiber setup to local file '%s'! "
1296 "Aborting ...", cpl_frame_get_filename(sext_frame));
1298 cpl_frame_delete(sext_frame);
1300 giraffe_extraction_destroy(extraction);
1301 giraffe_localization_destroy(localization);
1309 cpl_frameset_insert(set, sext_frame);
1313 if (extraction->model != NULL) {
1318 GIFRAME_STANDARD_EXTMODEL,
1319 CPL_FRAME_LEVEL_FINAL,
1322 if (sext_frame == NULL) {
1323 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1325 giraffe_extraction_destroy(extraction);
1326 giraffe_localization_destroy(localization);
1337 cpl_msg_error(_id,
"Cannot attach fiber setup to local file '%s'! "
1338 "Aborting ...", cpl_frame_get_filename(sext_frame));
1340 cpl_frame_delete(sext_frame);
1342 giraffe_extraction_destroy(extraction);
1343 giraffe_localization_destroy(localization);
1351 cpl_frameset_insert(set, sext_frame);
1361 filename = (cxchar *)cpl_frame_get_filename(wcal_frame);
1367 cpl_msg_error(_id,
"Cannot load dispersion solution from "
1368 "'%s'. Aborting ...", filename);
1370 giraffe_extraction_destroy(extraction);
1371 giraffe_localization_destroy(localization);
1386 filename = (cxchar *)cpl_frame_get_filename(grating_frame);
1394 cpl_msg_error(_id,
"Cannot load grating data from '%s'. "
1395 "Aborting ...", filename);
1397 giraffe_extraction_destroy(extraction);
1398 giraffe_localization_destroy(localization);
1414 filename = (cxchar *)cpl_frame_get_filename(slit_frame);
1418 if (slitgeometry == NULL) {
1419 cpl_msg_error(_id,
"Cannot load slit geometry data from '%s'. "
1420 "Aborting ...", filename);
1424 giraffe_extraction_destroy(extraction);
1425 giraffe_localization_destroy(localization);
1443 cpl_msg_error(_id,
"Slit geometry data from '%s' is not "
1444 "applicable for current fiber setup! "
1445 "Aborting ...", filename);
1450 giraffe_extraction_destroy(extraction);
1451 giraffe_localization_destroy(localization);
1468 cpl_msg_info(_id,
"Spectrum rebinning");
1477 localization, grating, slitgeometry,
1478 wcalcoeff, rebin_config);
1481 cpl_msg_error(_id,
"Rebinning of standard spectra failed! "
1486 giraffe_extraction_destroy(extraction);
1487 giraffe_localization_destroy(localization);
1501 giraffe_extraction_destroy(extraction);
1504 giraffe_localization_destroy(localization);
1505 localization = NULL;
1508 rebin_config = NULL;
1520 GIFRAME_STANDARD_RBNSPECTRA,
1521 CPL_FRAME_LEVEL_FINAL,
1524 if (rbin_frame == NULL) {
1525 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1541 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1542 "file '%s'! Aborting ...",
1543 cpl_frame_get_filename(rbin_frame));
1552 cpl_frame_delete(rbin_frame);
1557 cpl_frameset_insert(set, rbin_frame);
1564 GIFRAME_STANDARD_RBNERRORS,
1565 CPL_FRAME_LEVEL_FINAL,
1568 if (rbin_frame == NULL) {
1569 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1585 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1586 "file '%s'! Aborting ...",
1587 cpl_frame_get_filename(rbin_frame));
1597 cpl_frame_delete(rbin_frame);
1602 cpl_frameset_insert(set, rbin_frame);
1613 if (mode == GIMODE_IFU || mode == GIMODE_ARGUS) {
1615 cpl_frame* rimg_frame = NULL;
1617 GiFieldOfView* fov = NULL;
1619 GiFieldOfViewConfig* fov_config = NULL;
1621 GiFieldOfViewCubeFormat cube_format = GIFOV_FORMAT_ESO3D;
1626 cube_format = fov_config->format;
1629 cpl_msg_info(_id,
"Reconstructing image and data cube from rebinned "
1635 slitgeometry, fov_config);
1640 cpl_msg_warning(_id,
"No reconstructed image was built. "
1641 "Fiber list has no fiber position "
1645 cpl_msg_error(_id,
"Image reconstruction failed! Aborting...");
1675 GIFRAME_STANDARD_RCSPECTRA,
1676 CPL_FRAME_LEVEL_FINAL,
1679 if (rimg_frame == NULL) {
1680 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1694 cpl_frameset_insert(set, rimg_frame);
1702 GIFRAME_STANDARD_RCERRORS,
1703 CPL_FRAME_LEVEL_FINAL,
1706 if (rimg_frame == NULL) {
1707 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1721 cpl_frameset_insert(set, rimg_frame);
1726 if (cube_format == GIFOV_FORMAT_SINGLE) {
1730 if (fov->cubes.spectra != NULL) {
1732 cxint component = 0;
1738 properties = cpl_propertylist_duplicate(properties);
1743 CPL_FRAME_LEVEL_FINAL,
1749 cpl_propertylist_delete(properties);
1752 if (rimg_frame == NULL) {
1753 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1765 slitgeometry = NULL;
1779 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1780 "file '%s'! Aborting ...",
1781 cpl_frame_get_filename(rimg_frame));
1783 cpl_frame_delete(rimg_frame);
1795 slitgeometry = NULL;
1806 cpl_frameset_insert(set, rimg_frame);
1812 if (fov->cubes.errors != NULL) {
1814 cxint component = 1;
1820 properties = cpl_propertylist_duplicate(properties);
1825 CPL_FRAME_LEVEL_FINAL,
1831 cpl_propertylist_delete(properties);
1834 if (rimg_frame == NULL) {
1835 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1847 slitgeometry = NULL;
1861 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1862 "file '%s'! Aborting ...",
1863 cpl_frame_get_filename(rimg_frame));
1865 cpl_frame_delete(rimg_frame);
1877 slitgeometry = NULL;
1888 cpl_frameset_insert(set, rimg_frame);
1899 properties = cpl_propertylist_duplicate(properties);
1904 CPL_FRAME_LEVEL_FINAL,
1910 cpl_propertylist_delete(properties);
1913 if (rimg_frame == NULL) {
1914 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1926 slitgeometry = NULL;
1940 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1941 "file '%s'! Aborting ...",
1942 cpl_frame_get_filename(rimg_frame));
1944 cpl_frame_delete(rimg_frame);
1956 slitgeometry = NULL;
1967 cpl_frameset_insert(set, rimg_frame);
1981 cpl_msg_info(_id,
"Computing instrument response function...");
1983 filename = cpl_frame_get_filename(flxstd_frame);
1989 cpl_msg_error(_id,
"Cannot load flux standards catalog from "
1990 "'%s'. Aborting ...", filename);
1999 slitgeometry = NULL;
2016 refflx = giraffe_select_flux_standard(flxstd, rebinning->spectra, 1.);
2018 if (refflx == NULL) {
2019 cpl_msg_error(_id,
"No matching flux standard found in the "
2020 "catalog '%s'! Aborting ...", filename);
2032 slitgeometry = NULL;
2047 filename = cpl_frame_get_filename(atmext_frame);
2053 cpl_msg_error(_id,
"Cannot load atmospheric extinction data from "
2054 "'%s'. Aborting ...", filename);
2066 slitgeometry = NULL;
2078 fxcal_config = giraffe_fxcalibration_config_create(config);
2080 response = giraffe_response_new();
2083 refflx, atmext, fxcal_config);
2087 cpl_msg_error(_id,
"Instrument response computation failed!");
2089 giraffe_response_delete(response);
2093 fxcal_config = NULL;
2108 slitgeometry = NULL;
2121 fxcal_config = NULL;
2137 GIFRAME_INSTRUMENT_RESPONSE,
2138 CPL_FRAME_LEVEL_FINAL,
2141 if (rsp_frame == NULL) {
2143 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
2145 giraffe_response_delete(response);
2155 slitgeometry = NULL;
2167 cpl_frameset_insert(set, rsp_frame);
2177 GIFRAME_EFFICIENCY_CURVE,
2178 CPL_FRAME_LEVEL_FINAL,
2181 if (rsp_frame == NULL) {
2183 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
2185 giraffe_response_delete(response);
2195 slitgeometry = NULL;
2207 cpl_frameset_insert(set, rsp_frame);
2209 giraffe_response_delete(response);
2231 giqcstandard(cpl_frameset* set)
2234 const cxchar*
const fctid =
"giqcstandard";
2237 const cxdouble saturation = 60000.;
2238 const cxdouble wlscale = 0.1;
2244 cxint nsaturated = 0;
2246 const cxdouble* pixels = NULL;
2248 cxdouble wlmin = 0.;
2249 cxdouble wlmax = 0.;
2250 cxdouble efficiency = 0.;
2252 cpl_propertylist* properties = NULL;
2253 cpl_propertylist* _properties = NULL;
2254 cpl_propertylist* qclog = NULL;
2256 cpl_frame* rframe = NULL;
2257 cpl_frame* pframe = NULL;
2259 cpl_image* _rimage = NULL;
2261 cpl_table* _ptable = NULL;
2263 GiImage* rimage = NULL;
2265 GiTable* ptable = NULL;
2270 cpl_msg_info(fctid,
"Computing QC1 parameters ...");
2272 qc = giraffe_qclog_open(0);
2275 cpl_msg_error(fctid,
"Cannot create QC1 log!");
2279 qclog = giraffe_paf_get_properties(qc);
2280 cx_assert(qclog != NULL);
2288 CPL_FRAME_GROUP_PRODUCT);
2290 if (pframe == NULL) {
2291 cpl_msg_error(fctid,
"Missing product frame (%s)",
2292 GIFRAME_EFFICIENCY_CURVE);
2294 giraffe_paf_delete(qc);
2300 cpl_msg_info(fctid,
"Processing product frame '%s' (%s)",
2301 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
2305 "EFFICIENCY_CURVE");
2308 cpl_msg_error(fctid,
"Could not load efficiency table '%s'! "
2309 "Aborting ...", cpl_frame_get_filename(pframe));
2314 giraffe_paf_delete(qc);
2325 rframe = cpl_frameset_find(set, GIFRAME_STANDARD);
2327 if (rframe == NULL) {
2328 cpl_msg_error(fctid,
"Missing raw frame (%s)", GIFRAME_STANDARD);
2333 giraffe_paf_delete(qc);
2343 cpl_msg_error(fctid,
"Could not load standard star observation '%s'!",
2344 cpl_frame_get_filename(rframe));
2352 giraffe_paf_delete(qc);
2360 cx_assert(_rimage != NULL);
2363 cx_assert(properties != NULL);
2368 cpl_propertylist_update_string(qclog,
"PRO.CATG",
2369 cpl_frame_get_tag(pframe));
2370 cpl_propertylist_set_comment(qclog,
"PRO.CATG",
2371 "Pipeline product category");
2378 pixels = cpl_image_get_data(_rimage);
2379 npixel = cpl_image_get_size_x(_rimage) * cpl_image_get_size_y(_rimage);
2383 for (i = 0; i < npixel; i++) {
2384 if (pixels[i] > saturation) {
2401 cx_assert(_ptable != NULL);
2404 cx_assert(properties != NULL);
2406 if (cpl_propertylist_has(properties, GIALIAS_GRATWLEN) == FALSE) {
2411 giraffe_paf_delete(qc);
2414 cpl_msg_error(fctid,
"Missing property '%s'", GIALIAS_GRATWLEN);
2421 cxdouble wlband = 0.;
2422 cxdouble wl0 = cpl_propertylist_get_double(properties,
2426 wlmin = cpl_propertylist_get_double(properties, GIALIAS_BINWLMIN);
2427 wlmax = cpl_propertylist_get_double(properties, GIALIAS_BINWLMAX);
2429 cx_assert((wlmin < wl0) && (wl0 < wlmax));
2431 wlband = wlscale * fabs(wlmax - wlmin);
2433 wlmin = CX_MAX(wlmin, (wl0 - wlband));
2434 wlmax = CX_MIN(wlmax, (wl0 + wlband));
2436 cpl_msg_info(fctid,
"Computing spectrograph efficiency from "
2437 "wavelength range ]%.1f, %.1f[", wlmin, wlmax);
2443 for (i = 0; i < cpl_table_get_nrow(_ptable); ++i) {
2445 cxdouble wavelength = cpl_table_get_double(_ptable,
"WLEN", i, NULL);
2447 if ((wavelength > wlmin) && (wavelength < wlmax)) {
2449 efficiency += cpl_table_get_double(_ptable,
"EFFICIENCY",
2457 efficiency /= (cxdouble)nbin;
2460 cpl_propertylist_update_int(properties, GIALIAS_QCNSAT, nsaturated);
2461 cpl_propertylist_set_comment(properties, GIALIAS_QCNSAT,
"Number of "
2462 "saturated pixels in the first raw frame");
2468 cpl_propertylist_update_double(properties, GIALIAS_QCEFFICIENCY,
2470 cpl_propertylist_set_comment(properties, GIALIAS_QCEFFICIENCY,
2471 "Efficiency of the spectrograph.");
2474 GIALIAS_QCEFFICIENCY);
2477 if (cpl_propertylist_has(properties, GIALIAS_SKY_LEVEL) == TRUE) {
2479 cxdouble mean_sky = cpl_propertylist_get_double(properties,
2482 cpl_propertylist_update_double(properties, GIALIAS_QCSKYLEVEL,
2484 cpl_propertylist_set_comment(properties, GIALIAS_QCSKYLEVEL,
2485 "Mean sky level [ADU]");
2488 GIALIAS_QCSKYLEVEL);
2497 _properties = cpl_propertylist_load_regexp(cpl_frame_get_filename(pframe),
2498 0,
"^COMMENT$", TRUE);
2500 cpl_propertylist_erase_regexp(_properties,
"ESO QC.*", 0);
2502 cpl_image_save(NULL, cpl_frame_get_filename(pframe), CPL_BPP_8_UNSIGNED,
2503 _properties, CPL_IO_CREATE);
2505 cpl_propertylist_delete(_properties);
2513 giraffe_qclog_close(qc);
2527 cpl_plugin_get_info(cpl_pluginlist* list)
2530 cpl_recipe* recipe = cx_calloc(1,
sizeof *recipe);
2531 cpl_plugin* plugin = &recipe->interface;
2534 cpl_plugin_init(plugin,
2536 GIRAFFE_BINARY_VERSION,
2537 CPL_PLUGIN_TYPE_RECIPE,
2539 "Process a spectro-photometric standard star "
2540 "observation and compute the instrument response curve.",
2541 "For detailed information please refer to the "
2542 "GIRAFFE pipeline user manual.\nIt is available at "
2543 "http://www.eso.org/pipelines.",
2549 gistandard_destroy);
2551 cpl_pluginlist_append(list, plugin);
cpl_frame * giraffe_get_slitgeometry(const cpl_frameset *set)
Get the slit geometry frame from a frame set.
cxint giraffe_image_add_info(GiImage *image, const GiRecipeInfo *info, const cpl_frameset *set)
Add additional frame information to an image.
cxint giraffe_table_add_info(GiTable *table, const GiRecipeInfo *info, const cpl_frameset *set)
Add additional frame information to a table.
GiFieldOfView * giraffe_fov_new(void)
Create an empty container for the results of the field of view reconstruction.
GiInstrumentMode giraffe_get_mode(cpl_propertylist *properties)
Determines the instrument mode from a property list.
cpl_frame * giraffe_get_frame(const cpl_frameset *set, const cxchar *tag, cpl_frame_group group)
Get a frame from a frame set.
void giraffe_fov_delete(GiFieldOfView *self)
Deallocate a field of view object and its contents.
cxint giraffe_add_frameset_info(cpl_propertylist *plist, const cpl_frameset *set, cxint sequence)
Add frameset specific information to a property list.
void giraffe_fov_config_add(cpl_parameterlist *list)
Adds parameters for the image and data cube construction.
void giraffe_rebin_config_add(cpl_parameterlist *list)
Adds parameters for the rebinning.
GiFieldOfViewConfig * giraffe_fov_config_create(cpl_parameterlist *list)
Creates a setup structure for the field of view reconstruction.
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.
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.
cpl_table * giraffe_table_get(const GiTable *self)
Get the table data from a Giraffe table.
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_flat_config_add(cpl_parameterlist *list)
Adds parameters for the flat field correction.
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.
void giraffe_table_delete(GiTable *self)
Destroys a Giraffe table.
cxint giraffe_table_attach(GiTable *self, const cxchar *filename, cxint position, const cxchar *id)
Attach a Giraffe table to a file.
GiRebinConfig * giraffe_rebin_config_create(cpl_parameterlist *list)
Creates a setup structure for the rebinning.
GiTable * giraffe_table_new(void)
Creates a new, empty Giraffe table.
cpl_frame * giraffe_frame_create_table(GiTable *table, const cxchar *tag, cpl_frame_level level, cxbool save, cxbool update)
Create a table product frame.
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_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_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_fxcalibration_config_add(cpl_parameterlist *parameters)
Add flux calibration parameters to a parameter list.
cxint giraffe_fiberlist_attach(cpl_frame *frame, GiTable *fibers)
Attach a fiber table to a frame.
GiBiasConfig * giraffe_bias_config_create(cpl_parameterlist *list)
Creates a setup structure for a bias removal task.
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_image_delete(GiImage *self)
Destroys an image.
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_propertylist_copy(cpl_propertylist *self, const cxchar *name, const cpl_propertylist *other, const cxchar *othername)
Copy a property from one list to another.
GiImage * giraffe_image_new(cpl_type type)
Creates an empty image container.
void giraffe_fxcalibration_config_destroy(GiFxCalibrationConfig *self)
Destroy a flux calibration setup structure.
void giraffe_flat_config_destroy(GiFlatConfig *config)
Destroys a flat field setup structure.
GiTable * giraffe_fibers_setup(const cpl_frame *frame, const cpl_frame *reference)
Setup a fiber list.
void giraffe_rebinning_destroy(GiRebinning *rebinning)
Destroys a rebinning results container and its contents.
void giraffe_bias_config_add(cpl_parameterlist *list)
Adds parameters for the bias removal.
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.
GiFlatConfig * giraffe_flat_config_create(cpl_parameterlist *list)
Creates a setup structure for the flat field correction.
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.
const cxchar * giraffe_get_license(void)
Get the pipeline copyright and license.
cpl_image * giraffe_image_get(const GiImage *self)
Gets the image data.
GiRebinning * giraffe_rebinning_new(void)
Create an empty rebinning results container.
cpl_propertylist * giraffe_table_get_properties(const GiTable *self)
Gets the table properties.
cpl_frame * giraffe_frame_create_image(GiImage *image, const cxchar *tag, cpl_frame_level level, cxbool save, cxbool update)
Create an image product frame.
cxint giraffe_fiberlist_compare(const GiTable *fibers, const GiTable *reference)
Compare two fiber lists.
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.
cpl_propertylist * giraffe_image_get_properties(const GiImage *self)
Get the properties of an image.
void giraffe_fov_config_destroy(GiFieldOfViewConfig *config)
Destroys a field of view setup structure.
cxint giraffe_transmission_attach(GiTable *fibers, const cxchar *filename)
Load relative fiber transmission data from a file and add it to a fiber table.