74#define RECIPE_ID "xsh_scired_ifu_stare"
75#define RECIPE_AUTHOR "A.Modigliani, J.Vernet, P. Bristow"
76#define RECIPE_CONTACT "Andrea.Modigliani@eso.org"
97"Reduce science IFU stare exposures and build a 3D cube";
100"This recipe reduce science IFU stare exposures with 3D cube generation\n\
102 - A set of n Science frames ( n == 1 or >=3, \
103 Tag = OBJECT_IFU_STARE_UVB)\n\
104 - A spectral format table frame (Tag = SPECTRAL_FORMAT_TAB_arm)\n\
105 - [UVB,VIS] A master bias frame (Tag = MASTER_BIAS_arm)\n\
106 - A master dark frame (Tag = MASTER_DARK_arm)\n\
107 - A master flat frame (Tag = MASTER_FLAT_IFU_arm)\n\
108 - An order edges table frame(Tag = ORDER_TAB_EDGES_IFU_arm)\n\
109 - [physmod] An AFC corrected model cfg frame (Tag = XSH_MOD_CFG_OPT_AFC_arm)\n\
110 - [poly] An AFC corrected model wavesol frame (Tag = WAVE_TAB_AFC_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\
114 - Merged 3D data cube (PREFIX_MERGE3D_DATA_OBJ_arm)\n\
115 - QC Traces of 3D data cube (PREFIX_MERGE3D_TRACE_OBJ_arm)\n\
116 - Order by order 3D data cube (PREFIX_ORDER3D_DATA_OBJ_arm)\n\
117 - Order by order 3D qual cube (IFU_CFG_COR_arm)\n\
118 - Order by order 3D qual cube (PREFIX_MERGE3D_DATA_SKY_arm)\n\
119 - where PREFIX is SCI, FLUX, TELL if input raw DPR.TYPE contains OBJECT or FLUX or TELLURIC\n";
137 cpl_recipe *recipe = NULL;
138 cpl_plugin *plugin = NULL;
140 recipe = cpl_calloc(1,
sizeof(*recipe));
141 if ( recipe == NULL ){
145 plugin = &recipe->interface ;
147 cpl_plugin_init(plugin,
150 CPL_PLUGIN_TYPE_RECIPE,
161 cpl_pluginlist_append(list, plugin);
163 return (cpl_error_get_code() != CPL_ERROR_NONE);
179 cpl_recipe *recipe = NULL;
183 CPL_KERNEL_DEFAULT, 2,
198 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin");
201 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
202 CPL_ERROR_TYPE_MISMATCH,
203 "Plugin is not a recipe");
205 recipe = (cpl_recipe *)plugin;
208 recipe->parameters = cpl_parameterlist_new();
209 assure( recipe->parameters != NULL,
210 CPL_ERROR_ILLEGAL_OUTPUT,
211 "Memory allocation failed!");
240 "compute-map", FALSE,
241 "if TRUE recompute (wave and slit) maps from the dispersion solution. If sky-subtract is set to TRUE this must be set to TRUE."));
245 "if TRUE trace object position on each IFU slice. In this case order TAB edges is required"));
250 "Input AFC corrected model/wave solution and science frame check. If TRUE the recipe verify that the input mode/wave solution is AFC corrected, its INS.OPTIi.NAME is 'Pin_0.5 ', and its OBS.ID and OBS.TARG.NAME values matches with the corresponding values of the science frame."));
253 "cut-uvb-spectrum", TRUE,
254 "TRUE if recipe cuts the UVB spectrum at 556 nm (dichroich)"));
256 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
279 cpl_frame* frame=NULL;
280 const char* name=NULL;
281 cpl_propertylist* plist=NULL;
285 check(frame=cpl_frameset_get_frame(raws,0));
286 check(name=cpl_frame_get_filename(frame));
287 check(plist=cpl_propertylist_load(name,0));
345 return cpl_error_get_code();
358 cpl_recipe *recipe = NULL;
362 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin" );
365 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
366 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
368 recipe = (cpl_recipe *)plugin;
374 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
393 cpl_recipe *recipe = NULL;
398 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin" );
400 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
401 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
403 recipe = (cpl_recipe *)plugin;
408 if (cpl_error_get_code() != CPL_ERROR_NONE)
429 xsh_msg_dbg_low(
"rectify params: radius=%g bin_lambda=%g bin_space=%g",
433 return cpl_error_get_code();
447 cpl_frameset* frameset)
454 int recipe_tags_size = 4;
457 cpl_frameset *raws = NULL;
458 cpl_frameset *calib = NULL;
462 cpl_frame *spectral_format = NULL;
463 cpl_frame *ifu_cfg_tab_frame = NULL ;
464 cpl_frame *ifu_cfg_cor_frame = NULL ;
469 cpl_frame *bpmap = NULL;
470 cpl_frame *master_bias = NULL;
471 cpl_frame *master_dark = NULL;
472 cpl_frame *master_flat = NULL;
473 cpl_frame *order_tab_edges = NULL;
475 cpl_frame *model_config_frame = NULL ;
476 cpl_frame *wavemap = NULL ;
477 cpl_frame *slitmap = NULL ;
478 cpl_frame *disp_tab_frame = NULL;
486 int do_compute_map = 0;
488 int recipe_use_model = FALSE;
489 int check_afc = TRUE;
490 int do_trace_obj = 0;
496 cpl_frame * crhm_frame = NULL ;
497 cpl_frame * rmbias = NULL;
498 cpl_frame * rmdark = NULL;
499 cpl_frame * rmbkg = NULL ;
500 cpl_frame *div_frame = NULL ;
503 cpl_frame* grid_backg=NULL;
504 cpl_frame* frame_backg=NULL;
506 const char* ftag=NULL;
507 char rec_prefix[256];
512 cpl_frame* wavesol=NULL;
513 cpl_frame* order_tab_edges_frame=NULL;
515 char wave_map_tag[256];
516 char slit_map_tag[256];
518 int pre_overscan_corr=0;
519 cpl_frame* ifu_sky_map=NULL;
524 recipe_tags, recipe_tags_size,
RECIPE_ID, XSH_BINARY_VERSION,
528 "Instrument NOT in IFU Mode");
536 check( nb_raw_frames = cpl_frameset_get_size( raws ) ) ;
539 if(nb_raw_frames>1) {
544 "pre-overscan-corr"));
548 check(strcpy(rec_prefix,(
const char*)prefix));
552 &master_dark, &master_flat, &order_tab_edges,
553 &model_config_frame, &bpmap, &wavemap, &slitmap,
554 &ifu_cfg_tab_frame, &ifu_cfg_cor_frame, &wavesol,
555 RECIPE_ID, &recipe_use_model, pre_overscan_corr));
562 recipe_use_model = ( model_config_frame != NULL);
583 if ( do_compute_map && recipe_use_model==FALSE){
602 xsh_msg(
"---Prepare raws frames");
608 if ( nb_raw_frames >= 3 ) {
615 "Error in xsh_remove_crh" ) ;
619 check( crhm_frame = cpl_frame_duplicate(cpl_frameset_get_frame( raws,0 )));
621 xsh_msg(
"created %s", cpl_frame_get_filename( crhm_frame));
624 if (recipe_use_model){
626 xsh_msg(
"correct for temperature");
631 if ( do_compute_map){
634 if (recipe_use_model){
640 wave_map_tag,slit_map_tag,
641 &wavemap, &slitmap,0));
645 xsh_msg(
"Compute the wave map and the slit map");
648 &wavemap, &slitmap,rec_prefix));
650 cpl_frameset_insert( calib, wavemap);
651 cpl_frameset_insert( calib, slitmap);
661 pre_overscan_corr,0));
669 if(model_config_frame!=NULL) {
681 if ( master_dark != NULL ) {
683 sprintf(name,
"%s_DARK_%s.fits",
690 check( rmdark = cpl_frame_duplicate( rmbias ) ) ;
696 xsh_msg(
"---Subtract_background");
698 order_tab_edges, backg_par,
instrument, rec_prefix,&grid_backg,
699 &frame_backg,0,0,0 ));
704 sprintf( tag,
"%s_FF_%s",
706 sprintf(name,
"%s.fits",tag);
713 if(do_trace_obj && do_compute_map) {
718 cpl_frame_get_filename(order_tab_edges_frame),
719 cpl_frame_get_filename(slitmap),
720 cpl_frame_get_filename(wavemap)));
729 parameters,rectify_par,
RECIPE_ID,rec_prefix,1));
static xsh_instrument * instrument
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
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_ASSURE_NOT_ILLEGAL(cond)
#define assure(CONDITION, ERROR_CODE,...)
#define xsh_error_dump(level)
#define check_msg(COMMAND,...)
#define xsh_error_reset()
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
void xsh_mode_set(xsh_instrument *instrument, XSH_MODE mode)
set the instrument mode as user specifies
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(...)
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_frame * xsh_remove_crh_multiple(cpl_frameset *rawFrames, const char *name, xsh_stack_param *stack_param, xsh_clipping_param *crh_clipping, xsh_instrument *inst, cpl_imagelist **, cpl_image **, const int save_tmp)
static cpl_error_code xsh_params_monitor(xsh_background_param *backg, xsh_rectify_param *rectify_par)
static char xsh_scired_ifu_stare_description[]
static char xsh_scired_ifu_stare_description_short[]
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.
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.
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.
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.
void xsh_add_temporary_file(const char *name)
Add temporary file to temprary files list.
void xsh_create_map(cpl_frame *dispsol_frame, cpl_frame *ordertab_frame, cpl_frame *pre_frame, xsh_instrument *instrument, cpl_frame **wavemap_frame, cpl_frame **slitmap_frame, const char *rec_prefix)
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_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.
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)
cpl_frame * xsh_find_slitmap(cpl_frameset *frames, xsh_instrument *instr)
Find a slit map.
cpl_error_code xsh_frameset_check_uniform_exptime(cpl_frameset *raws, xsh_instrument *inst)
#define XSH_STD_FLUX_IFU_STARE
#define XSH_SLIT_STARE_REMOVE_CRH
#define XSH_SLIT_MAP_MODEL
#define XSH_STD_TELL_IFU_STARE
#define XSH_OBJECT_IFU_STARE
#define XSH_WAVE_MAP_MODEL
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
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_error_code xsh_model_temperature_update_frame(cpl_frame **model_config_frame, cpl_frame *ref_frame, xsh_instrument *instrument, int *found_temp)
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
cpl_error_code xsh_parameters_decode_bp(const char *recipe_id, cpl_parameterlist *plist, const int ival)
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
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
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
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)
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
static int xsh_scired_ifu_stare_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static int xsh_scired_ifu_stare_create(cpl_plugin *)
Setup the recipe options.
static int xsh_scired_ifu_stare_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static cpl_error_code xsh_params_bin_scale(cpl_frameset *raws, xsh_background_param *backg)
Rescale input parameters for binning.
static void xsh_scired_ifu_stare(cpl_parameterlist *, cpl_frameset *)
Interpret the command line options and execute the data processing.
#define XSH_FREE(POINTER)
cpl_error_code xsh_build_ifu_cube(cpl_frame *div_frame, cpl_frame *ifu_cfg_tab_frame, cpl_frame *ifu_cfg_cor_frame, cpl_frame *spectral_format_frame, cpl_frame *model_config_frame, cpl_frame *wavesol_frame, xsh_instrument *instrument, cpl_frameset *frameset, cpl_parameterlist *parameters, xsh_rectify_param *rectify_par, const char *recipe_id, const char *rec_prefix, const int frame_is_object)
Reconstruct IFU cube.
cpl_error_code xsh_frame_check_model_cfg_is_proper_for_sci(cpl_frame *model_config_frame, cpl_frame *sci_frame, xsh_instrument *instrument)
Check if a model configuration frame has been corrected for flexures.
cpl_error_code xsh_frame_check_model_cfg_is_afc_corrected(cpl_frame *model_config_frame)
utility to check if a frame has been corrected for flexures
cpl_frame * xsh_build_ifu_map(cpl_frame *div_frame, cpl_frame *wavemap_frame, cpl_frame *slitmap_frame, xsh_instrument *instrument)
Reconstruct IFU cube.
cpl_error_code xsh_ifu_trace_object_calibrate(const char *ifu_object_ff_name, const char *order_tab_edges_ifu_name, const char *slit_map_name, const char *wave_map_name)
Function to calibrate object traces in IFU mode.
cpl_error_code xsh_ifu_stare_get_calibs(cpl_frameset *calib, xsh_instrument *inst, cpl_frame **spectral_format, cpl_frame **mbias, cpl_frame **mdark, cpl_frame **mflat, cpl_frame **otab_edges, cpl_frame **model_cfg, cpl_frame **bpmap, cpl_frame **wmap, cpl_frame **smap, cpl_frame **ifu_cfg_tab, cpl_frame **ifu_cfg_cor, cpl_frame **wavesol, const char *rec_id, int *recipe_use_model, int pscan)