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
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036
00037 #include "visir_recipe.h"
00038 #include "visir_spectro.h"
00039 #include "visir_spc_distortion.h"
00040 #include "visir_spc_photom.h"
00041
00042
00043
00044
00045
00046 #define RECIPE_STRING "visir_spc_phot_ech"
00047
00048
00049 #define RECIPE_KEYS_REGEXP_ALL \
00050 VISIR_PFITS_REGEXP_IMG_RECOMBINE \
00051 "|" VISIR_PFITS_REGEXP_SPC_GET_RES_WL \
00052 "|" VISIR_PFITS_REGEXP_SPC_SENSIT
00053
00054
00055 #define RECIPE_KEYS_REGEXP \
00056 RECIPE_KEYS_REGEXP_ALL \
00057 "|" VISIR_PFITS_SPC_PHOT_COPY \
00058 "|" VISIR_PFITS_REGEXP_CAPA \
00059 "|" VISIR_PFITS_REGEXP_SPC_PHOT_PAF
00060
00061
00062 #define RECIPE_KEYS_REGEXP_WCS \
00063 RECIPE_KEYS_REGEXP \
00064 "|" IRPLIB_PFITS_WCS_REGEXP
00065
00066
00067
00068
00069
00070 static cpl_error_code visir_spc_phot_ech_save(cpl_frameset *,
00071 const cpl_parameterlist *,
00072 const cpl_propertylist *,
00073 const cpl_propertylist *,
00074 const cpl_image *,
00075 const cpl_image *,
00076 const cpl_table *);
00077
00078 VISIR_RECIPE_DEFINE(visir_spc_phot_ech,
00079 VISIR_PARAM_EMIS_TOL |
00080 VISIR_PARAM_ZERODIST | VISIR_PARAM_ORDEROFF |
00081 VISIR_PARAM_REFINE | VISIR_PARAM_XCORR |
00082 VISIR_PARAM_OFFSETS | VISIR_PARAM_OBJECTS |
00083 VISIR_PARAM_NODPOS | VISIR_PARAM_AUTOBPM |
00084 VISIR_PARAM_GLITCH | VISIR_PARAM_PURGE |
00085 VISIR_PARAM_UNION | VISIR_PARAM_REJECT |
00086 VISIR_PARAM_STRIPITE | VISIR_PARAM_STRIPMOR |
00087 VISIR_PARAM_PLOT | VISIR_PARAM_SLITSKEW |
00088 VISIR_PARAM_SPECSKEW | VISIR_PARAM_VERTARC |
00089 VISIR_PARAM_REJLEFT | VISIR_PARAM_REJRIGHT |
00090 VISIR_PARAM_HORIARC | VISIR_PARAM_FIXCOMBI,
00091 "Sensitivity computation in echelle spectroscopy",
00092 "This recipe estimates the dispersion relation using the "
00093 "atmospheric spectrum\n"
00094 "in a echelle spectroscopy half-cycle frame.\n"
00095 "It also extracts the spectrum of an observed object "
00096 "using a combined frame.\n"
00097 "Lastly, it computes the spectral photometry of an "
00098 "observed standard star.\n"
00099 "The files listed in the Set Of Frames (sof-file) "
00100 "must be tagged:\n"
00101 "VISIR-Echelle-Spectroscopy-file.fits "
00102 VISIR_SPC_PHOT_ECH_RAW "\n"
00103 "VISIR-Quantum-Efficiency-Calibration-file.fits "
00104 VISIR_CALIB_QEFF_SPC "\n"
00105 "VISIR-Atmospheric-Emission-Lines-Calibration-file.fits "
00106 VISIR_CALIB_LINES_SPC
00107 "\n"
00108 "VISIR-Spectroscopic-Standard-Star-Catalog.fits "
00109 VISIR_CALIB_STDSTAR_SPC "\n"
00110 MAN_VISIR_CALIB_BPM_SPC);
00111
00112
00116
00117
00118
00119
00120
00121
00122
00129
00130 static int visir_spc_phot_ech(cpl_frameset * framelist,
00131 const cpl_parameterlist * parlist)
00132 {
00133 irplib_framelist * allframes = NULL;
00134 irplib_framelist * rawframes = NULL;
00135 cpl_propertylist * qclist = cpl_propertylist_new();
00136 cpl_propertylist * paflist = cpl_propertylist_new();
00137 const char * badpix;
00138 const char * star_cat;
00139 const char * spc_cal_qeff;
00140 const char * spc_cal_lines;
00141 const char * flat;
00142 cpl_image ** combinedpair = NULL;
00143 cpl_image * combined = NULL;
00144 cpl_table * tab = NULL;
00145 cpl_image * weight2d = NULL;
00146 double wlen, slitw, temp, fwhm;
00147 visir_spc_resol resol;
00148 visir_spc_phot_config config;
00149 cpl_boolean drop_wcs;
00150 const char * keys_regexp = "^(" RECIPE_KEYS_REGEXP_WCS ")$";
00151
00152
00153
00154 config.plot = visir_parameterlist_get_int(parlist, RECIPE_STRING, VISIR_PARAM_PLOT);
00155
00156 config.phi = visir_parameterlist_get_double(parlist, RECIPE_STRING, VISIR_PARAM_SLITSKEW);
00157 config.ksi = visir_parameterlist_get_double(parlist, RECIPE_STRING, VISIR_PARAM_SPECSKEW);
00158 config.eps = visir_parameterlist_get_double(parlist, RECIPE_STRING, VISIR_PARAM_VERTARC);
00159 config.delta = visir_parameterlist_get_double(parlist, RECIPE_STRING, VISIR_PARAM_HORIARC);
00160
00161 config.orderoffset = visir_parameterlist_get_int(parlist, RECIPE_STRING, VISIR_PARAM_ORDEROFF);
00162
00163 config.do_fixcombi = visir_parameterlist_get_bool(parlist, RECIPE_STRING, VISIR_PARAM_FIXCOMBI);
00164
00165 config.emis_tol = visir_parameterlist_get_double(parlist, RECIPE_STRING, VISIR_PARAM_EMIS_TOL);
00166
00167 skip_if (0);
00168
00169
00170 skip_if (visir_dfs_set_groups(framelist));
00171
00172
00173 allframes = irplib_framelist_cast(framelist);
00174 skip_if(allframes == NULL);
00175 rawframes = irplib_framelist_extract(allframes, VISIR_SPC_PHOT_ECH_RAW);
00176 skip_if (rawframes == NULL);
00177
00178 irplib_framelist_empty(allframes);
00179
00180 skip_if(irplib_framelist_load_propertylist(rawframes, 0, 0, keys_regexp,
00181 CPL_FALSE));
00182
00183 skip_if(irplib_framelist_load_propertylist_all(rawframes, 0, "^("
00184 RECIPE_KEYS_REGEXP_ALL
00185 ")$", CPL_FALSE));
00186
00187 skip_if(visir_dfs_check_framelist_tag(rawframes));
00188
00189
00190 star_cat = irplib_frameset_find_file(framelist, VISIR_CALIB_STDSTAR_SPC);
00191 if (star_cat == NULL) {
00192 cpl_msg_error(cpl_func, "The file with the star catalog is missing");
00193 skip_if(1);
00194 }
00195
00196
00197 spc_cal_qeff = irplib_frameset_find_file(framelist, VISIR_CALIB_QEFF_SPC);
00198
00199
00200 spc_cal_lines = irplib_frameset_find_file(framelist, VISIR_CALIB_LINES_SPC);
00201
00202
00203 badpix = irplib_frameset_find_file(framelist, VISIR_CALIB_BPM);
00204
00205
00206 flat = irplib_frameset_find_file(framelist, VISIR_CALIB_FLAT);
00207
00208
00209 resol = visir_spc_get_res_wl(rawframes, &wlen, &slitw, &temp, &fwhm);
00210
00211 skip_if (0);
00212
00213 if (resol != VISIR_SPC_R_GHR) {
00214 if (config.orderoffset == 0) {
00215 cpl_msg_warning(cpl_func,"Reducing non-HR Grism data as main order");
00216 } else {
00217 cpl_msg_error(cpl_func, "This recipe cannot reduce non-HR Grism "
00218 "data with an order-offset of %d",
00219 config.orderoffset);
00220 visir_error_set(CPL_ERROR_TYPE_MISMATCH);
00221 skip_if(1);
00222 }
00223 }
00224
00225
00226 combinedpair = visir_img_recombine(RECIPE_STRING, parlist, rawframes, badpix,
00227 flat, CPL_GEOM_FIRST, &drop_wcs,
00228 !config.do_fixcombi, wlen, resol);
00229
00230 if (combinedpair == NULL) {
00231 cpl_msg_error(cpl_func, "Could not combine the input frames");
00232 skip_if (1);
00233 }
00234
00235 cpl_image_delete(combinedpair[1]);
00236 combined = cpl_image_cast(combinedpair[0], CPL_TYPE_DOUBLE);
00237 cpl_image_delete(combinedpair[0]);
00238
00239 skip_if (0);
00240
00241
00242 cpl_msg_info(cpl_func, "Compute the sensitivity");
00243 tab = visir_spc_phot_sensit(&combined, rawframes, RECIPE_STRING, parlist,
00244 &config, star_cat,
00245 spc_cal_lines, spc_cal_qeff, &weight2d, qclist,
00246 CPL_TRUE, wlen, slitw, temp, fwhm, resol);
00247
00248 if (tab == NULL) {
00249 cpl_msg_error(cpl_func, "Cannot compute sensitivity: '%s' in %s",
00250 cpl_error_get_message(), cpl_error_get_where());
00251 skip_if(1);
00252 }
00253
00254 bug_if (visir_spectro_qc(qclist, paflist, drop_wcs, rawframes,
00255 "^(" VISIR_PFITS_SPC_PHOT_COPY ")$",
00256 "^(" VISIR_PFITS_REGEXP_SPC_PHOT_PAF ")$"));
00257 irplib_framelist_empty(rawframes);
00258
00259
00260 cpl_msg_info(cpl_func, "Save the results");
00261
00262
00263 bug_if (cpl_propertylist_append_string(paflist, CPL_DFS_PRO_CATG,
00264 VISIR_SPC_PHOT_ECH_COMBINED_PROCATG));
00265
00266 skip_if (visir_spc_phot_ech_save(framelist, parlist, qclist, paflist,
00267 combined, weight2d, tab));
00268
00269 end_skip;
00270
00271 cpl_propertylist_delete(qclist);
00272 cpl_propertylist_delete(paflist);
00273 irplib_framelist_delete(allframes);
00274 irplib_framelist_delete(rawframes);
00275 cpl_image_delete(combined);
00276 cpl_table_delete(tab);
00277 cpl_image_delete(weight2d);
00278
00279 cpl_free(combinedpair);
00280
00281 return cpl_error_get_code();
00282 }
00283
00284
00296
00297 static cpl_error_code visir_spc_phot_ech_save(cpl_frameset * set,
00298 const cpl_parameterlist * parlist,
00299 const cpl_propertylist * qclist,
00300 const cpl_propertylist * paflist,
00301 const cpl_image *combined,
00302 const cpl_image *weight2d,
00303 const cpl_table * table)
00304 {
00305 bug_if (0);
00306
00307
00308 skip_if (irplib_dfs_save_table(set, parlist, set, table, NULL, RECIPE_STRING,
00309 VISIR_SPC_PHOT_ECH_TAB_PROCATG,
00310 qclist, NULL, visir_pipe_id,
00311 RECIPE_STRING "_tab" CPL_DFS_FITS));
00312
00313
00314 skip_if (irplib_dfs_save_image(set, parlist, set, combined, CPL_BPP_IEEE_FLOAT,
00315 RECIPE_STRING, VISIR_SPC_PHOT_ECH_COMBINED_PROCATG,
00316 qclist, NULL, visir_pipe_id,
00317 RECIPE_STRING CPL_DFS_FITS));
00318
00319
00320 skip_if (irplib_dfs_save_image(set, parlist, set, weight2d, CPL_BPP_IEEE_FLOAT,
00321 RECIPE_STRING, VISIR_SPC_PHOT_ECH_WEIGHT_PROCATG,
00322 qclist, NULL, visir_pipe_id,
00323 RECIPE_STRING "_weight" CPL_DFS_FITS));
00324
00325 #ifdef VISIR_SAVE_PAF
00326
00327 skip_if (cpl_dfs_save_paf("VISIR", RECIPE_STRING, paflist,
00328 RECIPE_STRING CPL_DFS_PAF));
00329 #else
00330 bug_if(paflist == NULL);
00331 #endif
00332
00333 end_skip;
00334
00335 return cpl_error_get_code();
00336
00337 }