00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef HAVE_CONFIG_H
00021 #include <config.h>
00022 #endif
00023
00024
00025
00026
00027
00028 #include "visir_recipe.h"
00029
00030 #include <string.h>
00031
00032
00033
00034
00035
00036 #define RECIPE_STRING "visir_util_qc"
00037
00038
00039
00040
00041
00042 #ifdef VISIR_CHAIN
00043 #define cpl_plugin_get_info visir_util_qc_get_info
00044 #endif
00045
00046 cpl_recipe_define(visir_util_qc, VISIR_BINARY_VERSION,
00047 "Julian Taylor", PACKAGE_BUGREPORT, "2012",
00048 "Prepares qc parameters from data where the beam has "
00049 "been deteteced and bad images have been removed",
00050 "The files listed in the Set Of Frames (sof-file) "
00051 "must be tagged:\n"
00052 "VISIR-chopnod-corrected-file.fits "VISIR_UTIL_CORRECTED
00053 "\nThe product(s) will have a FITS card\n"
00054 "'HIERARCH ESO PRO CATG' with a value of: "
00055 VISIR_UTIL_QC_PROCATG"\n");
00056
00057
00061
00062
00063
00064
00065
00066
00067
00068
00076
00077 static cpl_error_code
00078 visir_util_qc_fill_parameterlist(cpl_parameterlist * self)
00079 {
00080 if (self) {}
00081 return CPL_ERROR_NONE;
00082 }
00083
00084
00085
00092
00093 static int visir_util_qc(cpl_frameset * framelist,
00094 const cpl_parameterlist * parlist)
00095 {
00096 cpl_frameset * usedframes = cpl_frameset_new();
00097 cpl_propertylist * outlist = cpl_propertylist_new();
00098 irplib_framelist * allframes = irplib_framelist_cast(framelist);
00099
00100 irplib_framelist * rawframes =
00101 irplib_framelist_extract(allframes, VISIR_UTIL_CORRECTED);
00102 const int nrawframes = irplib_framelist_get_size(rawframes);
00103 cpl_boolean undefined_beampos = CPL_FALSE;
00104
00105 cpl_fits_set_mode(CPL_FITS_STOP_CACHING);
00106
00107 irplib_framelist_load_propertylist_all(rawframes, 0, ".*", CPL_FALSE);
00108
00109 double t_exptime = 0;
00110 double t_eff_exptime = 0;
00111 cpl_size t_nimages = 0;
00112 cpl_size t_neff_images = 0;
00113 double t_bkg_sum = 0;
00114 double t_min_obsstart = 1e300;
00115 double t_max_filewrite = 0;
00116
00117 for (int iframe = 0; iframe < nrawframes; iframe++) {
00118 cpl_propertylist * plist =
00119 irplib_framelist_get_propertylist(rawframes, iframe);
00120 cpl_frame * frm = irplib_framelist_get(rawframes, iframe);
00121 float imgwgt = visir_pfits_get_img_weight(plist);
00122 visir_data_type dtype;
00123 visir_get_data_type(frm, plist, &dtype, NULL);
00124 t_max_filewrite =
00125 CX_MAX(cpl_propertylist_get_double(plist, "ESO DRS DATE"),
00126 t_max_filewrite);
00127 t_min_obsstart =
00128 CX_MIN(cpl_propertylist_get_double(plist, "ESO DRS DATE-OBS"),
00129 t_min_obsstart);
00130
00131 const int ndit = visir_pfits_get_ndit(plist);
00132 const int navrg = visir_pfits_get_navrg(plist);
00133
00134 const double dit = visir_pfits_get_dit(plist);
00135 if (iframe == 0)
00136 cpl_propertylist_append(outlist, plist);
00137
00138 const cpl_size ncycles = visir_pfits_get_chop_ncycles(plist);
00139 const char * beamid = cpl_propertylist_get_string(plist, "ESO QC BEAMID");
00140
00141 double time_per_img;
00142 cpl_size nimages;
00143 if (visir_data_is_burst(dtype)) {
00144 time_per_img = dit * navrg;
00145 nimages = ncycles * ndit / navrg;
00146 }
00147 else if (dtype == VISIR_DATA_AQU_INT) {
00148 time_per_img = ncycles * dit * ndit * navrg;
00149 nimages = 1;
00150 }
00151 else {
00152 time_per_img = dit * ndit * navrg;
00153 nimages = ncycles / navrg;
00154 }
00155 const cpl_size neff_images = cpl_frame_get_nextensions(frm);
00156
00157 double exptime = nimages * time_per_img;
00158 double eff_exptime = neff_images * time_per_img;
00159 double bkg_sum = 0;
00160
00161 exptime *= imgwgt;
00162 eff_exptime *= imgwgt;
00163
00164 char filename[128];
00165 sprintf(filename, "qc_header_%03d.fits", iframe);
00166
00167 if (cpl_propertylist_has(plist, "ESO QC BACKGD MEAN"))
00168 bkg_sum = cpl_propertylist_get_double(plist, "ESO QC BACKGD MEAN");
00169
00170 if (strcmp(beamid, "UNDEFINED") == 0)
00171 undefined_beampos = CPL_TRUE;
00172
00173 cpl_frame_set_group(frm, CPL_FRAME_GROUP_RAW);
00174 cpl_frameset_insert(usedframes, cpl_frame_duplicate(frm));
00175
00176
00177 cpl_propertylist_append_double(outlist, "ESO DRS IMGWGT", imgwgt);
00178
00179 cpl_propertylist_append_double(outlist, "ESO QC EXPTIME TOTAL", exptime);
00180 cpl_propertylist_append_double(outlist, "ESO QC EXPTIME EFFECTIVE", eff_exptime);
00181 cpl_propertylist_append_int(outlist, "ESO QC NIMAGES TOTAL", (int)nimages);
00182 cpl_propertylist_append_int(outlist, "ESO QC NIMAGES EFFECTIVE",
00183 (int)neff_images);
00184 cpl_propertylist_append_double(outlist, "ESO QC BACKGD MEAN", bkg_sum);
00185 cpl_propertylist_update_string(outlist, "ESO QC BEAMID", beamid);
00186 cpl_propertylist_update_double(outlist, "ESO QC BEAMX",
00187 cpl_propertylist_get_double(plist, "ESO QC BEAMX"));
00188 cpl_propertylist_update_double(outlist, "ESO QC BEAMY",
00189 cpl_propertylist_get_double(plist, "ESO QC BEAMY"));
00190 cpl_propertylist_append_double(outlist, "ESO QC EXECTIME",
00191 (t_max_filewrite - t_min_obsstart) * 24 * 3600);
00192
00193 irplib_dfs_save_propertylist(framelist, parlist, usedframes,
00194 RECIPE_STRING,
00195 nrawframes > 1 ? VISIR_UTIL_QC_PROCATG :
00196 VISIR_UTIL_QC_PROCATG "_COMBINED",
00197 outlist, NULL,
00198 visir_pipe_id, filename);
00199 skip_if(0);
00200
00201 t_nimages += nimages;
00202 t_neff_images += neff_images;
00203 t_exptime += exptime;
00204 t_eff_exptime += eff_exptime;
00205 t_bkg_sum += bkg_sum;
00206 }
00207
00208 double mean_bkg = t_bkg_sum / nrawframes;
00209
00210 cpl_msg_info(cpl_func, "Total exposure time: %gs", t_exptime);
00211 cpl_msg_info(cpl_func, "Total effective exposure time: %gs", t_eff_exptime);
00212 cpl_msg_info(cpl_func, "Total input images: %d", (int)t_nimages);
00213 cpl_msg_info(cpl_func, "Total accepted input images: %d", (int)t_neff_images);
00214 cpl_msg_info(cpl_func, "Mean input background: %g", mean_bkg);
00215
00216 if (nrawframes > 1) {
00217 cpl_propertylist_append_double(outlist, "ESO DRS IMGWGT", 1.);
00218 cpl_propertylist_append_double(outlist, "ESO QC EXPTIME TOTAL", t_exptime);
00219 cpl_propertylist_append_double(outlist, "ESO QC EXPTIME EFFECTIVE", t_eff_exptime);
00220 cpl_propertylist_append_int(outlist, "ESO QC NIMAGES TOTAL", (int)t_nimages);
00221 cpl_propertylist_append_int(outlist, "ESO QC NIMAGES EFFECTIVE",
00222 (int)t_neff_images);
00223 cpl_propertylist_append_double(outlist, "ESO QC BACKGD MEAN", mean_bkg);
00224 cpl_propertylist_append_string(outlist, "ESO QC BEAMID",
00225 undefined_beampos ? "UNDEFINED" : "COMBINED");
00226 cpl_propertylist_erase(outlist, "ESO QC BEAMX");
00227 cpl_propertylist_erase(outlist, "ESO QC BEAMY");
00228
00229 cpl_propertylist_append_double(outlist, "ESO QC EXECTIME",
00230 (t_max_filewrite - t_min_obsstart) * 24 * 3600);
00231
00232 skip_if(irplib_dfs_save_propertylist(framelist, parlist, usedframes,
00233 RECIPE_STRING,
00234 VISIR_UTIL_QC_PROCATG"_COMBINED",
00235 outlist, NULL,
00236 visir_pipe_id, "qc_header_all.fits"));
00237 }
00238
00239 end_skip;
00240 cpl_frameset_delete(usedframes);
00241 irplib_framelist_delete(allframes);
00242 irplib_framelist_delete(rawframes);
00243 cpl_propertylist_delete(outlist);
00244
00245 return cpl_error_get_code();
00246 }