27#include <cxmessages.h>
30#include <cpl_recipe.h>
31#include <cpl_plugininfo.h>
32#include <cpl_parameterlist.h>
33#include <cpl_frameset.h>
35#include <cpl_errorstate.h>
40#include "gifiberutils.h"
41#include "gislitgeometry.h"
47#include "gitransmission.h"
48#include "girebinning.h"
50#include "gifxcalibration.h"
51#include "gimessages.h"
57static cxint gistandard(cpl_parameterlist* config, cpl_frameset* set);
58static cxint giqcstandard(cpl_frameset* set);
68gistandard_create(cpl_plugin* plugin)
71 cpl_recipe* recipe = (cpl_recipe*)plugin;
73 cpl_parameter* p = NULL;
85 recipe->parameters = cpl_parameterlist_new();
86 cx_assert(recipe->parameters != NULL);
109 p = cpl_parameterlist_find(recipe->parameters,
"giraffe.flat.apply");
110 cx_assert(p != NULL);
112 cpl_parameter_set_default_bool(p, FALSE);
118 p = cpl_parameterlist_find(recipe->parameters,
119 "giraffe.rebinning.range");
120 cx_assert(p != NULL);
122 cpl_parameter_set_default_string(p,
"common");
142gistandard_exec(cpl_plugin* plugin)
147 cpl_recipe* recipe = (cpl_recipe*)plugin;
150 cx_assert(recipe->parameters != NULL);
151 cx_assert(recipe->frames != NULL);
153 status = gistandard(recipe->parameters, recipe->frames);
159 status = giqcstandard(recipe->frames);
171gistandard_destroy(cpl_plugin* plugin)
174 cpl_recipe* recipe = (cpl_recipe*)plugin;
183 cpl_parameterlist_delete(recipe->parameters);
185 giraffe_error_clear();
197gistandard(cpl_parameterlist* config, cpl_frameset* set)
200 const cxchar*
const _id =
"gistandard";
203 const cxchar* filename = NULL;
208 cxlong nstandard = 0;
210 cxdouble exptime = 0.;
212 cx_slist* slist = NULL;
214 cpl_propertylist* properties = NULL;
216 cpl_matrix* biasareas = NULL;
218 cpl_frame* standard_frame = NULL;
219 cpl_frame* mbias_frame = NULL;
220 cpl_frame* mdark_frame = NULL;
221 cpl_frame* bpixel_frame = NULL;
222 cpl_frame* slight_frame = NULL;
223 cpl_frame* locy_frame = NULL;
224 cpl_frame* locw_frame = NULL;
225 cpl_frame* flat_frame = NULL;
226 cpl_frame* psfdata_frame = NULL;
227 cpl_frame* grating_frame = NULL;
228 cpl_frame* slit_frame = NULL;
229 cpl_frame* wcal_frame = NULL;
230 cpl_frame* rstandard_frame = NULL;
231 cpl_frame* sext_frame = NULL;
232 cpl_frame* rbin_frame = NULL;
233 cpl_frame* atmext_frame = NULL;
234 cpl_frame* flxstd_frame = NULL;
235 cpl_frame* rsp_frame = NULL;
237 GiImage* mbias = NULL;
238 GiImage* mdark = NULL;
239 GiImage* bpixel = NULL;
240 GiImage* slight = NULL;
241 GiImage* sstandard = NULL;
242 GiImage* rstandard = NULL;
244 GiTable* fibers = NULL;
245 GiTable* slitgeometry = NULL;
246 GiTable* grating = NULL;
247 GiTable* wcalcoeff = NULL;
248 GiTable* atmext = NULL;
249 GiTable* flxstd = NULL;
250 GiTable* refflx = NULL;
252 GiLocalization* localization = NULL;
253 GiExtraction* extraction = NULL;
254 GiRebinning* rebinning = NULL;
255 GiResponse* response = NULL;
257 GiBiasConfig* bias_config = NULL;
258 GiExtractConfig* extract_config = NULL;
259 GiFlatConfig* flat_config = NULL;
260 GiRebinConfig* rebin_config = NULL;
261 GiFxCalibrationConfig* fxcal_config = NULL;
264 GiInstrumentMode mode;
266 GiRecipeInfo info = {(cxchar*)_id, 1, NULL, config};
268 GiGroupInfo groups[] = {
269 {GIFRAME_STANDARD, CPL_FRAME_GROUP_RAW},
270 {GIFRAME_BADPIXEL_MAP, CPL_FRAME_GROUP_CALIB},
271 {GIFRAME_BIAS_MASTER, CPL_FRAME_GROUP_CALIB},
272 {GIFRAME_DARK_MASTER, CPL_FRAME_GROUP_CALIB},
273 {GIFRAME_FIBER_FLAT_EXTSPECTRA, CPL_FRAME_GROUP_CALIB},
274 {GIFRAME_FIBER_FLAT_EXTERRORS, CPL_FRAME_GROUP_CALIB},
275 {GIFRAME_SCATTERED_LIGHT_MODEL, CPL_FRAME_GROUP_CALIB},
276 {GIFRAME_LOCALIZATION_CENTROID, CPL_FRAME_GROUP_CALIB},
277 {GIFRAME_LOCALIZATION_WIDTH, CPL_FRAME_GROUP_CALIB},
278 {GIFRAME_PSF_CENTROID, CPL_FRAME_GROUP_CALIB},
279 {GIFRAME_PSF_WIDTH, CPL_FRAME_GROUP_CALIB},
280 {GIFRAME_PSF_DATA, CPL_FRAME_GROUP_CALIB},
281 {GIFRAME_WAVELENGTH_SOLUTION, CPL_FRAME_GROUP_CALIB},
282 {GIFRAME_SLITSETUP, CPL_FRAME_GROUP_CALIB},
283 {GIFRAME_SLITMASTER, CPL_FRAME_GROUP_CALIB},
284 {GIFRAME_GRATING, CPL_FRAME_GROUP_CALIB},
285 {GIFRAME_EXTINCTION, CPL_FRAME_GROUP_CALIB},
286 {GIFRAME_FLUX_STANDARDS, CPL_FRAME_GROUP_CALIB},
287 {NULL, CPL_FRAME_GROUP_NONE}
293 cpl_msg_error(_id,
"Invalid parameter list! Aborting ...");
298 cpl_msg_error(_id,
"Invalid frame set! Aborting ...");
302 status = giraffe_frameset_set_groups(set, groups);
305 cpl_msg_error(_id,
"Setting frame group information failed!");
314 nstandard = cpl_frameset_count_tags(set, GIFRAME_STANDARD);
317 cpl_msg_error(_id,
"Too few (%ld) raw frames (%s) present in "
318 "frame set! Aborting ...", nstandard, GIFRAME_STANDARD);
322 locy_frame = cpl_frameset_find(set, GIFRAME_PSF_CENTROID);
324 if (locy_frame == NULL) {
326 locy_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_CENTROID);
328 if (locy_frame == NULL) {
329 cpl_msg_info(_id,
"No master localization (centroid position) "
330 "present in frame set. Aborting ...");
336 locw_frame = cpl_frameset_find(set, GIFRAME_PSF_WIDTH);
338 if (locw_frame == NULL) {
340 locw_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_WIDTH);
342 if (locw_frame == NULL) {
343 cpl_msg_info(_id,
"No master localization (spectrum width) "
344 "present in frame set. Aborting ...");
350 flat_frame = cpl_frameset_find(set, GIFRAME_FIBER_FLAT_EXTSPECTRA);
352 if (flat_frame == NULL) {
354 cpl_msg_error(_id,
"No extracted flat field spectra frame present in frame set. "
360 grating_frame = cpl_frameset_find(set, GIFRAME_GRATING);
362 if (!grating_frame) {
363 cpl_msg_error(_id,
"No grating data present in frame set. "
371 cpl_msg_error(_id,
"No slit geometry present in frame set. "
376 wcal_frame = cpl_frameset_find(set, GIFRAME_WAVELENGTH_SOLUTION);
379 cpl_msg_error(_id,
"No dispersion solution present in frame set. "
384 atmext_frame = cpl_frameset_find(set, GIFRAME_EXTINCTION);
387 cpl_msg_error(_id,
"No atmospheric extinction table present in "
388 "frame set. Aborting ...");
392 flxstd_frame = cpl_frameset_find(set, GIFRAME_FLUX_STANDARDS);
395 cpl_msg_error(_id,
"No flux standards present in frame set. "
400 bpixel_frame = cpl_frameset_find(set, GIFRAME_BADPIXEL_MAP);
403 cpl_msg_info(_id,
"No bad pixel map present in frame set.");
406 mbias_frame = cpl_frameset_find(set, GIFRAME_BIAS_MASTER);
409 cpl_msg_info(_id,
"No master bias present in frame set.");
412 mdark_frame = cpl_frameset_find(set, GIFRAME_DARK_MASTER);
415 cpl_msg_info(_id,
"No master dark present in frame set.");
418 slight_frame = cpl_frameset_find(set, GIFRAME_SCATTERED_LIGHT_MODEL);
421 cpl_msg_info(_id,
"No scattered light model present in frame set.");
424 psfdata_frame = cpl_frameset_find(set, GIFRAME_PSF_DATA);
426 if (!psfdata_frame) {
427 cpl_msg_info(_id,
"No PSF profile parameters present in frame set.");
435 slist = cx_slist_new();
437 standard_frame = cpl_frameset_find(set, GIFRAME_STANDARD);
439 for (i = 0; i < nstandard; i++) {
441 filename = cpl_frame_get_filename(standard_frame);
449 cpl_msg_error(_id,
"Cannot load raw standard frame from '%s'. "
450 "Aborting ...", filename);
457 cx_slist_push_back(slist, raw);
459 standard_frame = cpl_frameset_find(set, NULL);
463 nstandard = (cxint)cx_slist_size(slist);
464 sstandard = cx_slist_pop_front(slist);
467 cx_assert(properties != NULL);
476 cpl_msg_info(_id,
"Averaging standard star observations ...");
478 exptime = cpl_propertylist_get_double(properties, GIALIAS_EXPTIME);
480 for (i = 1; i < nstandard; i++) {
482 cpl_propertylist* _properties;
484 GiImage* standard = cx_slist_pop_front(slist);
491 cx_assert(_properties != NULL);
493 exptime += cpl_propertylist_get_double(_properties,
503 cx_assert(cx_slist_empty(slist));
504 cx_slist_delete(slist);
514 cpl_msg_info(_id,
"Updating stacked standard star image "
517 cpl_propertylist_set_double(properties, GIALIAS_EXPTIME,
518 exptime / nstandard);
520 cpl_propertylist_append_double(properties, GIALIAS_EXPTTOT, exptime);
521 cpl_propertylist_set_comment(properties, GIALIAS_EXPTTOT,
522 "Total exposure time of all frames "
526 cpl_propertylist_erase(properties, GIALIAS_TPLEXPNO);
530 cpl_propertylist_append_int(properties, GIALIAS_DATANCOM, nstandard);
531 cpl_propertylist_set_comment(properties, GIALIAS_DATANCOM,
"Number of "
545 if (bias_config->method == GIBIAS_METHOD_MASTER ||
546 bias_config->method == GIBIAS_METHOD_ZMASTER) {
549 cpl_msg_error(_id,
"Missing master bias frame! Selected bias "
550 "removal method requires a master bias frame!");
558 filename = cpl_frame_get_filename(mbias_frame);
565 cpl_msg_error(_id,
"Cannot load master bias from '%s'. "
566 "Aborting ...", filename);
583 filename = cpl_frame_get_filename(bpixel_frame);
590 cpl_msg_error(_id,
"Cannot load bad pixel map from '%s'. "
591 "Aborting ...", filename);
620 biasareas, bias_config);
632 cpl_msg_error(_id,
"Bias removal failed. Aborting ...");
637 if (bpixel != NULL) {
653 GiDarkConfig dark_config = {GIDARK_METHOD_ZMASTER, 0.};
656 cpl_msg_info(_id,
"Correcting for dark current ...");
658 filename = cpl_frame_get_filename(mdark_frame);
664 cpl_msg_error(_id,
"Cannot load master dark from '%s'. "
665 "Aborting ...", filename);
670 if (bpixel != NULL) {
682 cpl_msg_error(_id,
"Dark subtraction failed! Aborting ...");
690 if (bpixel != NULL) {
709 cpl_msg_info(_id,
"Writing pre-processed standard star image ...");
714 GIFRAME_STANDARD_REDUCED,
715 CPL_FRAME_LEVEL_INTERMEDIATE,
718 if (rstandard_frame == NULL) {
719 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
726 cpl_frameset_insert(set, rstandard_frame);
733 standard_frame = cpl_frameset_find(set, GIFRAME_STANDARD);
735 cpl_msg_info(_id,
"Building fiber setup for frame '%s'.",
736 cpl_frame_get_filename(standard_frame));
741 cpl_msg_error(_id,
"Cannot create fiber setup for frame '%s'! "
742 "Aborting ...", cpl_frame_get_filename(standard_frame));
754 cpl_msg_info(_id,
"Fiber reference setup taken from localization "
755 "frame '%s'.", cpl_frame_get_filename(locy_frame));
762 localization = giraffe_localization_new();
764 filename = cpl_frame_get_filename(locy_frame);
771 cpl_msg_error(_id,
"Cannot load localization (centroid "
772 "position) frame from '%s'. Aborting ...",
775 giraffe_localization_destroy(localization);
789 filename = cpl_frame_get_filename(locw_frame);
796 cpl_msg_error(_id,
"Cannot load localization (spectrum width) "
797 "frame from '%s'. Aborting ...", filename);
799 giraffe_localization_destroy(localization);
819 filename = cpl_frame_get_filename(slight_frame);
826 cpl_msg_error(_id,
"Cannot load scattered light model from '%s'. "
827 "Aborting ...", filename);
831 giraffe_localization_destroy(localization);
850 if ((extract_config->emethod == GIEXTRACT_OPTIMAL) ||
851 (extract_config->emethod == GIEXTRACT_HORNE)) {
853 if (psfdata_frame == NULL) {
855 const cxchar* emethod =
"Optimal";
857 if (extract_config->emethod == GIEXTRACT_HORNE) {
861 cpl_msg_error(_id,
"%s spectrum extraction requires PSF "
862 "profile data. Aborting ...", emethod);
865 extract_config = NULL;
867 if (slight != NULL) {
872 giraffe_localization_destroy(localization);
891 filename = cpl_frame_get_filename(psfdata_frame);
894 localization->psf = giraffe_psfdata_new();
895 status = giraffe_psfdata_load(localization->psf, filename);
898 cpl_msg_error(_id,
"Cannot load PSF profile data frame from "
899 "'%s'. Aborting ...", filename);
902 extract_config = NULL;
904 if (slight != NULL) {
909 giraffe_localization_destroy(localization);
932 extraction = giraffe_extraction_new();
935 localization, bpixel, slight,
939 cpl_msg_error(_id,
"Spectrum extraction failed! Aborting ...");
941 giraffe_extraction_destroy(extraction);
946 giraffe_localization_destroy(localization);
978 filename = cpl_frame_get_filename(flat_frame);
980 cpl_msg_info(_id,
"Loading relative fiber transmission data from '%s'.",
987 giraffe_extraction_destroy(extraction);
988 giraffe_localization_destroy(localization);
993 cpl_msg_error(_id,
"Cannot load relative fiber transmission data "
994 "from '%s'. Aborting ...", filename);
1007 if (flat_config->apply == TRUE) {
1009 const cpl_frame* flat_errors_frame = NULL;
1011 GiImage* flat = NULL;
1012 GiImage* errors = NULL;
1015 filename = cpl_frame_get_filename(flat_frame);
1021 cpl_msg_error(_id,
"Cannot load flat field spectra from '%s'. "
1022 "Aborting ...", filename);
1028 giraffe_extraction_destroy(extraction);
1029 giraffe_localization_destroy(localization);
1039 cpl_frameset_find(set, GIFRAME_FIBER_FLAT_EXTERRORS);
1041 if (flat_errors_frame == NULL) {
1042 cpl_msg_warning(_id,
"Missing flat field spectra errors "
1047 filename = cpl_frame_get_filename(flat_errors_frame);
1053 cpl_msg_error(_id,
"Cannot load flat field spectra "
1054 "errors from '%s'. Aborting ...",
1062 giraffe_extraction_destroy(extraction);
1063 giraffe_localization_destroy(localization);
1073 cpl_msg_info(_id,
"Applying flat field correction ...");
1079 cpl_msg_error(_id,
"Flat field correction failed! "
1087 giraffe_extraction_destroy(extraction);
1088 giraffe_localization_destroy(localization);
1104 if (flat_config->transmission == TRUE) {
1106 cpl_msg_info(_id,
"Applying relative fiber transmission "
1109 status = giraffe_transmission_apply(extraction, fibers);
1113 cpl_msg_error(_id,
"Relative transmission correction failed! "
1119 giraffe_extraction_destroy(extraction);
1120 giraffe_localization_destroy(localization);
1140 cpl_msg_info(_id,
"Writing extracted spectra ...");
1147 GIFRAME_STANDARD_EXTSPECTRA,
1148 CPL_FRAME_LEVEL_FINAL,
1151 if (sext_frame == NULL) {
1152 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1154 giraffe_extraction_destroy(extraction);
1155 giraffe_localization_destroy(localization);
1166 cpl_msg_error(_id,
"Cannot attach fiber setup to local file '%s'! "
1167 "Aborting ...", cpl_frame_get_filename(sext_frame));
1169 cpl_frame_delete(sext_frame);
1171 giraffe_extraction_destroy(extraction);
1172 giraffe_localization_destroy(localization);
1180 cpl_frameset_insert(set, sext_frame);
1187 GIFRAME_STANDARD_EXTERRORS,
1188 CPL_FRAME_LEVEL_FINAL,
1191 if (sext_frame == NULL) {
1192 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1194 giraffe_extraction_destroy(extraction);
1195 giraffe_localization_destroy(localization);
1206 cpl_msg_error(_id,
"Cannot attach fiber setup to local file '%s'! "
1207 "Aborting ...", cpl_frame_get_filename(sext_frame));
1209 cpl_frame_delete(sext_frame);
1211 giraffe_extraction_destroy(extraction);
1212 giraffe_localization_destroy(localization);
1220 cpl_frameset_insert(set, sext_frame);
1224 if (extraction->npixels != NULL) {
1229 GIFRAME_STANDARD_EXTPIXELS,
1230 CPL_FRAME_LEVEL_FINAL,
1233 if (sext_frame == NULL) {
1234 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1236 giraffe_extraction_destroy(extraction);
1237 giraffe_localization_destroy(localization);
1248 cpl_msg_error(_id,
"Cannot attach fiber setup to local file "
1249 "'%s'! Aborting ...",
1250 cpl_frame_get_filename(sext_frame));
1252 cpl_frame_delete(sext_frame);
1254 giraffe_extraction_destroy(extraction);
1255 giraffe_localization_destroy(localization);
1263 cpl_frameset_insert(set, sext_frame);
1272 GIFRAME_STANDARD_EXTTRACE,
1273 CPL_FRAME_LEVEL_FINAL,
1276 if (sext_frame == NULL) {
1277 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1279 giraffe_extraction_destroy(extraction);
1280 giraffe_localization_destroy(localization);
1291 cpl_msg_error(_id,
"Cannot attach fiber setup to local file '%s'! "
1292 "Aborting ...", cpl_frame_get_filename(sext_frame));
1294 cpl_frame_delete(sext_frame);
1296 giraffe_extraction_destroy(extraction);
1297 giraffe_localization_destroy(localization);
1305 cpl_frameset_insert(set, sext_frame);
1309 if (extraction->model != NULL) {
1314 GIFRAME_STANDARD_EXTMODEL,
1315 CPL_FRAME_LEVEL_FINAL,
1318 if (sext_frame == NULL) {
1319 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1321 giraffe_extraction_destroy(extraction);
1322 giraffe_localization_destroy(localization);
1333 cpl_msg_error(_id,
"Cannot attach fiber setup to local file '%s'! "
1334 "Aborting ...", cpl_frame_get_filename(sext_frame));
1336 cpl_frame_delete(sext_frame);
1338 giraffe_extraction_destroy(extraction);
1339 giraffe_localization_destroy(localization);
1347 cpl_frameset_insert(set, sext_frame);
1357 filename = (cxchar *)cpl_frame_get_filename(wcal_frame);
1363 cpl_msg_error(_id,
"Cannot load dispersion solution from "
1364 "'%s'. Aborting ...", filename);
1366 giraffe_extraction_destroy(extraction);
1367 giraffe_localization_destroy(localization);
1382 filename = (cxchar *)cpl_frame_get_filename(grating_frame);
1390 cpl_msg_error(_id,
"Cannot load grating data from '%s'. "
1391 "Aborting ...", filename);
1393 giraffe_extraction_destroy(extraction);
1394 giraffe_localization_destroy(localization);
1410 filename = (cxchar *)cpl_frame_get_filename(slit_frame);
1414 if (slitgeometry == NULL) {
1415 cpl_msg_error(_id,
"Cannot load slit geometry data from '%s'. "
1416 "Aborting ...", filename);
1420 giraffe_extraction_destroy(extraction);
1421 giraffe_localization_destroy(localization);
1439 cpl_msg_error(_id,
"Slit geometry data from '%s' is not "
1440 "applicable for current fiber setup! "
1441 "Aborting ...", filename);
1446 giraffe_extraction_destroy(extraction);
1447 giraffe_localization_destroy(localization);
1464 cpl_msg_info(_id,
"Spectrum rebinning");
1473 localization, grating, slitgeometry,
1474 wcalcoeff, rebin_config);
1477 cpl_msg_error(_id,
"Rebinning of standard spectra failed! "
1482 giraffe_extraction_destroy(extraction);
1483 giraffe_localization_destroy(localization);
1497 giraffe_extraction_destroy(extraction);
1500 giraffe_localization_destroy(localization);
1501 localization = NULL;
1504 rebin_config = NULL;
1516 GIFRAME_STANDARD_RBNSPECTRA,
1517 CPL_FRAME_LEVEL_FINAL,
1520 if (rbin_frame == NULL) {
1521 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1537 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1538 "file '%s'! Aborting ...",
1539 cpl_frame_get_filename(rbin_frame));
1548 cpl_frame_delete(rbin_frame);
1553 cpl_frameset_insert(set, rbin_frame);
1560 GIFRAME_STANDARD_RBNERRORS,
1561 CPL_FRAME_LEVEL_FINAL,
1564 if (rbin_frame == NULL) {
1565 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1581 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1582 "file '%s'! Aborting ...",
1583 cpl_frame_get_filename(rbin_frame));
1593 cpl_frame_delete(rbin_frame);
1598 cpl_frameset_insert(set, rbin_frame);
1609 if (mode == GIMODE_IFU || mode == GIMODE_ARGUS) {
1611 cpl_frame* rimg_frame = NULL;
1613 GiFieldOfView* fov = NULL;
1615 GiFieldOfViewConfig* fov_config = NULL;
1617 GiFieldOfViewCubeFormat cube_format = GIFOV_FORMAT_ESO3D;
1622 cube_format = fov_config->format;
1625 cpl_msg_info(_id,
"Reconstructing image and data cube from rebinned "
1631 slitgeometry, fov_config);
1636 cpl_msg_warning(_id,
"No reconstructed image was built. "
1637 "Fiber list has no fiber position "
1641 cpl_msg_error(_id,
"Image reconstruction failed! Aborting...");
1665 cpl_errorstate tempes = cpl_errorstate_get();
1667 double fovFlux = 0.0;
1668 double badcolFlux = 0.0;
1669 double meanFlux = 0.0;
1672 int fovnx = cpl_image_get_size_x(fovimage);
1673 int fovny = cpl_image_get_size_y(fovimage);
1675 fovFlux = cpl_image_get_flux(fovimage);
1676 badcolFlux = cpl_image_get_flux_window(fovimage, fovnx- 1, 1, fovnx - 1, fovny);
1678 meanFlux = (fovFlux - badcolFlux) / ((fovnx -1) * fovny);
1683 cpl_propertylist_update_double(fovprop, GIALIAS_QCSIGMEAN, meanFlux);
1684 cpl_propertylist_set_comment(fovprop, GIALIAS_QCSIGMEAN,
"Mean of "
1685 "FOV image without bad row");
1687 cpl_errorstate_set(tempes);
1698 GIFRAME_STANDARD_RCSPECTRA,
1699 CPL_FRAME_LEVEL_FINAL,
1702 if (rimg_frame == NULL) {
1703 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1717 cpl_frameset_insert(set, rimg_frame);
1725 GIFRAME_STANDARD_RCERRORS,
1726 CPL_FRAME_LEVEL_FINAL,
1729 if (rimg_frame == NULL) {
1730 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1744 cpl_frameset_insert(set, rimg_frame);
1749 if (cube_format == GIFOV_FORMAT_SINGLE) {
1753 if (fov->cubes.spectra != NULL) {
1755 cxint component = 0;
1761 properties = cpl_propertylist_duplicate(properties);
1766 CPL_FRAME_LEVEL_FINAL,
1772 cpl_propertylist_delete(properties);
1775 if (rimg_frame == NULL) {
1776 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1788 slitgeometry = NULL;
1802 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1803 "file '%s'! Aborting ...",
1804 cpl_frame_get_filename(rimg_frame));
1806 cpl_frame_delete(rimg_frame);
1818 slitgeometry = NULL;
1829 cpl_frameset_insert(set, rimg_frame);
1835 if (fov->cubes.errors != NULL) {
1837 cxint component = 1;
1843 properties = cpl_propertylist_duplicate(properties);
1848 CPL_FRAME_LEVEL_FINAL,
1854 cpl_propertylist_delete(properties);
1857 if (rimg_frame == NULL) {
1858 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1870 slitgeometry = NULL;
1884 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1885 "file '%s'! Aborting ...",
1886 cpl_frame_get_filename(rimg_frame));
1888 cpl_frame_delete(rimg_frame);
1900 slitgeometry = NULL;
1911 cpl_frameset_insert(set, rimg_frame);
1922 properties = cpl_propertylist_duplicate(properties);
1927 CPL_FRAME_LEVEL_FINAL,
1933 cpl_propertylist_delete(properties);
1936 if (rimg_frame == NULL) {
1937 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1949 slitgeometry = NULL;
1963 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1964 "file '%s'! Aborting ...",
1965 cpl_frame_get_filename(rimg_frame));
1967 cpl_frame_delete(rimg_frame);
1979 slitgeometry = NULL;
1990 cpl_frameset_insert(set, rimg_frame);
2004 cpl_msg_info(_id,
"Computing instrument response function...");
2006 filename = cpl_frame_get_filename(flxstd_frame);
2011 cpl_msg_info(_id,
"Flux table loaded ...");
2014 cpl_msg_error(_id,
"Cannot load flux standards catalog from "
2015 "'%s'. Aborting ...", filename);
2024 slitgeometry = NULL;
2036 fxcal_config = giraffe_fxcalibration_config_create(config);
2043 refflx = giraffe_select_flux_standard(flxstd, rebinning->spectra, fxcal_config->max_dist);
2046 if (refflx == NULL) {
2047 cpl_msg_error(_id,
"No matching flux standard found in the "
2048 "catalog '%s'! Aborting ...", filename);
2060 slitgeometry = NULL;
2075 filename = cpl_frame_get_filename(atmext_frame);
2081 cpl_msg_error(_id,
"Cannot load atmospheric extinction data from "
2082 "'%s'. Aborting ...", filename);
2094 slitgeometry = NULL;
2105 response = giraffe_response_new();
2108 refflx, atmext, fxcal_config);
2112 cpl_msg_error(_id,
"Instrument response computation failed!");
2114 giraffe_response_delete(response);
2118 fxcal_config = NULL;
2133 slitgeometry = NULL;
2146 fxcal_config = NULL;
2162 GIFRAME_INSTRUMENT_RESPONSE,
2163 CPL_FRAME_LEVEL_FINAL,
2166 if (rsp_frame == NULL) {
2168 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
2170 giraffe_response_delete(response);
2180 slitgeometry = NULL;
2192 cpl_frameset_insert(set, rsp_frame);
2202 GIFRAME_EFFICIENCY_CURVE,
2203 CPL_FRAME_LEVEL_FINAL,
2206 if (rsp_frame == NULL) {
2208 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
2210 giraffe_response_delete(response);
2220 slitgeometry = NULL;
2232 cpl_frameset_insert(set, rsp_frame);
2234 giraffe_response_delete(response);
2256giqcstandard(cpl_frameset* set)
2259 const cxchar*
const fctid =
"giqcstandard";
2262 const cxdouble saturation = 60000.;
2263 const cxdouble wlscale = 0.1;
2269 cxint nsaturated = 0;
2271 const cxdouble* pixels = NULL;
2273 cxdouble wlmin = 0.;
2274 cxdouble wlmax = 0.;
2275 cxdouble efficiency = 0.;
2277 cpl_propertylist* properties = NULL;
2278 cpl_propertylist* _properties = NULL;
2279 cpl_propertylist* qclog = NULL;
2281 cpl_frame* rframe = NULL;
2282 cpl_frame* pframe = NULL;
2284 cpl_image* _rimage = NULL;
2286 cpl_table* _ptable = NULL;
2288 GiImage* rimage = NULL;
2290 GiTable* ptable = NULL;
2295 cpl_msg_info(fctid,
"Computing QC1 parameters ...");
2297 qc = giraffe_qclog_open(0);
2300 cpl_msg_error(fctid,
"Cannot create QC1 log!");
2304 qclog = giraffe_paf_get_properties(qc);
2305 cx_assert(qclog != NULL);
2313 CPL_FRAME_GROUP_PRODUCT);
2315 if (pframe == NULL) {
2316 cpl_msg_error(fctid,
"Missing product frame (%s)",
2317 GIFRAME_EFFICIENCY_CURVE);
2319 giraffe_paf_delete(qc);
2325 cpl_msg_info(fctid,
"Processing product frame '%s' (%s)",
2326 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
2330 "EFFICIENCY_CURVE");
2333 cpl_msg_error(fctid,
"Could not load efficiency table '%s'! "
2334 "Aborting ...", cpl_frame_get_filename(pframe));
2339 giraffe_paf_delete(qc);
2350 rframe = cpl_frameset_find(set, GIFRAME_STANDARD);
2352 if (rframe == NULL) {
2353 cpl_msg_error(fctid,
"Missing raw frame (%s)", GIFRAME_STANDARD);
2358 giraffe_paf_delete(qc);
2368 cpl_msg_error(fctid,
"Could not load standard star observation '%s'!",
2369 cpl_frame_get_filename(rframe));
2377 giraffe_paf_delete(qc);
2385 cx_assert(_rimage != NULL);
2388 cx_assert(properties != NULL);
2393 cpl_propertylist_update_string(qclog,
"PRO.CATG",
2394 cpl_frame_get_tag(pframe));
2395 cpl_propertylist_set_comment(qclog,
"PRO.CATG",
2396 "Pipeline product category");
2403 pixels = cpl_image_get_data(_rimage);
2404 npixel = cpl_image_get_size_x(_rimage) * cpl_image_get_size_y(_rimage);
2408 for (i = 0; i < npixel; i++) {
2409 if (pixels[i] > saturation) {
2426 cx_assert(_ptable != NULL);
2429 cx_assert(properties != NULL);
2431 if (cpl_propertylist_has(properties, GIALIAS_GRATWLEN) == FALSE) {
2436 giraffe_paf_delete(qc);
2439 cpl_msg_error(fctid,
"Missing property '%s'", GIALIAS_GRATWLEN);
2446 cxdouble wlband = 0.;
2447 cxdouble wl0 = cpl_propertylist_get_double(properties,
2451 wlmin = cpl_propertylist_get_double(properties, GIALIAS_BINWLMIN);
2452 wlmax = cpl_propertylist_get_double(properties, GIALIAS_BINWLMAX);
2454 cx_assert((wlmin < wl0) && (wl0 < wlmax));
2456 wlband = wlscale * fabs(wlmax - wlmin);
2458 wlmin = CX_MAX(wlmin, (wl0 - wlband));
2459 wlmax = CX_MIN(wlmax, (wl0 + wlband));
2461 cpl_msg_info(fctid,
"Computing spectrograph efficiency from "
2462 "wavelength range ]%.1f, %.1f[", wlmin, wlmax);
2468 for (i = 0; i < cpl_table_get_nrow(_ptable); ++i) {
2470 cxdouble wavelength = cpl_table_get_double(_ptable,
"WLEN", i, NULL);
2472 if ((wavelength > wlmin) && (wavelength < wlmax)) {
2474 efficiency += cpl_table_get_double(_ptable,
"EFFICIENCY",
2482 efficiency /= (cxdouble)nbin;
2485 cpl_propertylist_update_int(properties, GIALIAS_QCNSAT, nsaturated);
2486 cpl_propertylist_set_comment(properties, GIALIAS_QCNSAT,
"Number of "
2487 "saturated pixels in the first raw frame");
2493 cpl_propertylist_update_double(properties, GIALIAS_QCEFFICIENCY,
2495 cpl_propertylist_set_comment(properties, GIALIAS_QCEFFICIENCY,
2496 "Efficiency of the spectrograph.");
2499 GIALIAS_QCEFFICIENCY);
2502 if (cpl_propertylist_has(properties, GIALIAS_SKY_LEVEL) == TRUE) {
2504 cxdouble mean_sky = cpl_propertylist_get_double(properties,
2507 cpl_propertylist_update_double(properties, GIALIAS_QCSKYLEVEL,
2509 cpl_propertylist_set_comment(properties, GIALIAS_QCSKYLEVEL,
2510 "Mean sky level [ADU]");
2513 GIALIAS_QCSKYLEVEL);
2522 _properties = cpl_propertylist_load_regexp(cpl_frame_get_filename(pframe),
2523 0,
"^COMMENT$", TRUE);
2525 cpl_propertylist_erase_regexp(_properties,
"ESO QC.*", 0);
2529 GIALIAS_QCEFFICIENCY);
2534 giraffe_qc_airm_see_avg(_properties);
2536 cpl_image_save(NULL, cpl_frame_get_filename(pframe), CPL_BPP_8_UNSIGNED,
2537 _properties, CPL_IO_CREATE);
2539 cpl_propertylist_delete(_properties);
2547 giraffe_qclog_close(qc);
2561cpl_plugin_get_info(cpl_pluginlist* list)
2564 cpl_recipe* recipe = cx_calloc(1,
sizeof *recipe);
2565 cpl_plugin* plugin = &recipe->interface;
2568 cpl_plugin_init(plugin,
2570 GIRAFFE_BINARY_VERSION,
2571 CPL_PLUGIN_TYPE_RECIPE,
2573 "Process a spectro-photometric standard star "
2574 "observation and compute the instrument response curve.",
2575 "For detailed information please refer to the "
2576 "GIRAFFE pipeline user manual.\nIt is available at "
2577 "http://www.eso.org/pipelines.",
2583 gistandard_destroy);
2585 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.
GiFieldOfViewConfig * giraffe_fov_config_create(cpl_parameterlist *list)
Creates a setup structure for the field of view reconstruction.
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.
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_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.
void giraffe_fxcalibration_config_add(cpl_parameterlist *parameters)
Add flux calibration parameters to a parameter list.
cxint giraffe_calibrate_flux(GiResponse *result, const GiRebinning *spectra, const GiTable *fibers, const GiImage *flat, const GiTable *flux, const GiTable *extinction, const GiFxCalibrationConfig *config)
Compute the response and efficiency curves.
void giraffe_fxcalibration_config_destroy(GiFxCalibrationConfig *self)
Destroy a flux calibration setup structure.
cpl_image * giraffe_image_get(const GiImage *self)
Gets the image data.
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.
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.
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_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.