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