62#define RECIPE_ID "xsh_util_efficiency2d"
63#define RECIPE_AUTHOR "A.Modigliani"
64#define RECIPE_CONTACT "Andrea.Modigliani@eso.org"
65#define PRO_IMA "PRO_IMA_UVB"
66#define KEY_VALUE_HPRO_DID "PRO-1.15"
68#define SPEED_LIGHT 2.99792458*1.E8
69#define TEL_AREA 51.2e4
86"This recipe compute efficiency.\n"
87"The input files should be tagged as: \n"
88"input observed spectrum: RAW_IMA_SLIT_arm,\n"
89"input reference spectrum: FLUX_STD_TABLE_arm,\n"
90"input atmospheric extintion table: EXTCOEFF_TABLE_arm)\n"
91"The output is a table with efficiency as function of wavelength\n"
92"Information on relevant parameters can be found with\n"
93"esorex --params xsh_util_efficiency2d\n"
94"esorex --help xsh_util_efficiency2d\n"
119 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe ) ;
120 cpl_plugin * plugin = &recipe->interface ;
122 cpl_plugin_init(plugin,
125 CPL_PLUGIN_TYPE_RECIPE,
136 cpl_pluginlist_append(list, plugin) ;
153 cpl_recipe * recipe ;
160 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
161 recipe = (cpl_recipe *)plugin ;
167 recipe->parameters = cpl_parameterlist_new() ;
172 recipe->parameters ) ) ;
175 p = cpl_parameter_new_value(
"xsh.xsh_util_efficiency2d.sky1_lly",
178 "xsh.xsh_util_efficiency2d",2);
179 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"sky1_lly") ;
180 cpl_parameterlist_append(recipe->parameters, p) ;
185 p = cpl_parameter_new_value(
"xsh.xsh_util_efficiency2d.sky1_ury",
188 "xsh.xsh_util_efficiency2d",20);
189 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"sky1_ury") ;
190 cpl_parameterlist_append(recipe->parameters, p) ;
196 p = cpl_parameter_new_value(
"xsh.xsh_util_efficiency2d.sky2_lly",
199 "xsh.xsh_util_efficiency2d",75);
200 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"sky2_lly") ;
201 cpl_parameterlist_append(recipe->parameters, p) ;
206 p = cpl_parameter_new_value(
"xsh.xsh_util_efficiency2d.sky2_ury",
209 "xsh.xsh_util_efficiency2d",100);
210 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"sky2_ury") ;
211 cpl_parameterlist_append(recipe->parameters, p) ;
218 p = cpl_parameter_new_value(
"xsh.xsh_util_efficiency2d.obj_lly",
221 "xsh.xsh_util_efficiency2d",22);
222 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"obj_lly") ;
223 cpl_parameterlist_append(recipe->parameters, p) ;
228 p = cpl_parameter_new_value(
"xsh.xsh_util_efficiency2d.obj_ury",
231 "xsh.xsh_util_efficiency2d",70);
232 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"obj_ury") ;
233 cpl_parameterlist_append(recipe->parameters, p) ;
253 cpl_recipe * recipe ;
255 cpl_errorstate initial_errorstate = cpl_errorstate_get();
258 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
259 recipe = (cpl_recipe *)plugin ;
266 if (!cpl_errorstate_is_equal(initial_errorstate)) {
269 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
284 cpl_recipe * recipe ;
287 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
288 recipe = (cpl_recipe *)plugin ;
291 cpl_parameterlist_delete(recipe->parameters) ;
313 w1=cpl_table_get_column_min(tbl,colx);
314 w2=cpl_table_get_column_max(tbl,colx);
315 pos_y1=cpl_table_get_column_min(tbl,coly);
316 pos_y2=cpl_table_get_column_max(tbl,coly);
319 pw=cpl_table_get_data_float(tbl,colx);
320 pe=cpl_table_get_data_float(tbl,coly);
321 nrow=cpl_table_get_nrow(tbl);
324 for(i=0;i<nrow-1;i++) {
333 y=pos_y1+(pos_y2-pos_y1)/(w2-w1)*(wav-w1);
351 cpl_frameset * frames)
354 int recipe_tags_size = 1;
357 cpl_parameter * param= NULL ;
358 cpl_frame* frm_sci=NULL;
359 cpl_frame* frm_ref=NULL;
360 cpl_frame* frm_atmext=NULL;
362 cpl_frameset* raws=NULL;
363 cpl_frameset* calib=NULL;
365 cpl_image* ima_sci=NULL;
366 cpl_table* tbl_ref=NULL;
367 cpl_table* tbl_ext=NULL;
368 cpl_table* tbl_atmext=NULL;
370 const char* name=NULL;
376 cpl_propertylist* plist=NULL;
385 double aimprim=1.446;
392 double airmass_start=0;
393 double airmass_end=0;
398 cpl_image* ima_ord=0;
399 cpl_image* ima_obj=0;
400 cpl_image* ima_sky1=0;
401 cpl_image* ima_sky2=0;
402 cpl_image* ima_sky=0;
413 cpl_table* obj_tab=NULL;
423 cpl_table* tbl_sel=NULL;
426 xsh_msg(
"Welcome to XSHOOTER Pipeline release %d.%d.%d",
427 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
431 recipe_tags, recipe_tags_size,
437 check(param=cpl_parameterlist_find(parlist,
"xsh.xsh_util_efficiency2d.sky1_lly"));
438 check(sky1_lly=cpl_parameter_get_int(param));
440 check(param=cpl_parameterlist_find(parlist,
"xsh.xsh_util_efficiency2d.sky1_ury"));
441 check(sky1_ury=cpl_parameter_get_int(param));
444 check(param=cpl_parameterlist_find(parlist,
"xsh.xsh_util_efficiency2d.sky2_lly"));
445 check(sky2_lly=cpl_parameter_get_int(param));
447 check(param=cpl_parameterlist_find(parlist,
"xsh.xsh_util_efficiency2d.sky2_ury"));
448 check(sky2_ury=cpl_parameter_get_int(param));
453 check(param=cpl_parameterlist_find(parlist,
"xsh.xsh_util_efficiency2d.obj_lly"));
454 check(obj_lly=cpl_parameter_get_int(param));
456 check(param=cpl_parameterlist_find(parlist,
"xsh.xsh_util_efficiency2d.obj_ury"));
457 check(obj_ury=cpl_parameter_get_int(param));
458 xsh_msg(
"Obj extraction window: %d %d",obj_lly,obj_ury);
459 xsh_msg(
"Sky1 extraction window: %d %d",sky1_lly,sky1_ury);
460 xsh_msg(
"Sky2 extraction window: %d %d",sky2_lly,sky2_ury);
468 check(next = cpl_frame_get_nextensions(frm_sci));
472 name=cpl_frame_get_filename(frm_sci);
474 check(plist=cpl_propertylist_load(name,0));
489 airmass=0.5*(airmass_start+airmass_end);
495 obj_tab=cpl_table_new(nrow);
496 cpl_table_new_column(obj_tab,
"ORD",CPL_TYPE_INT);
497 cpl_table_new_column(obj_tab,
"WAVELENGTH",CPL_TYPE_DOUBLE);
498 cpl_table_new_column(obj_tab,
"FLUX",CPL_TYPE_DOUBLE);
500 check(po=cpl_table_get_data_int(obj_tab,
"ORD"));
501 check(pw=cpl_table_get_data_double(obj_tab,
"WAVELENGTH"));
502 check(pf=cpl_table_get_data_double(obj_tab,
"FLUX"));
504 check(cpl_table_fill_column_window_int(obj_tab,
"ORD",0,nrow,-1));
505 check(cpl_table_fill_column_window_double(obj_tab,
"WAVELENGTH",0,nrow,-1));
506 check(cpl_table_fill_column_window_double(obj_tab,
"FLUX",0,nrow,-1));
517 for(i=0;i<next;i+=3) {
518 xsh_msg(
"processing extension %d",i);
519 check(ima_ord=cpl_image_load(name,CPL_TYPE_DOUBLE,0,i));
520 check(plist=cpl_propertylist_load(name,i));
521 check(sx=cpl_image_get_size_x(ima_ord));
522 check(ima_obj=cpl_image_collapse_window_create(ima_ord,1,obj_lly,
524 check(ima_sky1=cpl_image_collapse_window_create(ima_ord,1,sky1_lly,
526 check(ima_sky2=cpl_image_collapse_window_create(ima_ord,1,sky2_lly,
528 check(cpl_image_divide_scalar(ima_sky1,sky1_ury-sky1_lly+1));
529 check(cpl_image_divide_scalar(ima_sky2,sky2_ury-sky2_lly+1));
532 check(ima_sky=cpl_image_duplicate(ima_sky1));
533 check(cpl_image_add(ima_sky,ima_sky2));
534 check(cpl_image_divide_scalar(ima_sky,2));
535 check(cpl_image_multiply_scalar(ima_sky,obj_ury-obj_lly+1));
536 check(cpl_image_subtract(ima_obj,ima_sky));
538 check(pobj=cpl_image_get_data_double(ima_obj));
544 for(j=0;j<naxis1;j++) {
550 ( (po[k+j]==3) ||(po[k+j]==8) ) ) {
569 xsh_msg(
"Extracted spectrum sampling bin=%g [nm]",cdelt1);
570 check(name=cpl_frame_get_filename(frm_ref));
571 check(tbl_ref=cpl_table_load(name,1,0));
580 cpl_table_multiply_scalar(obj_tab,
"WAVELENGTH",nm2AA);
583 check(ref_wmin=cpl_table_get_column_min(tbl_ref,
"WAVELENGTH"));
584 check(ref_wmax=cpl_table_get_column_max(tbl_ref,
"WAVELENGTH"));
585 xsh_msg(
"Ref spectrum wmin=%g [A] wmax=%g [A]",ref_wmin,ref_wmax);
587 check(name=cpl_frame_get_filename(frm_atmext));
588 check(tbl_atmext=cpl_table_load(name,1,0));
591 check(ext_wmin=cpl_table_get_column_min(tbl_atmext,
"LAMBDA"));
592 check(ext_wmax=cpl_table_get_column_max(tbl_atmext,
"LAMBDA"));
593 xsh_msg(
"extinction wmin=%g [A] wmax=%g [A]",ext_wmin,ext_wmax);
596 check(cpl_table_new_column(obj_tab,
"REF",CPL_TYPE_DOUBLE));
597 check(cpl_table_fill_column_window_double(obj_tab,
"REF",0,nrow,-1));
599 check(cpl_table_new_column(obj_tab,
"EXT",CPL_TYPE_DOUBLE));
600 check(cpl_table_fill_column_window_double(obj_tab,
"EXT",0,nrow,-1));
602 check(cpl_table_new_column(obj_tab,
"COR",CPL_TYPE_DOUBLE));
603 check(cpl_table_fill_column_window_double(obj_tab,
"COR",0,nrow,-1));
605 check(cpl_table_new_column(obj_tab,
"EPHOT",CPL_TYPE_DOUBLE));
606 check(cpl_table_fill_column_window_double(obj_tab,
"EPHOT",0,nrow,-1));
609 check(pref=cpl_table_get_data_double(obj_tab,
"REF"));
610 check(pext=cpl_table_get_data_double(obj_tab,
"EXT"));
611 check(pcor=cpl_table_get_data_double(obj_tab,
"COR"));
612 check(peph=cpl_table_get_data_double(obj_tab,
"EPHOT"));
614 check(pw=cpl_table_get_data_double(obj_tab,
"WAVELENGTH"));
615 check(pf=cpl_table_get_data_double(obj_tab,
"FLUX"));
616 xsh_msg(
"Resample atmosphere and std star");
617 for(i=0;i<nrow;i++) {
624 "WAVELENGTH",
"FLUX"));
626 pcor[i]=pow(10,(0.4*pext[i]*aimprim));
627 if(airmass != 0) pcor[i]/=pow(10,(0.4*pext[i]*airmass));
628 peph[i]=1.e7*1.986e-19/(pw[i]*1e-4);
633 check(cpl_table_duplicate_column(obj_tab,
"SRC_COR",obj_tab,
"FLUX"));
634 check(cpl_table_multiply_columns(obj_tab,
"SRC_COR",
"COR"));
637 cpl_table_divide_scalar(obj_tab,
"SRC_COR",nm2AA);
638 cpl_table_divide_scalar(obj_tab,
"SRC_COR",cdelt1);
639 cpl_table_divide_scalar(obj_tab,
"SRC_COR",
biny);
641 check(cpl_table_duplicate_column(obj_tab,
"EFF",obj_tab,
"SRC_COR"));
643 check(cpl_table_multiply_scalar(obj_tab,
"EFF",gain));
644 check(cpl_table_multiply_columns(obj_tab,
"EFF",
"EPHOT"));
647 check(cpl_table_divide_columns(obj_tab,
"EFF",
"REF"));
650 cpl_table_and_selected_double(obj_tab,
"EFF",CPL_GREATER_THAN,1.e-5);
651 cpl_table_and_selected_double(obj_tab,
"EFF",CPL_LESS_THAN,1.);
652 tbl_sel=cpl_table_extract_selected(obj_tab);
655 check( cpl_table_save(tbl_sel, NULL, NULL,
"eff.fits", CPL_IO_DEFAULT));
680 if (cpl_error_get_code()) {
static xsh_instrument * instrument
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.
double xsh_pfits_get_conad(const cpl_propertylist *plist)
find out the CONAD value
double xsh_pfits_get_airm_end(const cpl_propertylist *plist)
find out the TEL AIRM END value
double xsh_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
double xsh_pfits_get_win1_dit1(const cpl_propertylist *plist)
find out the DET WIN1 DIT1 value
double xsh_pfits_get_cdelt1(const cpl_propertylist *plist)
find out the cdelt1
int xsh_pfits_get_biny(const cpl_propertylist *plist)
find out the BINY value
int xsh_pfits_get_naxis1(const cpl_propertylist *plist)
find out the NAXIS1 value
double xsh_pfits_get_crval1(const cpl_propertylist *plist)
find out the crval1
double xsh_pfits_get_airm_start(const cpl_propertylist *plist)
find out the TEL AIRM START value
static cpl_vector * rec_profile
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int xsh_util_efficiency2d_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static int xsh_util_efficiency2d(cpl_parameterlist *, cpl_frameset *)
Get the command line options and execute the data reduction.
static int xsh_util_efficiency2d_create(cpl_plugin *)
Setup the recipe options
static int xsh_util_efficiency2d_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static double xsh_table_get_interpolated(cpl_table *tbl, double wav, const char *colx, const char *coly)
void xsh_free_vector(cpl_vector **v)
Deallocate a vector and set the pointer to NULL.
void xsh_free_image(cpl_image **i)
Deallocate an image 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_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.
#define XSH_ATMOS_EXT_LIST_COLNAME_K
cpl_frame * xsh_find_frame_with_tag(cpl_frameset *frames, const char *tag, xsh_instrument *instr)
Find frame with a given tag.
cpl_error_code xsh_parameters_decode_bp(const char *recipe_id, cpl_parameterlist *plist, const int ival)
void xsh_parameters_generic(const char *recipe_id, cpl_parameterlist *plist)
static char xsh_util_efficiency2d_description[]
static char xsh_util_efficiency2d_description_short[]