75#define RECIPE_ID "xsh_mbias"
76#define RECIPE_AUTHOR "P.Goldoni, L.Guglielmi, R. Haigron, F. Royer, D. Bramich, A. Modigliani"
77#define RECIPE_CONTACT "amodigli@eso.org"
92static void xsh_mbias(cpl_parameterlist *, cpl_frameset *);
100 "This recipe creates a master bias frame by computing the median of all \
103 - A set of n RAW frames (Format=RAW, n >=3, Tag = BIAS_arm)\n\
104 - [OPTIONAL] A map of non linear bad pixels (Format=QUP, Tag = BP_MAP_NL_arm)\n\
105 - [OPTIONAL] A map of reference bad pixels (Format = QUP,RAW, Tag = BP_MAP_RP_arm)\n\
107 - A master bias frame (Format=PRE, PRO.CATG = MASTER_BIAS_arm)\n";
125 cpl_recipe *recipe = NULL;
126 cpl_plugin *plugin = NULL;
128 recipe = cpl_calloc(1,
sizeof(*recipe));
129 if (recipe == NULL) {
133 plugin = &recipe->interface;
135 cpl_plugin_init(plugin, CPL_PLUGIN_API,
137 CPL_PLUGIN_TYPE_RECIPE,
148 cpl_pluginlist_append(list, plugin);
150 return (cpl_error_get_code() != CPL_ERROR_NONE);
167 cpl_recipe *recipe = NULL;
170 10,100,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,25};
179 assure(plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin");
182 assure(cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
183 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
185 recipe = (cpl_recipe *) plugin;
188 recipe->parameters = cpl_parameterlist_new();
189 assure(recipe->parameters != NULL,
190 CPL_ERROR_ILLEGAL_OUTPUT,
"Memory allocation failed!");
202 if (cpl_error_get_code() != CPL_ERROR_NONE) {
220 cpl_recipe *recipe = NULL;
223 assure(plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin");
226 assure(cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
227 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
229 recipe = (cpl_recipe *) plugin;
232 xsh_mbias(recipe->parameters, recipe->frames);
235 if (cpl_error_get_code() != CPL_ERROR_NONE) {
253 cpl_recipe *recipe = NULL;
257 assure(plugin != NULL, CPL_ERROR_NULL_INPUT,
"Null plugin");
260 assure(cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
261 CPL_ERROR_TYPE_MISMATCH,
"Plugin is not a recipe");
263 recipe = (cpl_recipe *) plugin;
268 if (cpl_error_get_code() != CPL_ERROR_NONE) {
292 int dc_mask_x=cpl_parameter_get_int(p);
295 int dc_mask_y=cpl_parameter_get_int(p);
298 cpl_size nframes = cpl_frameset_get_size(frames);
299 cpl_frameset *fs_raws = cpl_frameset_new();
300 cpl_frameset *fs_masks = cpl_frameset_new();
302 for (cpl_size i = 0; i < nframes; i++) {
304 cpl_frame *frame = cpl_frameset_get_position(frames, i);
306 if (!strcmp(cpl_frame_get_tag(frame), bias_raw_tag)) {
307 cpl_frameset_insert(fs_raws, cpl_frame_duplicate(frame));
309 }
else if (!strcmp(cpl_frame_get_tag(frame), power_spectrum_mask_tag)) {
310 cpl_frameset_insert(fs_masks, cpl_frame_duplicate(frame));
314 cpl_size n_masks = cpl_frameset_count_tags(frames, power_spectrum_mask_tag);
316 cpl_size n_raws = cpl_frameset_get_size(fs_raws);
322 cpl_propertylist *qclist = cpl_propertylist_new();
324 for (
int n_frame = 0; n_frame < n_raws; n_frame++) {
325 cpl_frame *frm_raw = cpl_frameset_get_position(fs_raws, n_frame);
326 const char *filename_raw = cpl_frame_get_filename(frm_raw);
327 cpl_msg_info(cpl_func,
"Load image, filename=%s ...", filename_raw);
328 cpl_image *img_in = cpl_image_load(cpl_frame_get_filename(frm_raw),
329 CPL_TYPE_DOUBLE, 0, 0);
332 cpl_image *power_spectrum = NULL;
334 double std_mad = -1.;
335 cpl_mask *mask_in = NULL;
340 cpl_frame *frm_mask = cpl_frameset_get_position(fs_masks, 0);
341 const char *filename_mask = cpl_frame_get_filename(frm_mask);
344 cpl_msg_info(cpl_func,
"Load mask, filename=%s ...", filename_mask);
345 mask_in = cpl_mask_load(filename_mask, 0, 0);
348 if (hdrl_fpn_compute(img_in, mask_in, dc_mask_x, dc_mask_y,
349 &power_spectrum, &std, &std_mad) != CPL_ERROR_NONE) {
351 if (img_in ) cpl_image_delete(img_in);
352 if (mask_in ) cpl_mask_delete(mask_in);
353 if (power_spectrum ) cpl_image_delete(power_spectrum);
355 return cpl_error_get_code();
357 if (!isnan(std) && !isnan(std_mad)) {
359 const char* key = cpl_sprintf(
"ESO QC STDRAT%d",n_frame+1);
360 cpl_propertylist_update_double(qclist,key, std/std_mad);
366 cpl_size nqclist = cpl_propertylist_get_size(qclist);
368 double max = cpl_property_get_double(cpl_propertylist_get(qclist,0));
369 for(
int i=1;i<nqclist;i++){
370 double val = cpl_property_get_double(cpl_propertylist_get(qclist,i));
375 cpl_propertylist_update_double(qclist,
"ESO QC STD MAX",
max);
379 char *out_filename = cpl_sprintf(
"%s",
"bias_fpn_power_spectrum.fits");
380 char *out_filename_mask = cpl_sprintf(
"%s",
"bias_fpn_mask.fits");
381 for (
int n_frame = 0; n_frame < n_raws; n_frame++) {
382 cpl_frame *frm_raw = cpl_frameset_get_position(fs_raws, n_frame);
383 const char *filename_raw = cpl_frame_get_filename(frm_raw);
384 cpl_msg_info(cpl_func,
"Load image, filename=%s ...", filename_raw);
385 cpl_image *img_in = cpl_image_load(cpl_frame_get_filename(frm_raw),
386 CPL_TYPE_DOUBLE, 0, 0);
389 cpl_image *power_spectrum = NULL;
391 double std_mad = -1.;
392 cpl_mask *mask_in = NULL;
397 cpl_frame *frm_mask = cpl_frameset_get_position(fs_masks, 0);
398 const char *filename_mask = cpl_frame_get_filename(frm_mask);
401 cpl_msg_info(cpl_func,
"Load mask, filename=%s ...", filename_mask);
402 mask_in = cpl_mask_load(filename_mask, 0, 0);
405 if (hdrl_fpn_compute(img_in, mask_in, dc_mask_x, dc_mask_y,
406 &power_spectrum, &std, &std_mad) != CPL_ERROR_NONE) {
408 if (img_in ) cpl_image_delete(img_in);
409 if (mask_in ) cpl_mask_delete(mask_in);
410 if (power_spectrum ) cpl_image_delete(power_spectrum);
412 return cpl_error_get_code();
415 cpl_propertylist *plist = cpl_propertylist_new();
416 cpl_propertylist *xlist = cpl_propertylist_new();
420 cpl_propertylist_update_double(plist,
"ESO QC FPN STD", std);
421 cpl_propertylist_update_double(xlist,
"ESO QC FPN STD", std);
424 cpl_propertylist_update_double(plist,
"ESO QC FPN STD", -DBL_MAX);
425 cpl_propertylist_update_double(xlist,
"ESO QC FPN STD", -DBL_MAX);
429 if (!isnan(std_mad)) {
430 cpl_propertylist_update_double(plist,
"ESO QC FPN STDMAD", std_mad);
431 cpl_propertylist_update_double(xlist,
"ESO QC FPN STDMAD", std_mad);
433 cpl_propertylist_update_double(plist,
"ESO QC FPN STDMAD", -DBL_MAX);
434 cpl_propertylist_update_double(xlist,
"ESO QC FPN STDMAD", -DBL_MAX);
439 const char* extname = cpl_sprintf(
"BIAS_PN_%d",n_frame+1);
440 cpl_propertylist_update_string(xlist,
"EXTNAME",extname);
442 cpl_propertylist_update_string(plist,
"EXTNAME",
"BIAS_PN_1");
447 cpl_propertylist_update_string(plist, CPL_DFS_PRO_CATG,
448 power_spectrum_mask_tag);
455 cpl_image *out_mask_image = cpl_image_new_from_mask(cpl_image_get_bpm(power_spectrum));
458 cpl_dfs_save_image(frames, NULL, parameters, frames, frm_raw,
459 out_mask_image, CPL_TYPE_INT, recipe_id, plist, NULL,
460 PACKAGE
"/" PACKAGE_VERSION, out_filename_mask);
464 cpl_propertylist_append(plist,qclist);
468 cpl_propertylist_update_string(plist, CPL_DFS_PRO_CATG, bias_fpn_tag);
472 cpl_dfs_save_image(frames, NULL, parameters, frames, frm_raw,
473 power_spectrum, CPL_TYPE_DOUBLE, recipe_id, plist, NULL,
474 PACKAGE
"/" PACKAGE_VERSION, out_filename);
476 cpl_image_save(power_spectrum, out_filename, CPL_TYPE_DOUBLE, xlist, CPL_IO_EXTEND);
479 if(out_mask_image) cpl_image_delete(out_mask_image);
480 if(power_spectrum) cpl_image_delete(power_spectrum);
481 if (mask_in ) cpl_mask_delete(mask_in);
483 cpl_propertylist_delete(plist);
484 cpl_propertylist_delete(xlist);
487 cpl_propertylist_delete(qclist);
488 cpl_frameset_delete(fs_raws);
489 cpl_frameset_delete(fs_masks);
490 cpl_free(out_filename);
491 cpl_free(out_filename_mask);
492 return cpl_error_get_code();
504static void xsh_mbias(cpl_parameterlist * parameters, cpl_frameset * frameset)
506 const char* recipe_tags[1] = {
XSH_BIAS};
507 int recipe_tags_size = 1;
509 cpl_frameset *raws = NULL;
510 cpl_frameset *calib = NULL;
511 cpl_frame *bpmap = NULL;
512 cpl_frame *master_bias = NULL;
513 cpl_frame *product = NULL;
516 cpl_frame* bias_frm=NULL;
517 cpl_propertylist* plist=NULL;
521 int pre_overscan_corr=0;
528 recipe_tags, recipe_tags_size,
541 check(bias_frm=cpl_frameset_get_frame(raws,0));
542 check(plist=cpl_propertylist_load(cpl_frame_get_filename(bias_frm),0));
546 sprintf(name,
"%s.fits",ftag);
558 int pd_noise_compute=cpl_parameter_get_bool(p);
565 if(pd_noise_compute) {
589 xsh_msg(
"xsh_mbias success!!");
cpl_frame * xsh_compute_qc_on_master_bias(cpl_frameset *raws, cpl_frame *frame, xsh_instrument *instr, cpl_parameterlist *params)
Computes QC on a master bias frame.
cpl_frame * xsh_create_master_bias2(cpl_frameset *rawFrames, xsh_stack_param *stack_par, xsh_instrument *instr, const char *result_tag, const int method_code)
Creates master bias.
static xsh_instrument * instrument
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 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.
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
static char xsh_mbias_description[]
static cpl_error_code xsh_mbias_fpn(cpl_frameset *frames, const cpl_parameterlist *parameters, xsh_instrument *instrument, const char *recipe_id)
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static char xsh_mbias_description_short[]
static void xsh_mbias(cpl_parameterlist *, cpl_frameset *)
Interpret the command line options and execute the data processing.
static int xsh_mbias_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int xsh_mbias_create(cpl_plugin *)
Setup the recipe options.
static int xsh_mbias_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
#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_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_error_code xsh_end(const char *recipe_id, cpl_frameset *frames, cpl_parameterlist *parameters)
Recipe termination.
const char * stack_method
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)
char * xsh_get_tag_from_arm(const char *tag, xsh_instrument *instr)
Find arm specific tag from base and instrument setting.
#define XSH_GET_TAG_FROM_ARM_EXT(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_ron_create(const char *recipe_id, cpl_parameterlist *list, xsh_ron_param p)
create the RON determination parameters in a parameters list
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_fpn_create(const char *recipe_id, cpl_parameterlist *list, xsh_fpn_param p)
create the FPN parameters in a parameters list
void xsh_parameters_pd_noise_create(const char *recipe_id, cpl_parameterlist *list, xsh_pd_noise_param p)
create the FPN parameters in a parameters list
void xsh_parameters_struct_create(const char *recipe_id, cpl_parameterlist *list, xsh_struct_param p)
create the structX/Y region definition 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