28#include <cpl_recipe.h>
29#include <cpl_plugininfo.h>
30#include <cpl_parameterlist.h>
31#include <cpl_frameset.h>
33#include <cpl_errorstate.h>
38#include "gifiberutils.h"
39#include "gislitgeometry.h"
45#include "gitransmission.h"
46#include "girebinning.h"
48#include "gifxcalibration.h"
49#include "gimessages.h"
55static cxint gistandard(cpl_parameterlist* config, cpl_frameset* set);
56static cxint giqcstandard(cpl_frameset* set);
66gistandard_create(cpl_plugin* plugin)
69 cpl_recipe* recipe = (cpl_recipe*)plugin;
71 cpl_parameter* p = NULL;
83 recipe->parameters = cpl_parameterlist_new();
84 cx_assert(recipe->parameters != NULL);
107 p = cpl_parameterlist_find(recipe->parameters,
"giraffe.flat.apply");
108 cx_assert(p != NULL);
110 cpl_parameter_set_default_bool(p, FALSE);
116 p = cpl_parameterlist_find(recipe->parameters,
117 "giraffe.rebinning.range");
118 cx_assert(p != NULL);
120 cpl_parameter_set_default_string(p,
"common");
140gistandard_exec(cpl_plugin* plugin)
145 cpl_recipe* recipe = (cpl_recipe*)plugin;
148 cx_assert(recipe->parameters != NULL);
149 cx_assert(recipe->frames != NULL);
151 status = gistandard(recipe->parameters, recipe->frames);
157 status = giqcstandard(recipe->frames);
169gistandard_destroy(cpl_plugin* plugin)
172 cpl_recipe* recipe = (cpl_recipe*)plugin;
181 cpl_parameterlist_delete(recipe->parameters);
183 giraffe_error_clear();
195gistandard(cpl_parameterlist* config, cpl_frameset* set)
198 const cxchar*
const _id =
"gistandard";
201 const cxchar* filename = NULL;
206 cxlong nstandard = 0;
208 cxdouble exptime = 0.;
210 cx_slist* slist = NULL;
212 cpl_propertylist* properties = NULL;
214 cpl_matrix* biasareas = NULL;
216 cpl_frame* standard_frame = NULL;
217 cpl_frame* mbias_frame = NULL;
218 cpl_frame* mdark_frame = NULL;
219 cpl_frame* bpixel_frame = NULL;
220 cpl_frame* slight_frame = NULL;
221 cpl_frame* locy_frame = NULL;
222 cpl_frame* locw_frame = NULL;
223 cpl_frame* flat_frame = NULL;
224 cpl_frame* psfdata_frame = NULL;
225 cpl_frame* grating_frame = NULL;
226 cpl_frame* slit_frame = NULL;
227 cpl_frame* wcal_frame = NULL;
228 cpl_frame* rstandard_frame = NULL;
229 cpl_frame* sext_frame = NULL;
230 cpl_frame* rbin_frame = NULL;
231 cpl_frame* atmext_frame = NULL;
232 cpl_frame* flxstd_frame = NULL;
233 cpl_frame* rsp_frame = NULL;
235 GiImage* mbias = NULL;
236 GiImage* mdark = NULL;
237 GiImage* bpixel = NULL;
238 GiImage* slight = NULL;
239 GiImage* sstandard = NULL;
240 GiImage* rstandard = NULL;
242 GiTable* fibers = NULL;
243 GiTable* slitgeometry = NULL;
244 GiTable* grating = NULL;
245 GiTable* wcalcoeff = NULL;
246 GiTable* atmext = NULL;
247 GiTable* flxstd = NULL;
248 GiTable* refflx = NULL;
250 GiLocalization* localization = NULL;
251 GiExtraction* extraction = NULL;
252 GiRebinning* rebinning = NULL;
253 GiResponse* response = NULL;
255 GiBiasConfig* bias_config = NULL;
256 GiExtractConfig* extract_config = NULL;
257 GiFlatConfig* flat_config = NULL;
258 GiRebinConfig* rebin_config = NULL;
259 GiFxCalibrationConfig* fxcal_config = NULL;
262 GiInstrumentMode mode;
264 GiRecipeInfo info = {(cxchar*)_id, 1, NULL, config};
266 GiGroupInfo groups[] = {
267 {GIFRAME_STANDARD, CPL_FRAME_GROUP_RAW},
268 {GIFRAME_BADPIXEL_MAP, CPL_FRAME_GROUP_CALIB},
269 {GIFRAME_BIAS_MASTER, CPL_FRAME_GROUP_CALIB},
270 {GIFRAME_DARK_MASTER, CPL_FRAME_GROUP_CALIB},
271 {GIFRAME_FIBER_FLAT_EXTSPECTRA, CPL_FRAME_GROUP_CALIB},
272 {GIFRAME_FIBER_FLAT_EXTERRORS, CPL_FRAME_GROUP_CALIB},
273 {GIFRAME_SCATTERED_LIGHT_MODEL, CPL_FRAME_GROUP_CALIB},
274 {GIFRAME_LOCALIZATION_CENTROID, CPL_FRAME_GROUP_CALIB},
275 {GIFRAME_LOCALIZATION_WIDTH, CPL_FRAME_GROUP_CALIB},
276 {GIFRAME_PSF_CENTROID, CPL_FRAME_GROUP_CALIB},
277 {GIFRAME_PSF_WIDTH, CPL_FRAME_GROUP_CALIB},
278 {GIFRAME_PSF_DATA, CPL_FRAME_GROUP_CALIB},
279 {GIFRAME_WAVELENGTH_SOLUTION, CPL_FRAME_GROUP_CALIB},
280 {GIFRAME_SLITSETUP, CPL_FRAME_GROUP_CALIB},
281 {GIFRAME_SLITMASTER, CPL_FRAME_GROUP_CALIB},
282 {GIFRAME_GRATING, CPL_FRAME_GROUP_CALIB},
283 {GIFRAME_EXTINCTION, CPL_FRAME_GROUP_CALIB},
284 {GIFRAME_FLUX_STANDARDS, CPL_FRAME_GROUP_CALIB},
285 {NULL, CPL_FRAME_GROUP_NONE}
291 cpl_msg_error(_id,
"Invalid parameter list! Aborting ...");
296 cpl_msg_error(_id,
"Invalid frame set! Aborting ...");
300 status = giraffe_frameset_set_groups(set, groups);
303 cpl_msg_error(_id,
"Setting frame group information failed!");
312 nstandard = cpl_frameset_count_tags(set, GIFRAME_STANDARD);
315 cpl_msg_error(_id,
"Too few (%ld) raw frames (%s) present in "
316 "frame set! Aborting ...", nstandard, GIFRAME_STANDARD);
320 locy_frame = cpl_frameset_find(set, GIFRAME_PSF_CENTROID);
322 if (locy_frame == NULL) {
324 locy_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_CENTROID);
326 if (locy_frame == NULL) {
327 cpl_msg_info(_id,
"No master localization (centroid position) "
328 "present in frame set. Aborting ...");
334 locw_frame = cpl_frameset_find(set, GIFRAME_PSF_WIDTH);
336 if (locw_frame == NULL) {
338 locw_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_WIDTH);
340 if (locw_frame == NULL) {
341 cpl_msg_info(_id,
"No master localization (spectrum width) "
342 "present in frame set. Aborting ...");
348 flat_frame = cpl_frameset_find(set, GIFRAME_FIBER_FLAT_EXTSPECTRA);
350 if (flat_frame == NULL) {
352 cpl_msg_error(_id,
"No extracted flat field spectra frame present in frame set. "
358 grating_frame = cpl_frameset_find(set, GIFRAME_GRATING);
360 if (!grating_frame) {
361 cpl_msg_error(_id,
"No grating data present in frame set. "
369 cpl_msg_error(_id,
"No slit geometry present in frame set. "
374 wcal_frame = cpl_frameset_find(set, GIFRAME_WAVELENGTH_SOLUTION);
377 cpl_msg_error(_id,
"No dispersion solution present in frame set. "
382 atmext_frame = cpl_frameset_find(set, GIFRAME_EXTINCTION);
385 cpl_msg_error(_id,
"No atmospheric extinction table present in "
386 "frame set. Aborting ...");
390 flxstd_frame = cpl_frameset_find(set, GIFRAME_FLUX_STANDARDS);
393 cpl_msg_error(_id,
"No flux standards present in frame set. "
398 bpixel_frame = cpl_frameset_find(set, GIFRAME_BADPIXEL_MAP);
401 cpl_msg_info(_id,
"No bad pixel map present in frame set.");
404 mbias_frame = cpl_frameset_find(set, GIFRAME_BIAS_MASTER);
407 cpl_msg_info(_id,
"No master bias present in frame set.");
410 mdark_frame = cpl_frameset_find(set, GIFRAME_DARK_MASTER);
413 cpl_msg_info(_id,
"No master dark present in frame set.");
416 slight_frame = cpl_frameset_find(set, GIFRAME_SCATTERED_LIGHT_MODEL);
419 cpl_msg_info(_id,
"No scattered light model present in frame set.");
422 psfdata_frame = cpl_frameset_find(set, GIFRAME_PSF_DATA);
424 if (!psfdata_frame) {
425 cpl_msg_info(_id,
"No PSF profile parameters present in frame set.");
433 slist = cx_slist_new();
435 standard_frame = cpl_frameset_find(set, GIFRAME_STANDARD);
437 for (i = 0; i < nstandard; i++) {
439 filename = cpl_frame_get_filename(standard_frame);
447 cpl_msg_error(_id,
"Cannot load raw standard frame from '%s'. "
448 "Aborting ...", filename);
455 cx_slist_push_back(slist, raw);
457 standard_frame = cpl_frameset_find(set, NULL);
461 nstandard = (cxint)cx_slist_size(slist);
462 sstandard = cx_slist_pop_front(slist);
465 cx_assert(properties != NULL);
474 cpl_msg_info(_id,
"Averaging standard star observations ...");
476 exptime = cpl_propertylist_get_double(properties, GIALIAS_EXPTIME);
478 for (i = 1; i < nstandard; i++) {
480 cpl_propertylist* _properties;
482 GiImage* standard = cx_slist_pop_front(slist);
489 cx_assert(_properties != NULL);
491 exptime += cpl_propertylist_get_double(_properties,
501 cx_assert(cx_slist_empty(slist));
502 cx_slist_delete(slist);
512 cpl_msg_info(_id,
"Updating stacked standard star image "
515 cpl_propertylist_set_double(properties, GIALIAS_EXPTIME,
516 exptime / nstandard);
518 cpl_propertylist_append_double(properties, GIALIAS_EXPTTOT, exptime);
519 cpl_propertylist_set_comment(properties, GIALIAS_EXPTTOT,
520 "Total exposure time of all frames "
524 cpl_propertylist_erase(properties, GIALIAS_TPLEXPNO);
528 cpl_propertylist_append_int(properties, GIALIAS_DATANCOM, nstandard);
529 cpl_propertylist_set_comment(properties, GIALIAS_DATANCOM,
"Number of "
543 if (bias_config->method == GIBIAS_METHOD_MASTER ||
544 bias_config->method == GIBIAS_METHOD_ZMASTER) {
547 cpl_msg_error(_id,
"Missing master bias frame! Selected bias "
548 "removal method requires a master bias frame!");
556 filename = cpl_frame_get_filename(mbias_frame);
563 cpl_msg_error(_id,
"Cannot load master bias from '%s'. "
564 "Aborting ...", filename);
581 filename = cpl_frame_get_filename(bpixel_frame);
588 cpl_msg_error(_id,
"Cannot load bad pixel map from '%s'. "
589 "Aborting ...", filename);
618 biasareas, bias_config);
630 cpl_msg_error(_id,
"Bias removal failed. Aborting ...");
635 if (bpixel != NULL) {
651 GiDarkConfig dark_config = {GIDARK_METHOD_ZMASTER, 0.};
654 cpl_msg_info(_id,
"Correcting for dark current ...");
656 filename = cpl_frame_get_filename(mdark_frame);
662 cpl_msg_error(_id,
"Cannot load master dark from '%s'. "
663 "Aborting ...", filename);
668 if (bpixel != NULL) {
680 cpl_msg_error(_id,
"Dark subtraction failed! Aborting ...");
688 if (bpixel != NULL) {
707 cpl_msg_info(_id,
"Writing pre-processed standard star image ...");
712 GIFRAME_STANDARD_REDUCED,
713 CPL_FRAME_LEVEL_INTERMEDIATE,
716 if (rstandard_frame == NULL) {
717 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
724 cpl_frameset_insert(set, rstandard_frame);
731 standard_frame = cpl_frameset_find(set, GIFRAME_STANDARD);
733 cpl_msg_info(_id,
"Building fiber setup for frame '%s'.",
734 cpl_frame_get_filename(standard_frame));
739 cpl_msg_error(_id,
"Cannot create fiber setup for frame '%s'! "
740 "Aborting ...", cpl_frame_get_filename(standard_frame));
752 cpl_msg_info(_id,
"Fiber reference setup taken from localization "
753 "frame '%s'.", cpl_frame_get_filename(locy_frame));
760 localization = giraffe_localization_new();
762 filename = cpl_frame_get_filename(locy_frame);
769 cpl_msg_error(_id,
"Cannot load localization (centroid "
770 "position) frame from '%s'. Aborting ...",
773 giraffe_localization_destroy(localization);
787 filename = cpl_frame_get_filename(locw_frame);
794 cpl_msg_error(_id,
"Cannot load localization (spectrum width) "
795 "frame from '%s'. Aborting ...", filename);
797 giraffe_localization_destroy(localization);
817 filename = cpl_frame_get_filename(slight_frame);
824 cpl_msg_error(_id,
"Cannot load scattered light model from '%s'. "
825 "Aborting ...", filename);
829 giraffe_localization_destroy(localization);
848 if ((extract_config->emethod == GIEXTRACT_OPTIMAL) ||
849 (extract_config->emethod == GIEXTRACT_HORNE)) {
851 if (psfdata_frame == NULL) {
853 const cxchar* emethod =
"Optimal";
855 if (extract_config->emethod == GIEXTRACT_HORNE) {
859 cpl_msg_error(_id,
"%s spectrum extraction requires PSF "
860 "profile data. Aborting ...", emethod);
863 extract_config = NULL;
865 if (slight != NULL) {
870 giraffe_localization_destroy(localization);
889 filename = cpl_frame_get_filename(psfdata_frame);
892 localization->psf = giraffe_psfdata_new();
893 status = giraffe_psfdata_load(localization->psf, filename);
896 cpl_msg_error(_id,
"Cannot load PSF profile data frame from "
897 "'%s'. Aborting ...", filename);
900 extract_config = NULL;
902 if (slight != NULL) {
907 giraffe_localization_destroy(localization);
930 extraction = giraffe_extraction_new();
933 localization, bpixel, slight,
937 cpl_msg_error(_id,
"Spectrum extraction failed! Aborting ...");
939 giraffe_extraction_destroy(extraction);
944 giraffe_localization_destroy(localization);
976 filename = cpl_frame_get_filename(flat_frame);
978 cpl_msg_info(_id,
"Loading relative fiber transmission data from '%s'.",
985 giraffe_extraction_destroy(extraction);
986 giraffe_localization_destroy(localization);
991 cpl_msg_error(_id,
"Cannot load relative fiber transmission data "
992 "from '%s'. Aborting ...", filename);
1005 if (flat_config->apply == TRUE) {
1007 const cpl_frame* flat_errors_frame = NULL;
1009 GiImage* flat = NULL;
1010 GiImage* errors = NULL;
1013 filename = cpl_frame_get_filename(flat_frame);
1019 cpl_msg_error(_id,
"Cannot load flat field spectra from '%s'. "
1020 "Aborting ...", filename);
1026 giraffe_extraction_destroy(extraction);
1027 giraffe_localization_destroy(localization);
1037 cpl_frameset_find(set, GIFRAME_FIBER_FLAT_EXTERRORS);
1039 if (flat_errors_frame == NULL) {
1040 cpl_msg_warning(_id,
"Missing flat field spectra errors "
1045 filename = cpl_frame_get_filename(flat_errors_frame);
1051 cpl_msg_error(_id,
"Cannot load flat field spectra "
1052 "errors from '%s'. Aborting ...",
1060 giraffe_extraction_destroy(extraction);
1061 giraffe_localization_destroy(localization);
1071 cpl_msg_info(_id,
"Applying flat field correction ...");
1077 cpl_msg_error(_id,
"Flat field correction failed! "
1085 giraffe_extraction_destroy(extraction);
1086 giraffe_localization_destroy(localization);
1102 if (flat_config->transmission == TRUE) {
1104 cpl_msg_info(_id,
"Applying relative fiber transmission "
1107 status = giraffe_transmission_apply(extraction, fibers);
1111 cpl_msg_error(_id,
"Relative transmission correction failed! "
1117 giraffe_extraction_destroy(extraction);
1118 giraffe_localization_destroy(localization);
1138 cpl_msg_info(_id,
"Writing extracted spectra ...");
1145 GIFRAME_STANDARD_EXTSPECTRA,
1146 CPL_FRAME_LEVEL_FINAL,
1149 if (sext_frame == NULL) {
1150 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1152 giraffe_extraction_destroy(extraction);
1153 giraffe_localization_destroy(localization);
1164 cpl_msg_error(_id,
"Cannot attach fiber setup to local file '%s'! "
1165 "Aborting ...", cpl_frame_get_filename(sext_frame));
1167 cpl_frame_delete(sext_frame);
1169 giraffe_extraction_destroy(extraction);
1170 giraffe_localization_destroy(localization);
1178 cpl_frameset_insert(set, sext_frame);
1185 GIFRAME_STANDARD_EXTERRORS,
1186 CPL_FRAME_LEVEL_FINAL,
1189 if (sext_frame == NULL) {
1190 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1192 giraffe_extraction_destroy(extraction);
1193 giraffe_localization_destroy(localization);
1204 cpl_msg_error(_id,
"Cannot attach fiber setup to local file '%s'! "
1205 "Aborting ...", cpl_frame_get_filename(sext_frame));
1207 cpl_frame_delete(sext_frame);
1209 giraffe_extraction_destroy(extraction);
1210 giraffe_localization_destroy(localization);
1218 cpl_frameset_insert(set, sext_frame);
1222 if (extraction->npixels != NULL) {
1227 GIFRAME_STANDARD_EXTPIXELS,
1228 CPL_FRAME_LEVEL_FINAL,
1231 if (sext_frame == NULL) {
1232 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1234 giraffe_extraction_destroy(extraction);
1235 giraffe_localization_destroy(localization);
1246 cpl_msg_error(_id,
"Cannot attach fiber setup to local file "
1247 "'%s'! Aborting ...",
1248 cpl_frame_get_filename(sext_frame));
1250 cpl_frame_delete(sext_frame);
1252 giraffe_extraction_destroy(extraction);
1253 giraffe_localization_destroy(localization);
1261 cpl_frameset_insert(set, sext_frame);
1270 GIFRAME_STANDARD_EXTTRACE,
1271 CPL_FRAME_LEVEL_FINAL,
1274 if (sext_frame == NULL) {
1275 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1277 giraffe_extraction_destroy(extraction);
1278 giraffe_localization_destroy(localization);
1289 cpl_msg_error(_id,
"Cannot attach fiber setup to local file '%s'! "
1290 "Aborting ...", cpl_frame_get_filename(sext_frame));
1292 cpl_frame_delete(sext_frame);
1294 giraffe_extraction_destroy(extraction);
1295 giraffe_localization_destroy(localization);
1303 cpl_frameset_insert(set, sext_frame);
1307 if (extraction->model != NULL) {
1312 GIFRAME_STANDARD_EXTMODEL,
1313 CPL_FRAME_LEVEL_FINAL,
1316 if (sext_frame == NULL) {
1317 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1319 giraffe_extraction_destroy(extraction);
1320 giraffe_localization_destroy(localization);
1331 cpl_msg_error(_id,
"Cannot attach fiber setup to local file '%s'! "
1332 "Aborting ...", cpl_frame_get_filename(sext_frame));
1334 cpl_frame_delete(sext_frame);
1336 giraffe_extraction_destroy(extraction);
1337 giraffe_localization_destroy(localization);
1345 cpl_frameset_insert(set, sext_frame);
1355 filename = (cxchar *)cpl_frame_get_filename(wcal_frame);
1361 cpl_msg_error(_id,
"Cannot load dispersion solution from "
1362 "'%s'. Aborting ...", filename);
1364 giraffe_extraction_destroy(extraction);
1365 giraffe_localization_destroy(localization);
1380 filename = (cxchar *)cpl_frame_get_filename(grating_frame);
1388 cpl_msg_error(_id,
"Cannot load grating data from '%s'. "
1389 "Aborting ...", filename);
1391 giraffe_extraction_destroy(extraction);
1392 giraffe_localization_destroy(localization);
1408 filename = (cxchar *)cpl_frame_get_filename(slit_frame);
1412 if (slitgeometry == NULL) {
1413 cpl_msg_error(_id,
"Cannot load slit geometry data from '%s'. "
1414 "Aborting ...", filename);
1418 giraffe_extraction_destroy(extraction);
1419 giraffe_localization_destroy(localization);
1437 cpl_msg_error(_id,
"Slit geometry data from '%s' is not "
1438 "applicable for current fiber setup! "
1439 "Aborting ...", filename);
1444 giraffe_extraction_destroy(extraction);
1445 giraffe_localization_destroy(localization);
1462 cpl_msg_info(_id,
"Spectrum rebinning");
1471 localization, grating, slitgeometry,
1472 wcalcoeff, rebin_config);
1475 cpl_msg_error(_id,
"Rebinning of standard spectra failed! "
1480 giraffe_extraction_destroy(extraction);
1481 giraffe_localization_destroy(localization);
1495 giraffe_extraction_destroy(extraction);
1498 giraffe_localization_destroy(localization);
1499 localization = NULL;
1502 rebin_config = NULL;
1514 GIFRAME_STANDARD_RBNSPECTRA,
1515 CPL_FRAME_LEVEL_FINAL,
1518 if (rbin_frame == NULL) {
1519 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1535 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1536 "file '%s'! Aborting ...",
1537 cpl_frame_get_filename(rbin_frame));
1546 cpl_frame_delete(rbin_frame);
1551 cpl_frameset_insert(set, rbin_frame);
1558 GIFRAME_STANDARD_RBNERRORS,
1559 CPL_FRAME_LEVEL_FINAL,
1562 if (rbin_frame == NULL) {
1563 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1579 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1580 "file '%s'! Aborting ...",
1581 cpl_frame_get_filename(rbin_frame));
1591 cpl_frame_delete(rbin_frame);
1596 cpl_frameset_insert(set, rbin_frame);
1607 if (mode == GIMODE_IFU || mode == GIMODE_ARGUS) {
1609 cpl_frame* rimg_frame = NULL;
1611 GiFieldOfView* fov = NULL;
1613 GiFieldOfViewConfig* fov_config = NULL;
1615 GiFieldOfViewCubeFormat cube_format = GIFOV_FORMAT_ESO3D;
1620 cube_format = fov_config->format;
1623 cpl_msg_info(_id,
"Reconstructing image and data cube from rebinned "
1629 slitgeometry, fov_config);
1634 cpl_msg_warning(_id,
"No reconstructed image was built. "
1635 "Fiber list has no fiber position "
1639 cpl_msg_error(_id,
"Image reconstruction failed! Aborting...");
1663 cpl_errorstate tempes = cpl_errorstate_get();
1665 double fovFlux = 0.0;
1666 double badcolFlux = 0.0;
1667 double meanFlux = 0.0;
1670 int fovnx = cpl_image_get_size_x(fovimage);
1671 int fovny = cpl_image_get_size_y(fovimage);
1673 fovFlux = cpl_image_get_flux(fovimage);
1674 badcolFlux = cpl_image_get_flux_window(fovimage, fovnx- 1, 1, fovnx - 1, fovny);
1676 meanFlux = (fovFlux - badcolFlux) / ((fovnx -1) * fovny);
1681 cpl_propertylist_update_double(fovprop, GIALIAS_QCSIGMEAN, meanFlux);
1682 cpl_propertylist_set_comment(fovprop, GIALIAS_QCSIGMEAN,
"Mean of "
1683 "FOV image without bad row");
1685 cpl_errorstate_set(tempes);
1696 GIFRAME_STANDARD_RCSPECTRA,
1697 CPL_FRAME_LEVEL_FINAL,
1700 if (rimg_frame == NULL) {
1701 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1715 cpl_frameset_insert(set, rimg_frame);
1723 GIFRAME_STANDARD_RCERRORS,
1724 CPL_FRAME_LEVEL_FINAL,
1727 if (rimg_frame == NULL) {
1728 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1742 cpl_frameset_insert(set, rimg_frame);
1747 if (cube_format == GIFOV_FORMAT_SINGLE) {
1751 if (fov->cubes.spectra != NULL) {
1753 cxint component = 0;
1759 properties = cpl_propertylist_duplicate(properties);
1764 CPL_FRAME_LEVEL_FINAL,
1770 cpl_propertylist_delete(properties);
1773 if (rimg_frame == NULL) {
1774 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1786 slitgeometry = NULL;
1800 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1801 "file '%s'! Aborting ...",
1802 cpl_frame_get_filename(rimg_frame));
1804 cpl_frame_delete(rimg_frame);
1816 slitgeometry = NULL;
1827 cpl_frameset_insert(set, rimg_frame);
1833 if (fov->cubes.errors != NULL) {
1835 cxint component = 1;
1841 properties = cpl_propertylist_duplicate(properties);
1846 CPL_FRAME_LEVEL_FINAL,
1852 cpl_propertylist_delete(properties);
1855 if (rimg_frame == NULL) {
1856 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1868 slitgeometry = NULL;
1882 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1883 "file '%s'! Aborting ...",
1884 cpl_frame_get_filename(rimg_frame));
1886 cpl_frame_delete(rimg_frame);
1898 slitgeometry = NULL;
1909 cpl_frameset_insert(set, rimg_frame);
1920 properties = cpl_propertylist_duplicate(properties);
1925 CPL_FRAME_LEVEL_FINAL,
1931 cpl_propertylist_delete(properties);
1934 if (rimg_frame == NULL) {
1935 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
1947 slitgeometry = NULL;
1961 cpl_msg_error(_id,
"Cannot attach fiber setup to local "
1962 "file '%s'! Aborting ...",
1963 cpl_frame_get_filename(rimg_frame));
1965 cpl_frame_delete(rimg_frame);
1977 slitgeometry = NULL;
1988 cpl_frameset_insert(set, rimg_frame);
2002 cpl_msg_info(_id,
"Computing instrument response function...");
2004 filename = cpl_frame_get_filename(flxstd_frame);
2009 cpl_msg_info(_id,
"Flux table loaded ...");
2012 cpl_msg_error(_id,
"Cannot load flux standards catalog from "
2013 "'%s'. Aborting ...", filename);
2022 slitgeometry = NULL;
2034 fxcal_config = giraffe_fxcalibration_config_create(config);
2041 refflx = giraffe_select_flux_standard(flxstd, rebinning->spectra, fxcal_config->max_dist);
2044 if (refflx == NULL) {
2045 cpl_msg_error(_id,
"No matching flux standard found in the "
2046 "catalog '%s'! Aborting ...", filename);
2058 slitgeometry = NULL;
2073 filename = cpl_frame_get_filename(atmext_frame);
2079 cpl_msg_error(_id,
"Cannot load atmospheric extinction data from "
2080 "'%s'. Aborting ...", filename);
2092 slitgeometry = NULL;
2103 response = giraffe_response_new();
2106 refflx, atmext, fxcal_config);
2110 cpl_msg_error(_id,
"Instrument response computation failed!");
2112 giraffe_response_delete(response);
2116 fxcal_config = NULL;
2131 slitgeometry = NULL;
2144 fxcal_config = NULL;
2160 GIFRAME_INSTRUMENT_RESPONSE,
2161 CPL_FRAME_LEVEL_FINAL,
2164 if (rsp_frame == NULL) {
2166 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
2168 giraffe_response_delete(response);
2178 slitgeometry = NULL;
2190 cpl_frameset_insert(set, rsp_frame);
2200 GIFRAME_EFFICIENCY_CURVE,
2201 CPL_FRAME_LEVEL_FINAL,
2204 if (rsp_frame == NULL) {
2206 cpl_msg_error(_id,
"Cannot create local file! Aborting ...");
2208 giraffe_response_delete(response);
2218 slitgeometry = NULL;
2230 cpl_frameset_insert(set, rsp_frame);
2232 giraffe_response_delete(response);
2254giqcstandard(cpl_frameset* set)
2257 const cxchar*
const fctid =
"giqcstandard";
2260 const cxdouble saturation = 60000.;
2261 const cxdouble wlscale = 0.1;
2267 cxint nsaturated = 0;
2269 const cxdouble* pixels = NULL;
2271 cxdouble wlmin = 0.;
2272 cxdouble wlmax = 0.;
2273 cxdouble efficiency = 0.;
2275 cpl_propertylist* properties = NULL;
2276 cpl_propertylist* _properties = NULL;
2277 cpl_propertylist* qclog = NULL;
2279 cpl_frame* rframe = NULL;
2280 cpl_frame* pframe = NULL;
2282 cpl_image* _rimage = NULL;
2284 cpl_table* _ptable = NULL;
2286 GiImage* rimage = NULL;
2288 GiTable* ptable = NULL;
2293 cpl_msg_info(fctid,
"Computing QC1 parameters ...");
2295 qc = giraffe_qclog_open(0);
2298 cpl_msg_error(fctid,
"Cannot create QC1 log!");
2302 qclog = giraffe_paf_get_properties(qc);
2303 cx_assert(qclog != NULL);
2311 CPL_FRAME_GROUP_PRODUCT);
2313 if (pframe == NULL) {
2314 cpl_msg_error(fctid,
"Missing product frame (%s)",
2315 GIFRAME_EFFICIENCY_CURVE);
2317 giraffe_paf_delete(qc);
2323 cpl_msg_info(fctid,
"Processing product frame '%s' (%s)",
2324 cpl_frame_get_filename(pframe), cpl_frame_get_tag(pframe));
2328 "EFFICIENCY_CURVE");
2331 cpl_msg_error(fctid,
"Could not load efficiency table '%s'! "
2332 "Aborting ...", cpl_frame_get_filename(pframe));
2337 giraffe_paf_delete(qc);
2348 rframe = cpl_frameset_find(set, GIFRAME_STANDARD);
2350 if (rframe == NULL) {
2351 cpl_msg_error(fctid,
"Missing raw frame (%s)", GIFRAME_STANDARD);
2356 giraffe_paf_delete(qc);
2366 cpl_msg_error(fctid,
"Could not load standard star observation '%s'!",
2367 cpl_frame_get_filename(rframe));
2375 giraffe_paf_delete(qc);
2383 cx_assert(_rimage != NULL);
2386 cx_assert(properties != NULL);
2391 cpl_propertylist_update_string(qclog,
"PRO.CATG",
2392 cpl_frame_get_tag(pframe));
2393 cpl_propertylist_set_comment(qclog,
"PRO.CATG",
2394 "Pipeline product category");
2401 pixels = cpl_image_get_data(_rimage);
2402 npixel = cpl_image_get_size_x(_rimage) * cpl_image_get_size_y(_rimage);
2406 for (i = 0; i < npixel; i++) {
2407 if (pixels[i] > saturation) {
2424 cx_assert(_ptable != NULL);
2427 cx_assert(properties != NULL);
2429 if (cpl_propertylist_has(properties, GIALIAS_GRATWLEN) == FALSE) {
2434 giraffe_paf_delete(qc);
2437 cpl_msg_error(fctid,
"Missing property '%s'", GIALIAS_GRATWLEN);
2444 cxdouble wlband = 0.;
2445 cxdouble wl0 = cpl_propertylist_get_double(properties,
2449 wlmin = cpl_propertylist_get_double(properties, GIALIAS_BINWLMIN);
2450 wlmax = cpl_propertylist_get_double(properties, GIALIAS_BINWLMAX);
2452 cx_assert((wlmin < wl0) && (wl0 < wlmax));
2454 wlband = wlscale * fabs(wlmax - wlmin);
2456 wlmin = CX_MAX(wlmin, (wl0 - wlband));
2457 wlmax = CX_MIN(wlmax, (wl0 + wlband));
2459 cpl_msg_info(fctid,
"Computing spectrograph efficiency from "
2460 "wavelength range ]%.1f, %.1f[", wlmin, wlmax);
2466 for (i = 0; i < cpl_table_get_nrow(_ptable); ++i) {
2468 cxdouble wavelength = cpl_table_get_double(_ptable,
"WLEN", i, NULL);
2470 if ((wavelength > wlmin) && (wavelength < wlmax)) {
2472 efficiency += cpl_table_get_double(_ptable,
"EFFICIENCY",
2480 efficiency /= (cxdouble)nbin;
2483 cpl_propertylist_update_int(properties, GIALIAS_QCNSAT, nsaturated);
2484 cpl_propertylist_set_comment(properties, GIALIAS_QCNSAT,
"Number of "
2485 "saturated pixels in the first raw frame");
2491 cpl_propertylist_update_double(properties, GIALIAS_QCEFFICIENCY,
2493 cpl_propertylist_set_comment(properties, GIALIAS_QCEFFICIENCY,
2494 "Efficiency of the spectrograph.");
2497 GIALIAS_QCEFFICIENCY);
2500 if (cpl_propertylist_has(properties, GIALIAS_SKY_LEVEL) == TRUE) {
2502 cxdouble mean_sky = cpl_propertylist_get_double(properties,
2505 cpl_propertylist_update_double(properties, GIALIAS_QCSKYLEVEL,
2507 cpl_propertylist_set_comment(properties, GIALIAS_QCSKYLEVEL,
2508 "Mean sky level [ADU]");
2511 GIALIAS_QCSKYLEVEL);
2520 _properties = cpl_propertylist_load_regexp(cpl_frame_get_filename(pframe),
2521 0,
"^COMMENT$", TRUE);
2523 cpl_propertylist_erase_regexp(_properties,
"ESO QC.*", 0);
2527 GIALIAS_QCEFFICIENCY);
2532 giraffe_qc_airm_see_avg(_properties);
2534 cpl_image_save(NULL, cpl_frame_get_filename(pframe), CPL_BPP_8_UNSIGNED,
2535 _properties, CPL_IO_CREATE);
2537 cpl_propertylist_delete(_properties);
2545 giraffe_qclog_close(qc);
2559cpl_plugin_get_info(cpl_pluginlist* list)
2562 cpl_recipe* recipe = cx_calloc(1,
sizeof *recipe);
2563 cpl_plugin* plugin = &recipe->interface;
2566 cpl_plugin_init(plugin,
2568 GIRAFFE_BINARY_VERSION,
2569 CPL_PLUGIN_TYPE_RECIPE,
2571 "Process a spectro-photometric standard star "
2572 "observation and compute the instrument response curve.",
2573 "For detailed information please refer to the "
2574 "GIRAFFE pipeline user manual.\nIt is available at "
2575 "http://www.eso.org/pipelines.",
2581 gistandard_destroy);
2583 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.