Changeset 21156 for trunk/magic/remove/src/streaksremove.c
- Timestamp:
- Jan 23, 2009, 3:05:43 PM (17 years ago)
- Location:
- trunk/magic/remove/src
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
streaksremove.c (modified) (18 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/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;
Note:
See TracChangeset
for help on using the changeset viewer.
