72#define RECIPE_ID "xsh_scired_ifu_stare_drl"
73#define RECIPE_AUTHOR "P.Goldoni, L.Guglielmi, R. Haigron, F. Royer"
74#define RECIPE_CONTACT "amodigli@eso.org"
95"Reduce science exposure in IFU configuration and stare mode";
98"This recipe reduces science exposure in IFU configuration and stare mode\n\
100 - A set of n Science frames ( n == 1 or >=3, \
101Tag = OBJECT_IFU_STARE_arm or STD_TELL_IFU_STARE_arm or STD_FLUX_IFU_STARE_arm)\n\
102 - A spectral format table (Tag = SPECTRAL_FORMAT_TAB_arm)\n\
103 - [UVB,VIS] A master bias frame (Tag = MASTER_BIAS_arm)\n\
104 - [OPTIONAL]A master dark frame (Tag = MASTER_DARK_arm)\n\
105 - A master flat frame (Tag = MASTER_FLAT_IFU_arm)\n\
106 - An AFC corrected order table frame (Tag = ORDER_TAB_AFC_IFU_arm)\n\
107 - [physmod] An AFC corrected model cfg frame (Tag = XSH_MOD_CFG_OPT_AFC_arm)\n\
108 - [poly] An AFC corrected model wavesol frame (Tag = WAVE_TAB_AFC_arm) \n\
109 - [OPTIONAL] An AFC corrected dispersion solution frame (Tag = DISP_TAB_AFC_arm)\n\
110 - [OPTIONAL] A slit map (Tag = SLIT_MAP_arm)\n\
111 - [OPTIONAL] A badpixel map (Tag = BADPIXEL_MAP_arm)\n\
112 - [OPTIONAL] A mask of telluric lines (Tag = TELL_MASK_arm)\n\
114 - 3 Spectrum order tables 2D (1 per slitlet), PRO.CATG=ORDER2D_slitlet_IFU_arm\n\
115 - 3 Spectrum merge tables 2D (1 per slitlet), PRO.CATG=MERGE2D_slitlet_IFU_arm\n\
116 - 1 Spectrum merge 3D, PRO.CATG=MERGE3D_IFU_arm\n" ;
134 cpl_recipe *recipe = NULL;
135 cpl_plugin *plugin = NULL;
137 recipe = cpl_calloc(1,
sizeof(*recipe));
138 if ( recipe == NULL ){
142 plugin = &recipe->interface ;
144 cpl_plugin_init(plugin,
147 CPL_PLUGIN_TYPE_RECIPE,
158 cpl_pluginlist_append(list, plugin);
160 return (cpl_error_get_code() != CPL_ERROR_NONE);
176 cpl_recipe *recipe = NULL;
177 cpl_parameter* p=NULL;
179 char recipename[256];
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!");
253 recipe->parameters,ipol_par)) ;
255 "shift-offsettab-low", 0.0,
256 "Global shift of the lower slitlet slit positions, relative to the central one[arcsec]."));
258 "shift-offsettab-up", 0.0,
259 "Global shift of the upper slitlet slit positions, relative to the central one[arcsec]."));
263 "if TRUE recompute (wave and slit) maps from the dispersion solution. If sky-subtract is set to TRUE this must be set to TRUE."));
267 "Input AFC corrected model/wave solution and science frame check."\
268 "If TRUE the recipe verify that the input mode/wave solution is AFC corrected,"\
269 " its INS.OPTIi.NAME is 'Pin_0.5 ', and its OBS.ID and OBS.TARG.NAME values"\
270 " matches with the corresponding values of the science frame."));
273 sprintf(paramname,
"%s.%s",recipename,
"flat-method");
274 check( p = cpl_parameter_new_enum( paramname,CPL_TYPE_STRING,
275 "method adopted for flat:",
277 2,
"master",
"blaze"));
279 check(cpl_parameter_set_alias( p,CPL_PARAMETER_MODE_CLI,
281 check(cpl_parameterlist_append( recipe->parameters, p));
284 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
302 cpl_recipe *recipe = NULL;
306 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin" );
309 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
310 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
312 recipe = (cpl_recipe *)plugin;
318 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
337 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)
377 xsh_msg_dbg_low(
"rectify params: radius=%g bin_lambda=%g bin_space=%g",
384 return cpl_error_get_code();
402 cpl_frame* frame=NULL;
403 const char* name=NULL;
404 cpl_propertylist* plist=NULL;
408 check(frame=cpl_frameset_get_frame(raws,0));
409 check(name=cpl_frame_get_filename(frame));
410 check(plist=cpl_propertylist_load(name,0));
468 return cpl_error_get_code();
482 cpl_frameset* frameset)
487 int recipe_tags_size = 3;
492 cpl_frameset *raws = NULL;
493 cpl_frameset *calib = NULL;
496 cpl_frame *bpmap = NULL;
497 cpl_frame *master_bias = NULL;
498 cpl_frame *master_dark = NULL;
499 cpl_frame *master_flat = NULL;
500 cpl_frame *order_tab_edges = NULL;
501 cpl_frame *wavetab_frame = NULL;
502 cpl_frameset *wavetab_frameset = NULL ;
503 cpl_frame *model_config_frame = NULL ;
504 cpl_frame *spectral_format = NULL ;
505 cpl_frame *disp_tab_frame = NULL;
506 cpl_frame *shifttab_frame = NULL;
517 double offset_low =0.0;
518 double offset_up =0.0;
522 int recipe_use_model = FALSE;
523 int do_computemap = 0;
524 int check_afc = TRUE;
527 cpl_frame *slitmap_frame = NULL;
528 cpl_frame *wavemap_frame = NULL;
529 cpl_frame *crhm_frame = NULL ;
530 cpl_frame *rmbias = NULL;
531 cpl_frame *rmdark = NULL;
532 cpl_frame *rmbkg = NULL ;
533 cpl_frame *clean_frame = NULL ;
534 cpl_frame *div_frame = NULL ;
535 cpl_frameset *rect_frameset = NULL ;
536 cpl_frameset *loc_table_frameset = NULL ;
539 cpl_frameset *res_2D_frameset = NULL ;
540 cpl_frame *data_cube = NULL ;
543 const char * ftag=NULL;
544 cpl_frame* grid_backg=NULL;
545 cpl_frame* frame_backg=NULL;
546 cpl_frameset* rect_frameset_eso=NULL;
547 cpl_frameset* rect_frameset_tab=NULL;
548 char *rec_prefix = NULL;
549 int pre_overscan_corr=0;
551 cpl_frameset *shiftifu_frameset = NULL;
552 cpl_frameset *nshiftifu_frameset = NULL;
555 cpl_propertylist* plist=NULL;
556 const char* name=NULL;
559 cpl_frame* qc_trace_frame=NULL;
561 const int peack_search_hsize=5;
563 char* flat_method = NULL;
566 cpl_frame * blaze_frame = NULL;
572 recipe_tags, recipe_tags_size,
577 "Instrument NOT in IFU Mode" ) ;
581 check( nb_raw_frames = cpl_frameset_get_size( raws));
584 "This recipe expects either one or at least 3 input raw frames" );
609 if(model_config_frame==NULL) {
615 if ( model_config_frame == NULL){
616 xsh_msg(
"RECIPE USE WAVE SOLUTION");
617 recipe_use_model = FALSE;
621 recipe_use_model = TRUE;
624 (model_config_frame == NULL && wavetab_frame != NULL ) );
649 if ( recipe_use_model == FALSE){
680 if ( do_computemap && recipe_use_model==FALSE){
693 "shift-offsettab-low"));
696 "shift-offsettab-up"));
699 if ( shiftifu_frameset != NULL){
700 xsh_msg(
"offset low %f up %f", offset_low, offset_up);
702 offset_low, offset_up));
726 crhm_frame, model_config_frame, calib,
instrument,
727 do_computemap, recipe_use_model, rec_prefix,
728 &wavemap_frame, &slitmap_frame));
731 sprintf(prefix,
"%s_",rec_prefix);
735 pre_overscan_corr,0));
741 rmbias, wavetab_frameset, order_tab_edges, disp_tab_frame,
749 xsh_msg(
"Subtract inter-order background");
753 rec_prefix,&grid_backg,
754 &frame_backg,1,1,1 ));
756 if ( nb_raw_frames == 1 ) {
757 char * nocrh_tag = NULL ;
762 xsh_msg(
"Remove crh (single frame)" ) ;
770 clean_frame = cpl_frame_duplicate( rmbkg) ;
773 xsh_msg(
"---Divide by flat" ) ;
774 sprintf(div_tag,
"%s_DIV_FF_%s",
780 xsh_msg(
"method %s", flat_method);
782 if ( strcmp( flat_method,
"master") == 0){
787 xsh_msg(
"---Create blaze image");
797 rect_frameset_eso=cpl_frameset_new();
798 rect_frameset_tab=cpl_frameset_new();
805 slitmap_frame, &rect_frameset_eso,
806 &rect_frameset_tab,rec_prefix ));
812 xsh_msg(
"Merge orders with 2D frame" ) ;
814 merge_par,rec_prefix ));
820 xsh_msg(
"Saving Products for IFU" ) ;
822 for( i = 0 ; i<3 ; i++ ) {
823 cpl_frame * rec_frame = NULL ;
824 cpl_frame * res2d_frame = NULL ;
826 check( rec_frame = cpl_frameset_get_frame( rect_frameset_eso, i ) ) ;
830 check( res2d_frame = cpl_frameset_get_frame( res_2D_frameset, i ) ) ;
838 name=cpl_frame_get_filename(data_cube);
839 plist=cpl_propertylist_load(name,0);
static xsh_instrument * instrument
cpl_frame * xsh_divide_by_blaze(cpl_frame *pre_frame, cpl_frame *blaze_frame, xsh_instrument *instrument)
Divide a pre image by the blaze image.
cpl_frame * xsh_blaze_image(cpl_frame *masterflat_frame, cpl_frame *order_frame, xsh_instrument *instrument)
Normalize a master flat frame order by order.
cpl_frame * xsh_divide_flat(cpl_frame *frame, cpl_frame *flat, const char *tag, xsh_instrument *instr)
divide PRE frame with the master FLAT frame
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_REGDEBUG(...)
#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)
cpl_frameset * xsh_ifu_wavetab_create(cpl_frame *wave_tab_frame, cpl_frame *shift_tab_frame, xsh_instrument *instr)
Create an IFU wave tab frame set.
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_frameset * xsh_localize_obj_ifu(cpl_frameset *sci_frame, cpl_frame *skymask_frame, xsh_instrument *instrument, xsh_localize_obj_param *loc_obj_par, xsh_slit_limit_param *slit_limit_param)
cpl_frameset * xsh_merge_ord_ifu(cpl_frameset *rec_frameset, xsh_instrument *instrument, int merge_par, const char *rec_prefix)
Merge orders of the rectified frame using merge parameters.
#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 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
int xsh_pfits_get_naxis2(const cpl_propertylist *plist)
find out the NAXIS2 value
cpl_frameset * xsh_rectify_ifu(cpl_frame *sci_frame, cpl_frame *order_table_frame, cpl_frameset *wavesol_frame_set, cpl_frameset *shiftifu_frameset, cpl_frame *model_config_frame, xsh_instrument *instrument, xsh_rectify_param *rectify_par, cpl_frame *spectral_format, cpl_frame *slitmap_frame, cpl_frameset **rec_frameset_ext, cpl_frameset **rec_frameset_tab, const char *rec_prefix)
cpl_frame * xsh_remove_crh_single(cpl_frame *sci_frame, xsh_instrument *instrument, cpl_mask *sky_map, xsh_remove_crh_single_param *single_par, const char *name)
Remove cosmic rays from a single frame.
static int xsh_scired_ifu_stare_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static cpl_error_code xsh_params_monitor(xsh_background_param *backg, xsh_rectify_param *rectify_par, xsh_localize_obj_param *loc_obj_par)
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int xsh_scired_ifu_stare_create(cpl_plugin *)
Setup the recipe options.
static char xsh_scired_ifu_stare_description[]
static int xsh_scired_ifu_stare_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static char xsh_scired_ifu_stare_description_short[]
static cpl_error_code xsh_params_bin_scale(cpl_frameset *raws, xsh_background_param *backg)
Scales input parameters for binning.
static void xsh_scired_ifu_stare(cpl_parameterlist *, cpl_frameset *)
Interpret the command line options and execute the data processing.
cpl_frame * xsh_subtract_background(cpl_frame *frame, cpl_frame *ordertable, xsh_background_param *bckg, xsh_instrument *instr, const char *prefix, cpl_frame **grid_frame, cpl_frame **frame_backg, const int save_bkg, const int save_grid, const int save_sub_bkg)
Subtract the inter-order background 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.
char * xsh_set_recipe_file_prefix(cpl_frameset *raw, const char *recipe)
Set recipe frames prefix.
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.
cpl_error_code xsh_rectify_params_set_defaults(cpl_parameterlist *pars, const char *rec_id, xsh_instrument *inst, xsh_rectify_param *rectify_par)
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_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.
void xsh_add_product_pre(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instr, cpl_propertylist *qclist)
Add DFS keywords to a product frame.
void xsh_add_product_pre_3d(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instr)
Add 3d product frame.
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_frameset * xsh_find_offset_tab_ifu(cpl_frameset *frames, xsh_instrument *instr)
Find offset tab (One for each slitlet)
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.
cpl_frame * xsh_find_master_flat(cpl_frameset *frames, xsh_instrument *instr)
Find master flat frame.
cpl_frame * xsh_find_master_bpmap(cpl_frameset *set)
find the master bad pixel map in a set of files
#define XSH_MOD_CFG_OPT_AFC
#define XSH_ORDER_TAB_AFC_IFU
#define XSH_STD_FLUX_IFU_STARE
#define XSH_STD_TELL_IFU_STARE
#define XSH_SHIFT_TAB_IFU
#define XSH_SLIT_BIN_SIZE_PIPE_NIR
#define XSH_OBJECT_IFU_STARE
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
#define XSH_WAVE_BIN_SIZE_PIPE_NIR
#define XSH_IFU_STARE_REMOVE_CRH
cpl_frame * xsh_check_remove_crh_multiple(cpl_frameset *raws, const char *ftag, xsh_stack_param *stack_par, xsh_clipping_param *crh_clipping_par, xsh_instrument *instr, cpl_imagelist **lista, cpl_image **listb)
Check function.
void xsh_check_afc(int check_flag, cpl_frame *model_frame, cpl_frame *sci_frame, cpl_frameset *wave_frameset, cpl_frame *order_tab_frame, cpl_frame *disp_tab_frame, xsh_instrument *instrument)
Check AFC frame.
cpl_frame * xsh_check_subtract_bias(cpl_frame *crhm_frame, cpl_frame *master_bias, xsh_instrument *instrument, const char *prefix, const int pre_overscan_corr, const int save_tmp)
Check function to subtract bias.
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.
void xsh_check_get_map(cpl_frame *disp_tab_frame, cpl_frame *order_tab_edges, cpl_frame *crhm_frame, cpl_frame *model_config_frame, cpl_frameset *calib, xsh_instrument *instrument, int do_computemap, int recipe_use_model, const char *rec_prefix, cpl_frame **wavemap_frame, cpl_frame **slitmap_frame)
Check function to get wave and slit maps.
void xsh_parameters_pre_overscan(const char *recipe_id, cpl_parameterlist *plist)
void xsh_parameters_new_boolean(cpl_parameterlist *list, const char *recipe_id, const char *name, int value, const char *comment)
void xsh_parameters_stack_create(const char *recipe_id, cpl_parameterlist *list, xsh_stack_param sp)
create the RON determination parameters in a parameters list
int xsh_parameters_get_boolean(const cpl_parameterlist *list, const char *recipe_id, const char *name)
xsh_stack_param * xsh_stack_frames_get(const char *recipe_id, cpl_parameterlist *list)
get the detect arclines parameters in a parameters list
double xsh_parameters_get_double(const cpl_parameterlist *list, const char *recipe_id, const char *name)
cpl_error_code xsh_parameters_decode_bp(const char *recipe_id, cpl_parameterlist *plist, const int ival)
xsh_localize_obj_param * xsh_parameters_localize_obj_get(const char *recipe_id, cpl_parameterlist *list)
void xsh_parameters_new_double(cpl_parameterlist *list, const char *recipe_id, const char *name, double value, const char *comment)
void xsh_parameters_localize_obj_create(const char *recipe_id, cpl_parameterlist *plist, xsh_localize_obj_param p)
void xsh_parameters_clipping_crh_create(const char *recipe_id, cpl_parameterlist *list, xsh_clipping_param p)
create the crh clipping parameters in a parameters list
xsh_extract_param * xsh_parameters_extract_get(const char *recipe_id, cpl_parameterlist *list)
void xsh_parameters_rectify_create(const char *recipe_id, cpl_parameterlist *plist, xsh_rectify_param p)
void xsh_parameters_background_create(const char *recipe_id, cpl_parameterlist *list)
create the subtract background parameters in a parameters list
void xsh_parameters_interpolate_bp_create(const char *recipe_id, cpl_parameterlist *plist, xsh_interpolate_bp_param p)
void xsh_parameters_extract_create(const char *recipe_id, cpl_parameterlist *plist, xsh_extract_param p, enum extract_method method)
xsh_bary_corr_param * xsh_parameters_bary_corr_get(const char *recipe_id, cpl_parameterlist *list)
get the barycentric correction parameters in a parameters list
xsh_rectify_param * xsh_parameters_rectify_get(const char *recipe_id, cpl_parameterlist *list)
void xsh_parameters_bary_corr_create(const char *recipe_id, cpl_parameterlist *list, xsh_bary_corr_param p)
create the barycentric correction parameters in a parameters list
void xsh_parameters_remove_crh_single_create(const char *recipe_id, cpl_parameterlist *plist, xsh_remove_crh_single_param p)
xsh_remove_crh_single_param * xsh_parameters_remove_crh_single_get(const char *recipe_id, cpl_parameterlist *list)
xsh_clipping_param * xsh_parameters_clipping_crh_get(const char *recipe_id, cpl_parameterlist *list)
get the crh 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)
xsh_background_param * xsh_parameters_background_get(const char *recipe_id, cpl_parameterlist *list)
get the background parameters in a parameters list
char * xsh_parameters_get_string(const cpl_parameterlist *list, const char *recipe_id, const char *name)
#define XSH_FREE(POINTER)
cpl_frameset * xsh_shift_offsettab(cpl_frameset *shiftifu_frameset, double offset_low, double offset_up)
Do a wavelet decomposition using atrous from IDL.
cpl_frame * xsh_cube_qc_trace_window(cpl_frame *frm_cube, xsh_instrument *instrument, const char *suffix, const char *rec_prefix, const int win_min, const int win_max, const int hsize, const int method, const int compute_qc)
Trace object position in a cube.