71#define RECIPE_ID "xsh_mdark"
72#define RECIPE_AUTHOR "P.Goldoni, L.Guglielmi, R. Haigron, F. Royer, D. Bramich, A. Modigliani"
73#define RECIPE_CONTACT "amodigli@eso.org"
88static void xsh_mdark(cpl_parameterlist *, cpl_frameset *);
94"Create the master dark frame";
97"This recipe creates a master dark frame\n\
99 - A set of n RAW frames (Format=RAW, n >=3, Tag = DARK_arm)\n\
100 - [UVB,VIS] A master bias frame (Format=PRE, Tag = MASTER_BIAS_arm)\n\
101 - [OPTIONAL] A map of non linear bad pixels (Format=QUP, Tag = BP_MAP_NL_arm)\n\
102 - [OPTIONAL] A map of reference bad pixels (Format = QUP,RAW, Tag = BP_MAP_RP_arm)\n\
104 - A master dark frame (Format=PRE, PRO.CATG = MASTER_DARK_arm)\n\
105 A dark frame, (Format=PRE, PRO.CATG = DARK_arm)\n";
129 cpl_recipe *recipe = NULL;
130 cpl_plugin *plugin = NULL;
132 recipe = cpl_calloc(1,
sizeof(*recipe));
133 if ( recipe == NULL ){
137 plugin = &recipe->interface ;
139 cpl_plugin_init(plugin,
142 CPL_PLUGIN_TYPE_RECIPE,
153 cpl_pluginlist_append(list, plugin);
155 return (cpl_error_get_code() != CPL_ERROR_NONE);
171 cpl_recipe *recipe = NULL;
183 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin");
186 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
187 CPL_ERROR_TYPE_MISMATCH,
188 "Plugin is not a recipe");
190 recipe = (cpl_recipe *)plugin;
193 recipe->parameters = cpl_parameterlist_new();
194 assure( recipe->parameters != NULL,
195 CPL_ERROR_ILLEGAL_OUTPUT,
196 "Memory allocation failed!");
207 "Flag indicating whether the noise bad pixel map is to be computed"));
219 "noise-lower-rejection", 10.,
220 "Lower rejection percentile to flag bad pixels via noise"));
223 "noise-higher-rejection", 10.,
224 "Upper rejection percentile to flag bad pixels via noise"));
240 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
258 cpl_recipe *recipe = NULL;
262 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin" );
265 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
266 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
268 recipe = (cpl_recipe *)plugin;
271 xsh_mdark(recipe->parameters, recipe->frames);
274 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
293 cpl_recipe *recipe = NULL;
298 assure( plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin" );
301 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
302 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
303 recipe = (cpl_recipe *)plugin;
308 if (cpl_error_get_code() != CPL_ERROR_NONE)
322 cpl_parameter* p=NULL;
325 if(cpl_parameter_get_double(p) <= 0) {
327 cpl_parameter_set_double(p,11.);
329 cpl_parameter_set_double(p,9.);
335 return cpl_error_get_code();
345 cpl_frame* nirFrame = NULL;
347 cpl_parameter* p = NULL;
355 cpl_image* noise_image = NULL;
356 cpl_mask* bp_map_noise = NULL;
357 cpl_propertylist* plist = NULL;
358 const char* bp_map_noise_pro_catg = NULL;
359 char bp_map_noise_name[256];
363 "Noise parameters: Sigma %lf, Niteration %d, \
364 Fraction %lf, Diff %lf", noise_clipping->
sigma, noise_clipping->
niter, noise_clipping->
frac, noise_clipping->
diff);
370 p = cpl_parameterlist_find(parameters,
"xsh.xsh_mdark.ref1_llx");
371 llx = cpl_parameter_get_int(p);
372 p = cpl_parameterlist_find(parameters,
"xsh.xsh_mdark.ref1_lly");
373 lly = cpl_parameter_get_int(p);
374 p = cpl_parameterlist_find(parameters,
"xsh.xsh_mdark.ref1_urx");
375 urx = cpl_parameter_get_int(p);
376 p = cpl_parameterlist_find(parameters,
"xsh.xsh_mdark.ref1_ury");
377 ury = cpl_parameter_get_int(p);
378 p = cpl_parameterlist_find(parameters,
"xsh.xsh_mdark.noise-clip-niter");
379 iter = cpl_parameter_get_int(p);
380 p = cpl_parameterlist_find(parameters,
"xsh.xsh_mdark.noise-lower-rejection");
381 low_rej = cpl_parameter_get_double(p);
382 p = cpl_parameterlist_find(parameters,
"xsh.xsh_mdark.noise-higher-rejection");
383 high_rej = cpl_parameter_get_double(p);
387 bp_map_noise = cpl_mask_threshold_image_create(noise_image,
390 noise_image = cpl_image_new_from_mask(bp_map_noise);
391 cpl_mask_not(bp_map_noise);
396 cpl_image_threshold(noise_image, 1.1, DBL_MAX, 0, DBL_MAX);
398 plist = cpl_propertylist_new();
400 sprintf(bp_map_noise_name,
"%s.fits", bp_map_noise_pro_catg);
402 check(cpl_image_save(noise_image,bp_map_noise_name,CPL_BPP_IEEE_FLOAT, plist,CPL_IO_DEFAULT));
416 cpl_parameterlist* parameters,
418 const int pre_overscan_corr) {
419 cpl_frame* resFrame = NULL;
420 cpl_frame* rmbias = NULL;
421 if (master_bias != NULL) {
426 xsh_msg(
"Generates master dark");
429 "Error in create master dark");
431 check(resFrame=cpl_frame_duplicate(medFrame));
441 char* crh_name = NULL;
442 char* crh_pro_catg = NULL;
443 cpl_frame* crh_frm = NULL;
449 if (crh_ima != NULL) {
453 CPL_FRAME_GROUP_PRODUCT, CPL_FRAME_LEVEL_FINAL);
456 cpl_image_save(crh_ima, crh_name, CPL_BPP_32_SIGNED, NULL, CPL_IO_DEFAULT);
476static void xsh_mdark(cpl_parameterlist* parameters, cpl_frameset* frameset) {
478 const char* recipe_tags[1] = {
XSH_DARK };
479 int recipe_tags_size = 1;
481 cpl_frameset* raws = NULL;
482 cpl_frameset* calib = NULL;
483 cpl_frame* bpmap = NULL;
484 cpl_frame* master_bias = NULL;
485 cpl_frame* rmbias = NULL;
489 cpl_imagelist * dataList = NULL;
492 cpl_frame * medFrame = NULL;
493 cpl_frame * nirFrame = NULL;
494 cpl_frame * noisyFrame = NULL;
497 cpl_frame * resFrame = NULL;
499 cpl_image* crh_ima = NULL;
502 cpl_frame* crh_frm = NULL;
506 cpl_propertylist* plist = NULL;
507 char med_frame_tag[256];
510 cpl_frame* dark_on = NULL;
511 cpl_frame* dark_qc = NULL;
513 int pre_overscan_corr = 0;
517 cpl_propertylist* qc_log = NULL;
525 recipe_tags, recipe_tags_size,
543 sprintf(med_frame_tag,
"DARK_REMOVE_CRH_%s",
567 xsh_msg(
"Calling xsh_remove_crh_multiple" );
569 instrument,&dataList,&crh_ima,1 ),
"Error in xsh_remove_crh" );
576 xsh_msg(
"Create master dark");
580 "Error in create master dark");
604 if(noisyFrame != NULL) {
606 cpl_image* bpm=cpl_image_load(cpl_frame_get_filename(noisyFrame),
610 frm=
xsh_pre_save( pre, cpl_frame_get_filename(resFrame),cpl_frame_get_tag(resFrame), 0);
625 dark_on = cpl_frameset_get_frame(raws, 0);
626 sprintf(pcatg,
"DARK_ON");
627 sprintf(name,
"%s.fits", pcatg);
632 sz=cpl_frameset_get_size(raws);
633 dark_qc = cpl_frameset_get_frame(raws, sz-1);
634 sprintf(pcatg,
"DARK_QC");
635 sprintf(name,
"%s.fits", pcatg);
cpl_frame * xsh_create_master_dark(cpl_frame *medFrame, xsh_instrument *instr, cpl_parameterlist *parameters, cpl_frame *crh_frm, cpl_frame *bpm_frm)
cpl_frame * xsh_create_master_dark2(cpl_frameset *raws, xsh_stack_param *stack_param, cpl_parameterlist *params, cpl_propertylist *qc_log, xsh_instrument *instr)
static xsh_instrument * instrument
static xsh_clipping_param crh_clipping
cpl_error_code xsh_badpixelmap_image_coadd(cpl_image **self, const cpl_image *right, const int mode)
void xsh_bpmap_mask_bad_pixel(cpl_image *bpmap, cpl_mask *mask, int flag)
cpl_error_code xsh_badpixelmap_fill_bp_pattern_holes(cpl_frame *frm)
cpl_frame * xsh_compute_noise_map(cpl_imagelist *dataList, cpl_frame *medFrame, xsh_clipping_param *noise_clipping, xsh_instrument *instr, cpl_frame **noisyFrame)
xsh_pre * xsh_pre_load(cpl_frame *frame, xsh_instrument *instr)
Load a xsh_pre structure from a frame.
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
cpl_frame * xsh_pre_save(const xsh_pre *pre, const char *filename, const char *tag, int temp)
Save PRE on disk.
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.
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
static int xsh_mdark_create(cpl_plugin *)
Setup the recipe options.
static int xsh_mdark_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 char xsh_mdark_description_short[]
static int xsh_mdark_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static cpl_frame * xsh_get_master_dark_opt(cpl_frame *medFrame, cpl_frame *master_bias, cpl_parameterlist *parameters, cpl_frame *crh_frm, cpl_frame *bp_map_noise_frm, xsh_instrument *instrument, const int pre_overscan_corr)
static cpl_frame * xsh_get_crh_frame(cpl_image *crh_ima, xsh_instrument *instrument)
static char xsh_mdark_description[]
static void xsh_mdark(cpl_parameterlist *, cpl_frameset *)
Interpret the command line options and execute the data processing.
static cpl_frame * xsh_get_master_dark_nir_via_noise(cpl_imagelist *dataList, cpl_frame *medFrame, cpl_parameterlist *parameters, xsh_clipping_param *noise_clipping, xsh_instrument *instrument, cpl_frame **noisyFrame)
static cpl_error_code xsh_params_set_defaults(cpl_parameterlist *pars, xsh_instrument *inst)
#define xsh_msg(...)
Print a message on info level.
#define xsh_msg_dbg_low(...)
void xsh_pfits_set_pcatg(cpl_propertylist *plist, const char *value)
Write the PCATG 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)
cpl_frame * xsh_subtract_bias(cpl_frame *frame, cpl_frame *bias, xsh_instrument *instr, const char *type, const int pre_overscan_corr, const int save_tmp)
Subtract the master bias frame from PRE frame.
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.
void xsh_free_mask(cpl_mask **m)
Deallocate an image mask 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_error_code xsh_end(const char *recipe_id, cpl_frameset *frames, cpl_parameterlist *parameters)
Recipe termination.
void xsh_free_imagelist(cpl_imagelist **i)
Deallocate an image list and set the pointer to NULL.
void xsh_add_temporary_file(const char *name)
Add temporary file to temprary files list.
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_propertylist * xsh_frame_head_extract_qc(cpl_frame *frm)
cpl_frame * xsh_frame_product(const char *fname, const char *tag, cpl_frame_type type, cpl_frame_group group, cpl_frame_level level)
Creates a frame with given characteristics.
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_frameset_check_uniform_exptime(cpl_frameset *raws, xsh_instrument *inst)
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
cpl_frame * xsh_check_load_master_bpmap(cpl_frameset *calib, xsh_instrument *inst, const char *rec_id)
cpl_parameter * xsh_parameters_find(cpl_parameterlist *list, const char *recipe_id, const char *name)
find a parameter
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
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_new_double(cpl_parameterlist *list, const char *recipe_id, const char *name, double value, const char *comment)
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_clipping_noise_create(const char *recipe_id, cpl_parameterlist *list, xsh_clipping_param noise_param)
create the crh noise clipping parameters in a parameters list
void xsh_parameters_fpn_create(const char *recipe_id, cpl_parameterlist *list, xsh_fpn_param p)
create the FPN parameters in a parameters list
void xsh_parameters_ron_dark_create(const char *recipe_id, cpl_parameterlist *list, xsh_ron_dark_param p)
create the RON determination parameters in a parameters list
void xsh_parameters_ref1_create(const char *recipe_id, cpl_parameterlist *list, xsh_ref_param p)
create the reference region definition parameters in a parameters list
int xsh_parameters_get_int(const cpl_parameterlist *list, const char *recipe_id, const char *name)
xsh_clipping_param * xsh_parameters_clipping_noise_get(const char *recipe_id, cpl_parameterlist *list)
get the noise clipping parameters in a parameters 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)
#define DECODE_BP_FLAG_DEF
#define XSH_FREE(POINTER)
#define XSH_PREFIX(prefix, name, instr)
cpl_image * xsh_image_search_bad_pixels_via_noise(cpl_imagelist *darks, float thresh_sigma_factor, float low_threshold, float high_threshold, int llx, int lly, int urx, int ury)
search bad pixels