45 #include "uves_corrbadpix.h"
47 #include <uves_pfits.h>
48 #include <uves_dump.h>
49 #include <uves_error.h>
88 int binx,
int biny,
int mark_bad,
bool red_ccd_new)
90 int badpixels_cleaned = -1;
95 "Could not get bad pixel map");
97 check( badpixels_cleaned =
99 "Error cleaning bad pixels");
103 return badpixels_cleaned;
122 (*badmap)[row][0] != -1;
125 cpl_free((*badmap)[row]);
127 cpl_free((*badmap)[row]);
147 bool finished =
false;
152 for (row = 0; !finished; row++)
154 map = cpl_realloc(map, (row+1)*
sizeof(
int *));
157 map[row] = cpl_calloc(4,
sizeof(
int));
158 map[row][0] = badmap[row][0];
159 map[row][1] = badmap[row][1];
160 map[row][2] = badmap[row][2];
161 map[row][3] = badmap[row][3];
163 finished = (badmap[row][0] == -1);
187 int binx,
int biny,
int mark_bad,
bool red_ccd_new)
191 if (chip == UVES_CHIP_REDL)
193 if (binx == 1 && biny == 1)
197 int badmap[][4] = {{1,4,2088,4},
226 int badmap[][4] = {{1,4,2088,4},
239 else if (binx == 1 && biny == 2)
245 int badmap[][4] = {{1,4,1045,4},
256 int badmap[][4] = {{1,4,1044,4},
268 else if (binx == 2 && biny == 2)
272 int badmap[][4] = {{1,4,1045,4},
283 int badmap[][4] = {{1,3,1044,3},
294 else if (binx == 2 && biny == 3)
299 int badmap[][4] = {{1,3,696,3},
316 int badmap[][4] = {{1,3,696,3},
330 assure(
false, CPL_ERROR_ILLEGAL_INPUT,
331 "Don't know bad pixel map for %dx%d binning, red, lower chip",
335 else if (chip == UVES_CHIP_REDU)
340 if (binx == 1 && biny ==1)
360 {1269,2033,4096,2033},
361 {1201, 491, 3271, 492},
374 else if (binx == 1 && biny == 2)
379 int badmap[][4] = {{1,1396,845,1396},
392 int badmap[][4] = {{1,2030,634,2033},
393 {635,2033,2048,2033},
394 {600, 491,1635, 492},
407 else if (binx == 2 && biny == 2)
412 int badmap[][4] = {{1,422,1526,422},
425 int badmap[][4] = {{1,1013,634,1016},
426 {635,1015,2048,1016},
427 {600, 244,1635, 245},
440 else if (binx == 2 && biny == 3)
444 int badmap[][4] = {{1,61,287,62},
446 {400, 872,1265, 872},
460 int badmap[][4] = {{1,1013,423,1016},
461 {424,1015,1365,1016},
462 {400, 244,1090, 245},
479 assure(
false, CPL_ERROR_ILLEGAL_INPUT,
480 "Don't know bad pixel map for %dx%d binning, red, upper chip",
487 int badmap[][4] = {{-1,-1,-1,-1}};
519 int xstart, ystart, xend, yend;
521 bool finished =
false;
523 cpl_mask *image_bad = NULL;
524 cpl_binary*image_bpm = NULL;
527 type=cpl_image_get_type(master_bias);
528 assure( (type == CPL_TYPE_DOUBLE) || (type == CPL_TYPE_FLOAT),
529 CPL_ERROR_UNSUPPORTED_MODE,
530 "Image type must be float or double. It is %s",
533 image_bad = cpl_image_get_bpm(master_bias);
534 image_bpm = cpl_mask_get_data(image_bad);
536 nx = cpl_image_get_size_x(master_bias);
537 ny = cpl_image_get_size_y(master_bias);
542 xstart = badmap[row][0];
543 ystart = badmap[row][1];
544 xend = badmap[row][2];
545 yend = badmap[row][3];
552 assure( 1 <= xstart && xstart <= nx &&
553 1 <= xend && xend <= nx &&
554 1 <= ystart && ystart <= ny &&
555 1 <= yend && yend <= ny, CPL_ERROR_ILLEGAL_INPUT,
556 "Illegal window (%d, %d) - (%d, %d). Image size = %dx%d",
557 xstart, ystart, xend, yend, nx, ny);
561 assure( yend + 2 <= ny, CPL_ERROR_ILLEGAL_INPUT,
562 "Too large range in y: %d - %d", ystart, yend);
567 else if (yend > ny - 3 )
569 assure( ystart - 2 >= 1, CPL_ERROR_ILLEGAL_INPUT,
570 "Too large range in y: %d - %d", ystart, yend);
581 uves_msg(
"Correcting window (%d, %d)-(%d, %d)", xstart, ystart, xend, yend);
583 if(type == CPL_TYPE_DOUBLE) {
585 for (x = xstart; x <= xend; x++) {
586 for (y = ystart; y <= yend; y++) {
594 image_bpm[(x-1) + (y-1)*nx] = CPL_BINARY_1;
599 double *master_bias_data;
601 double i1 = cpl_image_get(master_bias, x, ylow , &pis_rejected);
602 double i2 = cpl_image_get(master_bias, x, yhigh, &pis_rejected);
609 master_bias_data = cpl_image_get_data_double(master_bias);
610 master_bias_data[(x-1) + (y-1)*nx] = (i1+i2)/2;
619 for (x = xstart; x <= xend; x++) {
620 for (y = ystart; y <= yend; y++) {
627 image_bpm[(x-1) + (y-1)*nx] = CPL_BINARY_1;
632 float *master_bias_data;
634 float i1 = cpl_image_get(master_bias, x, ylow , &pis_rejected);
635 float i2 = cpl_image_get(master_bias, x, yhigh, &pis_rejected);
642 master_bias_data = cpl_image_get_data_float(master_bias);
643 master_bias_data[(x-1) + (y-1)*nx] = (i1+i2)/2;
664 "Error updating product header");
static int uves_correct_badpix(cpl_image *master_bias, uves_propertylist *header, int **badmap, bool mark_bad)
Correct bad pixels.
cpl_error_code uves_pfits_set_badpixcorr(uves_propertylist *plist, const char *corr)
Write the object keyword.
void uves_badmap_free(int ***badmap)
Deallocate bpm position.
int ** uves_get_badpix(enum uves_chip chip, int binx, int biny, int mark_bad, bool red_ccd_new)
Get hard-coded bpm map.
#define uves_msg(...)
Print a message on 'info' or 'debug' level.
static int ** dup_map(int badmap[][4])
Copy bpm to heap.
const char * uves_tostring_cpl_type(cpl_type t)
Convert a CPL type to a string.
int uves_correct_badpix_all(cpl_image *master_bias, uves_propertylist *mbias_header, enum uves_chip chip, int binx, int biny, int mark_bad, bool red_ccd_new)
Correct all bad pixels on a chip.