36 #include "visir_recipe.h"
37 #include "visir_spectro.h"
38 #include "visir_spc_distortion.h"
39 #include "visir_spc_photom.h"
47 #define RECIPE_STRING "visir_old_spc_phot"
50 #define RECIPE_KEYS_REGEXP_ALL \
51 VISIR_PFITS_REGEXP_IMG_RECOMBINE \
52 "|" VISIR_PFITS_REGEXP_SPC_GET_RES_WL \
53 "|" VISIR_PFITS_REGEXP_SPC_SENSIT
56 #define RECIPE_KEYS_REGEXP \
57 RECIPE_KEYS_REGEXP_ALL \
58 "|" VISIR_PFITS_SPC_PHOT_COPY \
59 "|" VISIR_PFITS_REGEXP_CAPA \
60 "|" VISIR_PFITS_REGEXP_SPC_PHOT_PAF
63 #define RECIPE_KEYS_REGEXP_WCS \
65 "|" IRPLIB_PFITS_WCS_REGEXP
70 static cpl_error_code visir_spc_phot_save(cpl_frameset *,
71 const cpl_parameterlist *,
72 const cpl_propertylist *,
73 const cpl_propertylist *,
78 VISIR_RECIPE_DEFINE(visir_old_spc_phot,
79 VISIR_PARAM_EMIS_TOL |
80 VISIR_PARAM_REFINE | VISIR_PARAM_XCORR |
81 VISIR_PARAM_OFFSETS | VISIR_PARAM_OBJECTS |
82 VISIR_PARAM_NODPOS | VISIR_PARAM_AUTOBPM |
83 VISIR_PARAM_GLITCH | VISIR_PARAM_PURGE |
84 VISIR_PARAM_UNION | VISIR_PARAM_REJECT |
85 VISIR_PARAM_STRIPITE | VISIR_PARAM_STRIPMOR |
86 VISIR_PARAM_PLOT | VISIR_PARAM_SLITSKEW |
87 VISIR_PARAM_SPECSKEW | VISIR_PARAM_VERTARC |
88 VISIR_PARAM_REJLEFT | VISIR_PARAM_REJRIGHT |
89 VISIR_PARAM_HORIARC | VISIR_PARAM_FIXCOMBI,
90 "Old DRS detector: Sensitivity computation in spectroscopy",
91 "This recipe estimates the dispersion relation using the "
92 "atmospheric spectrum\n"
93 "in a long-slit spectroscopy half-cycle frame.\n"
94 "It also extracts the spectrum of an observed object "
95 "using a combined frame.\n"
96 "Lastly, it computes the spectral photometry of an "
97 "observed standard star.\n"
98 "The files listed in the Set Of Frames (sof-file) "
100 "VISIR-Long-Slit-Spectroscopy-file.fits "
101 VISIR_SPC_PHOT_RAW
"\n"
102 "VISIR-Quantum-Efficiency-Calibration-file.fits "
103 VISIR_CALIB_QEFF_SPC
"\n"
104 "VISIR-Atmospheric-Emission-Lines-Calibration-file.fits "
105 VISIR_CALIB_LINES_SPC
107 "VISIR-Spectroscopic-Standard-Star-Catalog.fits "
108 VISIR_CALIB_STDSTAR_SPC
"\n"
109 MAN_VISIR_CALIB_BPM_SPC);
129 static int visir_old_spc_phot(cpl_frameset * framelist,
130 const cpl_parameterlist * parlist)
132 irplib_framelist * allframes = NULL;
133 irplib_framelist * rawframes = NULL;
134 cpl_propertylist * qclist = cpl_propertylist_new();
135 cpl_propertylist * paflist = cpl_propertylist_new();
137 const char * star_cat;
138 const char * spc_cal_qeff;
139 const char * spc_cal_lines;
141 cpl_image ** combinedpair = NULL;
142 cpl_image * combined = NULL;
143 cpl_table * tab = NULL;
144 cpl_image * weight2d = NULL;
145 double wlen, slitw, temp, fwhm;
146 visir_spc_resol resol;
148 cpl_boolean drop_wcs;
149 const char * keys_regexp =
"^(" RECIPE_KEYS_REGEXP_WCS
150 "|" VISIR_PFITS_REGEXP_DIT
152 const char * dit_key = VISIR_PFITS_DOUBLE_DIT;
155 config.recipename = RECIPE_STRING;
156 config.parlist = parlist;
157 config.orderoffset = 0;
175 config.phot_emis_tol =
185 skip_if(allframes == NULL);
187 skip_if (rawframes == NULL);
195 RECIPE_KEYS_REGEXP_ALL
196 "|" VISIR_PFITS_REGEXP_DIT
203 VISIR_PFITS_DOUBLE_SEQ1_DIT))
204 dit_key = VISIR_PFITS_DOUBLE_SEQ1_DIT;
209 if (star_cat == NULL) {
210 cpl_msg_error(cpl_func,
"The file with the star catalog is missing");
214 visir_data_type data_type;
217 skip_if(visir_get_data_type(frm, plist, &data_type, NULL));
232 resol = visir_spc_get_res_wl(rawframes, &wlen, &slitw, &temp, &fwhm,
233 visir_data_is_aqu(data_type));
237 if (resol == VISIR_SPC_R_GHR) {
238 cpl_msg_error(cpl_func,
"This recipe cannot reduce HR Grism data");
239 visir_error_set(CPL_ERROR_TYPE_MISMATCH);
245 flat, CPL_GEOM_FIRST, &drop_wcs,
246 !config.do_fixcombi, wlen, resol);
248 if (combinedpair == NULL) {
249 cpl_msg_error(cpl_func,
"Could not combine the input frames");
253 cpl_image_delete(combinedpair[1]);
254 combined = cpl_image_cast(combinedpair[0], CPL_TYPE_DOUBLE);
255 cpl_image_delete(combinedpair[0]);
260 cpl_msg_info(cpl_func,
"Compute the sensitivity");
262 star_cat, spc_cal_lines,
263 spc_cal_qeff, &weight2d, qclist,
264 CPL_FALSE, wlen, slitw, temp, fwhm,
268 cpl_msg_error(cpl_func,
"Cannot compute sensitivity: '%s' in %s",
269 cpl_error_get_message(), cpl_error_get_where());
273 bug_if (visir_spectro_qc(qclist, paflist, drop_wcs, rawframes,
274 "^(" VISIR_PFITS_SPC_PHOT_COPY
")$",
275 "^(" VISIR_PFITS_REGEXP_SPC_PHOT_PAF
")$"));
279 cpl_msg_info(cpl_func,
"Save the results");
282 bug_if (cpl_propertylist_append_string(paflist, CPL_DFS_PRO_CATG,
283 VISIR_SPC_PHOT_COMBINED_PROCATG));
285 skip_if (visir_spc_phot_save(framelist, parlist, qclist, paflist,
286 combined, weight2d, tab));
290 cpl_propertylist_delete(qclist);
291 cpl_propertylist_delete(paflist);
294 cpl_image_delete(combined);
295 cpl_table_delete(tab);
296 cpl_image_delete(weight2d);
298 cpl_free(combinedpair);
300 return cpl_error_get_code();
316 static cpl_error_code visir_spc_phot_save(cpl_frameset * set,
317 const cpl_parameterlist * parlist,
318 const cpl_propertylist * qclist,
319 const cpl_propertylist * paflist,
320 const cpl_image * combined,
321 const cpl_image * weight2d,
322 const cpl_table * table)
329 VISIR_SPC_PHOT_TAB_PROCATG,
330 qclist, NULL, visir_pipe_id,
331 RECIPE_STRING
"_tab" CPL_DFS_FITS));
335 RECIPE_STRING, VISIR_SPC_PHOT_COMBINED_PROCATG,
336 qclist, NULL, visir_pipe_id,
337 RECIPE_STRING CPL_DFS_FITS));
341 RECIPE_STRING, VISIR_SPC_PHOT_WEIGHT_PROCATG,
342 qclist, NULL, visir_pipe_id,
343 RECIPE_STRING
"_weight" CPL_DFS_FITS));
345 #ifdef VISIR_SAVE_PAF
348 skip_if (cpl_dfs_save_paf(
"VISIR", RECIPE_STRING, paflist,
349 RECIPE_STRING CPL_DFS_PAF));
351 bug_if(paflist == NULL);
356 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.
const cpl_frame * irplib_framelist_get_const(const irplib_framelist *self, int pos)
Get the specified frame from the framelist.
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.