74#define RECIPE_ID "xsh_wavecal"
75#define RECIPE_AUTHOR "L.Guglielmi"
76#define RECIPE_CONTACT "amodigli@eso.org"
91static void xsh_wavecal(cpl_parameterlist *, cpl_frameset *);
97"Compute arclines tilt and instrument resolution";
100"This recipe detects and follow arc lines in a fully illuminated slit\n\
103 Raw frame (Tag = ARC_SLIT_arm)\n\
104 Arc Line List (Tag = ARC_LINE_LIST_arm)\n\
105 Master Bias (Tag = MASTER_BIAS_arm)\n\
106 [OPTIONAL] Master Dark (Tag = MASTER_DARK_arm)\n\
107 Order Table (Tag = ORDER_TABLE_EDGES_arm)\n\
108 [poly mode] Wave Solution (Tag = WAVE_TAB_2D_arm)\n\
109 [poly mode] Theoretical Map (Tag = THEO_TAB_spec_arm, spec=SING/IFU)\n\
110 [physical model mode] Model cfg tab (Tag = XSH_MOD_CFG_TAB_arm)\n\
111 - [OPTIONAL] A non-linear badpixel map (Tag = BP_MAP_NL_arm)\n\
112 - [OPTIONAL] A reference badpixel map (Tag = BP_MAP_RP_arm)\n\
113 [OPTIONAL-To compute spectral resolution] Dispersion Table Frame (Tag = DISP_TAB_arm)\n\
114Prepare PRE structures.\n\
115Subtract the master Dark (UVB, VIS and NIR)\n\
116Substract the master Bias (UVB and VIS)\n\
118Detect and follow arc lines.\n\
120 Wavelength solution, PRO.CATG = WAVE_TAB_ARC_SLIT_arm [if poly mode]\n\
121 Linetilt list, PRO.CATG = TILT_TAB_SLIT_arm\n\
122 Residuals table, PRO.CATG = RESID_TAB_GOOD_LINES_arm\n\
123 Wave Map, PRO.CATG = WAVE_MAP_arm [if model-wavemap-compute=TRUE]\n\
124 In case of IFU mode cdata previous producs repat for each IFU slices\n\
125 Arc frame, Bias subtracted in PRE format, PRO.CATG = ARC_BIAS_SUBTRACT_arm\n\
126 If arm=UVB/VIS and PRO.CATG=ARC_NIR_ON if arm=NIR\n\
127 Arc frame, Bias subtracted, FLAT-FIELDED, PRO.CATG = WAVECAL_FLATFIELDED_arm";
145 cpl_recipe *recipe = NULL;
146 cpl_plugin *plugin = NULL;
148 recipe = cpl_calloc(1,
sizeof(*recipe));
149 if ( recipe == NULL ){
153 plugin = &recipe->interface ;
155 cpl_plugin_init(plugin,
158 CPL_PLUGIN_TYPE_RECIPE,
169 cpl_pluginlist_append(list, plugin);
171 return (cpl_error_get_code() != CPL_ERROR_NONE);
188 cpl_recipe *recipe = NULL;
196 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin");
199 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
200 CPL_ERROR_TYPE_MISMATCH,
201 "Plugin is not a recipe");
203 recipe = (cpl_recipe *)plugin;
206 recipe->parameters = cpl_parameterlist_new();
207 assure( recipe->parameters != NULL,
208 CPL_ERROR_ILLEGAL_OUTPUT,
209 "Memory allocation failed!");
218 recipe->parameters));
221 recipe->parameters));
224 recipe->parameters));
227 recipe->parameters ) ) ;
230 recipe->parameters ) ) ;
233 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
252 cpl_recipe *recipe = NULL;
255 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin" );
258 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
259 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
261 recipe = (cpl_recipe *)plugin;
267 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
287 cpl_recipe *recipe = NULL;
290 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin" );
293 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
294 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
296 recipe = (cpl_recipe *)plugin;
301 if (cpl_error_get_code() != CPL_ERROR_NONE)
341 return cpl_error_get_code();
352 cpl_parameter* p=NULL;
354 if(cpl_parameter_get_double(p) <= 0) {
356 cpl_parameter_set_double(p,6);
358 cpl_parameter_set_double(p,15);
365 return cpl_error_get_code();
387 cpl_frame* frame=NULL;
388 const char* name=NULL;
389 cpl_propertylist* plist=NULL;
393 check(frame=cpl_frameset_get_frame(raws,0));
394 check(name=cpl_frame_get_filename(frame));
395 check(plist=cpl_propertylist_load(name,0));
414 return cpl_error_get_code();
428 cpl_frameset* frameset)
431 int recipe_tags_size = 1;
433 const char *prefix =
"ARC_";
435 cpl_frameset* raws = NULL;
436 cpl_frameset* calib = NULL;
437 cpl_frameset* on = NULL;
438 cpl_frameset* off = NULL;
439 cpl_frameset* on_off = NULL;
441 cpl_frame * raw_frame = NULL ;
442 cpl_frame * bpmap = NULL;
443 cpl_frame * order_tab_edges = NULL ;
444 cpl_frame * arc_line_list = NULL ;
445 cpl_frame * model_config_frame = NULL;
446 cpl_frame * spectralformat_frame = NULL;
447 cpl_frame * wave_tab_2d = NULL ;
448 cpl_frame * master_bias = NULL ;
449 cpl_frame * master_dark = NULL ;
450 cpl_frame * rmbias = NULL ;
451 cpl_frame * intFrame = NULL ;
452 cpl_frame * resFrame = NULL ;
453 cpl_frame *wavemap_frame = NULL;
454 cpl_frame *disptab_frame = NULL;
455 cpl_frame *slitmap_frame = NULL;
458 cpl_frame * shiftFrame = NULL ;
459 cpl_frame * tilt_list = NULL ;
462 cpl_frameset * tilt_set = NULL ;
467 int follow_param_init=
false;
480 char file_prefix[10];
483 int pre_overscan_corr=0;
485 const char* rec_prefix =
"xsh_wavecal";
491 recipe_tags, recipe_tags_size,
525 wavemap_frame = cpl_frame_duplicate( wavemap_frame);
529 slitmap_frame = cpl_frame_duplicate( slitmap_frame);
533 xsh_msg_warning(
"No input DISP_TAB_ARM provided. Spectral Resolution will not be computed");
541 "UVB,VIS arm provide one slit,arc lamp frame");
563 "NIR arm provide one slit,arc lamp on frame");
565 "NIR arm provide one slit,arc lamp off frame");
568 spectralformat_frame));
576 follow_param_init=
true;
579 xsh_msg_dbg_low(
"Clipping Tilt Parameters: sigma = %.2lf, Niter = %d, Frac = %.2lf",
599 check(raw_frame = cpl_frameset_get_frame(raws,0));
602 if(master_bias != NULL) {
607 rmbias=cpl_frame_duplicate(raw_frame);
623 check( intFrame = cpl_frame_duplicate( cpl_frameset_get_frame( on_off,0)));
629 if ( model_config_frame != NULL && wavemap_frame == NULL){
630 char wave_map_tag[256];
631 char slit_map_tag[256];
645 wave_map_tag,slit_map_tag,
646 &wavemap_frame, &slitmap_frame,1));
657 xsh_msg(
"Call xsh_follow_arclines, SLIT mode" );
659 wave_tab_2d, order_tab_edges,
660 spectralformat_frame, model_config_frame,
661 wavemap_frame, slitmap_frame,
670 xsh_msg(
"Saving products, SLIT mode");
674 cpl_frame_get_filename(tilt_list));
681 xsh_msg(
"Call xsh_follow_arclines, IFU mode" ) ;
682 check( tilt_set = cpl_frameset_new() ) ;
684 wave_tab_2d, order_tab_edges,
685 spectralformat_frame, model_config_frame,
686 wavemap_frame, slitmap_frame, disptab_frame,
688 tilt_set, &shiftFrame));
692 xsh_msg(
"Saving products, IFU mode");
694 for( i = 0 ; i<3 ; i++ ) {
696 cpl_frame *tilt_frame = NULL;
698 check( tilt_frame = cpl_frameset_get_frame( tilt_set, i));
700 cpl_frame_get_filename( tilt_frame));
710 sprintf(tag,
"ARC_SLIT_ON");
712 sprintf(tag,
"ARC_IFU_ON");
716 cpl_frame_get_filename( rmbias));
726 cpl_frame_get_filename( intFrame));
736 cpl_frame_get_filename( shiftFrame));
754 if(follow_param_init) {
static xsh_instrument * instrument
void xsh_prepare(cpl_frameset *frames, cpl_frame *bpmap, cpl_frame *mbias, const char *prefix, xsh_instrument *instr, const int pre_overscan_corr, const bool flag_neg_and_thresh_pix)
This function transform RAW frames dataset in PRE frames dataset attaching the default bad pixel map ...
#define XSH_ASSURE_NOT_ILLEGAL(cond)
#define assure(CONDITION, ERROR_CODE,...)
#define xsh_error_dump(level)
#define xsh_error_reset()
#define XSH_ASSURE_NOT_ILLEGAL_MSG(cond, msg)
#define XSH_ASSURE_NOT_NULL(pointer)
void xsh_follow_arclines_slit(cpl_frame *inframe, cpl_frame *arclines, cpl_frame *wavesol, cpl_frame *order_table, cpl_frame *spectralformat_frame, cpl_frame *model_config_frame, cpl_frame *wavemap_frame, cpl_frame *slitmap_frame, cpl_frame *disptab_frame, xsh_follow_arclines_param *param, xsh_instrument *instrument, cpl_frame **tilt_list, cpl_frame **shift_frame)
void xsh_follow_arclines_ifu(cpl_frame *inframe, cpl_frame *arclines, cpl_frame *wavesol, cpl_frame *order_table, cpl_frame *spectralformat_frame, cpl_frame *model_config_frame, cpl_frame *wavemap_frame, cpl_frame *slitmap_frame, cpl_frame *disptab_frame, xsh_follow_arclines_param *follow_param, xsh_instrument *instrument, cpl_frameset *tilt_set, cpl_frame **shift_frame)
Detect and follow arc lines. Computes center, width and tilt parameters. The position of the center o...
const char * xsh_instrument_mode_tostring(xsh_instrument *i)
Get the string associated with a mode.
void xsh_instrument_update_from_spectralformat(xsh_instrument *i, cpl_frame *spectralformat_frame)
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
XSH_MODE xsh_instrument_get_mode(xsh_instrument *i)
Get a mode on instrument structure.
XSH_ARM xsh_instrument_get_arm(xsh_instrument *i)
Get an arm on instrument structure.
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
#define xsh_msg_warning(...)
Print an warning message.
#define xsh_msg(...)
Print a message on info level.
#define xsh_msg_dbg_low(...)
int xsh_pfits_get_binx(const cpl_propertylist *plist)
find out the BINX value
int xsh_pfits_get_biny(const cpl_propertylist *plist)
find out the BINY value
cpl_frameset * xsh_subtract_nir_on_off(cpl_frameset *on, cpl_frameset *off, xsh_instrument *instr)
(NIR only) subtract the OFF set of files from the On set of files
cpl_frame * xsh_subtract_bias(cpl_frame *frame, cpl_frame *bias, xsh_instrument *instr, const char *type, const int pre_overscan_corr, const int save_tmp)
Subtract the master bias frame from PRE frame.
void xsh_free_parameterlist(cpl_parameterlist **p)
Deallocate a parameter list and set the pointer to NULL.
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
const char * xsh_get_license(void)
Get the pipeline copyright and license.
void xsh_init(void)
Reset library state.
cpl_error_code xsh_begin(cpl_frameset *frames, const cpl_parameterlist *parameters, xsh_instrument **instrument, cpl_frameset **raws, cpl_frameset **calib, const char *tag_list[], int tag_list_size, const char *recipe_id, unsigned int binary_version, const char *short_descr)
Recipe initialization.
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
cpl_error_code xsh_end(const char *recipe_id, cpl_frameset *frames, cpl_parameterlist *parameters)
Recipe termination.
static char xsh_wavecal_description_short[]
static void xsh_wavecal(cpl_parameterlist *, cpl_frameset *)
Interpret the command line options and execute the data processing.
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static char xsh_wavecal_description[]
static int xsh_wavecal_create(cpl_plugin *)
Setup the recipe options.
static cpl_error_code xsh_params_monitor(xsh_follow_arclines_param follow_param)
static int xsh_wavecal_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int xsh_wavecal_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static void xsh_wavecal_get_parameters(cpl_parameterlist *parameters, xsh_follow_arclines_param *par)
static cpl_error_code xsh_params_bin_scale(cpl_frameset *raws, xsh_follow_arclines_param follow_param)
Scale input parameters.
static cpl_error_code xsh_params_set_defaults(cpl_parameterlist *pars, xsh_instrument *inst)
xsh_clipping_param * tilt_clipping
xsh_clipping_param * specres_clipping
void xsh_create_model_map(cpl_frame *model_frame, xsh_instrument *instrument, const char *wtag, const char *stag, cpl_frame **wavemap_frame, cpl_frame **slitmap_frame, const int save_tmp)
cpl_frame * xsh_find_wavemap(cpl_frameset *frames, xsh_instrument *instr)
Find Wave Map frame. The frame returned should not be free by the caller.
cpl_frame * xsh_find_master_dark(cpl_frameset *frames, xsh_instrument *instr)
Find master dark frame.
cpl_frame * xsh_find_spectral_format(cpl_frameset *frames, xsh_instrument *instr)
Find spectral format frame.
cpl_frame * xsh_find_disp_tab(cpl_frameset *frames, xsh_instrument *instr)
Find Dispersol tab frame. The frame returned should not be free by the caller.
cpl_frame * xsh_find_order_tab_edges(cpl_frameset *frames, xsh_instrument *instr)
Find an order tab EDGES.
cpl_frame * xsh_find_wave_tab_2d(cpl_frameset *frames, xsh_instrument *instr)
Find a wave tab 2D.
void xsh_add_product_image(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instrument, const char *final_prefix)
void xsh_add_product_table(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instrument, const char *final_prefix)
Save Table product (input frame has several extensions, 1 table per extension)
void xsh_dfs_split_nir(cpl_frameset *input, cpl_frameset **on, cpl_frameset **off)
split input RAW NIR sof in ON and OFF
cpl_frame * xsh_find_slitmap(cpl_frameset *frames, xsh_instrument *instr)
Find a slit map.
cpl_frame * xsh_find_frame_with_tag(cpl_frameset *frames, const char *tag, xsh_instrument *instr)
Find frame with a given tag.
#define XSH_MOD_CFG_OPT_2D
#define XSH_SLIT_MAP_MODEL
#define XSH_WAVE_MAP_MODEL
#define XSH_ARC_LINE_LIST
cpl_frame * xsh_check_subtract_dark(cpl_frame *rmbias_frame, cpl_frame *master_dark, xsh_instrument *instrument, const char *prefix)
Check function for dark subtraction.
cpl_frame * xsh_check_load_master_bpmap(cpl_frameset *calib, xsh_instrument *inst, const char *rec_id)
cpl_error_code xsh_model_temperature_update_frame(cpl_frame **model_config_frame, cpl_frame *ref_frame, xsh_instrument *instrument, int *found_temp)
double xsh_parameters_wavecal_s_n_get(const char *recipe_id, cpl_parameterlist *list)
cpl_parameter * xsh_parameters_find(cpl_parameterlist *list, const char *recipe_id, const char *name)
find a parameter
void xsh_parameters_pre_overscan(const char *recipe_id, cpl_parameterlist *plist)
void xsh_parameters_wavecal_s_n_create(const char *recipe_id, cpl_parameterlist *list)
void xsh_parameters_clipping_tilt_create(const char *recipe_id, cpl_parameterlist *list)
create the xsh_wavecal (function follow_arclines) clipping parameters in a parameters list
cpl_error_code xsh_parameters_decode_bp(const char *recipe_id, cpl_parameterlist *plist, const int ival)
xsh_clipping_param * xsh_parameters_clipping_tilt_get(const char *recipe_id, cpl_parameterlist *list)
get the xsh_wavecal (follow_arclines) clipping parameters in a parameters list
void xsh_parameters_wavecal_range_create(const char *recipe_id, cpl_parameterlist *list)
xsh_clipping_param * xsh_parameters_clipping_specres_get(const char *recipe_id, cpl_parameterlist *list)
get the xsh_wavecal (follow_arclines) clipping parameters in a parameters list
int xsh_parameters_wavecal_range_get(const char *recipe_id, cpl_parameterlist *list)
int xsh_parameters_wavecal_margin_get(const char *recipe_id, cpl_parameterlist *list)
void xsh_parameters_clipping_specres_create(const char *recipe_id, cpl_parameterlist *list)
create the xsh_wavecal (function follow_arclines) clipping parameters in a parameters list
void xsh_parameters_generic(const char *recipe_id, cpl_parameterlist *plist)
cpl_error_code xsh_recipe_params_check(cpl_parameterlist *parameters, xsh_instrument *instrument, const char *rec_id)
void xsh_parameters_wavecal_margin_create(const char *recipe_id, cpl_parameterlist *list)
#define XSH_FREE(POINTER)