75#define RECIPE_ID "xsh_flexcomp"
76#define RECIPE_AUTHOR "P.Goldoni, L.Guglielmi, R. Haigron, F. Royer"
77#define RECIPE_CONTACT "amodigli@eso.org"
79#define XSH_AFC_UVB_XMIN 573
80#define XSH_AFC_UVB_YMIN 1501
81#define XSH_AFC_UVB_XMAX 1572
82#define XSH_AFC_UVB_YMAX 2500
83#define XSH_AFC_UVB_ORDER 18
85#define XSH_AFC_VIS_XMIN 534
86#define XSH_AFC_VIS_YMIN 2301
87#define XSH_AFC_VIS_XMAX 1533
88#define XSH_AFC_VIS_YMAX 3300
89#define XSH_AFC_VIS_ORDER 26
104static void xsh_flexcomp(cpl_parameterlist *, cpl_frameset *);
110"Compute the flexure of the instrument";
113"This recipe computes the flexure of the instrument and correct CAL files.\n\
115 - [UVB, VIS] One RAW frame (Format = RAW, Tag = AFF_ATT_arm)\n\
116 - [NIR] Two RAW frames ((Format = RAW, Tag = AFC_ATT_arm_ON,\
118 - An arc line list (Format = TABLE, Tag = ARC_LINE_LIST_AFC_arm)\n\
119 - A spectral format table frame (Format = TABLE, Tag = SPECTRAL_FORMAT_TAB_arm)\n\
120 - [UVB,VIS] A master bias (Format = PRE, Tag = MASTER_BIAS_arm)\n\
121 - [UVB,VIS] A master dark (Format = PRE, Tag = MASTER_DARK_arm)\n\
122 - An order table frame (Format = TABLE, Tag = ORDER_TAB_EDGES_IFU_arm)\n\
123 - [OPTIONAL] A non-linear badpixel map (Tag = BP_MAP_NL_arm)\n\
124 - [OPTIONAL] A reference badpixel map (Tag = BP_MAP_RP_arm)\n\
125 - [poly mode] A wave solution frame (Format = TABLE, Tag = WAVE_TAB_2D_arm)\n\
126 - [physical model mode] A model cfg table (Format = TABLE, Tag = XSH_MOD_CFG_OPT_2D_arm)\n\
128 - [poly mode] An updated wave solution frame (Format = TABLE, Tag = WAVE_TAB_AFC_arm)\n\
129 - [physical model mode] An updated model cfg table (Format = TABLE, Tag = XSH_MOD_CFG_OPT_AFC_arm)\n\
130 - An updated order table frame (Format = TABLE, Tag = ORDER_TAB_AFC_IFU_arm)\n\
131 - [poly mode] A dispersion table frame (Format = TABLE, Tag = DISP_TAB_AFC_arm)\n";
148 cpl_recipe *recipe = NULL;
149 cpl_plugin *plugin = NULL;
151 recipe = cpl_calloc(1,
sizeof(*recipe));
152 if ( recipe == NULL ){
156 plugin = &recipe->interface ;
158 cpl_plugin_init(plugin,
161 CPL_PLUGIN_TYPE_RECIPE,
172 cpl_pluginlist_append(list, plugin);
174 return (cpl_error_get_code() != CPL_ERROR_NONE);
190 cpl_recipe *recipe = NULL;
196 cpl_parameter* p=NULL;
203 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin");
206 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
207 CPL_ERROR_TYPE_MISMATCH,
208 "Plugin is not a recipe");
210 recipe = (cpl_recipe *)plugin;
213 recipe->parameters = cpl_parameterlist_new();
214 assure( recipe->parameters != NULL,
215 CPL_ERROR_ILLEGAL_OUTPUT,
216 "Memory allocation failed!");
232 recipe->parameters, detarc_clip_param));
241 "Number/10 of annealing iterations "
242 "if in physical model mode."));
245 "model-anneal-factor",1.0,
246 "Multiplier applied to the automatic "
247 "parameter ranges (i.e. when scenario!=0). "
248 "For routine operations should be 1.0. "
249 "(physical model mode)."));
252 sprintf(paramname,
"xsh.%s.%s",
RECIPE_ID,
"model-scenario");
254 check(p=cpl_parameter_new_enum(paramname,CPL_TYPE_INT,
255 "selects preset flag and range combinations "
256 "appropriate to common scenarios: "
257 "-1 - Only the position across the slit and"
258 " camera focal length are open\n"
259 " 0 - No scenario, input cfg flags and limits"
261 " 1 - scenario appropriate for the startup"
262 " recipe (large ranges for parameters "
263 " affecting single ph exposures, dist "
265 " 2 - Like 1, but includes parameters "
266 " affecting all ph positions"
267 " 3 - Scenario for use in fine tuning cfg"
268 " to match routine wavecal exposures. All"
269 " parameters affecting 1ph exposures"
270 " except dist coeffs are included and"
271 " parameter ranges are small. (For use by"
272 " flexcomp in 1ph case)."
273 " 4 - Like 3 but includes parameters"
274 " affecting all ph positions (Standard for"
275 " use by flexcomp in 9ph case and 2dmap)."
276 " 5 - Like 4 but includes also dist coeffs"
277 " 6 - Just dist coeffs (and chipx, chipy)",
278 RECIPE_ID,3,9,-1,0,1,2,3,4,5,6,8));
281 check(cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,
283 check(cpl_parameterlist_append(recipe->parameters,p));
287 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
305 cpl_recipe *recipe = NULL;
308 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin" );
311 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
312 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
314 recipe = (cpl_recipe *)plugin;
320 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
339 cpl_recipe *recipe = NULL;
342 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin" );
345 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
346 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
348 recipe = (cpl_recipe *)plugin;
353 if (cpl_error_get_code() != CPL_ERROR_NONE)
368 cpl_parameter* p=NULL;
371 if(cpl_parameter_get_double(p) <= 0) {
374 cpl_parameter_set_double(p,4);
375 detect_arclines_p->
min_sn=4;
377 cpl_parameter_set_double(p,3);
378 detect_arclines_p->
min_sn=3;
384 return cpl_error_get_code();
392 cpl_propertylist* plist=NULL;
393 const char* name=NULL;
394 char* slit_value=NULL;
395 name=cpl_frame_get_filename(afcatt_frame);
396 plist=cpl_propertylist_load(name,0);
398 if (strcmp(slit_value,
"Pin_0.5") != 0 ) {
400 xsh_msg_error(
"Your input AFC frame should be the 1st of the AFC sequence");
401 xsh_msg_error(
"Its INS OPTIi NAME key value should be 'Pin_0.5'");
402 cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT);
408 return cpl_error_get_code();
422static void xsh_flexcomp(cpl_parameterlist* parameters, cpl_frameset* frameset)
425 int recipe_tags_size = 1;
433 cpl_frameset* raws = NULL;
434 cpl_frameset* calib = NULL;
437 cpl_frame* arclist_frame = NULL;
438 cpl_frame* afcatt_frame = NULL;
439 cpl_frame* spectralformat_frame = NULL;
440 cpl_frame* order_tab_edges_frame = NULL;
441 cpl_frame* wave_tab_frame = NULL;
443 cpl_frame* wave_map_frame = NULL;
444 cpl_frame* slit_map_frame = NULL;
446 cpl_frame* model_config_frame = NULL;
447 cpl_frame* masterbias_frame = NULL;
448 cpl_frame* masterdark_frame = NULL;
449 cpl_frame* bpmap_frame = NULL;
451 cpl_frame *subbpmap_frame = NULL;
452 cpl_frame *subbias_frame = NULL;
453 cpl_frame *subdark_frame = NULL;
459 cpl_frame* afcatt_rmbias = NULL;
460 cpl_frame* afcatt_rmdark = NULL;
461 cpl_frame* att_cleanlines = NULL;
462 cpl_frame* att_resid_tab = NULL;
463 cpl_frame *afcthetab_frame = NULL;
464 const char *tag = NULL;
466 cpl_frame *afc_wave_tab_frame = NULL;
467 cpl_frame *afc_order_tab_edges_frame = NULL;
468 cpl_frame *afc_disp_tab_frame = NULL;
469 cpl_frame *afc_config_tab_frame = NULL;
471 int pre_overscan_corr=0;
473 char wave_map_tag[256];
474 char slit_map_tag[256];
476 cpl_boolean mode_phys;
479 recipe_tags, recipe_tags_size,
482 nraws=cpl_frameset_get_size(raws);
483 assure(nraws > 0, CPL_ERROR_NULL_INPUT,
"Provide an input AFC_ATT_ARM frame");
495 "No input ARC_LINE_AFC_LIST_ARM arclines list provided");
499 "No spectral format provided");
502 "No input ORDER_TABLE_EDGES_MODE_ARM (MODE=IFU or SLIT) table provided");
518 if( (model_config_frame!=NULL) && (wave_tab_frame != NULL) ) {
520 xsh_msg_error(
"You cannot provide both a %s and a %s frame. Decide if you are in poly or physical model mode. We exit",
525 if((model_config_frame==NULL) && ( wave_tab_frame == NULL) ) {
548 spectralformat_frame));
550 "pre-overscan-corr"));
555 check(detect_arclines_clipping =
583 xsh_msg(
"AFC pre coordinates (%d,%d, %d,%d)",afc_xmin,afc_ymin,
586 if ( bpmap_frame != NULL){
588 afc_xmin, afc_ymin, afc_xmax, afc_ymax));
591 if ( masterbias_frame != NULL){
593 afc_xmin, afc_ymin, afc_xmax, afc_ymax,
597 if ( masterdark_frame != NULL){
599 afc_xmin, afc_ymin, afc_xmax, afc_ymax,
607 check( afcatt_frame = cpl_frameset_get_frame( raws,0));
610 if( subbias_frame != NULL) {
614 pre_overscan_corr,1));
617 afcatt_rmbias =cpl_frame_duplicate( afcatt_frame);
620 if( subdark_frame != NULL) {
622 sprintf( filename,
"AFCATT_DARK_%s.fits",
628 afcatt_rmdark =cpl_frame_duplicate( afcatt_rmbias);
631 model_config_frame, afc_order, spectralformat_frame,
632 arclist_frame, afc_xmin, afc_ymin,
637 arclist_frame, NULL, NULL,
638 NULL, spectralformat_frame, NULL,
641 detect_arclines_clipping,
647 order_tab_edges_frame, att_resid_tab,
649 &afc_order_tab_edges_frame,
650 &afc_config_tab_frame));
652 if(model_config_frame == NULL) {
655 if ( wave_tab_frame != NULL){
657 afc_order_tab_edges_frame,
658 spectralformat_frame,
662 &afc_disp_tab_frame, NULL));
665 check( cpl_frame_set_tag( afc_disp_tab_frame, tag));
670 sprintf(slit_map_tag,
"SLIT_MAP_%s",
673 sprintf(wave_map_tag,
"WAVE_MAP_%s",
676 wave_map_tag,slit_map_tag,
677 &wave_map_frame, &slit_map_frame,1));
680 afc_order_tab_edges_frame,
685 spectralformat_frame,
695 if ( afc_wave_tab_frame != NULL){
699 if ( afc_config_tab_frame != NULL){
700 cpl_msg_info(__func__,
"Writing out afc_config_tab_frame as %s\n",cpl_frame_get_filename(afc_config_tab_frame));
705 if ( afc_order_tab_edges_frame != NULL){
709 if (afc_disp_tab_frame != NULL){
714 xsh_msg(
"xsh_flexcomp success !!");
719 XSH_FREE( detect_arclines_clipping);
static xsh_instrument * instrument
cpl_frame * xsh_badpixelmap_extract(cpl_frame *frame, int xmin, int ymin, int xmax, int ymax)
This function create a sub bad pixel map frame from input bad pixel map frame. the sub frame is descr...
void xsh_detect_arclines(cpl_frame *frame, cpl_frame *theo_tab_frame, cpl_frame *arc_lines_tab_frame, cpl_frame *wave_tab_guess_frame, cpl_frame *order_tab_recov_frame, cpl_frame *config_model_frame, cpl_frame *spectralformat_frame, cpl_frame **resid_tab_orders_frame, cpl_frame **arc_lines_clean_tab_frame, cpl_frame **wave_tab_frame, cpl_frame **resid_tab_frame, xsh_sol_wavelength solwave_type, xsh_detect_arclines_param *da, xsh_clipping_param *dac, xsh_instrument *instr, const char *rec_id, const int clean_tmp, const int resid_tab_name_sw)
detect the position on the detector of emission lines listed in a catalogue, from expected position v...
cpl_frame * xsh_preframe_extract(cpl_frame *frame, int xmin, int ymin, int xmax, int ymax, const char *name, xsh_instrument *instr)
This function create a sub frame from PRE frame. the sub frame is described by a box.
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_NULL_MSG(pointer, msg)
#define assure(CONDITION, ERROR_CODE,...)
#define xsh_error_dump(level)
#define xsh_error_reset()
#define XSH_AFC_VIS_ORDER
#define XSH_AFC_UVB_ORDER
static int xsh_flexcomp_create(cpl_plugin *)
Setup the recipe options.
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int xsh_flexcomp_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static cpl_error_code xsh_frame_check_is_right_afcatt(cpl_frame *afcatt_frame, xsh_instrument *instrument)
cpl_frame * xsh_afcthetab_create(cpl_frame *wave_tab_frame, cpl_frame *model_config_frame, int order, cpl_frame *spectralformat_frame, cpl_frame *arclines_frame, int xmin, int ymin, xsh_instrument *instr, const int clean_tmp)
Create a The tab for AFC.
static int xsh_flexcomp_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static cpl_error_code xsh_params_set_defaults(cpl_parameterlist *pars, xsh_instrument *inst, xsh_detect_arclines_param *detect_arclines_p)
static void xsh_flexcomp(cpl_parameterlist *, cpl_frameset *)
Interpret the command line options and execute the data processing.
cpl_frame * xsh_flexcor(cpl_frame *afc_frame, cpl_frame *wave_tab_frame, cpl_frame *model_config_frame, cpl_frame *order_tab_frame, cpl_frame *attresidtab_frame, int afc_xmin, int afc_ymin, xsh_instrument *instr, cpl_frame **afc_order_tab_frame, cpl_frame **afc_model_config_frame)
This function applies the computed shift betwwen AFC CAL and AFC ATT frame.
static char xsh_flexcomp_description_short[]
static char xsh_flexcomp_description[]
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_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_error(...)
Print an error message.
#define xsh_msg(...)
Print a message on info level.
char * xsh_pfits_get_slit_value(const cpl_propertylist *plist, xsh_instrument *instrument)
find out the INS OPTIx NAME value (the width of the slit)
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.
cpl_frame * xsh_subtract_dark(cpl_frame *frame, cpl_frame *dark, const char *filename, xsh_instrument *instr)
subtract the master dark 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.
cpl_frame * xsh_create_dispersol_physmod(cpl_frame *pre_frame, cpl_frame *order_tab_frame, cpl_frame *mod_cfg_frame, cpl_frame *wave_map_frame, cpl_frame *slit_map_frame, xsh_dispersol_param *dispsol_param, cpl_frame *spectral_format_frame, xsh_instrument *instrument, const int clean_tmp)
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_create_poly_wavemap(cpl_frame *pre_frame, cpl_frame *wave_tab_2d_frame, cpl_frame *order_tab_frame, cpl_frame *spectral_format_frame, xsh_dispersol_param *dispsol_par, xsh_instrument *instrument, const char *wm_tag, cpl_frame **dispersol_frame, cpl_frame **slitmap_frame)
cpl_frame * xsh_find_order_tab_edges(cpl_frameset *frames, xsh_instrument *instr)
Find an order tab EDGES.
cpl_boolean xsh_mode_is_physmod(cpl_frameset *set, xsh_instrument *instrument)
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)
cpl_frame * xsh_find_wave_tab(cpl_frameset *frames, xsh_instrument *instr)
Find a wave tab 2D or a wave tab ARC.
cpl_frame * xsh_find_frame_with_tag(cpl_frameset *frames, const char *tag, xsh_instrument *instr)
Find frame with a given tag.
#define XSH_ARC_LINE_LIST_AFC
#define XSH_MOD_CFG_OPT_2D
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
#define XSH_SPECTRAL_FORMAT
cpl_frame * xsh_check_load_master_bpmap(cpl_frameset *calib, xsh_instrument *inst, const char *rec_id)
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_clipping_detect_arclines_create(const char *recipe_id, cpl_parameterlist *list, xsh_clipping_param p)
Create the arclines clipping parameters in a parameters list.
cpl_error_code xsh_parameters_decode_bp(const char *recipe_id, cpl_parameterlist *plist, const int ival)
void xsh_parameters_new_double(cpl_parameterlist *list, const char *recipe_id, const char *name, double value, const char *comment)
xsh_detect_arclines_param * xsh_parameters_detect_arclines_get(const char *recipe_id, cpl_parameterlist *list)
get the detect arclines parameters in a parameters list
void xsh_parameters_dispersol_create(const char *recipe_id, cpl_parameterlist *list, xsh_dispersol_param p)
Create the dispersol compute parameters in a parameters list.
xsh_clipping_param * xsh_parameters_clipping_detect_arclines_get(const char *recipe_id, cpl_parameterlist *list)
Get the arclines clipping parameters in a parameters list.
int xsh_parameters_get_int(const cpl_parameterlist *list, const char *recipe_id, const char *name)
void xsh_parameters_generic(const char *recipe_id, cpl_parameterlist *plist)
void xsh_parameters_detect_arclines_create(const char *recipe_id, cpl_parameterlist *list, xsh_detect_arclines_param p)
create the detect arclines parameters in a parameters list
cpl_error_code xsh_recipe_params_check(cpl_parameterlist *parameters, xsh_instrument *instrument, const char *rec_id)
void xsh_parameters_new_int(cpl_parameterlist *list, const char *recipe_id, const char *name, int value, const char *comment)
xsh_dispersol_param * xsh_parameters_dispersol_get(const char *recipe_id, cpl_parameterlist *list)
Get the dispersion solution compute parameters in a parameters list.
#define DECODE_BP_FLAG_DEF
#define XSH_FREE(POINTER)