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
70 static cpl_error_code visir_spc_phot_ech_save(cpl_frameset *,
71 const cpl_parameterlist *,
72 const cpl_propertylist *,
73 const cpl_propertylist *,
78 VISIR_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 "Old DRS detector: Sensitivity computation in echelle spectroscopy",
92 "This recipe estimates the dispersion relation using the "
93 "atmospheric spectrum\n"
94 "in a echelle spectroscopy half-cycle frame.\n"
95 "It also extracts the spectrum of an observed object "
96 "using a combined frame.\n"
97 "Lastly, it computes the spectral photometry of an "
98 "observed standard star.\n"
99 "The files listed in the Set Of Frames (sof-file) "
101 "VISIR-Echelle-Spectroscopy-file.fits "
102 VISIR_SPC_PHOT_ECH_RAW
"\n"
103 "VISIR-Quantum-Efficiency-Calibration-file.fits "
104 VISIR_CALIB_QEFF_SPC
"\n"
105 "VISIR-Atmospheric-Emission-Lines-Calibration-file.fits "
106 VISIR_CALIB_LINES_SPC
108 "VISIR-Spectroscopic-Standard-Star-Catalog.fits "
109 VISIR_CALIB_STDSTAR_SPC
"\n"
110 MAN_VISIR_CALIB_BPM_SPC);
130 static int visir_old_spc_phot_ech(cpl_frameset * framelist,
131 const cpl_parameterlist * parlist)
133 irplib_framelist * allframes = NULL;
134 irplib_framelist * rawframes = NULL;
135 cpl_propertylist * qclist = cpl_propertylist_new();
136 cpl_propertylist * paflist = cpl_propertylist_new();
138 const char * star_cat;
139 const char * spc_cal_qeff;
140 const char * spc_cal_lines;
142 cpl_image ** combinedpair = NULL;
143 cpl_image * combined = NULL;
144 cpl_table * tab = NULL;
145 cpl_image * weight2d = NULL;
146 double wlen, slitw, temp, fwhm;
147 visir_spc_resol resol;
149 cpl_boolean drop_wcs;
150 const char * keys_regexp =
"^(" RECIPE_KEYS_REGEXP_WCS
151 "|" VISIR_PFITS_REGEXP_DIT
153 const char * dit_key = VISIR_PFITS_DOUBLE_DIT;
155 config.recipename = RECIPE_STRING;
156 config.parlist = parlist;
177 config.phot_emis_tol =
187 skip_if(allframes == NULL);
189 skip_if (rawframes == NULL);
201 VISIR_PFITS_DOUBLE_SEQ1_DIT))
202 dit_key = VISIR_PFITS_DOUBLE_SEQ1_DIT;
207 if (star_cat == NULL) {
208 cpl_msg_error(cpl_func,
"The file with the star catalog is missing");
225 resol = visir_spc_get_res_wl(rawframes, &wlen, &slitw, &temp, &fwhm, 0);
229 if (resol != VISIR_SPC_R_GHR) {
230 if (config.orderoffset == 0) {
231 cpl_msg_warning(cpl_func,
"Reducing non-HR Grism data as main order");
233 cpl_msg_error(cpl_func,
"This recipe cannot reduce non-HR Grism "
234 "data with an order-offset of %d",
236 visir_error_set(CPL_ERROR_TYPE_MISMATCH);
243 flat, CPL_GEOM_FIRST, &drop_wcs,
244 !config.do_fixcombi, wlen, resol);
246 if (combinedpair == NULL) {
247 cpl_msg_error(cpl_func,
"Could not combine the input frames");
251 cpl_image_delete(combinedpair[1]);
252 combined = cpl_image_cast(combinedpair[0], CPL_TYPE_DOUBLE);
253 cpl_image_delete(combinedpair[0]);
258 cpl_msg_info(cpl_func,
"Compute the sensitivity");
260 star_cat, spc_cal_lines,
261 spc_cal_qeff, &weight2d, qclist,
262 CPL_TRUE, wlen, slitw, temp, fwhm,
266 cpl_msg_error(cpl_func,
"Cannot compute sensitivity: '%s' in %s",
267 cpl_error_get_message(), cpl_error_get_where());
271 bug_if (visir_spectro_qc(qclist, paflist, drop_wcs, rawframes,
272 "^(" VISIR_PFITS_SPC_PHOT_COPY
")$",
273 "^(" VISIR_PFITS_REGEXP_SPC_PHOT_PAF
")$"));
277 cpl_msg_info(cpl_func,
"Save the results");
280 bug_if (cpl_propertylist_append_string(paflist, CPL_DFS_PRO_CATG,
281 VISIR_SPC_PHOT_ECH_COMBINED_PROCATG));
283 skip_if (visir_spc_phot_ech_save(framelist, parlist, qclist, paflist,
284 combined, weight2d, tab));
288 cpl_propertylist_delete(qclist);
289 cpl_propertylist_delete(paflist);
292 cpl_image_delete(combined);
293 cpl_table_delete(tab);
294 cpl_image_delete(weight2d);
296 cpl_free(combinedpair);
298 return cpl_error_get_code();
314 static cpl_error_code visir_spc_phot_ech_save(cpl_frameset * set,
315 const cpl_parameterlist * parlist,
316 const cpl_propertylist * qclist,
317 const cpl_propertylist * paflist,
318 const cpl_image *combined,
319 const cpl_image *weight2d,
320 const cpl_table * table)
326 VISIR_SPC_PHOT_ECH_TAB_PROCATG,
327 qclist, NULL, visir_pipe_id,
328 RECIPE_STRING
"_tab" CPL_DFS_FITS));
332 RECIPE_STRING, VISIR_SPC_PHOT_ECH_COMBINED_PROCATG,
333 qclist, NULL, visir_pipe_id,
334 RECIPE_STRING CPL_DFS_FITS));
338 RECIPE_STRING, VISIR_SPC_PHOT_ECH_WEIGHT_PROCATG,
339 qclist, NULL, visir_pipe_id,
340 RECIPE_STRING
"_weight" CPL_DFS_FITS));
342 #ifdef VISIR_SAVE_PAF
344 skip_if (cpl_dfs_save_paf(
"VISIR", RECIPE_STRING, paflist,
345 RECIPE_STRING CPL_DFS_PAF));
347 bug_if(paflist == NULL);
352 return cpl_error_get_code();
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_error_code visir_dfs_check_framelist_tag(const irplib_framelist *self)
Check the tags in a frameset (group raw only)
cpl_error_code irplib_dfs_save_table(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_table *table, const cpl_propertylist *tablelist, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)
Save a table as a DFS-compliant pipeline product.
int visir_parameterlist_get_int(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR integer parameter.
cpl_boolean visir_parameterlist_get_bool(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR boolean parameter.
void irplib_framelist_empty(irplib_framelist *self)
Erase all frames from a framelist.
cpl_error_code irplib_dfs_save_image(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_image *image, cpl_type_bpp bpp, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)
Save an image as a DFS-compliant pipeline product.
cpl_error_code irplib_framelist_load_propertylist_all(irplib_framelist *self, int ind, const char *regexp, cpl_boolean invert)
Load the propertylists of all frames in the framelist.
irplib_framelist * irplib_framelist_extract(const irplib_framelist *self, const char *tag)
Extract the frames with the given tag from a framelist.
int visir_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
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.
void irplib_framelist_delete(irplib_framelist *self)
Deallocate an irplib_framelist with its frames and properties.
const char * irplib_frameset_find_file(const cpl_frameset *self, const char *tag)
Find the filename with the given tag in a frame set.
cpl_propertylist * irplib_framelist_get_propertylist(irplib_framelist *self, int pos)
Get the propertylist of the specified frame in the framelist.
cpl_error_code irplib_framelist_load_propertylist(irplib_framelist *self, int pos, int ind, const char *regexp, cpl_boolean invert)
Load the propertylist of the specified frame in the framelist.
irplib_framelist * irplib_framelist_cast(const cpl_frameset *frameset)
Create an irplib_framelist from a cpl_framelist.