44 #include "gravi_data.h" 45 #include "gravi_pfits.h" 46 #include "gravi_dfs.h" 48 #include "gravi_utils.h" 50 #include "gravi_calib.h" 51 #include "gravi_wave.h" 52 #include "gravi_preproc.h" 53 #include "gravi_disp.h" 59 static int gravity_wavelamp_create(cpl_plugin *);
60 static int gravity_wavelamp_exec(cpl_plugin *);
61 static int gravity_wavelamp_destroy(cpl_plugin *);
62 static int gravity_wavelamp(cpl_frameset *,
const cpl_parameterlist *);
68 static char gravity_wavelamp_short[] =
"Measure the position of the Argon lines in the spectra.";
69 static char gravity_wavelamp_description[] =
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" 77 GRAVI_RECIPE_INPUT
"\n" 78 GRAVI_FLAT_MAP
" : flat calibration (PRO.CATG="GRAVI_FLAT_MAP
")\n" 79 GRAVI_BAD_MAP
" : badpixel calibration (PRO.CATG="GRAVI_BAD_MAP
") \n" 80 GRAVI_WAVE_MAP
" : wave calibration (PRO.CATG="GRAVI_WAVE_MAP
")\n" 81 GRAVI_P2VM_MAP
" : p2vm calibration (PRO.CATG="GRAVI_P2VM_MAP
")\n" 82 GRAVI_WAVELAMP_RAW
" : long exposure of Argon lamp\n" 83 GRAVI_DARK_RAW
" : dark of Argon exposure\n" 84 GRAVI_RECIPE_OUTPUT
"\n" 85 GRAVI_WAVELAMP_MAP
" : spectrum of Argon, with position of lines\n" 103 int cpl_plugin_get_info(cpl_pluginlist * list)
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,
113 gravity_wavelamp_short,
114 gravity_wavelamp_description,
115 "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
118 gravity_wavelamp_create,
119 gravity_wavelamp_exec,
120 gravity_wavelamp_destroy)) {
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);
144 static int gravity_wavelamp_create(cpl_plugin * plugin)
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);
177 gravi_parameter_add_static_name (recipe->parameters);
189 static int gravity_wavelamp_exec(cpl_plugin * plugin)
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);
228 recipe_status = gravity_wavelamp(recipe->frames, recipe->parameters);
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;
254 static int gravity_wavelamp_destroy(cpl_plugin * plugin)
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);
287 static int gravity_wavelamp(cpl_frameset * frameset,
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,
303 gravity_print_banner ();
304 cpl_msg_set_time_on();
305 cpl_msg_set_component_on();
306 gravi_msg_function_start(1);
309 cpl_error_get_code()) ;
312 wavelamp_frameset = gravi_frameset_extract_wavelamp_data (frameset);
314 darkcalib_frameset = gravi_frameset_extract_dark_map (frameset);
315 p2vmcalib_frameset = gravi_frameset_extract_p2vm_map (frameset);
316 wavecalib_frameset = gravi_frameset_extract_wave_map (frameset);
317 flatcalib_frameset = gravi_frameset_extract_flat_map (frameset);
318 badcalib_frameset = gravi_frameset_extract_bad_map (frameset);
320 wave_param_frameset = gravi_frameset_extract_wave_param (frameset);
323 if ( (cpl_frameset_is_empty (dark_frameset) &&
324 cpl_frameset_is_empty (darkcalib_frameset)) ||
325 cpl_frameset_is_empty (wavelamp_frameset) ||
326 cpl_frameset_is_empty (p2vmcalib_frameset) ||
327 cpl_frameset_is_empty (wavecalib_frameset) ||
328 cpl_frameset_is_empty (flatcalib_frameset) ||
329 cpl_frameset_is_empty (badcalib_frameset) ) {
331 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
332 "Mising DARK, WAVELAMP, P2VM, WAVE, FLAT or BAD") ;
337 used_frameset = cpl_frameset_new();
343 if (!cpl_frameset_is_empty (dark_frameset)) {
345 frame = cpl_frameset_get_position (dark_frameset, 0);
353 CPLCHECK_CLEAN (
"Could not compute the DARK map");
357 NULL, frame,
"gravity_wavelamp",
358 NULL, GRAVI_DARK_MAP);
360 CPLCHECK_CLEAN (
"Could not save the DARK map");
362 else if (!cpl_frameset_is_empty (darkcalib_frameset)) {
364 frame = cpl_frameset_get_position (darkcalib_frameset, 0);
367 CPLCHECK_CLEAN (
"Could not load the DARK map");
370 cpl_msg_info (cpl_func,
"There is no DARK in the frame set");
374 frame = cpl_frameset_get_position (badcalib_frameset, 0);
378 frame = cpl_frameset_get_position (flatcalib_frameset, 0);
382 frame = cpl_frameset_get_position (wavecalib_frameset, 0);
386 frame = cpl_frameset_get_position (p2vmcalib_frameset, 0);
389 CPLCHECK_CLEAN (
"Error while loading the calibration map");
395 frame = cpl_frameset_get_position (wavelamp_frameset, 0);
401 cpl_propertylist * argon_header = gravi_data_get_header (argon_data);
402 cpl_propertylist_append (argon_header, gravi_data_get_header (data));
412 cpl_image * img_median = cpl_imagelist_collapse_median_create (imglist);
415 cpl_imagelist_empty (imglist);
416 cpl_imagelist_set (imglist, img_median, 0);
420 badpix_map, NULL, parlist,
423 CPLCHECK_CLEAN (
"Cannot extract spectrum");
433 CPLCHECK_CLEAN (
"Cannot re-interpolate spectrum");
442 if (!cpl_frameset_is_empty (wave_param_frameset)) {
443 frame2 = cpl_frameset_get_position (wave_param_frameset, 0);
447 cpl_msg_error (cpl_func,
"There is no WAVE_PARAM in the frameset");
454 CPLCHECK_CLEAN (
"Cannot compute the positions");
458 used_frameset, frame,
"gravity_wavelamp",
459 NULL, GRAVI_WAVELAMP_MAP);
461 CPLCHECK_CLEAN(
"Could not save the WAVELAMP");
467 cpl_msg_info(cpl_func,
"Memory cleanup");
468 FREE (cpl_frameset_delete, wavelamp_frameset);
469 FREE (cpl_frameset_delete, wavecalib_frameset);
470 FREE (cpl_frameset_delete, badcalib_frameset);
471 FREE (cpl_frameset_delete, flatcalib_frameset);
472 FREE (cpl_frameset_delete, p2vmcalib_frameset);
473 FREE (cpl_frameset_delete, used_frameset);
474 FREE (cpl_frameset_delete, dark_frameset);
475 FREE (cpl_frameset_delete, darkcalib_frameset);
476 FREE (cpl_frameset_delete, wave_param_frameset);
486 gravi_msg_function_exit(1);
487 return (
int)cpl_error_get_code();
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_copy_ext(gravi_data *output, gravi_data *input, const char *name)
Copy extensions from one data to another.
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.
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_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
const char * gravi_get_license(void)
Get the pipeline copyright and license.
cpl_error_code gravi_data_detector_cleanup(gravi_data *data, const cpl_parameterlist *parlist)
Perform self-bias correction to the SC raw 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_imagelist * gravi_data_get_cube(gravi_data *self, const char *extname)
Return a pointer on an IMAGE extension by its EXTNAME.
cpl_error_code gravi_align_spectrum(gravi_data *spectrum_data, gravi_data *wave_map, gravi_data *p2vm_map, enum gravi_detector_type det_type, const cpl_parameterlist *parlist)
Regrid the regions into a common wavelength (in-place)
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
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.
gravi_data * gravi_compute_dark(gravi_data *raw_data)
Compute the DARK calibration map.