- Timestamp:
- Jun 21, 2011, 6:44:31 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110505/psLib/src/fits/psFitsImage.c
r31608 r31656 55 55 int psDatatype; // psLib data type 56 56 bool is_logscaled; // is this image log scaled using BOFFSET? 57 bool is_asinh; // is this image asinh scaled using BSOFTEN? 57 58 } p_psFitsReadInfo; 58 59 … … 129 130 130 131 // Check scale and zero 131 double bscale = 0.0, bzero = 0.0, boffset = NAN ; // Scale and zero point132 double bscale = 0.0, bzero = 0.0, boffset = NAN, bsoften = NAN; // Scale and zero point 132 133 if (fits_read_key_dbl(fits->fd, "BSCALE", &bscale, NULL, &status) && status != KEY_NO_EXIST) { 133 134 psFitsError(status, true, "Unable to read header."); … … 153 154 info->is_logscaled = false; 154 155 } 156 status = 0; 157 if (fits_read_key_dbl(fits->fd, "BSOFTEN", &bsoften, NULL, &status) && status != KEY_NO_EXIST) { 158 psFitsError(status, true, "Unable to read header."); 159 goto bad; 160 } 161 if (status == KEY_NO_EXIST) { 162 info->is_asinh = false; 163 } 164 else if (isfinite(bsoften)) { 165 info->is_asinh = true; 166 info->is_logscaled = false; 167 } 168 else { 169 info->is_asinh = false; 170 } 171 155 172 status = 0; 156 173 … … 262 279 double *bzero, // Zero point applied 263 280 double *boffset, // Log offset applied 281 double *bsoften, // asinh offset applied 264 282 long *blank, // Blank value (integer data) 265 283 psFitsFloat *floatType, // Type of custom floating-point … … 275 293 psAssert(bzero, "impossible"); 276 294 psAssert(boffset, "impossible"); 295 psAssert(bsoften, "impossible"); 277 296 psAssert(floatType, "impossible"); 278 297 psAssert(fits, "impossible"); … … 322 341 if (newScaleZero) { 323 342 // Choose an appropriate BSCALE and BZERO 324 if (!psFitsScaleDetermine(bscale, bzero, boffset, b lank, image, mask, maskVal, fits)) {343 if (!psFitsScaleDetermine(bscale, bzero, boffset, bsoften, blank, image, mask, maskVal, fits)) { 325 344 // We can't have the write dying for this reason --- try to save it somehow! 326 345 psWarning("Unable to determine BSCALE and BZERO for image --- refusing to quantise."); … … 348 367 } 349 368 350 return psFitsScaleForDisk(image, fits, *bscale, *bzero, *boffset, rng);369 return psFitsScaleForDisk(image, fits, *bscale, *bzero, *boffset, *bsoften, rng); 351 370 } 352 371 … … 480 499 outImage = psFitsFloatImageFromDisk(outImage, inImage, floatType); 481 500 } 482 483 501 // Need to apply BOFFSET if info->is_logscaled is true 502 484 503 if (info->is_logscaled) { 485 504 double boffset; … … 487 506 status = 0; 488 507 fits_read_key_dbl(fits->fd, "BOFFSET", &boffset, NULL, &status); 489 psImage *newImage = psFitsScaleFromDisk(outImage,boffset); 508 psImage *newImage = psFitsScaleFromDisk(outImage,boffset,0.0); 509 psFree (outImage); 510 outImage = newImage; 511 } 512 else if (info->is_asinh) { 513 double bsoften,boffset; 514 int status; 515 status = 0; 516 fits_read_key_dbl(fits->fd, "BSOFTEN", &bsoften, NULL, &status); 517 fits_read_key_dbl(fits->fd, "BOFFSET", &boffset, NULL, &status); 518 psImage *newImage = psFitsScaleFromDisk(outImage,boffset,bsoften); 490 519 psFree (outImage); 491 520 outImage = newImage; … … 602 631 double bscale = NAN, bzero = NAN; // Scale and zero point to put in header 603 632 double boffset = NAN; // Log offset to put into header. 633 double bsoften = NAN; // Asinh softening parameter to put into header 604 634 long blank = 0; // Blank (undefined) value for image 605 635 psFitsFloat floatType; // Custom floating-point convention type 606 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &boffset, &b lank, &floatType, fits, image,636 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &boffset, &bsoften, &blank, &floatType, fits, image, 607 637 mask, maskVal, NULL, true); // Image to write out 608 638 if (!diskImage) { … … 696 726 if (options&&(!((options->scaling == PS_FITS_SCALE_LOG_RANGE)|| 697 727 (options->scaling == PS_FITS_SCALE_LOG_MANUAL)|| 698 (options->scaling == PS_FITS_SCALE_LOG_STDEV_POSITIVE)|| 699 (options->scaling == PS_FITS_SCALE_LOG_STDEV_NEGATIVE)|| 700 (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)))) { 701 736 if (psMetadataLookup(header,"BOFFSET")) { 702 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"); 703 748 } 704 749 } … … 727 772 (options->scaling == PS_FITS_SCALE_LOG_STDEV_BOTH)))) { 728 773 fits_write_key_dbl(fits->fd, "BOFFSET", boffset, 12, 729 "Scaling: TRUE = BZERO + BSCALE * 10**(DISK) + BOFFSET)", &status);774 "Scaling: ORIGINAL = 10**(TRUE) + BOFFSET)", &status); 730 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 731 789 if (psFitsError(status, true, "Could not write BSCALE/BZERO headers to file.")) { 732 790 success = false; … … 831 889 double bscale = NAN, bzero = NAN; // Scale and zero point to put in header 832 890 double boffset = NAN; // Log offset to put in header 891 double bsoften = NAN; // Asinh softening parameter to put in header 833 892 long blank = 0; // Blank (undefined) value for image 834 893 psFitsFloat floatType; // Custom floating-point convention type 835 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &boffset, &b lank, &floatType, fits, input,894 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &boffset, &bsoften, &blank, &floatType, fits, input, 836 895 mask, maskVal, NULL, false); // Image to write out 837 896 if (!diskImage) {
Note:
See TracChangeset
for help on using the changeset viewer.
