115 #include "uves_corrbadpix.h"
117 #include <uves_pfits.h>
118 #include <uves_dump.h>
119 #include <uves_error.h>
120 #include <uves_msg.h>
158 int binx,
int biny,
int mark_bad,
bool red_ccd_new)
160 int badpixels_cleaned = -1;
165 "Could not get bad pixel map");
167 check( badpixels_cleaned =
169 "Error cleaning bad pixels");
173 return badpixels_cleaned;
192 (*badmap)[row][0] != -1;
195 cpl_free((*badmap)[row]);
197 cpl_free((*badmap)[row]);
217 bool finished =
false;
222 for (row = 0; !finished; row++)
224 map = cpl_realloc(map, (row+1)*
sizeof(
int *));
227 map[row] = cpl_calloc(4,
sizeof(
int));
228 map[row][0] = badmap[row][0];
229 map[row][1] = badmap[row][1];
230 map[row][2] = badmap[row][2];
231 map[row][3] = badmap[row][3];
233 finished = (badmap[row][0] == -1);
257 int binx,
int biny,
int mark_bad,
bool red_ccd_new)
261 if (chip == UVES_CHIP_REDL)
263 if (binx == 1 && biny == 1)
267 int badmap[][4] = {{1,4,2088,4},
296 int badmap[][4] = {{1,4,2088,4},
309 else if (binx == 1 && biny == 2)
315 int badmap[][4] = {{1,4,1045,4},
326 int badmap[][4] = {{1,4,1044,4},
338 else if (binx == 2 && biny == 2)
342 int badmap[][4] = {{1,4,1045,4},
353 int badmap[][4] = {{1,3,1044,3},
364 else if (binx == 2 && biny == 3)
369 int badmap[][4] = {{1,3,696,3},
386 int badmap[][4] = {{1,3,696,3},
400 assure(
false, CPL_ERROR_ILLEGAL_INPUT,
401 "Don't know bad pixel map for %dx%d binning, red, lower chip",
405 else if (chip == UVES_CHIP_REDU)
410 if (binx == 1 && biny ==1)
430 {1269,2033,4096,2033},
431 {1201, 491, 3271, 492},
444 else if (binx == 1 && biny == 2)
449 int badmap[][4] = {{1,1396,845,1396},
462 int badmap[][4] = {{1,2030,634,2033},
463 {635,2033,2048,2033},
464 {600, 491,1635, 492},
477 else if (binx == 2 && biny == 2)
482 int badmap[][4] = {{1,422,1526,422},
495 int badmap[][4] = {{1,1013,634,1016},
496 {635,1015,2048,1016},
497 {600, 244,1635, 245},
510 else if (binx == 2 && biny == 3)
514 int badmap[][4] = {{1,61,287,62},
516 {400, 872,1265, 872},
530 int badmap[][4] = {{1,1013,423,1016},
531 {424,1015,1365,1016},
532 {400, 244,1090, 245},
549 assure(
false, CPL_ERROR_ILLEGAL_INPUT,
550 "Don't know bad pixel map for %dx%d binning, red, upper chip",
557 int badmap[][4] = {{-1,-1,-1,-1}};
589 int xstart, ystart, xend, yend;
591 bool finished =
false;
593 cpl_mask *image_bad = NULL;
594 cpl_binary*image_bpm = NULL;
597 type=cpl_image_get_type(master_bias);
598 assure( (type == CPL_TYPE_DOUBLE) || (type == CPL_TYPE_FLOAT),
599 CPL_ERROR_UNSUPPORTED_MODE,
600 "Image type must be float or double. It is %s",
603 image_bad = cpl_image_get_bpm(master_bias);
604 image_bpm = cpl_mask_get_data(image_bad);
606 nx = cpl_image_get_size_x(master_bias);
607 ny = cpl_image_get_size_y(master_bias);
612 xstart = badmap[row][0];
613 ystart = badmap[row][1];
614 xend = badmap[row][2];
615 yend = badmap[row][3];
622 assure( 1 <= xstart && xstart <= nx &&
623 1 <= xend && xend <= nx &&
624 1 <= ystart && ystart <= ny &&
625 1 <= yend && yend <= ny, CPL_ERROR_ILLEGAL_INPUT,
626 "Illegal window (%d, %d) - (%d, %d). Image size = %dx%d",
627 xstart, ystart, xend, yend, nx, ny);
631 assure( yend + 2 <= ny, CPL_ERROR_ILLEGAL_INPUT,
632 "Too large range in y: %d - %d", ystart, yend);
637 else if (yend > ny - 3 )
639 assure( ystart - 2 >= 1, CPL_ERROR_ILLEGAL_INPUT,
640 "Too large range in y: %d - %d", ystart, yend);
651 uves_msg(
"Correcting window (%d, %d)-(%d, %d)", xstart, ystart, xend, yend);
654 if(type == CPL_TYPE_DOUBLE) {
656 for (x = xstart; x <= xend; x++) {
657 for (y = ystart; y <= yend; y++) {
666 image_bpm[(x-1) + (y-1)*nx] = CPL_BINARY_1;
671 double *master_bias_data;
673 i1 = cpl_image_get(master_bias, x, ylow , &pis_rejected);
674 i2 = cpl_image_get(master_bias, x, yhigh, &pis_rejected);
681 master_bias_data = cpl_image_get_data_double(master_bias);
682 master_bias_data[(x-1) + (y-1)*nx] = (i1+i2)/2;
692 for (x = xstart; x <= xend; x++) {
693 for (y = ystart; y <= yend; y++) {
702 image_bpm[(x-1) + (y-1)*nx] = CPL_BINARY_1;
707 float *master_bias_data;
709 i1 = cpl_image_get(master_bias, x, ylow , &pis_rejected);
710 i2 = cpl_image_get(master_bias, x, yhigh, &pis_rejected);
717 master_bias_data = cpl_image_get_data_float(master_bias);
718 master_bias_data[(x-1) + (y-1)*nx] = (i1+i2)/2;
740 "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.