52#define XSH_LINGAIN_ON_RAW(it) ((it) == 0 ? XSH_LINEARITY_UVB_ON : \
53 (it) == 1 ? XSH_LINEARITY_VIS_ON : \
54 (it) == 2 ? XSH_LINEARITY_NIR_ON : \
57#define XSH_LINGAIN_OFF_RAW(it) ((it) == 0 ? XSH_LINEARITY_UVB_OFF : \
58 (it) == 1 ? XSH_LINEARITY_VIS_OFF : \
59 (it) == 2 ? XSH_LINEARITY_NIR_OFF : \
62#define XSH_LINGAIN_DET_LIN_INFO(it) ((it) == 0 ? XSH_DET_LIN_INFO_UVB : \
63 (it) == 1 ? XSH_DET_LIN_INFO_VIS : \
64 (it) == 2 ? XSH_DET_LIN_INFO_NIR : \
67#define XSH_LINGAIN_GAIN_INFO(it) ((it) == 0 ? XSH_GAIN_INFO_UVB : \
68 (it) == 1 ? XSH_GAIN_INFO_VIS : \
69 (it) == 2 ? XSH_GAIN_INFO_NIR : \
72#define XSH_LINGAIN_COEFFS_CUBE(it) ((it) == 0 ? XSH_COEFFS_CUBE_UVB : \
73 (it) == 1 ? XSH_COEFFS_CUBE_VIS : \
74 (it) == 2 ? XSH_COEFFS_CUBE_NIR : \
77#define XSH_LINGAIN_BP_MAP_NL(it) ((it) == 0 ? XSH_BP_MAP_NL_UVB : \
78 (it) == 1 ? XSH_BP_MAP_NL_VIS : \
79 (it) == 2 ? XSH_BP_MAP_NL_NIR : \
82#define XSH_LINGAIN_RAW_BP_MAP_NL(it) ((it) == 0 ? XSH_RAW_BP_MAP_NL_UVB : \
83 (it) == 1 ? XSH_RAW_BP_MAP_NL_VIS : \
84 (it) == 2 ? XSH_RAW_BP_MAP_NL_NIR : \
87#define XSH_LINGAIN_AUTOCORR(it) ((it) == 0 ? XSH_AUTOCORR_UVB : \
88 (it) == 1 ? XSH_AUTOCORR_VIS : \
89 (it) == 2 ? XSH_AUTOCORR_NIR : \
92#define XSH_LINGAIN_DIFF_FLAT(it) ((it) == 0 ? XSH_DIFF_FLAT_UVB : \
93 (it) == 1 ? XSH_DIFF_FLAT_VIS : \
94 (it) == 2 ? XSH_DIFF_FLAT_NIR : \
97#define RECIPE_ID "xsh_lingain"
98#define RECIPE_AUTHOR "Lander de Bilbao,A.Modigliani"
99#define RECIPE_CONTACT "amodigli@eso.org"
102#define INSTREGEXP "ESO INS SETUP ID"
104#define PAFREGEXP "^(" REGEXP "|" INSTREGEXP ")$"
107#define XSH_PIX2PIX CPL_TRUE
108#define XSH_EXTS_RED -1
119 cpl_parameterlist * parlist);
143 "This recipe computes detector linearity coefficients and gain\n\
146 - A set of n RAW linearity frames (Format=RAW, n >=8, Tag = LINEARITY_arm_ON)\n\
147 - A set of n RAW bias frames (Format=RAW, n >=1, Tag = LINEARITY_arm_OFF)\n\
149 - A set of n RAW linearity on frames (Format=RAW, n >=8, Tag = LINEARITY_arm_ON)\n\
150 - A set of n RAW linearity off frames (Format=RAW, n >=8, Tag = LINEARITY_arm_OFF)\n\
151 - [OPTIONAL] a static bad pixel map (PRO.CATG=BP_MAP_RP_arm) \n\
152 Note: on and off frames are taken in pairs sequence: OFF-ON-ON-OFF, \n\
153 at least 16 frames.\n\
155 - A linearity map table, PRO.CATG = BP_MAP_LIN_NIR\n\
156 - A gain table, PRO.CATG = GAIN_INFO\n\
157 - A cube cointaining the linearity coefficients, PRO.CATG = COEFFS_CUBE_arm\n\
158 - A linearity map image (RAW format), PRO.CATG = RAW_BP_MAP_NL_arm\n\
159 - A linearity map image (PRE format), PRO.CATG = BP_MAP_NL_arm\n";
177 cpl_recipe *recipe = NULL;
178 cpl_plugin *plugin = NULL;
180 recipe = cpl_calloc(1,
sizeof(*recipe));
181 if (recipe == NULL) {
185 plugin = &recipe->interface;
187 cpl_plugin_init(plugin, CPL_PLUGIN_API,
189 CPL_PLUGIN_TYPE_RECIPE,
200 cpl_pluginlist_append(list, plugin);
202 return (cpl_error_get_code() != CPL_ERROR_NONE);
219 cpl_recipe *recipe = NULL;
224 assure(plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin");
227 assure(cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
228 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
230 recipe = (cpl_recipe *) plugin;
233 recipe->parameters = cpl_parameterlist_new();
234 assure(recipe->parameters != NULL,
235 CPL_ERROR_ILLEGAL_OUTPUT,
"Memory allocation failed!");
243 if (cpl_error_get_code() != CPL_ERROR_NONE) {
262 cpl_recipe *recipe = NULL;
265 assure(plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin");
268 assure(cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
269 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
271 recipe = (cpl_recipe *) plugin;
277 if (cpl_error_get_code() != CPL_ERROR_NONE) {
295 cpl_recipe *recipe = NULL;
299 assure(plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin");
302 assure(cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
303 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
305 recipe = (cpl_recipe *) plugin;
310 if (cpl_error_get_code() != CPL_ERROR_NONE) {
321 cpl_parameter* p=NULL;
325 p=cpl_parameterlist_find(pars,
"xshoo.xsh_lingain.kappa");
330 cpl_parameter_set_double(p,5.);
336 return cpl_error_get_code();
351 cpl_parameterlist * parlist)
357 int recipe_tags_size = 6;
359 cpl_error_code error=0;
361 cpl_parameterlist* plist=NULL;
363 cpl_frameset* raws=NULL;
364 cpl_frameset* calib=NULL;
365 cpl_frameset* pros=NULL;
367 cpl_propertylist * lintbl = NULL;
368 cpl_propertylist * gaintbl = NULL;
369 cpl_propertylist * coeffscube = NULL;
370 cpl_propertylist * bpm = NULL;
371 cpl_propertylist * corr = NULL;
372 cpl_propertylist * diff_flat =NULL;
373 cpl_frame* bpmap_nl=NULL;
376 cpl_propertylist* head=NULL;
377 cpl_frame *bpmap = NULL;
378 cpl_frame* coadd_bp_map=NULL;
379 cpl_image* crox=NULL;
382 char* bp_nl_tag=NULL;
383 char* bp_nl_name=NULL;
385 cpl_frame* bp_nl_frame = NULL;
392 recipe_tags, recipe_tags_size,
434 PACKAGE
"/" PACKAGE_VERSION,
471 PACKAGE
"/" PACKAGE_VERSION,
511 PACKAGE
"/" PACKAGE_VERSION,
518 pros=cpl_frameset_new();
528 bp_nl_name=cpl_sprintf(
"%s.fits",bp_nl_tag);
530 cpl_frameset_insert(frameset, bp_nl_frame);
533 check(sprintf(name,cpl_frame_get_filename(bp_nl_frame)));
534 check(ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
535 check(head=cpl_propertylist_load(name,0));
536 cpl_propertylist_erase_regexp(head,
"NPIXSAT",0);
537 cpl_propertylist_erase_regexp(head,
"FPIXSAT",0);
542 check(cpl_image_save(crox,name,CPL_BPP_IEEE_FLOAT,head,CPL_IO_DEFAULT));
545 check(cpl_image_save(ima,name,CPL_BPP_IEEE_FLOAT,head,CPL_IO_DEFAULT));
582 cpl_ensure_code(!error, error);
584 xsh_msg(
"No data has been processed.");
585 xsh_msg(
"Pls check if input frame set contains valid tags");
602 return CPL_ERROR_NONE;
669 cpl_error_code error =
673 cpl_ensure_code(!error, error);
677 p = cpl_parameterlist_find(parlist, PACKAGE
"." RECIPE_ID ".pix2pix");
679 cpl_ensure_code(p != NULL, CPL_ERROR_DATA_NOT_FOUND);
681 error = cpl_parameter_set_default_bool(p,
XSH_PIX2PIX);
683 p = cpl_parameterlist_find(parlist, PACKAGE
"." RECIPE_ID ".tolerance");
685 cpl_ensure_code(p != NULL, CPL_ERROR_DATA_NOT_FOUND);
687 error = cpl_parameter_set_default_double(p,
XSH_TOL);
689 cpl_ensure_code(!error, error);
691 return CPL_ERROR_NONE;
701 cpl_error_code error =
706 cpl_ensure_code(!error, error);
709 p = cpl_parameterlist_find(parlist, PACKAGE_TARNAME
"." RECIPE_ID ".bpmbin");
711 cpl_ensure_code(p != NULL, CPL_ERROR_DATA_NOT_FOUND);
713 error = cpl_parameter_set_default_bool(p,
XSH_BPMBIN);
715 cpl_ensure_code(!error, error);
718 return CPL_ERROR_NONE;
729 cpl_error_code error =0;
732 double thresh_max=65000;
738 cpl_ensure_code(!error, error);
740 p = cpl_parameterlist_find(parlist, PACKAGE
"." RECIPE_ID ".saturation_limit");
742 cpl_ensure_code(p != NULL, CPL_ERROR_DATA_NOT_FOUND);
743 val=cpl_parameter_get_double(p);
745 if( fabs(val+1.) < 0.00001) {
746 error = cpl_parameter_set_default_double(p, thresh_max);
748 cpl_ensure_code(!error, error);
750 return CPL_ERROR_NONE;
static xsh_instrument * instrument
cpl_image * xsh_image_flag_bptype_with_crox(cpl_image *ima)
void xsh_bpmap_bitwise_to_flag(cpl_image *bpmap, int flag)
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
xsh_pre * xsh_pre_create(cpl_frame *raw, cpl_frame *bpmap, cpl_image *bias_data, xsh_instrument *instr, const int pre_overscan_corr, const bool flag_neg_and_thresh_pix)
Create a XSH_PRE from a raw frame.
cpl_frame * xsh_pre_save(const xsh_pre *pre, const char *filename, const char *tag, int temp)
Save PRE on disk.
#define assure(CONDITION, ERROR_CODE,...)
#define xsh_error_dump(level)
#define xsh_error_reset()
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.
#define xsh_msg(...)
Print a message on info level.
void xsh_free_parameterlist(cpl_parameterlist **p)
Deallocate a parameter list 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_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.
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_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
cpl_parameterlist * xsh_parameterlist_duplicate(const cpl_parameterlist *pin)
Extract frames with given tag from frameset.
#define QFLAG_NON_LINEAR_PIXEL
cpl_propertylist * xsh_detmon_fill_prolist(const char *procatg, const char *protype, const char *protech, cpl_boolean proscience)
cpl_error_code xsh_detmon_lg_fill_parlist_opt_default(cpl_parameterlist *parlist, const char *recipe_name, const char *pipeline_name)
Parlist filling with OPT required parameters and its default values.
cpl_error_code xsh_detmon_lg_fill_parlist_nir_default(cpl_parameterlist *parlist, const char *recipe_name, const char *pipeline_name)
Parlist filling with NIR required parameters and its default values.
cpl_error_code xsh_detmon_lg(cpl_frameset *frameset, const cpl_parameterlist *parlist, const char *tag_on, const char *tag_off, const char *recipe_name, const char *pipeline_name, const char *pafregexp, const cpl_propertylist *pro_lintbl, const cpl_propertylist *pro_gaintbl, const cpl_propertylist *pro_coeffscube, const cpl_propertylist *pro_bpm, const cpl_propertylist *pro_corr, const cpl_propertylist *pro_diff, const char *package, int(*compare)(const cpl_frame *, const cpl_frame *), int(*load_fset)(const cpl_frameset *, cpl_type, cpl_imagelist *), const cpl_boolean opt_nir)
cpl_error_code xsh_frameset_merge(cpl_frameset *set1, cpl_frameset *set2)
Extracts raw frames.
int xsh_parameter_get_default_flag(const cpl_parameter *p)
Check if an input parameter has been changed by the user.
cpl_error_code xsh_dfs_extract_pro_frames(cpl_frameset *input, cpl_frameset *pros)
split input sof in groups: raw and calib
cpl_frame * xsh_find_frame_with_tag(cpl_frameset *frames, const char *tag, xsh_instrument *instr)
Find frame with a given tag.
#define XSH_LINEARITY_VIS_OFF
#define XSH_LINEARITY_NIR_ON
#define XSH_LINEARITY_UVB_OFF
#define XSH_LINEARITY_NIR_OFF
#define XSH_LINEARITY_UVB_ON
#define XSH_RAW_BP_MAP_NL
#define XSH_LINEARITY_VIS_ON
static char xsh_lingain_description_short[]
cpl_error_code xsh_lingain_fill_parlist_default_opt(cpl_parameterlist *parlist)
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static char xsh_lingain_description[]
static int xsh_lingain(cpl_frameset *frameset, cpl_parameterlist *parlist)
cpl_error_code xsh_lingain_fill_parlist_default_nir(cpl_parameterlist *parlist)
static cpl_error_code xsh_lingain_set_saturation_limit(cpl_parameterlist *parlist, xsh_instrument *instrument)
static int xsh_lingain_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int xsh_lingain_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static cpl_error_code xsh_params_set_defaults(cpl_parameterlist *pars, xsh_instrument *inst)
static int xsh_lingain_create(cpl_plugin *)
Setup the recipe options.
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)