36 #include "visir_recipe.h"
37 #include "visir_spectro.h"
38 #include "visir_spc_distortion.h"
45 #define RECIPE_STRING "visir_old_spc_wcal"
50 static cpl_error_code visir_spc_wcal_save(cpl_frameset *,
51 const cpl_parameterlist *,
52 const cpl_propertylist *,
53 const cpl_propertylist *,
56 VISIR_RECIPE_DEFINE(visir_old_spc_wcal,
58 VISIR_PARAM_PLOT | VISIR_PARAM_SLITSKEW |
59 VISIR_PARAM_SPECSKEW | VISIR_PARAM_VERTARC |
60 VISIR_PARAM_REJLEFT | VISIR_PARAM_REJRIGHT |
62 "Old DRS detector: Spectroscopic wavelength calibration recipe",
63 "This recipe estimates the dispersion relation using the "
64 "atmospheric spectrum\n"
65 "in a long-slit spectroscopy half-cycle frame.\n"
66 "The files listed in the Set Of Frames (sof-file) "
68 "VISIR-Long-Slit-Spectroscopy-file.fits "
69 VISIR_SPC_WCAL_RAW
"\n"
70 "VISIR-Quantum-Efficiency-Calibration-file.fits "
71 VISIR_CALIB_QEFF_SPC
"\n"
72 "VISIR-Atmospheric-Emission-Lines-Calibration-file.fits "
75 MAN_VISIR_CALIB_BPM_SPC);
90 } visir_spc_wcal_config;
110 static int visir_old_spc_wcal(cpl_frameset * framelist,
111 const cpl_parameterlist * parlist)
113 irplib_framelist * allframes = NULL;
114 irplib_framelist * rawframes = NULL;
115 cpl_propertylist * qclist = cpl_propertylist_new();
116 cpl_propertylist * paflist = cpl_propertylist_new();
117 const char * spc_cal_qeff;
118 const char * spc_cal_lines;
119 cpl_imagelist * hcycle = NULL;
120 cpl_image * imhcycle = NULL;
121 cpl_image * flipped = NULL;
122 cpl_image * imhcyclenarrow = NULL;
123 cpl_table * spc_table = NULL;
124 double wlen, slitw, temp, fwhm;
125 visir_spc_resol resol;
130 visir_spc_wcal_config.auto_bpm =
134 visir_spc_wcal_config.phi =
136 visir_spc_wcal_config.ksi =
138 visir_spc_wcal_config.eps =
140 visir_spc_wcal_config.delta =
144 VISIR_PARAM_REJLEFT);
146 VISIR_PARAM_REJRIGHT);
155 skip_if(allframes == NULL);
157 skip_if (rawframes == NULL);
172 resol = visir_spc_get_res_wl(rawframes, &wlen, &slitw, &temp, &fwhm, 0);
176 if (resol == VISIR_SPC_R_GHR) {
177 cpl_msg_error(cpl_func,
"This recipe cannot reduce HR Grism data");
178 visir_error_set(CPL_ERROR_TYPE_MISMATCH);
182 skip_if(visir_qc_append_background(qclist, rawframes, 0, 0));
188 imhcycle = cpl_imagelist_unset(hcycle, 0);
191 flipped = visir_spc_flip(imhcycle, wlen, resol, VISIR_DATA_CUBE2);
193 cpl_image_delete(imhcycle);
197 skip_if (visir_spc_det_fix(&imhcycle, 1, CPL_FALSE,
199 visir_spc_wcal_config.phi,
200 visir_spc_wcal_config.ksi,
201 visir_spc_wcal_config.eps,
202 visir_spc_wcal_config.delta,
203 visir_spc_wcal_config.plot));
206 icol2 = cpl_image_get_size_x(imhcycle);
209 cpl_msg_info(cpl_func,
"Ignoring %d leftmost columns", jcol1);
213 cpl_msg_info(cpl_func,
"Ignoring %d rightmost columns", jcol2);
217 if (jcol1 != 0 || jcol2 != 0) {
218 imhcyclenarrow = visir_spc_column_extract(imhcycle, icol1, icol2,
219 visir_spc_wcal_config.plot);
223 imhcyclenarrow = imhcycle;
226 skip_if (visir_spc_wavecal(imhcyclenarrow, qclist, wlen, slitw, temp, fwhm,
228 spc_cal_lines, spc_cal_qeff,
229 &spc_table, visir_spc_wcal_config.plot, 0));
232 skip_if (cpl_table_erase_column(spc_table,
"SPC_EMISSIVITY"));
234 bug_if (visir_spectro_qc(qclist, paflist, CPL_FALSE, rawframes, NULL,
235 "^(" VISIR_PFITS_REGEXP_SPC_WCAL_PAF
")$"));
239 cpl_msg_info(cpl_func,
"Saving the produced spectrum");
242 bug_if (cpl_propertylist_append_string(paflist, CPL_DFS_PRO_CATG,
243 VISIR_SPC_WCAL_TAB_PROCATG));
245 skip_if (visir_spc_wcal_save(framelist, parlist, qclist, paflist, spc_table));
249 cpl_propertylist_delete(qclist);
250 cpl_propertylist_delete(paflist);
253 cpl_table_delete(spc_table);
254 cpl_imagelist_delete(hcycle);
255 if (imhcyclenarrow != imhcycle) cpl_image_delete(imhcyclenarrow);
256 cpl_image_delete(imhcycle);
257 cpl_image_delete(flipped);
259 return cpl_error_get_code();
273 static cpl_error_code visir_spc_wcal_save(cpl_frameset * set,
274 const cpl_parameterlist * parlist,
275 const cpl_propertylist * qclist,
276 const cpl_propertylist * paflist,
277 const cpl_table * table)
283 VISIR_SPC_WCAL_TAB_PROCATG,
284 qclist, NULL, visir_pipe_id,
285 RECIPE_STRING
"_spectrum_tab" CPL_DFS_FITS));
287 #ifdef VISIR_SAVE_PAF
289 skip_if (cpl_dfs_save_paf(
"VISIR", RECIPE_STRING, paflist,
290 RECIPE_STRING CPL_DFS_PAF));
292 bug_if(paflist == NULL);
297 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_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.
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.
irplib_framelist * irplib_framelist_cast(const cpl_frameset *frameset)
Create an irplib_framelist from a cpl_framelist.