37#include "visir_recipe.h"
38#include "visir_spectro.h"
39#include "visir_spc_distortion.h"
40#include "visir_spc_photom.h"
46#define RECIPE_STRING "visir_old_spc_phot_ech"
49#define RECIPE_KEYS_REGEXP_ALL \
50 VISIR_PFITS_REGEXP_IMG_RECOMBINE \
51 "|" VISIR_PFITS_REGEXP_SPC_GET_RES_WL \
52 "|" VISIR_PFITS_REGEXP_SPC_SENSIT
55#define RECIPE_KEYS_REGEXP \
56 RECIPE_KEYS_REGEXP_ALL \
57 "|" VISIR_PFITS_SPC_PHOT_COPY \
58 "|" VISIR_PFITS_REGEXP_CAPA \
59 "|" VISIR_PFITS_REGEXP_SPC_PHOT_PAF
62#define RECIPE_KEYS_REGEXP_WCS \
64 "|" IRPLIB_PFITS_WCS_REGEXP
70static cpl_error_code visir_spc_phot_ech_save(cpl_frameset *,
71 const cpl_parameterlist *,
72 const cpl_propertylist *,
73 const cpl_propertylist *,
78VISIR_RECIPE_DEFINE(visir_old_spc_phot_ech,
79 VISIR_PARAM_EMIS_TOL |
80 VISIR_PARAM_ZERODIST | VISIR_PARAM_ORDEROFF |
81 VISIR_PARAM_REFINE | VISIR_PARAM_XCORR |
82 VISIR_PARAM_OFFSETS | VISIR_PARAM_OBJECTS |
83 VISIR_PARAM_NODPOS | VISIR_PARAM_AUTOBPM |
84 VISIR_PARAM_GLITCH | VISIR_PARAM_PURGE |
85 VISIR_PARAM_UNION | VISIR_PARAM_REJECT |
86 VISIR_PARAM_STRIPITE | VISIR_PARAM_STRIPMOR |
87 VISIR_PARAM_PLOT | VISIR_PARAM_SLITSKEW |
88 VISIR_PARAM_SPECSKEW | VISIR_PARAM_VERTARC |
89 VISIR_PARAM_REJLEFT | VISIR_PARAM_REJRIGHT |
90 VISIR_PARAM_HORIARC | VISIR_PARAM_FIXCOMBI |
91 VISIR_PARAM_GAIN | VISIR_PARAM_RONOISE |
92 VISIR_PARAM_OXSIGMA | VISIR_PARAM_OXNITER |
93 VISIR_PARAM_OXSMOOTH | VISIR_PARAM_OXKERNEL,
94 "Old DRS detector: Sensitivity computation in echelle spectroscopy",
95 "This recipe estimates the dispersion relation using the "
96 "atmospheric spectrum\n"
97 "in a echelle spectroscopy half-cycle frame.\n"
98 "It also extracts the spectrum of an observed object "
99 "using a combined frame.\n"
100 "Lastly, it computes the spectral photometry of an "
101 "observed standard star.\n"
102 "The files listed in the Set Of Frames (sof-file) "
104 "VISIR-Echelle-Spectroscopy-file.fits "
105 VISIR_SPC_PHOT_ECH_RAW
"\n"
106 "VISIR-Quantum-Efficiency-Calibration-file.fits "
107 VISIR_CALIB_QEFF_SPC
"\n"
108 "VISIR-Atmospheric-Emission-Lines-Calibration-file.fits "
109 VISIR_CALIB_LINES_SPC
111 "VISIR-Spectroscopic-Standard-Star-Catalog.fits "
112 VISIR_CALIB_STDSTAR_SPC
"\n"
113 MAN_VISIR_CALIB_BPM_SPC);
133static int visir_old_spc_phot_ech(cpl_frameset * framelist,
134 const cpl_parameterlist * parlist)
136 irplib_framelist * allframes = NULL;
137 irplib_framelist * rawframes = NULL;
138 cpl_propertylist * qclist = cpl_propertylist_new();
139 cpl_propertylist * paflist = cpl_propertylist_new();
141 const char * star_cat;
142 const char * spc_cal_qeff;
143 const char * spc_cal_lines;
145 cpl_image ** combinedpair = NULL;
146 cpl_image * combined = NULL;
147 cpl_table * tab = NULL;
148 cpl_image * weight2d = NULL;
149 double wlen, slitw, temp, fwhm;
150 visir_spc_resol resol;
151 visir_spc_config config;
152 cpl_boolean drop_wcs;
153 const char * keys_regexp =
"^(" RECIPE_KEYS_REGEXP_WCS
154 "|" VISIR_PFITS_REGEXP_DIT
156 const char * dit_key = VISIR_PFITS_DOUBLE_DIT;
158 config.recipename = RECIPE_STRING;
159 config.parlist = parlist;
163 parlist, RECIPE_STRING, VISIR_PARAM_FIXCOMBI);
165 parlist, RECIPE_STRING, VISIR_PARAM_PLOT);
167 parlist, RECIPE_STRING, VISIR_PARAM_SLITSKEW);
169 parlist, RECIPE_STRING, VISIR_PARAM_SPECSKEW);
171 parlist, RECIPE_STRING, VISIR_PARAM_VERTARC);
173 parlist, RECIPE_STRING, VISIR_PARAM_HORIARC);
175 parlist, RECIPE_STRING, VISIR_PARAM_GAIN);
177 parlist, RECIPE_STRING, VISIR_PARAM_RONOISE);
179 parlist, RECIPE_STRING, VISIR_PARAM_OXSIGMA);
181 parlist, RECIPE_STRING, VISIR_PARAM_OXNITER);
183 parlist, RECIPE_STRING, VISIR_PARAM_OXSMOOTH);
185 parlist, RECIPE_STRING, VISIR_PARAM_OXKERNEL);
187 parlist, RECIPE_STRING, VISIR_PARAM_ORDEROFF);
189 parlist, RECIPE_STRING, VISIR_PARAM_EMIS_TOL);
190 config.bkgcorrect = CPL_FALSE;
198 allframes = irplib_framelist_cast(framelist);
199 skip_if (allframes == NULL);
200 rawframes = irplib_framelist_extract(allframes, VISIR_SPC_PHOT_ECH_RAW);
201 skip_if (rawframes == NULL);
203 irplib_framelist_empty(allframes);
205 skip_if(irplib_framelist_load_propertylist(rawframes, 0, 0, keys_regexp,
208 skip_if(irplib_framelist_load_propertylist_all(rawframes, 0,
".*", CPL_FALSE));
212 if (cpl_propertylist_has(irplib_framelist_get_propertylist(rawframes, 0),
213 VISIR_PFITS_DOUBLE_SEQ1_DIT))
214 dit_key = VISIR_PFITS_DOUBLE_SEQ1_DIT;
218 star_cat = irplib_frameset_find_file(framelist, VISIR_CALIB_STDSTAR_SPC);
219 if (star_cat == NULL) {
220 cpl_msg_error(cpl_func,
"The file with the star catalog is missing");
225 spc_cal_qeff = irplib_frameset_find_file(framelist, VISIR_CALIB_QEFF_SPC);
228 spc_cal_lines = irplib_frameset_find_file(framelist, VISIR_CALIB_LINES_SPC);
231 badpix = irplib_frameset_find_file(framelist, VISIR_CALIB_BPM);
234 flat = irplib_frameset_find_file(framelist, VISIR_CALIB_FLAT);
237 resol = visir_spc_get_res_wl(rawframes, &wlen, &slitw, &temp, &fwhm, 0);
241 if (resol != VISIR_SPC_R_GHR) {
242 if (config.orderoffset == 0) {
243 cpl_msg_warning(cpl_func,
"Reducing non-HR Grism data as main order");
245 cpl_msg_error(cpl_func,
"This recipe cannot reduce non-HR Grism "
246 "data with an order-offset of %d",
248 visir_error_set(CPL_ERROR_TYPE_MISMATCH);
255 flat, CPL_GEOM_FIRST, &drop_wcs,
256 !config.do_fixcombi, wlen, resol);
258 if (combinedpair == NULL) {
259 cpl_msg_error(cpl_func,
"Could not combine the input frames");
263 cpl_image_delete(combinedpair[1]);
264 combined = cpl_image_cast(combinedpair[0], CPL_TYPE_DOUBLE);
265 cpl_image_delete(combinedpair[0]);
270 cpl_msg_info(cpl_func,
"Compute the sensitivity");
273 star_cat, spc_cal_lines,
274 spc_cal_qeff, &weight2d, qclist,
275 CPL_TRUE, wlen, slitw, temp, fwhm,
279 cpl_msg_error(cpl_func,
"Cannot compute sensitivity: '%s' in %s",
280 cpl_error_get_message(), cpl_error_get_where());
284 bug_if (visir_spectro_qc(qclist, paflist, drop_wcs, rawframes,
285 "^(" VISIR_PFITS_SPC_PHOT_COPY
")$",
286 "^(" VISIR_PFITS_REGEXP_SPC_PHOT_PAF
")$"));
287 irplib_framelist_empty(rawframes);
290 cpl_msg_info(cpl_func,
"Save the results");
293 bug_if (cpl_propertylist_append_string(paflist, CPL_DFS_PRO_CATG,
294 VISIR_SPC_PHOT_ECH_COMBINED_PROCATG));
296 skip_if (visir_spc_phot_ech_save(framelist, parlist, qclist, paflist,
297 combined, weight2d, tab));
301 cpl_propertylist_delete(qclist);
302 cpl_propertylist_delete(paflist);
303 irplib_framelist_delete(allframes);
304 irplib_framelist_delete(rawframes);
305 cpl_image_delete(combined);
306 cpl_table_delete(tab);
307 cpl_image_delete(weight2d);
309 cpl_free(combinedpair);
311 return cpl_error_get_code();
327static cpl_error_code visir_spc_phot_ech_save(cpl_frameset * set,
328 const cpl_parameterlist * parlist,
329 const cpl_propertylist * qclist,
330 const cpl_propertylist * paflist,
331 const cpl_image *combined,
332 const cpl_image *weight2d,
333 const cpl_table * table)
338 skip_if (irplib_dfs_save_table(set, parlist, set, table, NULL, RECIPE_STRING,
339 VISIR_SPC_PHOT_ECH_TAB_PROCATG,
340 qclist, NULL, visir_pipe_id,
341 RECIPE_STRING
"_tab" CPL_DFS_FITS));
344 skip_if (irplib_dfs_save_image(set, parlist, set, combined, CPL_BPP_IEEE_FLOAT,
345 RECIPE_STRING, VISIR_SPC_PHOT_ECH_COMBINED_PROCATG,
346 qclist, NULL, visir_pipe_id,
347 RECIPE_STRING CPL_DFS_FITS));
350 skip_if (irplib_dfs_save_image(set, parlist, set, weight2d, CPL_BPP_IEEE_FLOAT,
351 RECIPE_STRING, VISIR_SPC_PHOT_ECH_WEIGHT_PROCATG,
352 qclist, NULL, visir_pipe_id,
353 RECIPE_STRING
"_weight" CPL_DFS_FITS));
357 skip_if (cpl_dfs_save_paf(
"VISIR", RECIPE_STRING, paflist,
358 RECIPE_STRING CPL_DFS_PAF));
360 bug_if(paflist == NULL);
365 return cpl_error_get_code();
cpl_error_code visir_dfs_check_framelist_tag(const irplib_framelist *self)
Check the tags in a frameset (group raw only)
int visir_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
int visir_parameterlist_get_int(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR integer parameter.
double visir_parameterlist_get_double(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR parameter of type double.
cpl_boolean visir_parameterlist_get_bool(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR boolean parameter.
cpl_table * visir_spc_phot_sensit_from_image(cpl_image **combined, const irplib_framelist *rawframes, const visir_spc_config *pconfig, const char *star_cat, const char *spc_cal_lines, const char *spc_cal_qeff, cpl_image **pweight2d, cpl_propertylist *qclist, cpl_boolean do_ech, double wlen, double slitw, double temp, double fwhm, const visir_spc_resol resol, const char *dit_key)
Extract spectrum from image and compute sensitivity.