Changeset 21156 for trunk/magic/remove/src
- Timestamp:
- Jan 23, 2009, 3:05:43 PM (17 years ago)
- Location:
- trunk/magic/remove/src
- Files:
-
- 13 edited
-
. (modified) (1 prop)
-
.cvsignore (modified) (1 diff)
-
Line.c (modified) (2 diffs)
-
Makefile.simple (modified) (2 diffs)
-
streaksastrom.c (modified) (10 diffs)
-
streakscompare.c (modified) (1 diff)
-
streaksio.c (modified) (12 diffs)
-
streaksio.h (modified) (2 diffs)
-
streaksrelease.c (modified) (6 diffs)
-
streaksremove.c (modified) (18 diffs)
-
streaksremove.h (modified) (2 diffs)
-
streaksreplace.c (modified) (3 diffs)
-
warpedpixels.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/magic/remove/src
- Property svn:ignore
-
old new 2 2 streaksreplace 3 3 streakscompare 4 streaksrelease
-
- Property svn:ignore
-
trunk/magic/remove/src/.cvsignore
r20816 r21156 2 2 streaksreplace 3 3 streakscompare 4 streaksrelease -
trunk/magic/remove/src/Line.c
r20664 r21156 321 321 if (DistanceSquared (line, x, y) <= halfWidth2) 322 322 { 323 pixel = psAlloc (sizeof(PixelPos)); 324 pixel->x = (int) x; 325 pixel->y = (int) y; 326 psArrayAdd (pixels, 1024, pixel); 327 psFree (pixel); 323 if (x >=0 && y >= 0) { 324 pixel = psAlloc (sizeof(PixelPos)); 325 pixel->x = (unsigned int) x; 326 pixel->y = (unsigned int) y; 327 psArrayAdd (pixels, 1024, pixel); 328 psFree (pixel); 329 } 328 330 } 329 331 } … … 368 370 if (DistanceSquared (line, x, y) <= halfWidth2) 369 371 { 370 pixel = psAlloc (sizeof(PixelPos)); 371 pixel->x = (int) x; 372 pixel->y = (int) y; 373 psArrayAdd (pixels, 1024, pixel); 374 psFree (pixel); 372 if (x >=0 && y >= 0) { 373 pixel = psAlloc (sizeof(PixelPos)); 374 pixel->x = (unsigned int) x; 375 pixel->y = (unsigned int) y; 376 psArrayAdd (pixels, 1024, pixel); 377 psFree (pixel); 378 } 375 379 } 376 380 } -
trunk/magic/remove/src/Makefile.simple
r21085 r21156 6 6 COMMON_OBJECTS = \ 7 7 streaksio.o \ 8 streaksutil.o 8 streaksutil.o \ 9 streaksastrom.o 9 10 10 11 REMOVE_OBJECTS= \ 11 12 ${COMMON_OBJECTS} \ 12 13 streaksremove.o \ 13 streaksastrom.o \14 14 streaksextern.o \ 15 15 warpedpixels.o \ … … 30 30 STREAKSFLAGS=-DSTREAKS_COMPRESS_OUTPUT=1 31 31 OPTFLAGS= -g 32 #CFLAGS=`psmodules-config --cflags` -std=gnu99 ${OPTFLAGS} ${STREAKSFLAGS}33 CFLAGS=`psmodules-config --cflags` -std=gnu99 ${OPTFLAGS}32 CFLAGS=`psmodules-config --cflags` -std=gnu99 ${OPTFLAGS} ${STREAKSFLAGS} 33 #CFLAGS=`psmodules-config --cflags` -std=gnu99 ${OPTFLAGS} 34 34 LDFLAGS=`psmodules-config --libs` 35 35 -
trunk/magic/remove/src/streaksastrom.c
r20842 r21156 17 17 18 18 if (fromCell) { 19 // The metadata is the cell concepts 19 // XXX: I think that this is not needed 20 // We are only asked to get the concepts from the cell when we're reading from a pmfile (skycell) 21 // In that case we (x0,y0) = (0,0) and the parirties are positive 22 // If the x0, y0 are not zero they are probably in the FITS unity based array format 23 // We should probably assert that these are zero 20 24 cell_x0 = psMetadataLookupS32(&mdok, md, "CELL.X0"); 21 25 if (!mdok) { … … 28 32 return NULL; 29 33 } 30 31 34 xParityCell = psMetadataLookupS32(&mdok, md, "CELL.XPARITY"); 32 35 if (!mdok || (xParityCell != 1 && xParityCell != -1)) { … … 65 68 return false; 66 69 } 67 68 70 } else { 69 71 // no metadata regular cell 72 // used by warpedpixels 70 73 cell_x0 = 0; 71 74 cell_y0 = 0; … … 89 92 } 90 93 94 void 95 chipToCell(double *xCell, double *yCell, strkAstrom *astrom, double xChip, double yChip) 96 { 97 // convert from chip to cell 98 if (astrom->xParity > 0) { 99 *xCell = xChip - astrom->cell_x0; 100 } else { 101 *xCell = astrom->cell_x0 - 1 - xChip; 102 } 103 if (astrom->yParity > 0) { 104 *yCell = yChip - astrom->cell_y0; 105 } else { 106 *yCell = astrom->cell_y0 - 1 - yChip; 107 } 108 } 109 110 void 111 cellToChip(double *xChip, double *yChip, strkAstrom *astrom, double xCell, double yCell) 112 { 113 if (astrom->xParity > 0) { 114 *xChip = xCell + astrom->cell_x0; 115 } else { 116 *xChip = astrom->cell_x0 - 1 - xCell; 117 } 118 if (astrom->yParity > 0) { 119 *yChip = yCell + astrom->cell_y0; 120 } else { 121 *yChip = astrom->cell_y0 - 1 - yCell; 122 } 123 } 124 125 void 126 cellToChipInt(int *xChip, int *yChip, strkAstrom *astrom, int xCell, int yCell) 127 { 128 if (astrom->xParity > 0) { 129 *xChip = xCell + astrom->cell_x0; 130 } else { 131 *xChip = astrom->cell_x0 - 1 - xCell; 132 } 133 if (astrom->yParity > 0) { 134 *yChip = yCell + astrom->cell_y0; 135 } else { 136 *yChip = astrom->cell_y0 - 1 - yCell; 137 } 138 } 139 91 140 bool 92 141 skyToCell(strkPt *outPt, strkAstrom *astrom, double ra, double dec) … … 107 156 psPlaneTransformApply(pt->chip, chip->fromFPA, pt->FP); 108 157 109 // convert from chip to cell 110 outPt->x = (pt->chip->x - astrom->cell_x0) * astrom->xParity; 111 outPt->y = (pt->chip->y - astrom->cell_y0) * astrom->yParity; 158 chipToCell(&outPt->x, &outPt->y, astrom, pt->chip->x, pt->chip->y); 112 159 113 160 // printf("cell: %f %f chip: %f %f\n", outPt->x, outPt->y, pt->chip->x, pt->chip->y); … … 115 162 return true; 116 163 } 117 164 118 165 bool 119 166 cellToSky(strkPt *outPt, strkAstrom *astrom, double x, double y) … … 123 170 pmAstromObj *pt = (pmAstromObj *) astrom->pt; 124 171 125 // XXX: TODO: confirm that this cell to chip transformation is correct 126 pt->chip->x = (x * astrom->xParity) + astrom->cell_x0; 127 pt->chip->y = (y * astrom->yParity) + astrom->cell_y0; 172 cellToChip(&pt->chip->x, &pt->chip->y, astrom, x, y); 128 173 129 174 pt->chip->xErr = 0; // Is setting these errors to zero the right thing to do? … … 142 187 } 143 188 144 void145 cellToChip(PixelPos *chip, strkAstrom *astrom, PixelPos *cell)146 {147 // TODO: do I need to worry about going from int to float and back again here?148 chip->x = (cell->x * astrom->xParity) + astrom->cell_x0;149 chip->y = (cell->y * astrom->yParity) + astrom->cell_y0;150 }151 189 152 190 static bool … … 166 204 PS_ASSERT_PTR_NON_NULL(hdu->header, 1) 167 205 if (sf->bilevelAstrometry) { 168 // Do we get here for GPC1 ? I don't necessarily have an fpa for the input image169 206 if (!pmAstromReadBilevelMosaic(sf->inAstrom->fpa, phu->header)) { 170 207 psError(PS_ERR_UNKNOWN, false, "Unable to read bilevel mosaic astrometry for input FPA."); … … 232 269 } 233 270 } 271 272 void 273 linearizeTransforms(strkAstrom *astrom) 274 { 275 if (!pmAstromLinearizeTransforms((pmFPA *) astrom->fpa, (pmChip *) astrom->chip)) { 276 streaksExit("linear fit to astrometry failed\n", PS_EXIT_UNKNOWN_ERROR); 277 } 278 } -
trunk/magic/remove/src/streakscompare.c
r20843 r21156 39 39 streaksExit("failed to advance to next extesion\n", PS_EXIT_DATA_ERROR); 40 40 } 41 readImage(file1, 0, stage );42 readImage(file2, 0, stage );41 readImage(file1, 0, stage, false); 42 readImage(file2, 0, stage, false); 43 43 44 44 psImage *image1 = file1->image; -
trunk/magic/remove/src/streaksio.c
r21085 r21156 41 41 42 42 sf->inMask = sFileOpen(config, stage, "INPUT.MASK", NULL, false); 43 if (sf->inMask ) {43 if (sf->inMask && (sf->stage != IPP_STAGE_RAW)) { 44 44 inputBasename = basename(sf->inMask->name); 45 45 sf->outMask = sFileOpen(config, stage, "OUTPUT", inputBasename, true); … … 295 295 streakFilesNextExtension(streakFiles *sf) 296 296 { 297 // unless stage is raw or chipwhen we get here we're done297 // unless stage is raw when we get here we're done 298 298 if (sf->stage != IPP_STAGE_RAW) { 299 299 if (sf->view) { … … 315 315 if (sf->extnum < sf->nHDU) { 316 316 moveExt(sf->inImage, sf->extnum); 317 if (sf->inMask) { 318 moveExt(sf->inMask, sf->extnum); 319 } 320 if (sf->inWeight) { 321 moveExt(sf->inWeight, sf->extnum); 322 } 317 // No mask and weight images for raw stage 323 318 return true; 324 319 } else { 320 // we're all done 325 321 return false; 326 322 } … … 354 350 355 351 sFile *inMask = sfiles->inMask; 356 if (inMask ) {352 if (inMask && sfiles->outMask) { 357 353 psMetadata *maskHeader = psFitsReadHeader(NULL, inMask->fits); 358 354 if (!maskHeader) { … … 469 465 } 470 466 471 void472 setDataExtent(ippStage stage, sFile *in )473 { 474 if ( stage == IPP_STAGE_RAW) {467 static void 468 setDataExtent(ippStage stage, sFile *in, bool rawImage) 469 { 470 if (rawImage) { 475 471 psString datasec = psMetadataLookupStr(NULL, in->header, "DATASEC"); 476 472 if (!datasec) { … … 480 476 int xmin, xmax, ymin, ymax; 481 477 sscanf(datasec, "[%d:%d,%d:%d]", &xmin, &xmax, &ymin, &ymax); 478 479 // I've inadvertantly introduced an implicit assumption that cell coordinates 480 // are the same as image coordinates. This is true for GPC1 481 // Test for this condition not being true 482 if (xmin != 1) { 483 psError(PS_ERR_IO, true, "can't handle datasec with minimum x != 1: %s", datasec); 484 streaksExit("", PS_EXIT_PROG_ERROR); 485 } 486 if (ymin != 1) { 487 psError(PS_ERR_IO, true, "can't handle datasec with minimum y != 1: %s", datasec); 488 streaksExit("", PS_EXIT_PROG_ERROR); 489 } 490 491 // These values are different than the size of the actual image which includes 492 // the bias area. 482 493 in->numCols = xmax - xmin + 1; 483 494 in->numRows = ymax - ymin + 1; … … 489 500 490 501 void 491 readImage(sFile *in, int extnum, ippStage stage )502 readImage(sFile *in, int extnum, ippStage stage, bool isMask) 492 503 { 493 504 psRegion region = {0, 0, 0, 0}; … … 526 537 streaksExit("", PS_EXIT_DATA_ERROR); 527 538 } 539 if (in->image->type.type == PS_TYPE_U16) { 540 in->exciseValue = 65535; 541 psMetadataAddU16(in->header, PS_LIST_TAIL, "BLANK", 0, "", 65535); 542 psMetadataAddU16(in->header, PS_LIST_TAIL, "ZBLANK", 0, "", 65535); 543 } else { 544 in->exciseValue = NAN; 545 } 528 546 } else { 529 547 if (stage != IPP_STAGE_RAW) { … … 539 557 psImage *image = (psImage *) (in->imagecube->data[0]); 540 558 } 541 setDataExtent(stage, in );559 setDataExtent(stage, in, (stage == IPP_STAGE_RAW) && !isMask); 542 560 } 543 561 … … 676 694 writeImageCube(sFile *sfile, psArray *imagecube, psString extname, int extnum) 677 695 { 678 if (! imagecube) {696 if (!sfile || !imagecube) { 679 697 return; 680 698 } … … 687 705 sfile->header = NULL; 688 706 } 689 690 #ifdef notdef691 void692 writeImages(streakFiles *sf, bool exciseImageCube)693 {694 psString extname = NULL;695 if (sf->nHDU > 1) {696 bool mdok;697 extname = psMetadataLookupStr(&mdok, sf->inImage->header, "EXTNAME");698 }699 if (sf->inImage->numZPlanes == 0) {700 // note exciseing complete images is handled in readAndCopyToOutput701 writeImage(sf->outImage, extname, sf->extnum);702 writeImage(sf->recImage, extname, sf->extnum);703 } else {704 // we have an image cube705 double initValue;706 if (exciseImageCube) {707 // copy the entire input image to the recovery image708 writeImageCube(sf->recImage, sf->inImage->imagecube, extname, sf->extnum);709 initValue = NAN;710 } else {711 // otherwise write it to the output712 writeImageCube(sf->outImage, sf->inImage->imagecube, extname, sf->extnum);713 initValue = 0;714 }715 716 // borrow one of the images from the imagecube and set it to init value717 psImage *image = psArrayGet (sf->inImage->imagecube, 0);718 psMemIncrRefCounter(image);719 psImageInit(image, initValue);720 if (exciseImageCube) {721 sf->outImage->image = image;722 writeImage(sf->outImage, extname, sf->extnum);723 } else {724 // write zero valued image to reccovery725 if (sf->recImage) {726 sf->recImage->image = image;727 writeImage(sf->recImage, extname, sf->extnum);728 }729 }730 // Assumption: there are no mask and weight images for video cells731 return;732 }733 if (sf->outMask) {734 writeImage(sf->outMask, extname, sf->extnum);735 writeImage(sf->recMask, extname, sf->extnum);736 }737 if (sf->outWeight) {738 writeImage(sf->outWeight, extname, sf->extnum);739 writeImage(sf->recWeight, extname, sf->extnum);740 }741 }742 #endif743 707 744 708 void … … 952 916 } 953 917 918 bool 919 isExciseValue(double value, double exciseValue) 920 { 921 if (isnan(exciseValue)) { 922 return isnan(value); 923 } else { 924 return value == exciseValue; 925 } 926 } 927 928 void 929 setMaskedToNAN(streakFiles *sfiles, psU8 maskMask, bool printCounts) 930 { 931 int maskedPixels = 0; 932 int nandPixels = 0; 933 int nandWeights = 0; 934 935 psImage *image = sfiles->outImage->image; 936 psImage *mask = sfiles->inMask->image; 937 psImage *weight = NULL; 938 if (sfiles->outWeight) { 939 weight = sfiles->outWeight->image; 940 } 941 double exciseValue = sfiles->inImage->exciseValue; 942 943 if (printCounts) { 944 psTimerStart("NAN_MASKED"); 945 } 946 947 for (int y=0; y < sfiles->inImage->numRows; y++) { 948 for (int x=0; x < sfiles->inImage->numCols; x++) { 949 // these gets are not necessary, we could just set the pixels to nan 950 // but I want to get the counts 951 double imageVal = psImageGet(image, x, y); 952 psU8 maskVal; 953 if (sfiles->stage == IPP_STAGE_RAW) { 954 int xChip, yChip; 955 cellToChipInt(&xChip, &yChip, sfiles->astrom, x, y); 956 maskVal = psImageGet(mask, xChip, yChip); 957 } else { 958 maskVal = psImageGet(mask, x, y); 959 } 960 if (maskVal & maskMask) { 961 ++maskedPixels; 962 if (!isExciseValue(imageVal, sfiles->inImage->exciseValue)) { 963 ++nandPixels; 964 psImageSet(image, x, y, exciseValue); 965 } 966 if (weight) { 967 double weightVal = weight ? psImageGet(weight, x, y) : 0; 968 if (!isnan(weightVal)) { 969 ++nandWeights; 970 psImageSet(weight, x, y, NAN); 971 } 972 } 973 } 974 } 975 } 976 if (printCounts) { 977 printf("time to NAN mask pixels: %f\n", psTimerClear("NAN_MASKED")); 978 int totalPixels = image->numRows * image->numCols; 979 printf("pixels: %10ld\n", totalPixels); 980 printf("masked pixels: %10ld %4.2f%%\n", maskedPixels, 100. * maskedPixels / totalPixels); 981 printf("nand pixels: %10ld %4.2f%%\n", nandPixels, 100. * nandPixels / totalPixels); 982 if (weight) { 983 printf("nand weights: %10ld %4.2f%%\n", nandWeights, 100. * nandWeights / totalPixels); 984 } 985 } 986 } -
trunk/magic/remove/src/streaksio.h
r20816 r21156 12 12 void closeImage(sFile *sfile); 13 13 14 void readImage(sFile *sfile, int extnum, ippStage stage );14 void readImage(sFile *sfile, int extnum, ippStage stage, bool isMask); 15 15 void copyPHU(streakFiles *sfiles, bool remove); 16 16 void copyTable(sFile *out, sFile *in, int extnum); … … 25 25 bool streakFilesNextExtension(streakFiles *sf); 26 26 27 bool isExciseValue(double, double); 28 void setMaskedToNAN(streakFiles *sfiles, psU8 maskMask, bool printCounts); 27 29 #endif // STREAKS_IO_H -
trunk/magic/remove/src/streaksrelease.c
r21085 r21156 51 51 } 52 52 53 int totalPixels = 0;54 int totalMaskedPixels = 0;55 int totalNANdPixels = 0;56 int totalNANdWeights = 0;57 58 53 // Iterate through each component of the input (there is only one except for raw images) 59 54 do { … … 70 65 } 71 66 72 int maskedPixels = 0; 73 int nandPixels = 0; 74 int nandWeights = 0; 75 76 psImage *image = sfiles->outImage->image; 77 psImage *mask = sfiles->outMask->image; 78 psImage *weight= sfiles->outWeight->image; 79 80 for (int y=0; y < image->numRows; y++) { 81 for (int x=0; x < image->numCols; x++) { 82 // these gets are not necessary, we could just set the pixels to nan 83 // but I want to get the counts 84 double imageVal = psImageGet(image, x, y); 85 double weightVal = psImageGet(weight, x, y); 86 psU8 maskVal = psImageGet(mask, x, y); 87 if (maskVal & maskMask) { 88 ++maskedPixels; 89 if (!isnan(imageVal)) { 90 ++nandPixels; 91 psImageSet(image, x, y, NAN); 92 } 93 if (!isnan(weightVal)) { 94 ++nandWeights; 95 psImageSet(weight, x, y, NAN); 96 } 97 } 98 } 99 } 100 totalPixels += sfiles->inImage->numRows * sfiles->inImage->numCols; 101 totalMaskedPixels += maskedPixels; 102 totalNANdPixels += nandPixels; 103 totalNANdWeights += nandWeights; 67 setMaskedToNAN(sfiles, maskMask, true); 104 68 105 69 // write out the destreaked temporary images and the recovery images … … 108 72 printf("time to process component %d: %f\n", sfiles->extnum, psTimerClear("PROCESS_COMPONENT")); 109 73 } while (streakFilesNextExtension(sfiles)); 110 111 printf("pixels: %10ld\n", totalPixels);112 printf("masked pixels: %10ld %4.2f%%\n", totalMaskedPixels, 100. * totalMaskedPixels / totalPixels);113 printf("nand pixels: %10ld %4.2f%%\n", totalNANdPixels, 100. * totalNANdPixels / totalPixels);114 printf("nand weights: %10ld %4.2f%%\n", totalNANdWeights, 100. * totalNANdWeights / totalPixels);115 74 116 75 psTimerStart("CLOSE_IMAGES"); … … 292 251 } else { 293 252 // image data directly from psFits 294 readImage(sf->inImage, sf->extnum, sf->stage );253 readImage(sf->inImage, sf->extnum, sf->stage, false); 295 254 } 296 255 sf->outImage->header = (psMetadata*) psMemIncrRefCounter(sf->inImage->header); … … 325 284 326 285 if (sf->inMask) { 327 readImage(sf->inMask, sf->extnum, sf->stage );286 readImage(sf->inMask, sf->extnum, sf->stage, true); 328 287 sf->outMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header); 329 288 if (sf->recMask) { … … 358 317 359 318 if (sf->inWeight) { 360 readImage(sf->inWeight, sf->extnum, sf->stage );319 readImage(sf->inWeight, sf->extnum, sf->stage, false); 361 320 sf->outWeight->header = (psMetadata*) psMemIncrRefCounter(sf->inWeight->header); 362 321 if (sf->recWeight) { -
trunk/magic/remove/src/streaksremove.c
r21085 r21156 9 9 static void writeImages(streakFiles *sf, bool exciseImageCube); 10 10 static bool replicateOutputs(streakFiles *sfiles); 11 static void updateAstrometry(streakFiles *sfiles); 11 12 12 13 int … … 21 22 if (!config) { 22 23 psError(PS_ERR_UNKNOWN, false, "failed to parse arguments\n"); 23 return PS_EXIT_CONFIG_ERROR;24 streaksExit("", PS_EXIT_CONFIG_ERROR); 24 25 } 25 26 … … 27 28 if (!status) { 28 29 psError(PM_ERR_CONFIG, false, "failed to lookup MASKS in recipes\n"); 29 return PS_EXIT_CONFIG_ERROR;30 streaksExit("", PS_EXIT_CONFIG_ERROR); 30 31 } 31 32 double maskStreak = (double) psMetadataLookupU8(&status, masks, "STREAK"); 32 33 if (!status) { 33 34 psError(PM_ERR_CONFIG, false, "failed to lookup mask value for STREAK in recipes\n"); 34 return PS_EXIT_CONFIG_ERROR; 35 } 35 streaksExit("", PS_EXIT_CONFIG_ERROR); 36 } 37 38 // optionally setting pixels with any mask bits execpt POOR.WARP to NAN 39 psU8 poorWarp = (double) psMetadataLookupU8(&status, masks, "POOR.WARP"); 40 if (!status) { 41 psError(PM_ERR_CONFIG, false, "failed to lookup mask value for POOR.WARP in recipes\n"); 42 streaksExit("", PS_EXIT_CONFIG_ERROR); 43 } 44 psU8 maskMask = ~poorWarp; 36 45 37 46 psString streaksFileName = psMetadataLookupStr(NULL, config->arguments, "STREAKS"); … … 40 49 if (!streaks) { 41 50 psErrorStackPrint(stderr, "failed to read streaks file: %s", streaksFileName); 42 exit (PS_EXIT_PROG_ERROR);51 streaksExit("", PS_EXIT_PROG_ERROR); 43 52 } 44 53 45 54 streakFiles *sfiles = openFiles(config, true); 46 55 setupAstrometry(sfiles); 56 57 bool nanForRelease = psMetadataLookupBool(&status, config->arguments, "NAN_FOR_RELEASE"); 58 if (nanForRelease && (sfiles->inMask == NULL)) { 59 psError(PS_ERR_UNKNOWN, true, "mask image must be supplied with -release."); 60 streaksExit("", PS_EXIT_PROG_ERROR); 61 } 47 62 48 63 bool exciseAll = false; … … 113 128 printf("time to get streak pixels: %f\n", psTimerClear("GET_STREAK_PIXELS")); 114 129 115 if (checkNonWarpedPixels) {116 psTimerStart("EXCISE_NON_WARPED");117 118 exciseNonWarpedPixels(sfiles, maskStreak);119 120 printf("time to excise non warped pixels: %f\n", psTimerClear("EXCISE_NON_WARPED"));121 }122 130 123 131 if (sfiles->inImage->image) { 132 if (checkNonWarpedPixels) { 133 psTimerStart("EXCISE_NON_WARPED"); 134 135 exciseNonWarpedPixels(sfiles, maskStreak); 136 137 printf("time to excise non warped pixels: %f\n", psTimerClear("EXCISE_NON_WARPED")); 138 } 124 139 totalStreakPixels += psArrayLength(pixels); 125 140 psTimerStart("REMOVE_STREAKS"); … … 137 152 } 138 153 printf("time to remove streak pixels: %f\n", psTimerClear("REMOVE_STREAKS")); 154 155 if (nanForRelease) { 156 setMaskedToNAN(sfiles, maskMask, true); 157 } 158 139 159 } else { 140 160 // this component contains an image cube, excise it completely … … 142 162 } 143 163 psArrayElementsFree (pixels); 164 } 165 166 if (sfiles->stage == IPP_STAGE_CHIP) { 167 // if (CHIP_LEVEL_INPUT(sfiles->stage)) { 168 updateAstrometry(sfiles); 144 169 } 145 170 … … 302 327 true); 303 328 } 329 330 if ((argnum = psArgumentGet(argc, argv, "-release"))) { 331 psArgumentRemove(argnum, &argc, argv); 332 psMetadataAddBool(config->arguments, PS_LIST_TAIL, "NAN_FOR_RELEASE", 0, "set masked pixels to NAN", 333 true); 334 } 304 335 305 336 if ((argnum = psArgumentGet(argc, argv, "-keepnonwarped"))) { … … 424 455 425 456 return config; 457 } 458 459 static void 460 updateAstrometry(streakFiles *sf) 461 { 462 if (sf->bilevelAstrometry) { 463 linearizeTransforms(sf->astrom); 464 // XXX: pmAstrometry.c should set the correct CTYPE values 465 if (!pmAstromWriteWCS(sf->outImage->header, sf->inAstrom->fpa, sf->chip, 0.001)) { 466 psError(PS_ERR_UNKNOWN, false, "failed to update astrometry for extension %d", sf->extnum); 467 streaksExit("", PS_EXIT_UNKNOWN_ERROR); 468 } 469 if (sf->outMask) { 470 pmAstromWriteWCS(sf->outMask->header, sf->inAstrom->fpa, sf->chip, 0.001); 471 } 472 if (sf->outWeight) { 473 pmAstromWriteWCS(sf->outWeight->header, sf->inAstrom->fpa, sf->chip, 0.001); 474 } 475 } 426 476 } 427 477 … … 438 488 } else { 439 489 // image data directly from psFits 440 readImage(sf->inImage, sf->extnum, sf->stage );490 readImage(sf->inImage, sf->extnum, sf->stage, false); 441 491 if (SFILE_IS_IMAGE(sf->inImage)) { 442 492 sf->astrom = streakSetAstrometry(sf->astrom, sf->stage, sf->inAstrom->fpa, sf->chip, false, … … 493 543 494 544 if (sf->inMask) { 495 readImage(sf->inMask, sf->extnum, sf->stage); 496 sf->outMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header); 497 if (sf->recMask) { 498 sf->recMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header); 499 } 500 if (updateAstrometry) { 501 pmAstromWriteWCS(sf->outMask->header, sf->inAstrom->fpa, sf->chip, 0.001); 502 } 503 setupImageRefs(sf->outMask, sf->recMask, sf->inMask, sf->extnum, exciseAll); 504 if (sf->outChMask) { 505 sf->outChMask->header = (psMetadata *) psMemIncrRefCounter(sf->outMask->header); 506 sf->outChMask->image = (psImage *) psMemIncrRefCounter(sf->outMask->image); 507 if (sf->recChMask) { 508 sf->recChMask->header = (psMetadata *) psMemIncrRefCounter(sf->recMask->header); 509 sf->recChMask->image = (psImage *) psMemIncrRefCounter(sf->recMask->image); 510 } 511 } 545 readImage(sf->inMask, sf->extnum, sf->stage, true); 546 if (sf->outMask) { 547 sf->outMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header); 548 if (sf->recMask) { 549 sf->recMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header); 550 } 551 if (updateAstrometry) { 552 pmAstromWriteWCS(sf->outMask->header, sf->inAstrom->fpa, sf->chip, 0.001); 553 } 554 setupImageRefs(sf->outMask, sf->recMask, sf->inMask, sf->extnum, exciseAll); 555 if (sf->outChMask) { 556 sf->outChMask->header = (psMetadata *) psMemIncrRefCounter(sf->outMask->header); 557 sf->outChMask->image = (psImage *) psMemIncrRefCounter(sf->outMask->image); 558 if (sf->recChMask) { 559 sf->recChMask->header = (psMetadata *) psMemIncrRefCounter(sf->recMask->header); 560 sf->recChMask->image = (psImage *) psMemIncrRefCounter(sf->recMask->image); 561 } 562 } 512 563 513 564 #ifdef STREAKS_COMPRESS_OUTPUT 514 // XXX: see note above515 copyFitsOptions(sf->outMask, sf->recMask, sf->inMask);516 psFitsSetCompression(sf->outMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);517 if (sf->recMask) {518 psFitsSetCompression(sf->recMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);519 }520 if (sf->outChMask) {521 copyFitsOptions(sf->outChMask, sf->recChMask, sf->inMask);522 psFitsSetCompression(sf->outChMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);523 if (sf->recChMask) {524 psFitsSetCompression(sf->recChMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0);525 }526 }565 // XXX: see note above 566 copyFitsOptions(sf->outMask, sf->recMask, sf->inMask); 567 psFitsSetCompression(sf->outMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0); 568 if (sf->recMask) { 569 psFitsSetCompression(sf->recMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0); 570 } 571 if (sf->outChMask) { 572 copyFitsOptions(sf->outChMask, sf->recChMask, sf->inMask); 573 psFitsSetCompression(sf->outChMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0); 574 if (sf->recChMask) { 575 psFitsSetCompression(sf->recChMask->fits, PS_FITS_COMPRESS_PLIO, sf->tiles, 8, 0, 0); 576 } 577 } 527 578 #endif 579 } 528 580 } 529 581 530 582 if (sf->inWeight) { 531 readImage(sf->inWeight, sf->extnum, sf->stage );583 readImage(sf->inWeight, sf->extnum, sf->stage, false); 532 584 sf->outWeight->header = (psMetadata*) psMemIncrRefCounter(sf->inWeight->header); 533 585 if (sf->recWeight) { … … 661 713 excisePixel(streakFiles *sfiles, unsigned int x, unsigned int y, bool streak, double newMaskValue) 662 714 { 715 double exciseValue = sfiles->inImage->exciseValue; 716 663 717 // we clip so that the streak calculation code doesn't have to 664 718 if ((x < 0) || (x >= sfiles->inImage->numCols) || (y < 0) || (y >= sfiles->inImage->numRows)) { … … 667 721 668 722 double imageValue = psImageGet (sfiles->inImage->image, x, y); 669 if (sfiles->recImage && !is nan(imageValue) ) {723 if (sfiles->recImage && !isExciseValue(imageValue, sfiles->inImage->exciseValue) ) { 670 724 psImageSet (sfiles->recImage->image, x, y, imageValue); 671 725 } 672 726 673 727 if (sfiles->transparentStreaks == 0) { 674 psImageSet (sfiles->outImage->image, x, y, NAN);728 psImageSet (sfiles->outImage->image, x, y, exciseValue); 675 729 } else { 676 730 if (streak) { … … 678 732 psImageSet (sfiles->outImage->image, x, y, imageValue + sfiles->transparentStreaks); 679 733 } else { 680 psImageSet (sfiles->outImage->image, x, y, NAN);681 } 682 } 683 684 if (sfiles-> inWeight) {734 psImageSet (sfiles->outImage->image, x, y, exciseValue); 735 } 736 } 737 738 if (sfiles->outWeight) { 685 739 if (sfiles->recWeight) { 686 740 double weightValue = psImageGet (sfiles->inWeight->image, x, y); 687 741 psImageSet (sfiles->recWeight->image, x, y, weightValue); 688 742 } 743 // Assume that weight images are always a floating point type 689 744 psImageSet (sfiles->outWeight->image, x, y, NAN); 690 745 } 691 if (sfiles-> inMask) {746 if (sfiles->outMask) { 692 747 if (sfiles->recMask) { 693 748 double maskValue = psImageGet (sfiles->inMask->image, x, y); … … 705 760 int xParity = sfiles->astrom->xParity; 706 761 int yParity = sfiles->astrom->yParity; 707 int numCols = sfiles->inImage->numCols; 708 int numRows = sfiles->inImage->numRows; 762 int numCols = sfiles->inImage->numCols; // for raw images this was calculated from the width of datasec 763 int numRows = sfiles->inImage->numRows; // for raw images this was calculated from the height of datasec 709 764 710 765 // printf("%2d x0: %4d y0: %4d xpar: %d ypar: %d\n", sfiles->extnum, cell_x0, cell_y0, xParity, yParity); 711 766 767 // XXX: in the case of raw images we are making an implicit assumption here 768 // that the DATASEC begins at (x, y) = (0, 0) in the array for this image 769 // While this is true for GPC1 it isn't necessarily true 712 770 for (int yCell = 0; yCell < numRows; yCell++) { 713 771 int yChip; … … 751 809 752 810 // we clip so that the streak calculation code doesn't have to 811 // clipping here insures that we don't touch the overscan regions 753 812 if ((cellCoord->x < 0) || (cellCoord->x >= sfiles->inImage->numCols) || 754 813 (cellCoord->y < 0) || (cellCoord->y >= sfiles->inImage->numRows)) { … … 756 815 } 757 816 758 cellToChip(&chipCoord, sfiles->astrom, cellCoord); 759 760 #ifdef notdef 761 // Shouldn't need this but for raw images I'm getting 762 // x = warpedPixels->numCols for cell xy70 when cell.x = 0 763 // Perhaps cell_x0 should be IMNPIX-1 since IMNPIX is in the 1 based system of the fits 764 // headers 817 cellToChipInt(&chipCoord.x, &chipCoord.y, sfiles->astrom, cellCoord->x, cellCoord->y); 818 765 819 if (chipCoord.x < 0 || chipCoord.x >= sfiles->warpedPixels->numCols) { 766 820 return false; … … 769 823 return false; 770 824 } 771 #endif772 825 773 826 return psImageGet(sfiles->warpedPixels, chipCoord.x, chipCoord.y) ? true : false; -
trunk/magic/remove/src/streaksremove.h
r21085 r21156 26 26 psArray *imagecube; 27 27 pmFPAfile *pmfile; 28 int numCols; 29 int numRows; 28 int col0; 29 int numCols; // number of columns in data section of image (doesn't include bias section) 30 int xParity; 31 int row0; 32 int numRows; // number of rows in data section of image (does not include bias section) 33 int yParity; 34 double exciseValue; 30 35 } sFile; 31 36 … … 75 80 int numCols, int numRows); 76 81 // can't declare this in streaksastrom due to header file ordering 77 extern void cellToChip(PixelPos *chip, strkAstrom *astrom, PixelPos *cell); 82 extern void cellToChip(double *xChip, double *yChip, strkAstrom *astrom, double xCell, double yCell); 83 extern void cellToChipInt(int *xChip, int *yChip, strkAstrom *astrom, int xCell, int yCell); 78 84 79 85 extern bool computeWarpedPixels(streakFiles *sf); -
trunk/magic/remove/src/streaksreplace.c
r20816 r21156 327 327 } else { 328 328 // image data directly from psFits 329 readImage(sf->inImage, sf->extnum, sf->stage );329 readImage(sf->inImage, sf->extnum, sf->stage, false); 330 330 } 331 331 // read the recovery pixels 332 readImage(sf->recImage, sf->extnum, sf->stage );332 readImage(sf->recImage, sf->extnum, sf->stage, false); 333 333 334 334 sf->outImage->header = (psMetadata*) psMemIncrRefCounter(sf->inImage->header); … … 359 359 #endif 360 360 if (sf->inMask) { 361 readImage(sf->inMask, sf->extnum, sf->stage );362 readImage(sf->recMask, sf->extnum, sf->stage );361 readImage(sf->inMask, sf->extnum, sf->stage, true); 362 readImage(sf->recMask, sf->extnum, sf->stage, true); 363 363 sf->outMask->header = (psMetadata*) psMemIncrRefCounter(sf->inMask->header); 364 364 … … 372 372 373 373 if (sf->inWeight) { 374 readImage(sf->inWeight, sf->extnum, sf->stage );375 readImage(sf->recWeight, sf->extnum, sf->stage );374 readImage(sf->inWeight, sf->extnum, sf->stage, false); 375 readImage(sf->recWeight, sf->extnum, sf->stage, false); 376 376 377 377 sf->outWeight->header = (psMetadata*) psMemIncrRefCounter(sf->inWeight->header); -
trunk/magic/remove/src/warpedpixels.c
r20816 r21156 41 41 // write out the warped pixels 42 42 psMetadata * header = psMetadataAlloc(); 43 pmAstromWriteWCS(header, sf->inAstrom->fpa, sf->chip, 0.001); 43 if (sf->inAstrom->fpa->toSky->type != PS_PROJ_DIS) { 44 pmAstromWriteWCS(header, sf->inAstrom->fpa, sf->chip, 0.001); 45 } 44 46 psFits *fits = psFitsOpen("warpedpixels.fits", "w"); 45 47 … … 76 78 sf->astrom = streakSetAstrometry(sf->astrom, sf->stage, sf->inAstrom->fpa, sf->chip, false, NULL, 77 79 sf->warpedPixels->numCols, sf->warpedPixels->numRows); 78 79 80 80 81 // convert corners of skycell to sky coordinates
Note:
See TracChangeset
for help on using the changeset viewer.
