69 cpl_frame* merged_frame) {
71 cpl_table* qc_d2_tab = NULL;
72 cpl_table* qc_qth_tab = NULL;
73 cpl_table* qc_tot_tab=NULL;
74 cpl_propertylist* qc_qth_head = NULL;
84 double* pcenterx=NULL;
85 double* pcentery=NULL;
86 double* pedgelox=NULL;
87 double* pedgeupx=NULL;
88 double* pedgelofx=NULL;
89 double* pedgeupfx=NULL;
90 double* pedgelo_resx=NULL;
91 double* pedgeup_resx=NULL;
95 int* pabs_ord_org=NULL;
96 double* pcenterx_org=NULL;
97 double* pcentery_org=NULL;
98 double* pedgelox_org=NULL;
99 double* pedgeupx_org=NULL;
100 double* pedgelofx_org=NULL;
101 double* pedgeupfx_org=NULL;
102 double* pedgelo_resx_org=NULL;
103 double* pedgeup_resx_org=NULL;
105 qc_d2_tab = cpl_table_load(cpl_frame_get_filename(d2_frame), 3,0);
106 qc_qth_tab = cpl_table_load(cpl_frame_get_filename(qth_frame), 3,0);
107 qc_qth_head = cpl_propertylist_load(cpl_frame_get_filename(qth_frame), 3);
109 nrow_d2=cpl_table_get_nrow(qc_d2_tab);
110 nrow_qth=cpl_table_get_nrow(qc_qth_tab);
112 nrow_tot=nrow_d2+nrow_qth;
113 qc_tot_tab=cpl_table_new(nrow_tot);
116 cpl_table_copy_structure(qc_tot_tab,qc_qth_tab);
117 cpl_table_fill_column_window_int(qc_tot_tab,
"ORDER",0,nrow_tot,0);
118 cpl_table_fill_column_window_int(qc_tot_tab,
"ABSORDER",0,nrow_tot,0);
119 cpl_table_fill_column_window_double(qc_tot_tab,
"CENTERX",0,nrow_tot,0);
120 cpl_table_fill_column_window_double(qc_tot_tab,
"CENTERY",0,nrow_tot,0);
121 cpl_table_fill_column_window_double(qc_tot_tab,
"EDGELOX",0,nrow_tot,0);
122 cpl_table_fill_column_window_double(qc_tot_tab,
"EDGEUPX",0,nrow_tot,0);
123 cpl_table_fill_column_window_double(qc_tot_tab,
"EDGELOFX",0,nrow_tot,0);
124 cpl_table_fill_column_window_double(qc_tot_tab,
"EDGEUPFX",0,nrow_tot,0);
125 cpl_table_fill_column_window_double(qc_tot_tab,
"EDGELO_RESX",0,nrow_tot,0);
126 cpl_table_fill_column_window_double(qc_tot_tab,
"EDGEUP_RESX",0,nrow_tot,0);
129 pord=cpl_table_get_data_int(qc_tot_tab,
"ORDER");
130 pabs_ord=cpl_table_get_data_int(qc_tot_tab,
"ABSORDER");
131 pcenterx=cpl_table_get_data_double(qc_tot_tab,
"CENTERX");
132 pcentery=cpl_table_get_data_double(qc_tot_tab,
"CENTERY");
133 pedgelox=cpl_table_get_data_double(qc_tot_tab,
"EDGELOX");
134 pedgeupx=cpl_table_get_data_double(qc_tot_tab,
"EDGEUPX");
135 pedgelofx=cpl_table_get_data_double(qc_tot_tab,
"EDGELOFX");
136 pedgeupfx=cpl_table_get_data_double(qc_tot_tab,
"EDGEUPFX");
137 pedgelo_resx=cpl_table_get_data_double(qc_tot_tab,
"EDGELO_RESX");
138 pedgeup_resx=cpl_table_get_data_double(qc_tot_tab,
"EDGEUP_RESX");
140 pord_org=cpl_table_get_data_int(qc_qth_tab,
"ORDER");
141 pabs_ord_org=cpl_table_get_data_int(qc_qth_tab,
"ABSORDER");
142 pcenterx_org=cpl_table_get_data_double(qc_qth_tab,
"CENTERX");
143 pcentery_org=cpl_table_get_data_double(qc_qth_tab,
"CENTERY");
144 pedgelox_org=cpl_table_get_data_double(qc_qth_tab,
"EDGELOX");
145 pedgeupx_org=cpl_table_get_data_double(qc_qth_tab,
"EDGEUPX");
146 pedgelofx_org=cpl_table_get_data_double(qc_qth_tab,
"EDGELOFX");
147 pedgeupfx_org=cpl_table_get_data_double(qc_qth_tab,
"EDGEUPFX");
148 pedgelo_resx_org=cpl_table_get_data_double(qc_qth_tab,
"EDGELO_RESX");
149 pedgeup_resx_org=cpl_table_get_data_double(qc_qth_tab,
"EDGEUP_RESX");
152 for (i = 0; i < nrow_qth; i++) {
154 pord[i] = pord_org[i];
155 pabs_ord[i] = pabs_ord_org[i];
156 pcenterx[i] = pcenterx_org[i];
157 pcentery[i] = pcentery_org[i];
158 pedgelox[i] = pedgelox_org[i];
159 pedgeupx[i] = pedgeupx_org[i];
160 pedgelofx[i] = pedgelofx_org[i];
161 pedgeupfx[i] = pedgeupfx_org[i];
162 pedgelo_resx[i] = pedgelo_resx_org[i];
163 pedgeup_resx[i] = pedgeup_resx_org[i];
168 pord_org = cpl_table_get_data_int(qc_d2_tab,
"ORDER");
169 pabs_ord_org = cpl_table_get_data_int(qc_d2_tab,
"ABSORDER");
170 pcenterx_org = cpl_table_get_data_double(qc_d2_tab,
"CENTERX");
171 pcentery_org = cpl_table_get_data_double(qc_d2_tab,
"CENTERY");
172 pedgelox_org = cpl_table_get_data_double(qc_d2_tab,
"EDGELOX");
173 pedgeupx_org = cpl_table_get_data_double(qc_d2_tab,
"EDGEUPX");
174 pedgelofx_org = cpl_table_get_data_double(qc_d2_tab,
"EDGELOFX");
175 pedgeupfx_org = cpl_table_get_data_double(qc_d2_tab,
"EDGEUPFX");
176 pedgelo_resx_org = cpl_table_get_data_double(qc_d2_tab,
"EDGELO_RESX");
177 pedgeup_resx_org = cpl_table_get_data_double(qc_d2_tab,
"EDGEUP_RESX");
179 for (i = 0; i < nrow_d2; i++) {
181 pord[k] = pord_org[i];
182 pabs_ord[k] = pabs_ord_org[i];
183 pcenterx[k] = pcenterx_org[i];
184 pcentery[k] = pcentery_org[i];
185 pedgelox[k] = pedgelox_org[i];
186 pedgeupx[k] = pedgeupx_org[i];
187 pedgelofx[k] = pedgelofx_org[i];
188 pedgeupfx[k] = pedgeupfx_org[i];
189 pedgelo_resx[k] = pedgelo_resx_org[i];
190 pedgeup_resx[k] = pedgeup_resx_org[i];
193 cpl_table_save(qc_tot_tab, qc_qth_head, NULL, cpl_frame_get_filename(merged_frame), CPL_IO_EXTEND);
200 return cpl_error_get_code();
221 cpl_frame *d2_frame,cpl_frame *d2_order_tab_frame,
222 cpl_frame *qth_bkg_frame, cpl_frame *d2_bkg_frame,
223 cpl_frame **qth_d2_flat_frame,
224 cpl_frame **qth_d2_bkg_frame,
225 cpl_frame **qth_d2_order_tab_frame,
232 float *qth_data = NULL;
233 float *d2_data = NULL;
234 float *qth_errs = NULL;
235 float *d2_errs = NULL;
236 int *qth_qual = NULL;
239 float *d2_bkg_data = NULL;
241 float *qth_bkg_data = NULL;
247 cpl_polynomial *d2_limit = NULL;
248 cpl_polynomial *qth_limit = NULL;
249 cpl_image* d2_bkg_ima=NULL;
250 cpl_image* qth_bkg_ima=NULL;
252 const char* tag=NULL;
253 const char* fname=NULL;
258 double qth_flux_min=0;
259 double qth_flux_max=0;
260 double d2_flux_min=0;
261 double d2_flux_max=0;
293 check( qth_data = cpl_image_get_data_float( qth_pre->
data));
294 check( d2_data = cpl_image_get_data_float(d2_pre->
data));
296 fname=cpl_frame_get_filename(qth_bkg_frame);
297 qth_bkg_ima=cpl_image_load(fname,CPL_TYPE_FLOAT,0,0);
298 check( qth_bkg_data = cpl_image_get_data_float(qth_bkg_ima));
300 fname=cpl_frame_get_filename(d2_bkg_frame);
301 d2_bkg_ima=cpl_image_load(fname,CPL_TYPE_FLOAT,0,0);
302 check( d2_bkg_data = cpl_image_get_data_float(d2_bkg_ima));
305 check( qth_errs = cpl_image_get_data_float( qth_pre->
errs));
306 check( d2_errs = cpl_image_get_data_float(d2_pre->
errs));
308 check( qth_qual = cpl_image_get_data_int( qth_pre->
qual));
309 check( d2_qual = cpl_image_get_data_int(d2_pre->
qual));
321 for(
y=0;
y < d2_pre->
ny;
y++){
325 x_avg = floor( 0.5*(xd2+xqth));
332 for(
x=x_avg;
x< d2_pre->
nx;
x++){
334 d2_data[pixel] = qth_data[pixel];
335 d2_errs[pixel] = qth_errs[pixel];
336 d2_qual[pixel] = qth_qual[pixel];
338 d2_bkg_data[pixel] = qth_bkg_data[pixel];
363 flux_min=(qth_flux_min<d2_flux_min)? qth_flux_min:d2_flux_min;
364 flux_max=(qth_flux_max>d2_flux_max)? qth_flux_max:d2_flux_max;
374 check( cpl_frame_set_tag( *qth_d2_flat_frame, tag));
377 sprintf(file_tag,
"MFLAT_BACK_%s_%s",
381 sprintf(file_name,
"%s.fits",file_tag);
385 check(cpl_image_save(d2_bkg_ima,file_name,CPL_BPP_IEEE_FLOAT,
390 CPL_FRAME_TYPE_IMAGE,
391 CPL_FRAME_GROUP_CALIB,
392 CPL_FRAME_LEVEL_FINAL));
435 cpl_frame* full_edges_tab=NULL;
441 const char* tag=NULL;
467 return full_edges_tab;
493 cpl_frame *d2_frame,cpl_frame *d2_order_tab_frame,
494 cpl_frame *qth_bkg_frame, cpl_frame *d2_bkg_frame,
495 cpl_frame **qth_d2_flat_frame,
496 cpl_frame **qth_d2_bkg_frame,
497 cpl_frame **qth_d2_order_tab_frame,
506 float *qth_errs = NULL;
507 float *d2_errs = NULL;
508 int *qth_qual = NULL;
511 float *d2_bkg_data = NULL;
513 float *qth_bkg_data = NULL;
520 cpl_polynomial *d2_limit = NULL;
521 cpl_polynomial *qth_limit = NULL;
522 cpl_image* d2_bkg_ima=NULL;
523 cpl_image* qth_bkg_ima=NULL;
525 const char* tag=NULL;
526 const char* fname=NULL;
531 double qth_flux_min=0;
532 double qth_flux_max=0;
533 double d2_flux_min=0;
534 double d2_flux_max=0;
538 cpl_image* merged=NULL;
569 fname=cpl_frame_get_filename(qth_bkg_frame);
570 qth_bkg_ima=cpl_image_load(fname,CPL_TYPE_FLOAT,0,0);
571 check( qth_bkg_data = cpl_image_get_data_float(qth_bkg_ima));
573 fname=cpl_frame_get_filename(d2_bkg_frame);
574 d2_bkg_ima=cpl_image_load(fname,CPL_TYPE_FLOAT,0,0);
575 check( d2_bkg_data = cpl_image_get_data_float(d2_bkg_ima));
578 check( qth_errs = cpl_image_get_data_float( qth_pre->
errs));
579 check( d2_errs = cpl_image_get_data_float(d2_pre->
errs));
581 check( qth_qual = cpl_image_get_data_int( qth_pre->
qual));
582 check( d2_qual = cpl_image_get_data_int(d2_pre->
qual));
590 for(
y=0;
y < d2_pre->
ny;
y++){
597 x_avg = floor( (xd2+xqth)/2.0);
602 for(
x=x_avg;
x< d2_pre->
nx;
x++){
604 d2_errs[
x+
y*d2_pre->
nx] = qth_errs[
x+
y*d2_pre->
nx];
605 d2_qual[
x+
y*d2_pre->
nx] = qth_qual[
x+
y*d2_pre->
nx];
607 d2_bkg_data[
x+
y*d2_pre->
nx] = qth_bkg_data[
x+
y*d2_pre->
nx];
618 d2_pre->
data=cpl_image_duplicate(merged);
620 d2_pre->
data=cpl_image_duplicate(merged);
630 d2_bkg_ima=cpl_image_duplicate(merged);
632 d2_bkg_ima=cpl_image_duplicate(merged);
651 flux_min=(qth_flux_min<d2_flux_min)? qth_flux_min:d2_flux_min;
652 flux_max=(qth_flux_max>d2_flux_max)? qth_flux_max:d2_flux_max;
662 check( cpl_frame_set_tag( *qth_d2_flat_frame, tag));
665 sprintf(file_tag,
"MFLAT_BACK_%s_%s",
669 sprintf(file_name,
"%s.fits",file_tag);
673 check(cpl_image_save(d2_bkg_ima,file_name,CPL_BPP_IEEE_FLOAT,
678 CPL_FRAME_TYPE_IMAGE,
679 CPL_FRAME_GROUP_CALIB,
680 CPL_FRAME_LEVEL_FINAL));
static xsh_instrument * instrument
void xsh_order_list_set_bin_y(xsh_order_list *list, int bin)
Set the bin of image in y.
cpl_frame * xsh_order_list_save(xsh_order_list *order_list, xsh_instrument *instrument, const char *filename, const char *tag, const int ny)
Save an order list to a frame.
void xsh_order_list_set_bin_x(xsh_order_list *list, int bin)
Set the bin of image in x.
int xsh_order_list_eval_int(xsh_order_list *list, cpl_polynomial *poly, double y)
Evaluate an order list poly but return the central pixel position rounding the polynomial.
xsh_order_list * xsh_order_list_load(cpl_frame *frame, xsh_instrument *instr)
load an order list from a frame
xsh_order_list * xsh_order_list_merge(xsh_order_list *lista, xsh_order_list *listb)
void xsh_order_list_free(xsh_order_list **list)
free memory associated to an order_list
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.
#define XSH_REGDEBUG(...)
#define XSH_ASSURE_NOT_NULL(pointer)
static cpl_error_code xsh_add_qc_tab(cpl_frame *d2_frame, cpl_frame *qth_frame, cpl_frame *merged_frame)
cpl_frame * xsh_flat_merge_qth_d2_tabs(cpl_frame *qth_edges_tab, cpl_frame *d2_edges_tab, xsh_instrument *instrument)
Merge two order edges tables according the spectral format.
void xsh_flat_merge_qth_d2(cpl_frame *qth_frame, cpl_frame *qth_order_tab_frame, cpl_frame *d2_frame, cpl_frame *d2_order_tab_frame, cpl_frame *qth_bkg_frame, cpl_frame *d2_bkg_frame, cpl_frame **qth_d2_flat_frame, cpl_frame **qth_d2_bkg_frame, cpl_frame **qth_d2_order_tab_frame, xsh_instrument *instrument)
Merge two master flat fields and order tables according the spectral format.
void xsh_flat_merge_qth_d2_smooth(cpl_frame *qth_frame, cpl_frame *qth_order_tab_frame, cpl_frame *d2_frame, cpl_frame *d2_order_tab_frame, cpl_frame *qth_bkg_frame, cpl_frame *d2_bkg_frame, cpl_frame **qth_d2_flat_frame, cpl_frame **qth_d2_bkg_frame, cpl_frame **qth_d2_order_tab_frame, xsh_instrument *instrument)
Merge two master flat fields and order tables according the spectral format.
const char * xsh_instrument_mode_tostring(xsh_instrument *i)
Get the string associated with a mode.
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
void xsh_instrument_update_lamp(xsh_instrument *i, XSH_LAMP lamp)
#define xsh_msg_dbg_medium(...)
#define xsh_msg(...)
Print a message on info level.
void xsh_pfits_set_pcatg(cpl_propertylist *plist, const char *value)
Write the PCATG value.
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
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.
cpl_polynomial * edguppoly
cpl_polynomial * edglopoly
cpl_propertylist * data_header
#define XSH_NAME_LAMP_MODE_ARM(name, id, ext, instr)
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.
#define XSH_ORDER_TAB_EDGES
#define XSH_GET_TAG_FROM_LAMP(TAG, instr)
#define XSH_FREE(POINTER)
cpl_image * xsh_combine_flats(cpl_image *ima1_in, cpl_image *ima2_in, xsh_order_list *qth_list, xsh_order_list *d2_list, const int xrad, const int yrad)
Combine flat frames line adjusting illumination level to merge them smoothly.