55#define RECIPE_ID "xsh_util_efficiency"
56#define RECIPE_AUTHOR "A.Modigliani"
57#define RECIPE_CONTACT "Andrea.Modigliani@eso.org"
58#define PRO_IMA "PRO_IMA_UVB"
59#define KEY_VALUE_HPRO_DID "PRO-1.15"
61#define SPEED_LIGHT 2.99792458*1.E8
62#define TEL_AREA 51.2e4
79"This recipe compute efficiency.\n"
80"The input files should be tagged as: \n"
81"input observed spectrum: IMA_arm,\n"
82"input reference spectrum: FLUX_STD_TABLE,\n"
83"input atmospheric extintion table: EXTCOEFF_TABLE)\n"
84"The output is a table with efficiency as function of wavelength\n"
85"Information on relevant parameters can be found with\n"
86"esorex --params xsh_util_efficiency\n"
87"esorex --help xsh_util_efficiency\n"
112 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe ) ;
113 cpl_plugin * plugin = &recipe->interface ;
115 cpl_plugin_init(plugin,
118 CPL_PLUGIN_TYPE_RECIPE,
129 cpl_pluginlist_append(list, plugin) ;
146 cpl_recipe * recipe ;
153 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
154 recipe = (cpl_recipe *)plugin ;
160 recipe->parameters = cpl_parameterlist_new() ;
165 recipe->parameters ) ) ;
168 p = cpl_parameter_new_value(
"xsh.xsh_util_efficiency.airmass",
171 "xsh.xsh_util_efficiency",1.2);
172 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"airmass") ;
173 cpl_parameterlist_append(recipe->parameters, p) ;
176 p = cpl_parameter_new_value(
"xsh.xsh_util_efficiency.gain",
178 "Detector gain value",
179 "xsh.xsh_util_efficiency",1.5);
180 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"gain") ;
181 cpl_parameterlist_append(recipe->parameters, p) ;
198 cpl_recipe * recipe ;
200 cpl_errorstate initial_errorstate = cpl_errorstate_get();
203 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
204 recipe = (cpl_recipe *)plugin ;
211 if (!cpl_errorstate_is_equal(initial_errorstate)) {
214 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
229 cpl_recipe * recipe ;
232 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
233 recipe = (cpl_recipe *)plugin ;
236 cpl_parameterlist_delete(recipe->parameters) ;
258 w1=cpl_table_get_column_min(tbl,colx);
259 w2=cpl_table_get_column_max(tbl,colx);
260 y1=cpl_table_get_column_min(tbl,coly);
261 y2=cpl_table_get_column_max(tbl,coly);
264 pw=cpl_table_get_data_float(tbl,colx);
265 pe=cpl_table_get_data_float(tbl,coly);
266 nrow=cpl_table_get_nrow(tbl);
269 for(i=0;i<nrow-1;i++) {
278 y=y1+(y2-y1)/(w2-w1)*(wav-w1);
296 cpl_frameset * frames)
299 int recipe_tags_size = 1;
302 cpl_parameter * param= NULL ;
303 cpl_frame* frm_sci=NULL;
304 cpl_frame* frm_ref=NULL;
305 cpl_frame* frm_atmext=NULL;
307 cpl_frameset* raws=NULL;
308 cpl_frameset* calib=NULL;
310 cpl_image* ima_sci=NULL;
311 cpl_table* tbl_ref=NULL;
312 cpl_table* tbl_ext=NULL;
313 cpl_table* tbl_atmext=NULL;
315 const char* name=NULL;
316 double aimprim=1.446;
330 cpl_propertylist* plist=NULL;
352 xsh_msg(
"Welcome to XSHOOTER Pipeline release %d.%d.%d",
353 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
362 check(param=cpl_parameterlist_find(parlist,
"xsh.xsh_util_efficiency.airmass"));
363 check(airmass=cpl_parameter_get_double(param));
366 check(param=cpl_parameterlist_find(parlist,
"xsh.xsh_util_efficiency.gain"));
367 check(gain=cpl_parameter_get_double(param));
371 check(frm_sci=cpl_frameset_get_frame(frames,0));
372 check(frm_ref=cpl_frameset_get_frame(frames,1));
373 check(frm_atmext=cpl_frameset_get_frame(frames,2));
375 check(name=cpl_frame_get_filename(frm_sci));
376 check(ima_sci=cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
377 check(plist=cpl_propertylist_load(name,0));
386 src_wmax=src_wmin+naxis1*cdelt1;
388 check(name=cpl_frame_get_filename(frm_ref));
389 check(tbl_ref=cpl_table_load(name,1,0));
391 check(name=cpl_frame_get_filename(frm_atmext));
392 check(tbl_atmext=cpl_table_load(name,1,0));
394 cpl_table_divide_scalar(tbl_ref,
"WAVELENGTH",10.);
395 check(ref_wmin=cpl_table_get_column_min(tbl_ref,
"WAVELENGTH"));
396 check(ref_wmax=cpl_table_get_column_max(tbl_ref,
"WAVELENGTH"));
399 cpl_table_divide_scalar(tbl_atmext,
"LAMBDA",10.);
400 check(ext_wmin=cpl_table_get_column_min(tbl_atmext,
"LAMBDA"));
401 check(ext_wmax=cpl_table_get_column_max(tbl_atmext,
"LAMBDA"));
402 nrow=cpl_table_get_nrow(tbl_atmext);
403 ext_wdel=(ext_wmax-ext_wmin)/(nrow-1);
405 wmin=(src_wmin>ref_wmin) ? src_wmin : ref_wmin;
406 wmax=(src_wmax<ref_wmax) ? src_wmax : ref_wmax;
407 xsh_msg(
"eff wave min: %g max: %g",wmin,wmax);
409 wmin=(ext_wmin>wmin) ? ext_wmin : wmin;
410 wmax=(ext_wmax<wmax) ? ext_wmax : wmax;
412 xsh_msg(
"ref wave min: %g max: %g",ref_wmin,ref_wmax);
413 xsh_msg(
"src wave min: %g max: %g",src_wmin,src_wmax);
414 xsh_msg(
"ext wave min: %g max: %g",ext_wmin,ext_wmax);
415 xsh_msg(
"eff wave min: %g max: %g",wmin,wmax);
417 check(cpl_table_and_selected_float(tbl_ref,
"WAVELENGTH",CPL_NOT_LESS_THAN,wmin));
418 check(cpl_table_and_selected_float(tbl_ref,
"WAVELENGTH",CPL_NOT_GREATER_THAN,wmax));
419 check(tbl_ext=cpl_table_extract_selected(tbl_ref));
420 check(ref_wmin=cpl_table_get_column_min(tbl_ext,
"WAVELENGTH"));
421 check(ref_wmax=cpl_table_get_column_max(tbl_ext,
"WAVELENGTH"));
422 xsh_msg(
"sel wave min: %g max: %g",ref_wmin,ref_wmax);
424 check(nrow=cpl_table_get_nrow(tbl_ext));
426 check(cpl_table_new_column(tbl_ext,
"SRC",CPL_TYPE_FLOAT));
427 check(cpl_table_fill_column_window_float(tbl_ext,
"SRC",0,nrow,-1));
429 check(cpl_table_new_column(tbl_ext,
"REF",CPL_TYPE_FLOAT));
430 check(cpl_table_fill_column_window_float(tbl_ext,
"REF",0,nrow,-1));
432 check(cpl_table_new_column(tbl_ext,
"EXT",CPL_TYPE_FLOAT));
433 check(cpl_table_fill_column_window_float(tbl_ext,
"EXT",0,nrow,-1));
435 check(cpl_table_new_column(tbl_ext,
"COR",CPL_TYPE_FLOAT));
436 check(cpl_table_fill_column_window_float(tbl_ext,
"COR",0,nrow,-1));
438 check(cpl_table_new_column(tbl_ext,
"EPHOT",CPL_TYPE_FLOAT));
439 check(cpl_table_fill_column_window_float(tbl_ext,
"EPHOT",0,nrow,-1));
442 check(psrc=cpl_table_get_data_float(tbl_ext,
"SRC"));
443 check(pref=cpl_table_get_data_float(tbl_ext,
"REF"));
444 check(pext=cpl_table_get_data_float(tbl_ext,
"EXT"));
445 check(pcor=cpl_table_get_data_float(tbl_ext,
"COR"));
446 check(peph=cpl_table_get_data_float(tbl_ext,
"EPHOT"));
447 check(peph=cpl_table_get_data_float(tbl_ext,
"EPHOT"));
449 check(pwav=cpl_table_get_data_float(tbl_ext,
"WAVELENGTH"));
454 for(i=0;i<nrow;i++) {
455 x=(pwav[i]-src_wmin)/cdelt1;
457 check(psrc[i]=cpl_image_get_interpolated( ima_sci,
x, 1,
471 "WAVELENGTH",
"FLUX"));
473 pcor[i]=pow(10,(0.4*pext[i]*aimprim));
474 if(airmass != 0) pcor[i]/=pow(10,(0.4*pext[i]*airmass));
475 peph[i]=1.986e-16/(pwav[i]*1e-8);
479 check(cpl_table_duplicate_column(tbl_ext,
"SRC_COR",tbl_ext,
"SRC"));
480 check(cpl_table_multiply_columns(tbl_ext,
"SRC_COR",
"COR"));
481 check(cpl_table_duplicate_column(tbl_ext,
"EFF",tbl_ext,
"SRC_COR"));
483 check(cpl_table_multiply_scalar(tbl_ext,
"EFF",gain));
484 check(cpl_table_multiply_columns(tbl_ext,
"EFF",
"EPHOT"));
487 check(cpl_table_divide_columns(tbl_ext,
"EFF",
"REF"));
489 check(cpl_table_save(tbl_ext,NULL,NULL,
"tab.fits",CPL_IO_DEFAULT));
497 if (cpl_error_get_code()) {
static xsh_instrument * instrument
#define xsh_msg(...)
Print a message on info level.
double xsh_pfits_get_crpix1(const cpl_propertylist *plist)
find out the CRPIX1 value
double xsh_pfits_get_cdelt1(const cpl_propertylist *plist)
find out the cdelt1
double xsh_pfits_get_exptime(const cpl_propertylist *plist)
find out the exposure time
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
static cpl_vector * rec_profile
static int xsh_util_efficiency_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int xsh_util_efficiency_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int xsh_util_efficiency(cpl_parameterlist *, cpl_frameset *)
Get the command line options and execute the data reduction.
static double xsh_table_get_interpolated(cpl_table *tbl, double wav, const char *colx, const char *coly)
static int xsh_util_efficiency_create(cpl_plugin *)
Setup the recipe options
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.
const char * xsh_get_license(void)
Get the pipeline copyright and license.
void xsh_init(void)
Reset library state.
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_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_efficiency_description[]
static char xsh_util_efficiency_description_short[]