Changeset 31621
- Timestamp:
- Jun 13, 2011, 3:52:49 PM (15 years ago)
- Location:
- branches/czw_branch/20110406
- Files:
-
- 3 edited
-
ippconfig/recipes/fitstypes.mdc (modified) (1 diff)
-
psLib/src/fits/psFitsImage.c (modified) (4 diffs)
-
psLib/src/fits/psFitsScale.c (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20110406/ippconfig/recipes/fitstypes.mdc
r31618 r31621 101 101 COMP_STACK METADATA 102 102 BITPIX S32 16 103 SCALING STR ASINH_STDEV_POSITIVE 104 STDEV.BITS S32 4 105 STDEV.NUM F32 10 103 SCALING STR ASINH_RANGE 104 # SCALING STR LOG_RANGE 105 # STDEV.BITS S32 4 106 # STDEV.NUM F32 100 106 107 COMPRESSION STR RICE 107 108 TILE.X S32 0 -
branches/czw_branch/20110406/psLib/src/fits/psFitsImage.c
r31618 r31621 164 164 else if (isfinite(bsoften)) { 165 165 info->is_asinh = true; 166 info->is_logscaled = false; 166 167 } 167 168 else { … … 510 511 } 511 512 else if (info->is_asinh) { 512 double bsoften ;513 double bsoften,boffset; 513 514 int status; 514 515 status = 0; 515 516 fits_read_key_dbl(fits->fd, "BSOFTEN", &bsoften, NULL, &status); 516 psImage *newImage = psFitsScaleFromDisk(outImage,0.0,bsoften); 517 fits_read_key_dbl(fits->fd, "BOFFSET", &boffset, NULL, &status); 518 psImage *newImage = psFitsScaleFromDisk(outImage,boffset,bsoften); 517 519 psFree (outImage); 518 520 outImage = newImage; … … 724 726 if (options&&(!((options->scaling == PS_FITS_SCALE_LOG_RANGE)|| 725 727 (options->scaling == PS_FITS_SCALE_LOG_MANUAL)|| 726 (options->scaling == PS_FITS_SCALE_LOG_STDEV_POSITIVE)|| 727 (options->scaling == PS_FITS_SCALE_LOG_STDEV_NEGATIVE)|| 728 (options->scaling == PS_FITS_SCALE_LOG_STDEV_BOTH)))) { 728 (options->scaling == PS_FITS_SCALE_LOG_STDEV_POSITIVE)|| 729 (options->scaling == PS_FITS_SCALE_LOG_STDEV_NEGATIVE)|| 730 (options->scaling == PS_FITS_SCALE_LOG_STDEV_BOTH)|| 731 (options->scaling == PS_FITS_SCALE_ASINH_RANGE)|| 732 (options->scaling == PS_FITS_SCALE_ASINH_MANUAL)|| 733 (options->scaling == PS_FITS_SCALE_ASINH_STDEV_POSITIVE)|| 734 (options->scaling == PS_FITS_SCALE_ASINH_STDEV_NEGATIVE)|| 735 (options->scaling == PS_FITS_SCALE_ASINH_STDEV_BOTH)))) { 729 736 if (psMetadataLookup(header,"BOFFSET")) { 730 737 psMetadataRemoveKey(header,"BOFFSET"); 738 } 739 } 740 // Remove any BSOFTENvalues that exist in the header if we are not using that scaling anymore 741 if (options&&(!((options->scaling == PS_FITS_SCALE_ASINH_RANGE)|| 742 (options->scaling == PS_FITS_SCALE_ASINH_MANUAL)|| 743 (options->scaling == PS_FITS_SCALE_ASINH_STDEV_POSITIVE)|| 744 (options->scaling == PS_FITS_SCALE_ASINH_STDEV_NEGATIVE)|| 745 (options->scaling == PS_FITS_SCALE_ASINH_STDEV_BOTH)))) { 746 if (psMetadataLookup(header,"BSOFTEN")) { 747 psMetadataRemoveKey(header,"BSOFTEN"); 731 748 } 732 749 } … … 757 774 "Scaling: TRUE = BZERO + BSCALE * 10**(DISK) + BOFFSET)", &status); 758 775 } 776 if (options&&(((options->scaling == PS_FITS_SCALE_ASINH_RANGE)|| 777 (options->scaling == PS_FITS_SCALE_ASINH_MANUAL)|| 778 (options->scaling == PS_FITS_SCALE_ASINH_STDEV_POSITIVE)|| 779 (options->scaling == PS_FITS_SCALE_ASINH_STDEV_NEGATIVE)|| 780 (options->scaling == PS_FITS_SCALE_ASINH_STDEV_BOTH)))) { 781 fits_write_key_dbl(fits->fd, "BOFFSET", boffset, 12, 782 "Scaling: NORM = DISK + BOFFSET", &status); 783 fits_write_key_dbl(fits->fd, "BSOFTEN", bsoften, 12, 784 "Scaling: TRUE = 2 * BSOFTEN * sinh(NORM/a)",&status); 785 786 787 } 788 759 789 if (psFitsError(status, true, "Could not write BSCALE/BZERO headers to file.")) { 760 790 success = false; -
branches/czw_branch/20110406/psLib/src/fits/psFitsScale.c
r31618 r31621 214 214 case PS_FITS_SCALE_STDEV_POSITIVE: 215 215 case PS_FITS_SCALE_LOG_STDEV_POSITIVE: 216 case PS_FITS_SCALE_ASINH_STDEV_POSITIVE: 216 217 // Put (mean - N sigma) at the lowest possible value: predominantly positive images 217 218 imageVal = mean - options->stdevNum * stdev; … … 220 221 case PS_FITS_SCALE_STDEV_NEGATIVE: 221 222 case PS_FITS_SCALE_LOG_STDEV_NEGATIVE: 223 case PS_FITS_SCALE_ASINH_STDEV_NEGATIVE: 222 224 // Put (mean + N sigma) at the highest possible value: predominantly negative images 223 225 imageVal = mean + options->stdevNum * stdev; … … 226 228 case PS_FITS_SCALE_STDEV_BOTH: 227 229 case PS_FITS_SCALE_LOG_STDEV_BOTH: 230 case PS_FITS_SCALE_ASINH_STDEV_BOTH: 228 231 // Put mean right in the middle: images with an equal abundance of positive and negative values 229 232 imageVal = mean; … … 460 463 static bool asinhStdev(double *bscale, // Scaling, to return 461 464 double *bzero, // Zero point, to return 465 double *boffset, // asinh flux zeropoint, to return 462 466 double *bsoften, // asinh softening parameter, to return 463 467 const psImage *image, // Image to scale … … 469 473 psAssert(bscale, "impossible"); 470 474 psAssert(bzero, "impossible"); 475 psAssert(boffset, "impossible"); 471 476 psAssert(bsoften, "impossible"); 472 477 psAssert(image, "impossible"); … … 578 583 float a = 1.0857362; // 2.5 * log(e); 579 584 *bsoften = sqrt(a) * stdev; 585 *boffset = mean; 580 586 // float m0 = 0; // Can I just arbitrarily set this? 581 587 … … 584 590 for (int y = 0; y < numRows; y++) { 585 591 for (int x = 0; x < numCols; x++) { 586 /* if (x == 2331 && y == 2843) { */ 587 /* fprintf(stderr,"psFS32: %d %d %g %g %g\n",x,y,offset,image->data.F32[y][x],log10(image->data.F32[y][x] - offset)); */ 592 /* if (x == 266 && y == 4584) { */ 593 /* fprintf(stderr,"psFS32: %d %d %g %g %g %g %g\n",x,y,*boffset,*bsoften,image->data.F32[y][x],log10(image->data.F32[y][x] - *boffset), */ 594 /* a * asinh((image->data.F32[y][x] - *boffset) / (2 * *bsoften))); */ 588 595 /* } */ 589 copy->data.F32[y][x] = -1.0 * a * asinh( image->data.F32[y][x] / (2 * *bsoften));// - 2.5 * log10(b) + m0; 596 if (isfinite(image->data.F32[y][x])) { 597 copy->data.F32[y][x] = a * asinh( (image->data.F32[y][x] - *boffset) / (2 * *bsoften));// - 2.5 * log10(b) + m0; 598 } 599 else { 600 copy->data.F32[y][x] = image->data.F32[y][x]; 601 } 590 602 } 591 603 } … … 595 607 for (int x = 0; x < numCols; x++) { 596 608 // fprintf(stderr,"psFS64: %d %d %g %g %g\n",x,y,offset,image->data.F64[y][x],log10(image->data.F64[y][x] - offset)); 597 copy->data.F32[y][x] = -1.0 * a * asinh( image->data.F32[y][x] / (2 * *bsoften));// - 2.5 * log10(b) + m0; 609 if (isfinite(image->data.F64[y][x])) { 610 copy->data.F64[y][x] = a * asinh( (image->data.F64[y][x] - *boffset) / (2 * *bsoften));// - 2.5 * log10(b) + m0; 611 } 612 else { 613 copy->data.F64[y][x] = image->data.F64[y][x]; 614 } 598 615 } 599 616 } … … 616 633 static bool asinhRange(double *bscale, // Scaling, to return 617 634 double *bzero, // Zero point, to return 635 double *boffset, // asinh flux zeropoint, to return 618 636 double *bsoften, // asinh softening parameter, to return 619 637 const psImage *image, // Image to scale … … 734 752 float a = 1.0857362; // 2.5 * log(e); 735 753 *bsoften = sqrt(a) * stdev; 754 *boffset = mean; 736 755 // float m0 = 0; // Can I just arbitrarily set this? 737 756 … … 743 762 /* fprintf(stderr,"psFS32: %d %d %g %g %g\n",x,y,offset,image->data.F32[y][x],log10(image->data.F32[y][x] - offset)); */ 744 763 /* } */ 745 copy->data.F32[y][x] = -1.0 * a * asinh( image->data.F32[y][x] / (2 * *bsoften));// - 2.5 * log10(b) + m0; 764 /* if (x == 266 && y == 4584) { */ 765 /* fprintf(stderr,"psFS32: %d %d %g %g %g %g %g\n",x,y,*boffset,*bsoften,image->data.F32[y][x],log10(image->data.F32[y][x] - *boffset), */ 766 /* a * asinh((image->data.F32[y][x] - *boffset) / (2 * *bsoften))); */ 767 /* } */ 768 769 if (isfinite(image->data.F32[y][x])) { 770 copy->data.F32[y][x] = a * asinh( (image->data.F32[y][x] - *boffset) / (2 * *bsoften));// - 2.5 * log10(b) + m0; 771 } 772 else { 773 copy->data.F32[y][x] = image->data.F32[y][x]; 774 } 746 775 } 747 776 } … … 751 780 for (int x = 0; x < numCols; x++) { 752 781 // fprintf(stderr,"psFS64: %d %d %g %g %g\n",x,y,offset,image->data.F64[y][x],log10(image->data.F64[y][x] - offset)); 753 copy->data.F32[y][x] = -1.0 * a * asinh( image->data.F32[y][x] / (2 * *bsoften));// - 2.5 * log10(b) + m0; 782 if (isfinite(image->data.F64[y][x])) { 783 copy->data.F64[y][x] = a * asinh( (image->data.F64[y][x] - *boffset)/ (2 * *bsoften));// - 2.5 * log10(b) + m0; 784 } 785 else { 786 copy->data.F64[y][x] = image->data.F32[y][x]; 787 } 754 788 } 755 789 } … … 761 795 } 762 796 763 // Do regular scaling on the logarithmimage797 // Do regular scaling on the asinh image 764 798 if (!scaleRange(bscale, bzero, copy, options)) { 765 799 psError(PS_ERR_UNKNOWN, false, "Unable to set BSCALE and BZERO from stdev"); … … 851 885 break; 852 886 case PS_FITS_SCALE_ASINH_RANGE: 853 if (!asinhRange(bscale,bzero,b soften,image,mask,maskVal,options)) {887 if (!asinhRange(bscale,bzero,boffset,bsoften,image,mask,maskVal,options)) { 854 888 psError(PS_ERR_UNKNOWN, false, "Unable to set BSCALE and BZERO from range"); 855 889 return false; … … 859 893 case PS_FITS_SCALE_ASINH_STDEV_NEGATIVE: 860 894 case PS_FITS_SCALE_ASINH_STDEV_BOTH: 861 if (!asinhStdev(bscale, bzero,b soften, image, mask, maskVal, options)) {895 if (!asinhStdev(bscale, bzero,boffset,bsoften, image, mask, maskVal, options)) { 862 896 psError(PS_ERR_UNKNOWN, false, "Unable to set BSCALE and BZERO from stdev"); 863 897 return false; … … 888 922 889 923 890 psTrace("psLib.fits", 3, "BSCALE = %.10lf, BZERO = %.10lf, BOFFSET = %.10lf, B LANK = %ld\n",891 *bscale, *bzero, *boffset, *b lank);924 psTrace("psLib.fits", 3, "BSCALE = %.10lf, BZERO = %.10lf, BOFFSET = %.10lf, BSOFTEN = %.10lf, BLANK = %ld\n", 925 *bscale, *bzero, *boffset, *bsoften, *blank); 892 926 return true; 893 927 } … … 956 990 (options->scaling == PS_FITS_SCALE_LOG_STDEV_NEGATIVE)|| \ 957 991 (options->scaling == PS_FITS_SCALE_LOG_STDEV_BOTH)) { \ 958 value = log10( (IN)->data.INTYPE[y][x] - boffset ); \ 992 if (isfinite((IN)->data.INTYPE[y][x])) { \ 993 value = log10( (IN)->data.INTYPE[y][x] - boffset ); \ 994 } \ 995 else { \ 996 value = (IN)->data.INTYPE[y][x]; \ 997 } \ 959 998 } \ 960 999 else if ((options->scaling == PS_FITS_SCALE_ASINH_RANGE)|| \ … … 963 1002 (options->scaling == PS_FITS_SCALE_ASINH_STDEV_NEGATIVE)|| \ 964 1003 (options->scaling == PS_FITS_SCALE_ASINH_STDEV_BOTH)) { \ 965 value = -1.0 * 1.0857362 * (asinh( (IN)->data.INTYPE[y][x] - bsoften)); \ 1004 if (isfinite((IN)->data.INTYPE[y][x])) { \ 1005 value = 1.0857362 * (asinh( ((IN)->data.INTYPE[y][x] - boffset) / (2.0 * bsoften))); \ 1006 } \ 1007 else { \ 1008 value = (IN)->data.INTYPE[y][x]; \ 1009 } \ 1010 if ((x == 1000)&&(y == 1000)) { \ 1011 fprintf(stderr,"ASINH: %f %f %f", \ 1012 (IN)->data.INTYPE[y][x],value,bsoften); \ 1013 } \ 966 1014 } \ 967 1015 else { \ … … 1056 1104 for (int y = 0; y < numRows; y++) { \ 1057 1105 for (int x = 0; x < numCols; x++) { \ 1058 if (boffset) { \ 1106 if (bsoften) { \ 1107 out->data.OUTTYPE[y][x] = 2 * bsoften * sinh(image->data.INTYPE[y][x] / (1.0857362)) + boffset; \ 1108 } \ 1109 else if (boffset) { \ 1059 1110 out->data.OUTTYPE[y][x] = pow(10,image->data.INTYPE[y][x]) + boffset;; \ 1060 1111 } \ 1061 else if (bsoften) { \1062 out->data.OUTTYPE[y][x] = sinh(image->data.INTYPE[y][x] * 2 * bsoften) / (-1.0 * 1.0857362);; \1063 } \1064 1112 } \ 1065 1113 } \
Note:
See TracChangeset
for help on using the changeset viewer.
