43 #include <uves_reduce_mflat_combine.h>
46 #include <uves_backsub.h>
47 #include <uves_chip.h>
49 #include <uves_pfits.h>
50 #include <uves_parameters.h>
51 #include <uves_utils.h>
52 #include <uves_utils_wrappers.h>
53 #include <uves_qclog.h>
54 #include <uves_error.h>
66 const cpl_parameterlist *parameters,
68 const char *recipe_id,
69 const char *starttime);
74 const char *
const uves_mflat_combine_desc =
75 "This recipe combined a MASTER_FLAT_xxxx with a MASTER_DFLAT_xxxx\n"
77 "a master flat (MASTER_FLAT_xxxx)\n"
78 "a master dflat (MASTER_DFLAT_xxxx)\n"
79 "an order table (ORDER_TABLE_xxxx)\n"
80 "provided for each chip (xxxx = BLUE, REDL, REDU). \n"
81 "Output is a MASTER_FLAT_xxxx\n";
93 const char *recipe_id)
99 if (uves_define_global_parameters(parameters) != CPL_ERROR_NONE)
104 return (cpl_error_get_code() != CPL_ERROR_NONE);
125 const cpl_parameterlist *parameters,
126 const char *starttime,
127 const char *recipe_id)
155 const cpl_frame* frm_dflat,
156 cpl_frameset* frames,
158 const int ORDER_THRESHOLD)
162 const char * name_flat=NULL ;
163 const char * name_dflat=NULL ;
164 const char *ordertable_filename =
"";
166 cpl_image* ima_flat=NULL;
167 cpl_image* ima_dflat=NULL;
168 cpl_image* ima_cflat=NULL;
169 cpl_image* ima_mask=NULL;
176 double* point_mask=NULL;
181 double order_ref=(double)ORDER_THRESHOLD;
198 cpl_table *ordertable = NULL;
201 cpl_table *traces = NULL;
202 const char *chip_name =
"";
203 enum uves_chip chip=UVES_CHIP_BLUE;
207 name_flat=cpl_frame_get_filename(frm_flat);
208 name_dflat=cpl_frame_get_filename(frm_dflat);
209 check_nomsg(ima_flat=cpl_image_load(name_flat,CPL_TYPE_DOUBLE,0,0));
210 check_nomsg(ima_dflat=cpl_image_load(name_dflat,CPL_TYPE_DOUBLE,0,0));
213 sx=cpl_image_get_size_x(ima_flat);
214 sy=cpl_image_get_size_y(ima_flat);
215 assure(sx==cpl_image_get_size_x(ima_dflat),CPL_ERROR_ILLEGAL_INPUT,
217 assure(sy==cpl_image_get_size_y(ima_dflat),CPL_ERROR_ILLEGAL_INPUT,
225 check( uves_load_ordertable(frames,
228 &ordertable_filename,
237 "Could not load order table");
238 uves_msg(
"Using order table in '%s'", ordertable_filename);
253 ima_mask = cpl_image_new(sx,sy,CPL_TYPE_DOUBLE);
254 point_mask=cpl_image_get_data_double(ima_mask);
256 for(j=(
int)ypos_max;j<sy;j++) {
258 point_mask[j*sx+i]=1.;
263 for(j=ypos_min;j<ypos_max;j++) {
275 point_mask[j*sx+i] = 1.;
294 fflux=cpl_image_get_median_window(ima_flat,llx,lly,urx,ury);
303 dflux=cpl_image_get_median_window(ima_dflat,llx,lly,urx,ury);
311 ima_cflat=cpl_image_duplicate(ima_flat);
312 cpl_image_multiply(ima_cflat,ima_mask);
313 cpl_image_multiply_scalar(ima_mask,-1.);
314 cpl_image_add_scalar(ima_mask,1.);
315 cpl_image_multiply(ima_dflat,ima_mask);
316 cpl_image_multiply_scalar(ima_dflat,scale);
317 cpl_image_add(ima_cflat,ima_dflat);
326 uves_free_table(&ordertable);
327 uves_free_propertylist(&ordertable_header);
329 uves_free_table(&traces);
330 uves_free_image(&ima_flat);
331 uves_free_image(&ima_dflat);
332 uves_free_image(&ima_mask);
349 const cpl_parameterlist *parameters,
351 const char *recipe_id,
352 const char *starttime)
355 cpl_frame * frm_dflat=NULL ;
356 cpl_frame * frm_flat=NULL ;
357 const char * name_flat=NULL ;
358 const char * name_dflat=NULL ;
362 cpl_table *qclog[] = {NULL, NULL};
364 cpl_image* ima_cflat=NULL;
368 char *product_filename = NULL;
369 const char *product_tag[2] = {NULL, NULL};
370 char pro_filename[255];
372 const char* PROCESS_CHIP=NULL;
373 int ORDER_THRESHOLD=7;
382 check( uves_get_parameter(parameters, NULL,
"uves",
"debug",
383 CPL_TYPE_BOOL , &debug_mode ),
384 "Could not read parameter");
386 check( uves_get_parameter(parameters, NULL,
"uves",
"process_chip",
387 CPL_TYPE_STRING, &PROCESS_CHIP),
388 "Could not read parameter");
392 check( uves_get_parameter(parameters, NULL,
"uves",
"order_threshold",
393 CPL_TYPE_INT, &ORDER_THRESHOLD),
394 "Could not read parameter");
397 chip != UVES_CHIP_INVALID;
401 cpl_frameset_find(frames,UVES_MASTER_FLAT(chip)) != NULL ||
402 cpl_frameset_find(frames,UVES_MASTER_DFLAT(chip)) != NULL
406 if(chip == UVES_CHIP_BLUE) {
420 chip != UVES_CHIP_INVALID;
424 if(strcmp(PROCESS_CHIP,
"REDU") == 0) {
433 frm_flat=cpl_frameset_find(frames,UVES_MASTER_FLAT(chip));
434 frm_dflat=cpl_frameset_find(frames,UVES_MASTER_DFLAT(chip));
436 if(frm_flat == NULL && frm_dflat == NULL) {
437 uves_msg_error(
"A %s or %s frame or both must be provided in input",
438 UVES_MASTER_FLAT(chip),UVES_MASTER_DFLAT(chip));
441 else if(frm_flat == NULL && frm_dflat != NULL) {
442 name_dflat=cpl_frame_get_filename(frm_dflat);
444 ima_cflat=cpl_image_load(name_dflat,CPL_TYPE_DOUBLE,0,0);
445 }
else if (frm_flat != NULL && frm_dflat == NULL) {
446 name_flat=cpl_frame_get_filename(frm_flat);
448 ima_cflat=cpl_image_load(name_flat,CPL_TYPE_DOUBLE,0,0);
450 check_nomsg(name_dflat=cpl_frame_get_filename(frm_dflat));
454 flames,ORDER_THRESHOLD));
458 cpl_free(product_filename);
459 check( product_filename = uves_masterflat_filename(chip),
460 "Error getting filename");
463 sprintf(pro_filename,
"%s", product_filename);
467 check( uves_frameset_insert(
470 CPL_FRAME_GROUP_PRODUCT,
471 CPL_FRAME_TYPE_IMAGE,
472 CPL_FRAME_LEVEL_INTERMEDIATE,
474 product_tag[raw_index],
480 PACKAGE
"/" PACKAGE_VERSION, qclog,
481 starttime,
true, UVES_ALL_STATS),
482 "Could not add master flat %s %s to frameset",
483 pro_filename, product_tag[raw_index]);
485 uves_msg(
"Master flat %s %s added to frameset",
486 pro_filename, product_tag[raw_index]);
489 if(strcmp(PROCESS_CHIP,
"REDL") == 0) {
494 uves_free_image(&ima_cflat);
496 uves_free_propertylist(&product_header);
497 uves_free_propertylist(&hflat);
504 uves_free_image(&ima_cflat);
506 uves_free_propertylist(&product_header);
507 uves_free_propertylist(&hflat);
508 cpl_free(product_filename);
#define uves_msg_error(...)
Print an error message.
void uves_polynomial_delete(polynomial **p)
Delete a polynomial.
int uves_qclog_delete(cpl_table **table)
delete QC-LOG table
#define uves_msg(...)
Print a message on 'info' or 'debug' level.
uves_propertylist * uves_propertylist_load(const char *name, int position)
Create a property list from a file.
static void uves_reduce_mflat_combine(cpl_frameset *frames, const cpl_parameterlist *parameters, bool flames, const char *recipe_id, const char *starttime)
Get the command line options and execute the data reduction.
double uves_polynomial_evaluate_2d(const polynomial *p, double x1, double x2)
Evaluate a 2d polynomial.
int uves_chip_get_index(enum uves_chip chip)
Convert to integer.
enum uves_chip uves_chip_get_first(bool blue)
Get first chip for blue or red arm.
enum uves_chip uves_chip_get_next(enum uves_chip chip)
Get next chip.
#define uves_msg_debug(...)
Print a debug message.
const char * uves_chip_tostring_upper(enum uves_chip chip)
Convert to string.
uves_propertylist * uves_propertylist_duplicate(const uves_propertylist *self)
Create a copy of the given property list.
const char * uves_string_toupper(char *s)
Convert all lowercase characters in a string into uppercase characters.
void uves_mflat_combine_exe_body(cpl_frameset *frames, const cpl_parameterlist *parameters, const char *starttime, const char *recipe_id)
Get the command line options and execute the data reduction.
int uves_mflat_combine_define_parameters_body(cpl_parameterlist *parameters, const char *recipe_id)
Setup the recipe options.
cpl_image * uves_combine_flats(const cpl_frame *frm_flat, const cpl_frame *frm_dflat, cpl_frameset *frames, bool flames, const int ORDER_THRESHOLD)
Get the command line options and execute the data reduction.