70"This recipe is associated to the template gravity_wavelamp.\n"
71"It reduces the raw file obtained with the Argon lamp (WAVELAMP) and process it so that it can be used to calibrate the fiber dispersion (recipe gravity_disp).\n"
73 "* Extract the spectra of the Argon exposure\n"
74 "* Interpolate the spectra into a common wavelength table\n"
75 "* Measure the wavelength position of known Argon lines\n"
76 "* Write the product\n"
105 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe );
106 cpl_plugin * plugin = &recipe->interface;
108 if (cpl_plugin_init(plugin,
110 GRAVI_BINARY_VERSION,
111 CPL_PLUGIN_TYPE_RECIPE,
115 "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
121 cpl_msg_error(cpl_func,
"Plugin initialization failed");
122 (void)cpl_error_set_where(cpl_func);
126 if (cpl_pluginlist_append(list, plugin)) {
127 cpl_msg_error(cpl_func,
"Error adding plugin to list");
128 (void)cpl_error_set_where(cpl_func);
149 if (cpl_error_get_code() != CPL_ERROR_NONE) {
150 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
151 cpl_func, __LINE__, cpl_error_get_where());
152 return (
int)cpl_error_get_code();
155 if (plugin == NULL) {
156 cpl_msg_error(cpl_func,
"Null plugin");
157 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
161 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
162 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
163 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
167 recipe = (cpl_recipe *)plugin;
170 recipe->parameters = cpl_parameterlist_new();
171 if (recipe->parameters == NULL) {
172 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
173 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
194 cpl_errorstate initial_errorstate = cpl_errorstate_get();
197 if (cpl_error_get_code() != CPL_ERROR_NONE) {
198 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
199 cpl_func, __LINE__, cpl_error_get_where());
200 return (
int)cpl_error_get_code();
203 if (plugin == NULL) {
204 cpl_msg_error(cpl_func,
"Null plugin");
205 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
209 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
210 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
211 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
215 recipe = (cpl_recipe *)plugin;
218 if (recipe->parameters == NULL) {
219 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
220 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
222 if (recipe->frames == NULL) {
223 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
224 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
232 if (cpl_dfs_update_product_header(recipe->frames)) {
234 recipe_status = (int)cpl_error_get_code();
238 if (!cpl_errorstate_is_equal(initial_errorstate)) {
241 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
244 return recipe_status;
258 if (plugin == NULL) {
259 cpl_msg_error(cpl_func,
"Null plugin");
260 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
264 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
265 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
266 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
270 recipe = (cpl_recipe *)plugin;
272 cpl_parameterlist_delete(recipe->parameters);
288 const cpl_parameterlist * parlist)
290 cpl_frameset * wavecalib_frameset = NULL,
291 * badcalib_frameset = NULL, * flatcalib_frameset = NULL,
292 * p2vmcalib_frameset = NULL, * dark_frameset = NULL,
293 * wavelamp_frameset = NULL, * used_frameset = NULL,
294 * darkcalib_frameset = NULL, *wave_param_frameset= NULL;
298 gravi_data * data = NULL, * dark_map = NULL, * wave_map = NULL,
299 * profile_map = NULL, * badpix_map = NULL, * preproc_data = NULL, * p2vm_map = NULL,
307 cpl_error_get_code()) ;
321 if ( (cpl_frameset_is_empty (dark_frameset) &&
322 cpl_frameset_is_empty (darkcalib_frameset)) ||
323 cpl_frameset_is_empty (wavelamp_frameset) ||
324 cpl_frameset_is_empty (p2vmcalib_frameset) ||
325 cpl_frameset_is_empty (wavecalib_frameset) ||
326 cpl_frameset_is_empty (flatcalib_frameset) ||
327 cpl_frameset_is_empty (badcalib_frameset) ) {
329 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
330 "Mising DARK, WAVELAMP, P2VM, WAVE, FLAT or BAD") ;
335 used_frameset = cpl_frameset_new();
341 if (!cpl_frameset_is_empty (dark_frameset)) {
343 frame = cpl_frameset_get_position (dark_frameset, 0);
355 NULL, frame,
"gravity_wavelamp",
360 else if (!cpl_frameset_is_empty (darkcalib_frameset)) {
362 frame = cpl_frameset_get_position (darkcalib_frameset, 0);
368 cpl_msg_info (cpl_func,
"There is no DARK in the frame set");
372 frame = cpl_frameset_get_position (badcalib_frameset, 0);
376 frame = cpl_frameset_get_position (flatcalib_frameset, 0);
380 frame = cpl_frameset_get_position (wavecalib_frameset, 0);
384 frame = cpl_frameset_get_position (p2vmcalib_frameset, 0);
393 frame = cpl_frameset_get_position (wavelamp_frameset, 0);
410 cpl_image * img_median = cpl_imagelist_collapse_median_create (imglist);
413 cpl_imagelist_empty (imglist);
414 cpl_imagelist_set (imglist, img_median, 0);
418 badpix_map, NULL, parlist,
440 if (!cpl_frameset_is_empty (wave_param_frameset)) {
441 frame2 = cpl_frameset_get_position (wave_param_frameset, 0);
446 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
447 "Missing is no WAVE_PARAM in the frameset") ;
461 cpl_vector * wave_diff_all = cpl_vector_new(cpl_table_get_nrow(pos_argon));
462 for(
unsigned short row = 0 ; row < (
unsigned short)cpl_table_get_nrow(pos_argon) ; ++row)
467 snprintf(keyname, 39,
"ESO QC WAVE%hu", row+1);
469 1e6 * cpl_table_get_double(pos_argon,
"WAVE", row, &null));
471 snprintf(keyname, 39,
"ESO QC WAVE TH%hu", row+1);
473 1e6 * cpl_table_get_double(pos_argon,
"WAVE_TH", row, &null));
475 snprintf(keyname, 39,
"ESO QC WAVE DIFF%hu", row+1);
476 double wave_diff = 1e6 * cpl_table_get_double(pos_argon,
"DIFF", row, &null);
477 cpl_vector_set(wave_diff_all, row, wave_diff);
481 "ESO QC WAVE DIFF RMS", cpl_vector_get_stdev(wave_diff_all));
485 used_frameset, frame,
"gravity_wavelamp",
495 FREE (cpl_frameset_delete, wavelamp_frameset);
496 FREE (cpl_frameset_delete, wavecalib_frameset);
497 FREE (cpl_frameset_delete, badcalib_frameset);
498 FREE (cpl_frameset_delete, flatcalib_frameset);
499 FREE (cpl_frameset_delete, p2vmcalib_frameset);
500 FREE (cpl_frameset_delete, used_frameset);
501 FREE (cpl_frameset_delete, dark_frameset);
502 FREE (cpl_frameset_delete, darkcalib_frameset);
503 FREE (cpl_frameset_delete, wave_param_frameset);
514 return (
int)cpl_error_get_code();
typedefCPL_BEGIN_DECLS struct _gravi_data_ gravi_data
#define gravi_data_get_header(data)
#define GRAVI_RECIPE_OUTPUT
#define GRAVI_RECIPE_FLOW
#define GRAVI_WAVELAMP_MAP
#define GRAVI_RECIPE_INPUT
#define GRAVI_WAVELAMP_RAW
cpl_msg_info(cpl_func, "Compute WAVE_SCAN for %s", GRAVI_TYPE(type_data))
cpl_propertylist_update_double(header, "ESO QC MINWAVE SC", cpl_propertylist_get_double(plist, "ESO QC MINWAVE SC"))
#define GRAVI_IMAGING_DATA_SC_EXT
#define GRAVI_IMAGING_DETECTOR_SC_EXT
#define CPLCHECK_CLEAN(msg)
#define gravi_msg_function_exit(flag)
#define FREE(function, variable)
#define gravi_msg_function_start(flag)
static char gravity_wavelamp_description[]
static int gravity_wavelamp_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int gravity_wavelamp_create(cpl_plugin *)
Setup the recipe options
static int gravity_wavelamp_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static int gravity_wavelamp(cpl_frameset *, const cpl_parameterlist *)
The perpese of the recipe is to reduce the raw calibration file for dispersion calibration.
static char gravity_wavelamp_short[]
gravi_data * gravi_compute_dark(gravi_data *raw_data)
Compute the DARK calibration map.
gravi_data * gravi_data_new(int nb_ext)
Create an empty gravi_data.
gravi_data * gravi_data_load_frame(cpl_frame *frame, cpl_frameset *used_frameset)
Load a FITS file and create a gravi_data.
cpl_error_code gravi_data_detector_cleanup(gravi_data *data, const cpl_parameterlist *parlist)
Perform self-bias correction to the SC raw data.
cpl_imagelist * gravi_data_get_cube(gravi_data *self, const char *extname)
Return a pointer on an IMAGE extension by its EXTNAME.
cpl_table * gravi_data_get_table(gravi_data *self, const char *extname)
Return a pointer on a table extension by its EXTNAME.
gravi_data * gravi_data_load_rawframe(cpl_frame *frame, cpl_frameset *used_frameset)
Load a RAW FITS file and create a gravi_data.
cpl_error_code gravi_data_save_new(gravi_data *self, cpl_frameset *allframes, const char *filename, const char *suffix, const cpl_parameterlist *parlist, cpl_frameset *usedframes, cpl_frame *frame, const char *recipe, cpl_propertylist *applist, const char *proCatg)
Save a gravi data in a CPL-complian FITS file.
cpl_error_code gravi_data_copy_ext(gravi_data *output, gravi_data *input, const char *name)
Copy extensions from one data to another.
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
cpl_parameter * gravi_parameter_add_static_name(cpl_parameterlist *self)
cpl_frameset * gravi_frameset_extract_wave_map(cpl_frameset *frameset)
cpl_frameset * gravi_frameset_extract_bad_map(cpl_frameset *frameset)
cpl_frameset * gravi_frameset_extract_dark_map(cpl_frameset *frameset)
cpl_error_code gravi_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
cpl_frameset * gravi_frameset_extract_p2vm_map(cpl_frameset *frameset)
cpl_frameset * gravi_frameset_extract_wave_param(cpl_frameset *frameset)
cpl_frameset * gravi_frameset_extract_wavelamp_data(cpl_frameset *frameset)
cpl_frameset * gravi_frameset_extract_flat_map(cpl_frameset *frameset)
void gravity_print_banner(void)
cpl_frameset * gravi_frameset_extract_dark_data(cpl_frameset *frameset)
Extract DARK_RAW frame from the input frameset.
cpl_error_code gravi_compute_argon_pos(gravi_data *preproc_data, gravi_data *wave_param)
Compute position of argon lines in SC spectrum.
cpl_error_code gravi_align_spectrum(gravi_data *spectrum_data, gravi_data *wave_map, gravi_data *p2vm_map, enum gravi_detector_type det_type)
Regrid the regions into a common wavelength (in-place)
gravi_data * gravi_extract_spectrum(gravi_data *raw_data, gravi_data *profile_map, gravi_data *dark_map, gravi_data *bad_map, gravi_data *sky_map, const cpl_parameterlist *parlist, enum gravi_detector_type det_type)
Create the SPECTRUM gravi_data with extracted spectrum per region.
const char * gravi_get_license(void)
Get the pipeline copyright and license.