83#define RECIPE_ID "xsh_predict"
84#define RECIPE_AUTHOR "P.Goldoni, L.Guglielmi, R. Haigron, F. Royer, P. Bristow, D. Bramich, A. Modigliani"
85#define RECIPE_CONTACT "amodigli@eso.org"
100static void xsh_predict(cpl_parameterlist *, cpl_frameset *);
102static void xsh_predict_qc(cpl_table* tab,cpl_propertylist* head,
const char* arm);
108"Compute a first guess dispersion solution and order table";
111"This recipe creates a wavelength solution and an order table.\n\
113 - [UVB, VIS] One RAW frame (Format = RAW, Tag = FMTCHK_arm)\n\
114 - [NIR] Two RAW frames ((Format = RAW, Tag = FMTCHK_arm_ON,\
116 - A spectral format table (Format = PRE, Tag = SPECTRAL_FORMAT_TAB_arm)\n\
117 - An arc line list (Format = TABLE, Tag = ARC_LINE_LIST_arm)\n\
118 - [UVB,VIS,OPTIONAL] A master bias (Format = PRE, Tag = MASTER_BIAS_arm)\n\
119 - [UVB,VIS,OPTIONAL] A master dark (Format = PRE, Tag = MASTER_DARK_arm)\n\
120 - [OPTIONAL] A reference badpixel map (Format = QUP, Tag = BP_MAP_RP_arm)\n\
121 - [OPTIONAL] A non-linear badpixel map (Format = QUP, Tag = BP_MAP_NL_arm)\n\
122 - [OPTIONAL] Reference list to monitor line intensity (Tag = ARC_LINE_LIST_INTMON_arm)\n \
123 - [poly mode] A theoretical map (Format = TABLE, Tag = THEO_TAB_SING_arm)\n\
124 - [physical model mode] A model cfg table (Format = TABLE, Tag = XSH_MOD_CFG_TAB_arm)\n\
126 - [poly mode] A wavelength solution (Format = TABLE, PRO.CATG = \
127WAVE_TAB_GUESS_arm)\n\
128 - An order table, PRO.CATG = ORDER_TAB_GUESS_arm\n\
129 (if at least degree+1 points are found in each order).\n \
130 - A line identification residual table, PRO.CATG = FMTCHK_RESID_TAB_LINES_arm\n\
131 - The bias subtracted formatcheck frame, PRO.CATG = FMTCHK_ON_arm\n\
132 - [physical model mode]An optimized model configuration table, PRO.CATG = XSH_MOD_CFG_OPT_FMT_ARM\n\
133 Prepare the frames.\n\
135 Subtract Master Bias.\n\
136 Subtract Master Dark\n\
139 Compute guess order table and wavelength solution\n";
156 cpl_recipe *recipe = NULL;
157 cpl_plugin *plugin = NULL;
159 recipe = cpl_calloc(1,
sizeof(*recipe));
160 if ( recipe == NULL ){
164 plugin = &recipe->interface ;
166 cpl_plugin_init(plugin,
169 CPL_PLUGIN_TYPE_RECIPE,
180 cpl_pluginlist_append(list, plugin);
182 return (cpl_error_get_code() != CPL_ERROR_NONE);
198 cpl_recipe *recipe = NULL;
203 cpl_parameter* p=NULL;
209 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin");
212 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
213 CPL_ERROR_TYPE_MISMATCH,
214 "Plugin is not a recipe");
216 recipe = (cpl_recipe *)plugin;
219 recipe->parameters = cpl_parameterlist_new();
220 assure( recipe->parameters != NULL,
221 CPL_ERROR_ILLEGAL_OUTPUT,
222 "Memory allocation failed!");
234 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");
255 check(p=cpl_parameter_new_enum(paramname,CPL_TYPE_INT,
256 "selects preset flag and range combinations "
257 "appropriate to common scenarios: \n"
260 " 0 - No scenario, input cfg flags and limits "
262 " 1 - scenario appropriate for the startup "
263 "recipe (large ranges for parameters "
264 "affecting single ph exposures, dist "
266 " 2 - Like 1, but includes parameters "
267 "affecting all ph positions.\n"
268 " 3 - Scenario for use in fine tuning cfg "
269 "to match routine single pinhole exposures. "
270 "All parameters affecting 1ph exposures "
271 "except dist coeffs are included and "
272 "parameter ranges are small. (For use by "
273 "predict in 1ph case).\n"
274 " 4 - Like 3 but includes parameters "
275 "affecting all ph positions (Standard for "
276 "use by predict in 9ph case and 2dmap). \n"
279 ,
RECIPE_ID,3,9,-1,0,1,2,3,4,5,6,8));
282 check(cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,
284 check(cpl_parameterlist_append(recipe->parameters,p));
286 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
304 cpl_recipe *recipe = NULL;
307 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin" );
310 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
311 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
313 recipe = (cpl_recipe *)plugin;
319 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
328static void xsh_predict_qc(cpl_table* tab,cpl_propertylist* head,
const char* arm){
330 for(cpl_size row=0;row<cpl_table_get_nrow(tab);row++){
335 if(!strcmp(arm,
"UVB")){
337 if(wave >= 303 && wave <= 304){
343 if(wave >= 550.5 && wave <= 551 &&
order == 13){
348 if(wave >= 325.7 && wave <= 326 &&
order == 23){
353 if(wave >= 585 && wave <= 587){
358 if(!strcmp(arm,
"VIS")){
360 if(wave >= 561.2 && wave <= 561.4 &&
order == 29){
365 if(wave >= 933 && wave <= 934 &&
order == 17){
370 if(wave >= 567.3 && wave <= 567.9 &&
order == 29){
375 if(wave >= 1033 && wave <= 1034){
380 if(!strcmp(arm,
"NIR")){
382 if(wave >= 1013 && wave <= 1014){
387 if(wave >= 2445 && wave <= 2446){
392 if(wave >= 992 && wave <= 993){
397 if(wave >= 2310 && wave <= 2311){
419 cpl_recipe *recipe = NULL;
422 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin" );
425 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
426 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
428 recipe = (cpl_recipe *)plugin;
433 if (cpl_error_get_code() != CPL_ERROR_NONE)
452static void xsh_predict(cpl_parameterlist* parameters, cpl_frameset* frameset)
455 int recipe_tags_size = 1;
462 cpl_frameset* raws = NULL;
463 cpl_frameset* calib = NULL;
464 cpl_frameset* on = NULL;
465 cpl_frameset* off = NULL;
466 cpl_frameset* on_off = NULL;
467 cpl_frame* predict_rmbias = NULL;
468 cpl_frame* predict_rmdark = NULL;
472 cpl_frame* model_config_frame = NULL;
473 cpl_frame* spectralformat_frame = NULL;
474 cpl_frame* bpmap = NULL;
475 cpl_frame* master_bias = NULL;
476 cpl_frame* master_dark = NULL;
477 cpl_frame* theo_tab_sing = NULL;
478 cpl_frame* resid_map = NULL;
479 cpl_frame* resid_dan = NULL;
480 cpl_frame* resid_tab_orders_frame = NULL;
481 cpl_frame *wave_tab_guess_frame = NULL;
482 cpl_frame *order_tab_recov_frame = NULL;
483 cpl_frame* arclines = NULL;
484 cpl_frame* clean_arclines = NULL;
485 cpl_frame* guess_order_table = NULL;
486 cpl_frame* guess_wavesol = NULL;
487 const char* filename=NULL;
488 cpl_frame* MODEL_CONF_OPT_frame=NULL;
495 cpl_parameter * p =NULL;
496 int pre_overscan_corr=0;
497 cpl_frame * line_intmon = NULL ;
499 cpl_propertylist* plist=NULL;
500 cpl_boolean mode_phys;
506 recipe_tags, recipe_tags_size,
546 "Provide one formatcheck frame for UVB,VIS arm");
565 "Provide one formatcheck on frame for NIR arm");
567 "Provide one formatcheck off frame for NIR arm");
570 spectralformat_frame));
580 check(detect_arclines_clipping =
585 "pre-overscan-corr"));
593 cpl_frame* fmtchk = NULL;
597 pre_overscan_corr,CPL_TRUE));
598 check(fmtchk = cpl_frameset_get_frame(raws,0));
600 if(master_bias != NULL) {
604 pre_overscan_corr,0));
606 predict_rmbias =cpl_frame_duplicate(fmtchk);
609 if(master_dark != NULL) {
613 ".fits", (
void*)NULL ) ;
619 predict_rmdark =cpl_frame_duplicate(predict_rmbias);
632 check(predict_rmdark = cpl_frame_duplicate(
633 cpl_frameset_get_frame(on_off,0)));
639 plist=cpl_propertylist_load(cpl_frame_get_filename(predict_rmdark),0);
643 xsh_msg(
"Calling the xsh_detect_arclines");
647 if(model_config_frame!=NULL) {
651 arclines, wave_tab_guess_frame,
652 order_tab_recov_frame,
654 spectralformat_frame,
655 &resid_tab_orders_frame,
656 &clean_arclines, &guess_wavesol,
659 detect_arclines_clipping,
672 resid_map = cpl_frame_duplicate(resid_dan);
673 cpl_table* resid = NULL;
674 cpl_table* ext = NULL;
675 const char* fname = NULL;
678 cpl_propertylist* phead = NULL;
679 cpl_propertylist* xhead = NULL;
681 fname = cpl_frame_get_filename(resid_dan);
682 resid = cpl_table_load(fname, 1, 0);
683 phead = cpl_propertylist_load(fname, 0);
685 cpl_propertylist* qhead = NULL;
686 qhead=cpl_propertylist_new();
687 fname = cpl_frame_get_filename(clean_arclines);
688 plist = cpl_propertylist_load(fname, 0);
689 cpl_propertylist_copy_property_regexp(qhead, plist,
"ESO QC*",0);
690 cpl_propertylist_append(phead,qhead);
693 sprintf(rtag,
"FMTCHK_RESID_TAB_LINES_GFIT_%s",
695 sprintf(fout,
"%s.fits", rtag);
697 cpl_table_and_selected_int(resid,
"Flag", CPL_EQUAL_TO, 0);
698 ext = cpl_table_extract_selected(resid);
703 cpl_table_save(ext, phead, xhead, fout, CPL_IO_DEFAULT);
705 cpl_frame_set_filename(resid_map, fout);
706 cpl_frame_set_tag(resid_map, rtag);
707 if(model_config_frame != NULL) {
730 if ( model_config_frame != NULL){
731 xsh_msg(
"Produce new config file");
748 sprintf(paramname,
"xsh.%s.%s",
RECIPE_ID,
"model-maxit");
749 check(p = cpl_parameterlist_find(parameters,paramname));
750 check(maxit=cpl_parameter_get_int(p));
752 sprintf(paramname,
"xsh.%s.%s",
RECIPE_ID,
"model-anneal-factor");
753 check(p = cpl_parameterlist_find(parameters,paramname));
754 check(ann_fac=cpl_parameter_get_double(p));
756 sprintf(paramname,
"xsh.%s.%s",
RECIPE_ID,
"model-scenario");
757 check(p = cpl_parameterlist_find(parameters,paramname));
758 check(scenario=cpl_parameter_get_int(p));
759 xsh_msg(
"maxit=%d ann_fac=%g scenario=%d",maxit,ann_fac,scenario);
762 maxit,ann_fac,scenario,1));
767 spectralformat_frame,
768 resid_tab_orders_frame,
771 detect_arclines_clipping,
787 if ( guess_wavesol != NULL){
791 if ( guess_order_table != NULL){
795 if(model_config_frame == NULL) {
802 if(model_config_frame!=NULL) {
810 cpl_propertylist* header=NULL;
811 const char* name=cpl_frame_get_filename(resid_dan);
812 tab=cpl_table_load(name,1,0);
813 header=cpl_propertylist_load(name,0);
826 cpl_table_save(tab,header,NULL,name,CPL_IO_DEFAULT);
852 if ( model_config_frame != NULL){
857 xsh_msg(
"xsh_predict success !!");
static xsh_instrument * instrument
cpl_error_code xsh_frame_table_resid_merge(cpl_frame *self, cpl_frame *right, const int solution_type)
void xsh_detect_arclines_dan(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...
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 assure(CONDITION, ERROR_CODE,...)
#define xsh_error_dump(level)
#define xsh_error_reset()
#define XSH_ASSURE_NOT_ILLEGAL_MSG(cond, msg)
void xsh_instrument_set_mode(xsh_instrument *i, XSH_MODE mode)
Set a mode on instrument structure.
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
cpl_frame * xsh_model_pipe_anneal(cpl_frame *cfg_frame, cpl_frame *resid_frame, int maxit, double ann_fac, int scenario, int rec_id)
Run the annealing (optimisation) algoritm to improve the fit of the model parameter set to a given wa...
#define xsh_msg_warning(...)
Print an warning message.
#define xsh_msg(...)
Print a message on info level.
double xsh_pfits_get_exptime(const cpl_propertylist *plist)
find out the exposure time
static void xsh_predict(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 int xsh_predict_create(cpl_plugin *)
Setup the recipe options.
static char xsh_predict_description[]
static int xsh_predict_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static void xsh_predict_qc(cpl_table *tab, cpl_propertylist *head, const char *arm)
static int xsh_predict_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static char xsh_predict_description_short[]
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.
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
cpl_error_code xsh_wavecal_qclog_intmon(cpl_frame *line_check, const cpl_frame *line_intmon, const double exptime, xsh_instrument *inst)
computes intmon QC log
void xsh_free_parameterlist(cpl_parameterlist **p)
Deallocate a parameter list and set the pointer to NULL.
cpl_error_code xsh_check_input_is_unbinned(cpl_frame *in)
Check if an input frame is not binned.
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.
char * xsh_stringcat_any(const char *s,...)
Concatenate an arbitrary number of strings.
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_table(cpl_table **t)
Deallocate a table and set the pointer to NULL.
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.
void xsh_add_temporary_file(const char *name)
Add temporary file to temprary files list.
cpl_frame * xsh_create_order_table(cpl_frame *in_frame, cpl_frame *spectralformat_frame, cpl_frame *resid_frame, cpl_frame *arclines, xsh_detect_arclines_param *da, xsh_clipping_param *dac, xsh_instrument *instrument)
cpl_error_code xsh_wavetab_qc(cpl_frame *frm_tab, const int is_poly)
Monitor min/max/med/avg distance between detected lines on each ordee.
#define XSH_RESID_TAB_TABLE_COLNAME_ORDER
#define XSH_RESID_TAB_TABLE_COLNAME_XGAUSS
#define XSH_RESID_TAB_TABLE_COLNAME_WAVELENGTH
#define XSH_RESID_TAB_TABLE_COLNAME_YGAUSS
#define XSH_RESID_TAB_TABLE_COLNAME_XTHANNEAL
#define XSH_RESID_TAB_TABLE_COLNAME_XTHPRE
cpl_boolean xsh_mode_is_physmod(cpl_frameset *set, xsh_instrument *instrument)
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_arc_line_list(cpl_frameset *frames, xsh_instrument *instr)
Find an arc line list frame.
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_REC
#define XSH_THEO_TAB_SING
#define XSH_ARC_LINE_LIST_INTMON
#define XSH_WAVE_TAB_GUESS
#define XSH_ORDER_TAB_RECOV
#define XSH_SPECTRAL_FORMAT
#define XSH_DETECT_ARCLINES_TYPE_POLY
#define XSH_DETECT_ARCLINES_TYPE_MODEL
cpl_frame * xsh_check_load_master_bpmap(cpl_frameset *calib, xsh_instrument *inst, const char *rec_id)
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
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)
#define DECODE_BP_FLAG_DEF
#define XSH_FREE(POINTER)