00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "muse_sky.h"
00026
00027 #include "muse_pfits.h"
00028
00032
00044
00045 void
00046 muse_sky_qc_lines(cpl_propertylist *aHeader, cpl_table *aLines,
00047 const char *aPrefix)
00048 {
00049 if (!aHeader || !aLines || !aPrefix) {
00050 cpl_error_set(__func__, CPL_ERROR_NULL_INPUT);
00051 return;
00052 }
00053 if (cpl_table_get_nrow(aLines) < 1) {
00054 cpl_error_set(__func__, CPL_ERROR_DATA_NOT_FOUND);
00055 return;
00056 }
00057
00058 char keyword[KEYWORD_LENGTH];
00059 int i, ngroups = cpl_table_get_column_max(aLines, "group") + 1;
00060 for (i = 0; i < ngroups; i++) {
00061 cpl_table_unselect_all(aLines);
00062 cpl_table_or_selected_int(aLines, "group", CPL_EQUAL_TO, i);
00063 cpl_table *gtable = cpl_table_extract_selected(aLines);
00064 cpl_size irow;
00065 cpl_table_get_column_maxpos(gtable, "flux", &irow);
00066 const char *name = cpl_table_get_string(gtable, "name", irow);
00067 double wavelength = cpl_table_get_double(gtable, "lambda", irow, NULL),
00068 flux = cpl_table_get_double(gtable, "flux", irow, NULL);
00069 snprintf(keyword, KEYWORD_LENGTH, "%s LINE%i NAME", aPrefix, i+1);
00070 cpl_propertylist_append_string(aHeader, keyword, name);
00071 snprintf(keyword, KEYWORD_LENGTH, "%s LINE%i AWAV", aPrefix, i+1);
00072 cpl_propertylist_append_double(aHeader, keyword, wavelength);
00073 snprintf(keyword, KEYWORD_LENGTH, "%s LINE%i FLUX", aPrefix, i+1);
00074 if (!isfinite(flux)) {
00075
00076
00077 cpl_propertylist_append_double(aHeader, keyword, -9999.999);
00078 cpl_msg_error(__func__, "Sky-line fit failed for group %d, computed "
00079 "flux is infinite!", i+1);
00080 } else {
00081 cpl_propertylist_append_double(aHeader, keyword, flux);
00082 }
00083 cpl_table_delete(gtable);
00084 }
00085 cpl_table_unselect_all(aLines);
00086 }
00087
00088
00100
00101 void
00102 muse_sky_qc_continuum(cpl_propertylist *aHeader, cpl_table *aContinuum,
00103 const char *aPrefix)
00104 {
00105 if (!aHeader || !aContinuum || !aPrefix) {
00106 cpl_error_set(__func__, CPL_ERROR_NULL_INPUT);
00107 return;
00108 }
00109 cpl_size irow, nrow = cpl_table_get_nrow(aContinuum);
00110 if (nrow < 1) {
00111 cpl_error_set(__func__, CPL_ERROR_DATA_NOT_FOUND);
00112 return;
00113 }
00114
00115 double flux = 0.0;
00116 for (irow = 0; irow < nrow; irow++) {
00117 flux += cpl_table_get_double(aContinuum, "flux", irow, NULL);
00118 }
00119 char keyword[KEYWORD_LENGTH];
00120 snprintf(keyword, KEYWORD_LENGTH, "%s CONT FLUX", aPrefix);
00121 if (!isfinite(flux)) {
00122
00123 cpl_propertylist_append_double(aHeader, keyword, -9999.999);
00124 cpl_msg_error(__func__, "Sky-continuum contains infinite values, fit may "
00125 "have failed!");
00126 } else {
00127 cpl_propertylist_append_double(aHeader, keyword, flux);
00128 }
00129 double maxdev = 0.0,
00130 prev = cpl_table_get_double(aContinuum, "flux", 0, NULL),
00131 l_prev = cpl_table_get_double(aContinuum, "lambda", 0, NULL);
00132 for (irow = 1; irow < nrow; irow++) {
00133 double cur = cpl_table_get_double(aContinuum, "flux", irow, NULL),
00134 l_cur = cpl_table_get_double(aContinuum, "lambda", irow, NULL),
00135 dev = fabs((cur - prev)/ (l_cur - l_prev));
00136 if (maxdev < dev) {
00137 maxdev = dev;
00138 }
00139 prev = cur;
00140 l_prev = l_cur;
00141 }
00142 snprintf(keyword, KEYWORD_LENGTH, "%s CONT MAXDEV", aPrefix);
00143 cpl_propertylist_append_double(aHeader, keyword, maxdev);
00144 }
00145