68#define RECIPE_ID "xsh_orderpos"
69#define RECIPE_AUTHOR "L.Guglielmi,R.Haigron,P.Goldoni,F.Royer, A. Modigliani"
70#define RECIPE_CONTACT "amodigli@eso.org"
85static void xsh_orderpos(cpl_parameterlist *, cpl_frameset *);
91"Create the orders centre traces table file";
94"This recipe creates the orders centre traces table.\n\
95Input Frames for UVB and VIS:\n\
96 Raw file (Tag = ORDERDEF_arm_D2)\n\
97 Master Dark (Tag = MASTER_DARK_arm)\n\
98 Master Bias (Tag = MASTER_BIAS_arm)\n\
99Input Frames for NIR:\n\
100 Raw file ON(Tag = ORDERDEF_NIR_ON)\n\
101 Raw file OFF(Tag = ORDERDEF_NIR_OFF)\n\
102Input Frames for all arms\n\
103 Guess order table (Tag = ORDER_TAB_GUESS_arm)\n\
104 Spectral format table (Tag = SPECTRAL_FORMAT_TAB_arm)\n\
105 - [OPTIONAL] A map of non linear bad pixels (Format=QUP, Tag = BP_MAP_NL_arm)\n\
106 - [OPTIONAL] A map of reference bad pixels (Format = QUP,RAW, Tag = BP_MAP_RP_arm)\n\
107Prepare PRE structures.\n\
108For NIR, subtract NIR-OFF from NIR-ON.\n\
109For UVB and NIR, Substract the master Bias and master dark.\n\
110Detect Orders and calculate the order table.\n\
111The final products are:\n\
112 An updated Order Table, PRO.CATG=ORDER_TABLE_CENTR_arm.\n\
113 A order trace residuals Table, PRO.CATG=ORDERPOS_RESID_TAB_arm.\n\
114 The order pos frame bias subtracted, PRO.CATG=ORDERDEF_ON_arm.\n";
132 cpl_recipe *recipe = NULL;
133 cpl_plugin *plugin = NULL;
135 recipe = cpl_calloc(1,
sizeof(*recipe));
136 if ( recipe == NULL ){
140 plugin = &recipe->interface ;
142 cpl_plugin_init(plugin,
145 CPL_PLUGIN_TYPE_RECIPE,
156 cpl_pluginlist_append(list, plugin);
158 return (cpl_error_get_code() != CPL_ERROR_NONE);
174 cpl_recipe *recipe = NULL;
178 20, 50, 140., 2., 0 } ;
184 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin");
187 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
188 CPL_ERROR_TYPE_MISMATCH,
189 "Plugin is not a recipe");
191 recipe = (cpl_recipe *)plugin;
194 recipe->parameters = cpl_parameterlist_new();
195 assure( recipe->parameters != NULL,
196 CPL_ERROR_ILLEGAL_OUTPUT,
197 "Memory allocation failed!");
208 recipe->parameters ) ) ;
210 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
228 cpl_recipe *recipe = NULL;
231 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin" );
234 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
235 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
237 recipe = (cpl_recipe *)plugin;
244 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
264 cpl_recipe *recipe = NULL;
267 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin" );
270 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
271 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
273 recipe = (cpl_recipe *)plugin;
278 if (cpl_error_get_code() != CPL_ERROR_NONE)
298 cpl_frameset* frameset)
301 int recipe_tags_size = 1;
304 cpl_frameset* raws = NULL;
305 cpl_frameset* calib = NULL;
306 cpl_frame* bpmap = NULL;
307 cpl_frame* master_bias = NULL;
308 cpl_frame* master_dark = NULL;
309 cpl_frame * order_tab_guess = NULL ;
310 cpl_frame * orderframe = NULL ;
311 cpl_frame * spectralformat_frame = NULL ;
312 cpl_frame * rmbias = NULL ;
313 cpl_frame * intFrame = NULL ;
314 cpl_frame * nir_on = NULL ;
315 cpl_frame * nir_off = NULL ;
318 cpl_frame * resFrame = NULL ;
324 cpl_frame* resid_tab=NULL;
327 int pre_overscan_corr=0;
333 recipe_tags, recipe_tags_size,
378 spectralformat_frame));
384 "pre-overscan-corr"));
390 xsh_msg_dbg_low(
"Search Window: %d, Running Window: %d, Fit Window: %d",
424 if(master_bias!= NULL) {
429 rmbias=cpl_frame_duplicate(orderframe);
433 if(master_dark!= NULL) {
435 sprintf( fname,
"ORDERPOS_%s_DARK.fits",
440 intFrame=cpl_frame_duplicate(rmbias);
457 xsh_msg(
"Calling detect continuum" ) ;
460 spectralformat_frame,
464 "Error in xsh_detect_continuum, try to increase detectcontinuum-fit-win-hsize or detectcontinuum-ordertab-deg-y or detectcontinuum-clip-sigma or detectcontinuum-search-win-hsize" ) ;
470 xsh_msg(
"Save Order Table product" ) ;
478 sprintf(tag,
"ORDERDEF_ON");
481 sprintf(tag,
"ORDERDEF_ON");
static xsh_instrument * instrument
cpl_frame * xsh_pre_frame_subtract(cpl_frame *one, cpl_frame *two, const char *filename, xsh_instrument *instr, const int clean_tmp)
Subtract 2 frames (in XSH_PRE format) Just loads the 2 frames, subtract (xsh_pre_subtract) and save r...
cpl_frame * xsh_detect_continuum(cpl_frame *frame, cpl_frame *order_table, cpl_frame *spectral_frame, xsh_detect_continuum_param *detect_param, xsh_clipping_param *dcn_clipping, xsh_instrument *instr, cpl_frame **resid_frame)
Detect order and compute polynomial description of ordermin and order max. Uses a guess order table i...
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 check_msg(COMMAND,...)
#define xsh_error_reset()
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.
void xsh_instrument_update_lamp(xsh_instrument *i, XSH_LAMP lamp)
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.
#define xsh_msg_dbg_low(...)
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static char xsh_orderpos_description_short[]
static char xsh_orderpos_description[]
static int xsh_orderpos_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static int xsh_orderpos_create(cpl_plugin *)
Setup the recipe options.
static int xsh_orderpos_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static void xsh_orderpos(cpl_parameterlist *, cpl_frameset *)
Interpret the command line options and execute the data processing.
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.
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.
cpl_error_code xsh_monitor_flux(cpl_frame *frm_ima, const cpl_frame *frm_tab, xsh_instrument *instrument, const char *qc_key_prefix)
Monitor Flux level along the orders traces given by an input table
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.
cpl_error_code xsh_end(const char *recipe_id, cpl_frameset *frames, cpl_parameterlist *parameters)
Recipe termination.
cpl_frame * xsh_find_raw_orderdef_vis_uvb(cpl_frameset *frames)
Find orderdef raw frame for UVB or VIS.
cpl_frame * xsh_find_raw_orderdef_nir(cpl_frameset *frames)
Find orderdef raw frame for NIR.
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)
cpl_frame * xsh_find_raw_orderdef_nir_off(cpl_frameset *frames)
Find orderdef raw frame for NIR OFF.
cpl_frame * xsh_find_frame_with_tag(cpl_frameset *frames, const char *tag, xsh_instrument *instr)
Find frame with a given tag.
#define XSH_ORDER_TAB_GUESS
#define XSH_SPECTRAL_FORMAT
cpl_frame * xsh_check_load_master_bpmap(cpl_frameset *calib, xsh_instrument *inst, const char *rec_id)
xsh_detect_continuum_param * xsh_parameters_detect_continuum_get(const char *recipe_id, cpl_parameterlist *list)
Get the detect continuum parameters in a parameters list.
void xsh_parameters_pre_overscan(const char *recipe_id, cpl_parameterlist *plist)
cpl_error_code xsh_parameters_decode_bp(const char *recipe_id, cpl_parameterlist *plist, const int ival)
xsh_clipping_param * xsh_parameters_clipping_dcn_get(const char *recipe_id, cpl_parameterlist *list)
Get the detectcontinuum 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_detect_continuum_create(const char *recipe_id, cpl_parameterlist *list, xsh_detect_continuum_param par)
create the detect continuum parameter "window" 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_clipping_dcn_create(const char *recipe_id, cpl_parameterlist *list)
create the DetectContiNuum clipping parameters in a parameters list
#define DETECT_CONTINUUM_POLYNOMIAL_DEGREE
#define XSH_FREE(POINTER)